├── AUTHORS ├── THANKS ├── TODO ├── NEWS ├── output_range.h ├── output_json.h ├── fitscut.spec ├── fitscut.spec.in ├── blurb.h ├── INSTALL_SOLARIS ├── output_graphic.h ├── revision.h ├── output_fits.h ├── file_check.h ├── colormap.h ├── histogram.h ├── util.h ├── draw.h ├── INSTALL_OSX ├── INSTALL_WITH_SCISOFT ├── image_scale.h ├── resize.h ├── wcs_align.h ├── INSTALL_HLAWEB ├── README.md ├── extract.h ├── mkinstalldirs ├── config.h.in ├── blurb.c ├── output_json.c ├── output_range.c ├── Makefile.am ├── configure.in ├── ChangeLog ├── getopt.h ├── getopt1.c ├── util.c ├── histogram.c ├── install-sh ├── colormap.c ├── INSTALL ├── fitscut.h ├── tailor.h ├── resize.c ├── file_check.c ├── missing ├── depcomp ├── wcs_align.c ├── output_fits.c ├── draw.c └── COPYING /AUTHORS: -------------------------------------------------------------------------------- 1 | William Jon McCann 2 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | Thanks to the authors of gzip and GIMP. -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Things to do 2 | 3 | * Fix leaks 4 | * Clean up verbose messages 5 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | fitscut 1.4.2 2 | ============= 3 | 4 | * Fix error checking of input files. 5 | * Allow specifying symbolic links as input files. 6 | 7 | fitscut 1.4.1 8 | ============= 9 | 10 | This version only includes changes to the packaging and build 11 | system. 12 | * include .spec file for generating RPMSs 13 | * look for fitsio.h with cfitsio prefix and without. 14 | 15 | fitscut 1.4.0 16 | ============= 17 | 18 | This is the first version to be released with a GPL license. New 19 | features include: 20 | 21 | * asinh scaling 22 | * autoscale-{min,max} options 23 | * ability to explicitly request linear scaling 24 | * GPL license 25 | * Improved --help text 26 | * Improved verbose messages 27 | -------------------------------------------------------------------------------- /output_range.h: -------------------------------------------------------------------------------- 1 | /* declarations for write_range.c 2 | * 3 | * This program is free software; you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation; either version 2 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software 15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 | */ 17 | 18 | int write_range(FitsCutImage *); 19 | -------------------------------------------------------------------------------- /output_json.h: -------------------------------------------------------------------------------- 1 | /* declarations for write_to_json.c 2 | * 3 | * This program is free software; you can redistribute it and/or modify 4 | * it under the terms of the GNU General Public License as published by 5 | * the Free Software Foundation; either version 2 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * This program is distributed in the hope that it will be useful, 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | * GNU General Public License for more details. 12 | * 13 | * You should have received a copy of the GNU General Public License 14 | * along with this program; if not, write to the Free Software 15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 | */ 17 | 18 | int write_to_json(FitsCutImage *); 19 | -------------------------------------------------------------------------------- /fitscut.spec: -------------------------------------------------------------------------------- 1 | Summary: A tool for making cutouts and color images from FITS files 2 | Name: fitscut 3 | Version: 1.4.2 4 | Release: 1 5 | License: GPL 6 | Group: Applications/Multimedia 7 | Source: fitscut-%{version}.tar.gz 8 | Buildroot: %{_tmppath}/%{name}-%{version}-root 9 | BuildPrereq: libjpeg-devel, libpng-devel, cfitsio-devel 10 | 11 | %description 12 | 13 | %prep 14 | %setup -q 15 | 16 | %build 17 | %configure 18 | 19 | make \ 20 | CC=%{__cc} \ 21 | CFLAGS="$RPM_OPT_FLAGS" 22 | 23 | %install 24 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 25 | 26 | mkdir -p $RPM_BUILD_ROOT 27 | make 28 | 29 | mkdir -p $RPM_BUILD_ROOT%{_bindir} 30 | 31 | %makeinstall 32 | 33 | %clean 34 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 35 | 36 | %files 37 | %defattr(-,root,root) 38 | %{_bindir}/* 39 | 40 | %changelog 41 | * Tue May 11 2004 William Jon McCann 42 | - Initial version 43 | -------------------------------------------------------------------------------- /fitscut.spec.in: -------------------------------------------------------------------------------- 1 | Summary: A tool for making cutouts and color images from FITS files 2 | Name: fitscut 3 | Version: @VERSION@ 4 | Release: 1 5 | License: GPL 6 | Group: Applications/Multimedia 7 | Source: fitscut-%{version}.tar.gz 8 | Buildroot: %{_tmppath}/%{name}-%{version}-root 9 | BuildPrereq: libjpeg-devel, libpng-devel, cfitsio-devel 10 | 11 | %description 12 | 13 | %prep 14 | %setup -q 15 | 16 | %build 17 | %configure 18 | 19 | make \ 20 | CC=%{__cc} \ 21 | CFLAGS="$RPM_OPT_FLAGS" 22 | 23 | %install 24 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 25 | 26 | mkdir -p $RPM_BUILD_ROOT 27 | make 28 | 29 | mkdir -p $RPM_BUILD_ROOT%{_bindir} 30 | 31 | %makeinstall 32 | 33 | %clean 34 | [ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 35 | 36 | %files 37 | %defattr(-,root,root) 38 | %{_bindir}/* 39 | 40 | %changelog 41 | * Tue May 11 2004 William Jon McCann 42 | - Initial version 43 | -------------------------------------------------------------------------------- /blurb.h: -------------------------------------------------------------------------------- 1 | /* declarations for blurb.c 2 | * 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * 19 | */ 20 | 21 | #define BLURB_BUFFER_INIT 2048 22 | 23 | void blurb_error (char *); 24 | char *blurb_read (char *); 25 | -------------------------------------------------------------------------------- /INSTALL_SOLARIS: -------------------------------------------------------------------------------- 1 | Rick White -- Mon Jun 12 16:39:58 EDT 2006 2 | 3 | To install using the routines under Solaris (working on archdev at 4 | the moment), do this: 5 | 6 | setenv CFLAGS "-I/usr/local/gnome-1.4/include -I/usr/local/include" 7 | setenv CPPFLAGS "-I/usr/local/gnome-1.4/include -I/usr/local/include" 8 | setenv LDFLAGS "-L/usr/local/gnome-1.4/lib -L/usr/local/lib" 9 | ./configure --prefix=/home/rlw 10 | make install 11 | 12 | This ought to install fitscut in the /home/rlw/bin directory... 13 | 14 | I'm omitting the wcstools libraries at the moment. They are supposed to 15 | be optional and I didn't find them in a quick search. 16 | 17 | # setenv CFLAGS "-I/usr/local/include -I/usr/local/wcstools" 18 | # setenv CPPFLAGS "-I/usr/local/include -I/usr/local/wcstools" 19 | # setenv LDFLAGS "-L/usr/local/lib -L/usr/local/wcstools/libwcs" 20 | 21 | I have not figured out where these libraries might be on stdatu. This 22 | works on archdev. 23 | -------------------------------------------------------------------------------- /output_graphic.h: -------------------------------------------------------------------------------- 1 | /* declarations for output_graphic.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | */ 18 | 19 | int write_to_jpg (FitsCutImage *); 20 | int write_to_png (FitsCutImage *); 21 | 22 | -------------------------------------------------------------------------------- /revision.h: -------------------------------------------------------------------------------- 1 | /* revision.h 2 | * Copyright (C) 1999 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: revision.h,v 1.30 2004/07/27 22:14:20 mccannwj Exp $ 19 | */ 20 | 21 | #define REVDATE "Tue Jul 27 18:12:34 EDT 2004" 22 | 23 | -------------------------------------------------------------------------------- /output_fits.h: -------------------------------------------------------------------------------- 1 | /* declarations for output_fits.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: output_fits.h,v 1.5 2004/04/21 20:13:10 mccannwj Exp $ 19 | */ 20 | 21 | void write_to_fits (FitsCutImage *); 22 | -------------------------------------------------------------------------------- /file_check.h: -------------------------------------------------------------------------------- 1 | /* declarations for file_check.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: file_check.h,v 1.2 2004/04/21 20:13:09 mccannwj Exp $ 19 | */ 20 | 21 | int check_output_file (char *, char *); 22 | int check_input_file (char *); 23 | int make_output_name (char *, char *); 24 | -------------------------------------------------------------------------------- /colormap.h: -------------------------------------------------------------------------------- 1 | /* declarations for colormap.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: colormap.h,v 1.3 2004/04/21 20:13:09 mccannwj Exp $ 19 | */ 20 | #include 21 | 22 | typedef struct { 23 | float *red; 24 | float *green; 25 | float *blue; 26 | } ColorMap; 27 | 28 | png_color *get_png_palette (int, long); 29 | 30 | -------------------------------------------------------------------------------- /histogram.h: -------------------------------------------------------------------------------- 1 | /* declarations for histogram.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: histogram.h,v 1.3 2004/04/21 20:13:10 mccannwj Exp $ 19 | */ 20 | 21 | float *compute_histogram (float *arrayp, int length, double dmin, double dmax, long npix, float bad_data_value, 22 | long *pixcount, float *inmin, float *inmax); 23 | unsigned char *eq_histogram (float *hist, int length, long npix); 24 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * util.h -- declarations for util.c 4 | * Copyright (C) 2003 William Jon McCann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * 20 | * $Id: util.h,v 1.2 2004/04/21 20:13:10 mccannwj Exp $ 21 | */ 22 | 23 | float *interpolate_points (long,float *,float *,long); 24 | long parse_coordinates (char *, float **, float **); 25 | char *strlwr (char *); 26 | -------------------------------------------------------------------------------- /draw.h: -------------------------------------------------------------------------------- 1 | /* declarations for draw.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: draw.h,v 1.2 2004/04/21 20:13:09 mccannwj Exp $ 19 | */ 20 | 21 | typedef struct { 22 | int x, y; 23 | } drawPoint, *drawPointPtr; 24 | 25 | void draw_wcs_compass (FitsCutImage *,float,float); 26 | void draw_center_marker (FitsCutImage *); 27 | void draw_line (FitsCutImage *, int, int, int, int, int, int); 28 | void draw_filled_polygon (FitsCutImage *, int, drawPointPtr, int, int); 29 | -------------------------------------------------------------------------------- /INSTALL_OSX: -------------------------------------------------------------------------------- 1 | Rick White -- Thu Jan 14 23:18:00 EST 2016 2 | 3 | To install into my home bin directory using the anaconda libraries, do this: 4 | 5 | First install the libwcs files in my private directories: 6 | 7 | cd ../libwcs 8 | make 9 | install -d ~/include/libwcs 10 | install *.h ~/include/libwcs 11 | install -d ~/lib 12 | install libwcs.a ~/lib 13 | back 14 | 15 | Then build fitscut: 16 | 17 | setenv CFLAGS "-I /Users/rlw/anaconda/include -I/Users/rlw/include" 18 | setenv CPPFLAGS "-I /Users/rlw/anaconda/include -I/Users/rlw/include" 19 | setenv LDFLAGS "-L/Users/rlw/anaconda/lib -L/Users/rlw/lib" 20 | ./configure --prefix=/Users/rlw 21 | make 22 | make test 23 | make install 24 | 25 | This ought to install fitscut in the ~/bin directory... 26 | 27 | Debug version: (using the ../libwcs version, which is linked with debug on) 28 | 29 | setenv CFLAGS "-g -I.." 30 | setenv CPPFLAGS "-g -I.." 31 | setenv LDFLAGS "-g -L../libwcs" 32 | ./configure --prefix=/Users/rlw 33 | make 34 | make test 35 | make install 36 | 37 | Optimized version: 38 | 39 | setenv CFLAGS "-O3 -I/Users/rlw/include" 40 | setenv CPPFLAGS "-O3 -I/Users/rlw/include" 41 | setenv LDFLAGS "-O3 -L/Users/rlw/lib" 42 | ./configure --prefix=/Users/rlw 43 | make 44 | make test 45 | make install 46 | -------------------------------------------------------------------------------- /INSTALL_WITH_SCISOFT: -------------------------------------------------------------------------------- 1 | Rick White -- Mon Jun 12 16:39:58 EDT 2006 2 | 3 | To install using the routines in scisoft, do this: 4 | 5 | source /Applications/scisoft/all/bin/Setup.csh 6 | setenv CFLAGS "-I${SCISOFT_INCLUDE} -I${SCISOFT_DIR}/Packages/wcstools" 7 | setenv CPPFLAGS "-I${SCISOFT_INCLUDE} -I${SCISOFT_DIR}/Packages/wcstools" 8 | setenv LDFLAGS "-L${SCISOFT_LIB} -L${SCISOFT_DIR}/Packages/wcstools/libwcs" 9 | ./configure --prefix=${SCISOFT_DIR} 10 | make 11 | make test 12 | sudo make install 13 | 14 | This ought to install fitscut in the scisoft bin directory... 15 | 16 | Debug version: 17 | 18 | setenv CFLAGS "-g -I${SCISOFT_INCLUDE} -I${SCISOFT_DIR}/Packages/wcstools" 19 | setenv CPPFLAGS "-g -I${SCISOFT_INCLUDE} -I${SCISOFT_DIR}/Packages/wcstools" 20 | setenv LDFLAGS "-g -L${SCISOFT_LIB} -L${SCISOFT_DIR}/Packages/wcstools/libwcs" 21 | ./configure --prefix=${SCISOFT_DIR} 22 | make 23 | make test 24 | sudo make install 25 | 26 | Optimized version: 27 | 28 | setenv CFLAGS "-O3 -I${SCISOFT_INCLUDE} -I${SCISOFT_DIR}/Packages/wcstools" 29 | setenv CPPFLAGS "-O3 -I${SCISOFT_INCLUDE} -I${SCISOFT_DIR}/Packages/wcstools" 30 | setenv LDFLAGS "-O3 -L${SCISOFT_LIB} -L${SCISOFT_DIR}/Packages/wcstools/libwcs" 31 | ./configure --prefix=${SCISOFT_DIR} 32 | make 33 | make test 34 | sudo make install 35 | -------------------------------------------------------------------------------- /image_scale.h: -------------------------------------------------------------------------------- 1 | /* declarations for image_scale.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: image_scale.h,v 1.9 2004/04/30 18:28:12 mccannwj Exp $ 19 | */ 20 | 21 | void autoscale_image (FitsCutImage *); 22 | void autoscale_channel (FitsCutImage *, int); 23 | void autoscale_full_channel (FitsCutImage *, int); 24 | void histeq_image (FitsCutImage *); 25 | void log_image (FitsCutImage *); 26 | void sqrt_image (FitsCutImage *); 27 | void asinh_image (FitsCutImage *); 28 | void scan_min_max (FitsCutImage *); 29 | void mult_image (FitsCutImage *); 30 | void rate_image (FitsCutImage *); 31 | 32 | double compute_hist_mode (FitsCutImage *Image, int k); 33 | -------------------------------------------------------------------------------- /resize.h: -------------------------------------------------------------------------------- 1 | /* declarations for resize.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: resize.h,v 1.3 2004/04/21 20:13:10 mccannwj Exp $ 19 | */ 20 | 21 | void exact_resize_image_channel (FitsCutImage *, int, int); 22 | void exact_resize_reference (FitsCutImage *, int); 23 | void interpolate_image (FitsCutImage *, FitsCutImage *, int, int); 24 | 25 | void get_zoom_size_channel (int ncols, int nrows, float zoom_factor, int output_size, 26 | int *pixfac, int *zoomcols, int *zoomrows, int *doshrink); 27 | void reduce_array (float *input, float *output, int orig_width, int orig_height, int pixfac, float bad_data_value); 28 | void enlarge_array (float *input, float *output, int orig_width, int orig_height, int pixfac); 29 | -------------------------------------------------------------------------------- /wcs_align.h: -------------------------------------------------------------------------------- 1 | /* declarations for wcs_align.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: wcs_align.h,v 1.4 2004/04/21 20:13:10 mccannwj Exp $ 19 | */ 20 | 21 | void wcs_initialize_channel (FitsCutImage *, int); 22 | 23 | void wcs_initialize (FitsCutImage *); 24 | void wcs_initialize_ref(FitsCutImage *, long *naxes); 25 | void wcs_align_ref (FitsCutImage *); 26 | int wcs_remap_channel (FitsCutImage *, int); 27 | void wcs_update (FitsCutImage *); 28 | int wcs_match_channel (FitsCutImage *, int); 29 | void wcs_update_channel(FitsCutImage *, int); 30 | void wcs_update_ref (FitsCutImage *); 31 | 32 | void wcs_apply_update (struct WorldCoor *, double, double, double, int, int); 33 | struct WorldCoor *wcs_read(char *filename, long *naxes); 34 | -------------------------------------------------------------------------------- /INSTALL_HLAWEB: -------------------------------------------------------------------------------- 1 | Rick White -- Mon Jul 26 13:43:41 EDT 2010 2 | 3 | Installing the routines on hladev (once Niall or Lee has already 4 | built cfitsio). 5 | 6 | Note that it is necessary to build these programs on hladev1 because 7 | hladev2 does not have the necessary jpg and png libraries. On the 8 | other hand, the gdb program exists only on hladev2 for some reason, 9 | so if you need to do debugging then you should run it there. 10 | 11 | First build and install libwcs (in the libwcs/ directory): 12 | 13 | make 14 | install -d /hladev/hladocs/hla/include/libwcs 15 | install *.h /hladev/hladocs/hla/include/libwcs 16 | install libwcs.a /hladev/hladocs/hla/lib 17 | 18 | Configure and install fitscut: 19 | 20 | setenv CFLAGS "-I/hladev/hladocs/hla/include" 21 | setenv CPPFLAGS "-I/hladev/hladocs/hla/include" 22 | setenv LDFLAGS "-L/hladev/hladocs/hla/lib" 23 | ./configure --prefix=/hladev/hladocs/hla 24 | make 25 | make install 26 | 27 | This ought to install fitscut in the /usr/local/hla/bin directory... 28 | 29 | Optimized version: 30 | 31 | setenv CFLAGS "-O3 -I/hladev/hladocs/hla/include" 32 | setenv CPPFLAGS "-O3 -I/hladev/hladocs/hla/include" 33 | setenv LDFLAGS "-O3 -L/hladev/hladocs/hla/lib" 34 | ./configure --prefix=/hladev/hladocs/hla 35 | make 36 | make install 37 | 38 | Debug version: (NOT INSTALLED) 39 | 40 | setenv CFLAGS "-g -I/hladev/hladocs/hla/include" 41 | setenv CPPFLAGS "-g -I/hladev/hladocs/hla/include" 42 | setenv LDFLAGS "-g -L/hladev/hladocs/hla/lib" 43 | ./configure --prefix=/hladev/hladocs/hla 44 | /bin/rm *.o 45 | make 46 | mv fitscut fitscut.debug 47 | /bin/rm *.o 48 | 49 | THEN REBUILD THE NORMAL VERSION (OPTIMIZED OR NOT) 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | General Information 2 | =================== 3 | 4 | fitscut is designed to extract cutouts from FITS image format files. 5 | FITS, PNG, and JPEG output types are supported. 6 | 7 | When multiple input files are specified and the output type is PNG or 8 | JPEG the resulting image is an RGB color image. 9 | 10 | 11 | Information on the FITS file format is available from 12 | http://fits.gsfc.nasa.gov/. 13 | 14 | 15 | A cgi interface to fiscut is avilable here: https://hla.stsci.edu/fitscutcgi_interface.html 16 | 17 | Dependencies 18 | ============ 19 | 20 | In order to build fitscut you will need: 21 | 22 | CFITSIO library 23 | 24 | 25 | LIBPNG 26 | 27 | 28 | JPEG library 29 | 30 | 31 | And optionally: 32 | 33 | WCS Subroutine library 34 | 35 | 36 | 37 | Supported Platforms 38 | =================== 39 | 40 | fitscut has been tested and is known to work on: 41 | 42 | RedHat Linux 8, 9 43 | RedHat Enterprise Linux 3 44 | Fedora Core 1 45 | Solaris 8, 9 46 | 47 | Installation 48 | ============ 49 | 50 | Please see the INSTALL file. 51 | 52 | This usually consists of: 53 | 54 | % gzip -cd fitscut-1.4.0.tar.gz | tar xvf - # unpack the sources 55 | % cd fitscut-1.4.0 # change to the directory 56 | % ./configure # run the 'configure' script 57 | % make # build fitscut 58 | [ Become root if necessary ] 59 | % make install # install fitscut 60 | 61 | 62 | ----- 63 | Copyright (C) 2001 William Jon McCann 64 | 65 | -------------------------------------------------------------------------------- /extract.h: -------------------------------------------------------------------------------- 1 | /* declarations for extract.c 2 | * Copyright (C) 2002 William Jon McCann 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | * 18 | * $Id: extract.h,v 1.6 2004/04/29 22:22:30 mccannwj Exp $ 19 | */ 20 | 21 | void extract_fits (FitsCutImage *); 22 | void printerror (int); 23 | double fits_get_exposure_time (char *, int); 24 | void fits_get_badpix (char *, int, float *, float *, float *); 25 | float *cutout_alloc (unsigned int nx, unsigned int ny, float value); 26 | int ext_exists(fitsfile *fptr, int qext, int *status); 27 | 28 | extern int get_qual_info (fitsfile **dqptr, long *nplanes, float *badmin, float *badmax, float *bad_data_value, 29 | fitsfile *fptr, char *header, int num_cards, 30 | int qext_set, int qext, int useBadpix, int *status); 31 | 32 | extern int apply_qual (fitsfile *dqptr, long nplanes, float badmin, float badmax, float bad_data_value, 33 | long fpixel[7], long lpixel[7], long inc[7], 34 | float *arrayptr, int anynull, int badvalue, 35 | int *status); 36 | 37 | extern int fitscut_read_subset(fitsfile *fptr, int datatype, long *fpixel, long *lpixel, long *inc, 38 | void *nulval, void *array, int *anynul, int *status); 39 | 40 | extern void invert_bsoften (double bsoften, double boffset, long fpixel[7], long lpixel[7], long inc[7], 41 | float *arrayptr, float bad_data_value); 42 | 43 | extern void fits_get_bsoften (FitsCutImage *Image, int k, int *useBsoften, double *bsoften, double *boffset); 44 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Public domain 6 | 7 | errstatus=0 8 | dirmode="" 9 | 10 | usage="\ 11 | Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." 12 | 13 | # process command line arguments 14 | while test $# -gt 0 ; do 15 | case "${1}" in 16 | -h | --help | --h* ) # -h for help 17 | echo "${usage}" 1>&2; exit 0 ;; 18 | -m ) # -m PERM arg 19 | shift 20 | test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; } 21 | dirmode="${1}" 22 | shift ;; 23 | -- ) shift; break ;; # stop option processing 24 | -* ) echo "${usage}" 1>&2; exit 1 ;; # unknown option 25 | * ) break ;; # first non-opt arg 26 | esac 27 | done 28 | 29 | for file 30 | do 31 | if test -d "$file"; then 32 | shift 33 | else 34 | break 35 | fi 36 | done 37 | 38 | case $# in 39 | 0) exit 0 ;; 40 | esac 41 | 42 | case $dirmode in 43 | '') 44 | if mkdir -p -- . 2>/dev/null; then 45 | echo "mkdir -p -- $*" 46 | exec mkdir -p -- "$@" 47 | fi ;; 48 | *) 49 | if mkdir -m "$dirmode" -p -- . 2>/dev/null; then 50 | echo "mkdir -m $dirmode -p -- $*" 51 | exec mkdir -m "$dirmode" -p -- "$@" 52 | fi ;; 53 | esac 54 | 55 | for file 56 | do 57 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 58 | shift 59 | 60 | pathcomp= 61 | for d 62 | do 63 | pathcomp="$pathcomp$d" 64 | case "$pathcomp" in 65 | -* ) pathcomp=./$pathcomp ;; 66 | esac 67 | 68 | if test ! -d "$pathcomp"; then 69 | echo "mkdir $pathcomp" 70 | 71 | mkdir "$pathcomp" || lasterr=$? 72 | 73 | if test ! -d "$pathcomp"; then 74 | errstatus=$lasterr 75 | else 76 | if test ! -z "$dirmode"; then 77 | echo "chmod $dirmode $pathcomp" 78 | 79 | lasterr="" 80 | chmod "$dirmode" "$pathcomp" || lasterr=$? 81 | 82 | if test ! -z "$lasterr"; then 83 | errstatus=$lasterr 84 | fi 85 | fi 86 | fi 87 | fi 88 | 89 | pathcomp="$pathcomp/" 90 | done 91 | done 92 | 93 | exit $errstatus 94 | 95 | # Local Variables: 96 | # mode: shell-script 97 | # sh-indentation: 3 98 | # End: 99 | # mkinstalldirs ends here 100 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.in by autoheader. */ 2 | 3 | /* Define to 1 if you have the header file. */ 4 | #undef HAVE_CFITSIO_FITSIO_H 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_FCNTL_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_FITSIO_H 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_INTTYPES_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_JPEGLIB_H 17 | 18 | /* Define to 1 if you have the `cfitsio' library (-lcfitsio). */ 19 | #undef HAVE_LIBCFITSIO 20 | 21 | /* Define to 1 if you have the `jpeg' library (-ljpeg). */ 22 | #undef HAVE_LIBJPEG 23 | 24 | /* Define to 1 if you have the `m' library (-lm). */ 25 | #undef HAVE_LIBM 26 | 27 | /* Define to 1 if you have the `nsl' library (-lnsl). */ 28 | #undef HAVE_LIBNSL 29 | 30 | /* Define to 1 if you have the `png' library (-lpng). */ 31 | #undef HAVE_LIBPNG 32 | 33 | /* Define to 1 if you have the `socket' library (-lsocket). */ 34 | #undef HAVE_LIBSOCKET 35 | 36 | /* Defined when libwcs is detected */ 37 | #undef HAVE_LIBWCS 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #undef HAVE_MEMORY_H 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_PNG_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_STDINT_H 47 | 48 | /* Define to 1 if you have the header file. */ 49 | #undef HAVE_STDLIB_H 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_STRINGS_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_STRING_H 56 | 57 | /* Define to 1 if you have the header file. */ 58 | #undef HAVE_SYS_STAT_H 59 | 60 | /* Define to 1 if you have the header file. */ 61 | #undef HAVE_SYS_TIME_H 62 | 63 | /* Define to 1 if you have the header file. */ 64 | #undef HAVE_SYS_TYPES_H 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_UNISTD_H 68 | 69 | /* Name of package */ 70 | #undef PACKAGE 71 | 72 | /* Define to the address where bug reports for this package should be sent. */ 73 | #undef PACKAGE_BUGREPORT 74 | 75 | /* Define to the full name of this package. */ 76 | #undef PACKAGE_NAME 77 | 78 | /* Define to the full name and version of this package. */ 79 | #undef PACKAGE_STRING 80 | 81 | /* Define to the one symbol short name of this package. */ 82 | #undef PACKAGE_TARNAME 83 | 84 | /* Define to the version of this package. */ 85 | #undef PACKAGE_VERSION 86 | 87 | /* Define as the return type of signal handlers (`int' or `void'). */ 88 | #undef RETSIGTYPE 89 | 90 | /* Define to 1 if you have the ANSI C header files. */ 91 | #undef STDC_HEADERS 92 | 93 | /* Version number of package */ 94 | #undef VERSION 95 | -------------------------------------------------------------------------------- /blurb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Blurb header update functions 4 | * 5 | * 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * 21 | * 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "getopt.h" 34 | #include 35 | #include 36 | 37 | #ifdef STDC_HEADERS 38 | #include 39 | #else /* Not STDC_HEADERS */ 40 | extern void exit (); 41 | extern char *malloc (); 42 | #endif /* STDC_HEADERS */ 43 | 44 | #ifdef HAVE_STRING_H 45 | #include 46 | #else 47 | #include 48 | #endif 49 | 50 | 51 | #include "blurb.h" 52 | 53 | void 54 | blurb_error (char *m) 55 | { 56 | fprintf (stderr, "\n%s\n", m); 57 | } 58 | 59 | 60 | char 61 | *blurb_read (char *fname) 62 | { 63 | int len = 0; 64 | int buf_size = BLURB_BUFFER_INIT; 65 | char card[73]; 66 | char *cards = NULL; 67 | FILE *fp = NULL; 68 | 69 | if ((cards = (char *)malloc (buf_size)) == NULL) { 70 | blurb_error ("memory allocation failed for blurb cards."); 71 | return NULL; 72 | } 73 | 74 | if ((fp = fopen (fname, "r")) == NULL) { 75 | blurb_error ("unable to open blurb file:"); 76 | blurb_error (fname); 77 | free (cards); 78 | return NULL; 79 | } 80 | 81 | cards[0] = '\0'; 82 | while (fgets (card, 73, fp) != NULL) { 83 | if ((len += strlen (card)) >= buf_size) { 84 | if ((cards = (char *)realloc (cards, buf_size + BLURB_BUFFER_INIT)) == NULL) { 85 | blurb_error ("memory allocation failed for blurb cards."); 86 | fclose (fp); 87 | return NULL; 88 | } else { 89 | buf_size += BLURB_BUFFER_INIT; 90 | } 91 | } 92 | strcat (cards , card); 93 | } 94 | 95 | if (ferror (fp)) { 96 | blurb_error ("trouble reading blurb file:"); 97 | blurb_error (fname); 98 | fclose (fp); 99 | free (cards); 100 | return NULL; 101 | } else { 102 | fclose (fp); 103 | } 104 | 105 | return cards; 106 | } 107 | -------------------------------------------------------------------------------- /output_json.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * JSON output functions 4 | * 5 | * Author: Rick White 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * 21 | */ 22 | 23 | #ifdef HAVE_CONFIG_H 24 | #include 25 | #endif 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "getopt.h" 33 | #include 34 | #include 35 | 36 | #ifdef STDC_HEADERS 37 | #include 38 | #else /* Not STDC_HEADERS */ 39 | extern void exit (); 40 | extern char *malloc (); 41 | #endif /* STDC_HEADERS */ 42 | 43 | #ifdef HAVE_STRING_H 44 | #include 45 | #else 46 | #include 47 | #endif 48 | 49 | #include "fitscut.h" 50 | #include "output_json.h" 51 | #include "revision.h" 52 | 53 | /* 54 | * Write extracted image pixel values in JSON format 55 | * 56 | * The format is a simple nested array of values: 57 | * [pixels0, pixels1, pixels2] 58 | * where pixels0,pixels1,pixels2 are the (up to) 3 color planes and 59 | * pixels is a 2-D pixel array, e.g.: 60 | * [ [ p00, p01, p02 ], [ p10, p11, p12 ] ] 61 | * 62 | * Note this format could be verbose if you write a lot of pixels. 63 | * It is intended for small image sections. 64 | */ 65 | 66 | int write_to_json(FitsCutImage *Image) 67 | { 68 | FILE *outfile; 69 | long i, j, k, ncols, nrows; 70 | float *data; 71 | 72 | if (to_stdout) { 73 | outfile = stdout; 74 | } else { 75 | outfile = fopen(Image->output_filename, "w"); 76 | } 77 | if (!outfile) return ERROR; 78 | 79 | fprintf(outfile, "["); 80 | for (k=0; kchannels; k++) { 81 | data = Image->data[k]; 82 | nrows = Image->nrows[k]; 83 | ncols = Image->ncols[k]; 84 | if (data) { 85 | if (k != 0) fprintf(outfile, ","); 86 | fprintf(outfile, "\n ["); 87 | for (i=0; i 25 | #endif 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "getopt.h" 33 | #include 34 | #include 35 | 36 | #ifdef STDC_HEADERS 37 | #include 38 | #else /* Not STDC_HEADERS */ 39 | extern void exit (); 40 | extern char *malloc (); 41 | #endif /* STDC_HEADERS */ 42 | 43 | #ifdef HAVE_STRING_H 44 | #include 45 | #else 46 | #include 47 | #endif 48 | 49 | #include "fitscut.h" 50 | #include "output_range.h" 51 | #include "revision.h" 52 | 53 | /* 54 | * Write image pixel value ranges in JSON format 55 | * 56 | * The format is a dictionary with a list of values: 57 | * 58 | * {'min': [0.0, 0.0, 0.0], 'max': [0.0, 0.0, 0.0]} 59 | * 60 | * The (up to) 3 values are for the red, green, blue bands. 61 | */ 62 | 63 | int write_range(FitsCutImage *Image) 64 | { 65 | FILE *outfile; 66 | long k; 67 | double *datamin, *datamax; 68 | 69 | if (to_stdout) { 70 | outfile = stdout; 71 | } else { 72 | outfile = fopen(Image->output_filename, "w"); 73 | } 74 | if (!outfile) return ERROR; 75 | 76 | switch (Image->output_scale_mode) { 77 | case SCALE_MODE_AUTO: 78 | case SCALE_MODE_FULL: 79 | datamin = Image->autoscale_min; 80 | datamax = Image->autoscale_max; 81 | /* check for user overrides */ 82 | if (Image->user_min_set == 1) { 83 | fitscut_message (1, "user min takes precedent over auto scale min\n"); 84 | datamin = Image->user_min; 85 | } 86 | if (Image->user_max_set == 1) { 87 | fitscut_message (1, "user max takes precedent over auto scale max\n"); 88 | datamax = Image->user_max; 89 | } 90 | break; 91 | case SCALE_MODE_USER: 92 | if (Image->user_min_set == 1) 93 | datamin = Image->user_min; 94 | else 95 | datamin = Image->data_min; 96 | if (Image->user_max_set == 1) 97 | datamax = Image->user_max; 98 | else 99 | datamax = Image->data_max; 100 | break; 101 | case SCALE_MODE_MINMAX: 102 | default: 103 | datamin = Image->data_min; 104 | datamax = Image->data_max; 105 | break; 106 | } 107 | 108 | fprintf(outfile, "{ 'min': ["); 109 | for (k=0; kchannels; k++) { 110 | if (Image->data[k] != NULL) { 111 | if (k > 0) fprintf(outfile, ", "); 112 | fprintf(outfile, "%.17e", datamin[k]); 113 | } 114 | } 115 | fprintf(outfile, "], 'max': ["); 116 | for (k=0; kchannels; k++) { 117 | if (Image->data[k] != NULL) { 118 | if (k > 0) fprintf(outfile, ", "); 119 | fprintf(outfile, "%.17e", datamax[k]); 120 | } 121 | } 122 | fprintf(outfile, "]}\n"); 123 | fflush(stdout); 124 | return OK; 125 | } 126 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS = fitscut 2 | 3 | if HAVE_LIBWCS 4 | 5 | wcs_SOURCES = wcs_align.c wcs_align.h 6 | 7 | fitscut_LDADD = $(WCS_LIBS) 8 | 9 | endif 10 | 11 | fitscut_SOURCES = \ 12 | blurb.c \ 13 | colormap.c \ 14 | draw.c \ 15 | extract.c \ 16 | file_check.c \ 17 | fitscut.c \ 18 | getopt1.c \ 19 | getopt.c \ 20 | histogram.c \ 21 | image_scale.c \ 22 | output_fits.c \ 23 | output_graphic.c \ 24 | output_json.c \ 25 | resize.c \ 26 | util.c \ 27 | colormap.h \ 28 | draw.h \ 29 | extract.h \ 30 | file_check.h \ 31 | fitscut.h \ 32 | getopt.h \ 33 | histogram.h \ 34 | image_scale.h \ 35 | output_fits.h \ 36 | output_graphic.h \ 37 | output_json.h \ 38 | resize.h \ 39 | util.h \ 40 | tailor.h \ 41 | revision.h \ 42 | $(wcs_SOURCES) 43 | 44 | EXTRA_DIST = \ 45 | AUTHORS \ 46 | ChangeLog \ 47 | COPYING \ 48 | INSTALL \ 49 | NEWS \ 50 | README \ 51 | THANKS \ 52 | TODO \ 53 | fitscut.spec.in \ 54 | fitscut.spec \ 55 | test.fits 56 | 57 | test: check 58 | check: fitscut 59 | ./fitscut -vv --x0=1 --y0=1 --columns=50 --rows=60 test.fits > _test.fits 60 | @LANG=""; export LANG; if test "-s _test.fits"; then \ 61 | if test `wc -c < _test.fits` -eq 17280; then \ 62 | echo fitscut FITS test OK; \ 63 | else \ 64 | echo FAILED fitscut FITS test: wrong size; \ 65 | fi; \ 66 | else \ 67 | echo FAILED fitscut FITS test: no output; \ 68 | fi 69 | rm -f _test.fits 70 | ./fitscut -vv --png --x0=1 --y0=1 --columns=50 --rows=60 test.fits > _test.png 71 | @LANG=""; export LANG; if test "-s _test.fits"; then \ 72 | if [ -f "_test.png" ]; then \ 73 | echo fitscut PNG test OK; \ 74 | else \ 75 | echo FAILED fitscut PNG test: wrong size; \ 76 | fi; \ 77 | else \ 78 | echo FAILED fitscut PNG test: no output; \ 79 | fi 80 | rm -f _test.png 81 | ./fitscut -vv --png --log-scale --x0=1 --y0=1 --columns=50 --rows=60 test.fits > _test.png 82 | @LANG=""; export LANG; if [ -s "_test.png" ]; then \ 83 | if [ -f "_test.png" ]; then \ 84 | echo fitscut PNG log test OK; \ 85 | else \ 86 | echo FAILED fitscut PNG log test: wrong size; \ 87 | fi; \ 88 | else \ 89 | echo FAILED fitscut PNG log test: no output; \ 90 | fi 91 | rm -f _test.png 92 | ./fitscut -vv --png --sqrt-scale --x0=1 --y0=1 --columns=50 --rows=60 test.fits > _test.png 93 | @LANG=""; export LANG; if [ -s "_test.png" ]; then \ 94 | if [ -f "_test.png" ]; then \ 95 | echo fitscut PNG sqrt test OK; \ 96 | else \ 97 | echo FAILED fitscut PNG sqrt test: wrong size; \ 98 | fi; \ 99 | else \ 100 | echo FAILED fitscut PNG sqrt test: no output; \ 101 | fi 102 | rm -f _test.png 103 | ./fitscut -vv --png --autoscale=98 --x0=1 --y0=1 --columns=50 --rows=60 test.fits > _test.png 104 | @LANG=""; export LANG; if [ -s "_test.png" ]; then \ 105 | if [ -f "_test.png" ]; then \ 106 | echo fitscut PNG autoscale test OK; \ 107 | else \ 108 | echo FAILED fitscut PNG autoscale test: wrong size; \ 109 | fi; \ 110 | else \ 111 | echo FAILED fitscut PNG autoscale test: no output; \ 112 | fi 113 | rm -f _test.png 114 | ./fitscut -vv --png --autoscale=98 --all --zoom=2.0 test.fits > _test.png 115 | @LANG=""; export LANG; if [ -s "_test.png" ]; then \ 116 | if [ -f "_test.png" ]; then \ 117 | echo fitscut PNG zoom test OK; \ 118 | else \ 119 | echo FAILED fitscut PNG zoom test: wrong size; \ 120 | fi; \ 121 | else \ 122 | echo FAILED fitscut PNG zoom test: no output; \ 123 | fi 124 | rm -f _test.png 125 | ./fitscut -vv --png --autoscale=98 --all --asinh-scale test.fits > _test.png 126 | @LANG=""; export LANG; if [ -s "_test.png" ]; then \ 127 | if [ -f "_test.png" ]; then \ 128 | echo fitscut PNG asinh test OK; \ 129 | else \ 130 | echo FAILED fitscut PNG asinh test: wrong size; \ 131 | fi; \ 132 | else \ 133 | echo FAILED fitscut PNG asinh test: no output; \ 134 | fi 135 | rm -f _test.png 136 | 137 | -------------------------------------------------------------------------------- /configure.in: -------------------------------------------------------------------------------- 1 | dnl $Id: configure.in,v 1.8 2004/07/27 22:14:20 mccannwj Exp $ 2 | dnl Process this file with autoconf to produce a configure script. 3 | 4 | AC_DEFUN([COMPILE_WARNINGS],[ 5 | if test -z "$1" ; then 6 | default_compile_warnings=yes 7 | else 8 | default_compile_warnings="$1" 9 | fi 10 | 11 | AC_ARG_ENABLE(compile-warnings, 12 | [ --enable-compile-warnings=[no/minimum/yes/maximum/error] Turn on compiler warnings.],, [enable_compile_warnings="$default_compile_warnings"]) 13 | 14 | warnCFLAGS= 15 | if test "x$GCC" != xyes; then 16 | enable_compile_warnings=no 17 | fi 18 | 19 | warning_flags= 20 | realsave_CFLAGS="$CFLAGS" 21 | 22 | case "$enable_compile_warnings" in 23 | no) 24 | warning_flags= 25 | ;; 26 | minimum) 27 | warning_flags="-Wall" 28 | ;; 29 | yes) 30 | warning_flags="-Wall -Wmissing-prototypes" 31 | ;; 32 | maximum|error) 33 | warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith" 34 | CFLAGS="$warning_flags $CFLAGS" 35 | for option in -Wno-sign-compare; do 36 | SAVE_CFLAGS="$CFLAGS" 37 | CFLAGS="$CFLAGS $option" 38 | AC_MSG_CHECKING([whether gcc understands $option]) 39 | AC_TRY_COMPILE([], [], 40 | has_option=yes, 41 | has_option=no,) 42 | CFLAGS="$SAVE_CFLAGS" 43 | AC_MSG_RESULT($has_option) 44 | if test $has_option = yes; then 45 | warning_flags="$warning_flags $option" 46 | fi 47 | unset has_option 48 | unset SAVE_CFLAGS 49 | done 50 | unset option 51 | if test "$enable_compile_warnings" = "error" ; then 52 | warning_flags="$warning_flags -Werror" 53 | fi 54 | ;; 55 | *) 56 | AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings) 57 | ;; 58 | esac 59 | CFLAGS="$realsave_CFLAGS" 60 | AC_MSG_CHECKING(what warning flags to pass to the C compiler) 61 | AC_MSG_RESULT($warning_flags) 62 | 63 | AC_ARG_ENABLE(iso-c, 64 | [ --enable-iso-c Try to warn if code is not ISO C ],, 65 | enable_iso_c=no) 66 | 67 | AC_MSG_CHECKING(what language compliance flags to pass to the C compiler) 68 | complCFLAGS= 69 | if test "x$enable_iso_c" != "xno"; then 70 | if test "x$GCC" = "xyes"; then 71 | case " $CFLAGS " in 72 | *[\ \ ]-ansi[\ \ ]*) ;; 73 | *) complCFLAGS="$complCFLAGS -ansi" ;; 74 | esac 75 | case " $CFLAGS " in 76 | *[\ \ ]-pedantic[\ \ ]*) ;; 77 | *) complCFLAGS="$complCFLAGS -pedantic" ;; 78 | esac 79 | fi 80 | fi 81 | AC_MSG_RESULT($complCFLAGS) 82 | 83 | WARN_CFLAGS="$warning_flags $complCFLAGS" 84 | AC_SUBST(WARN_CFLAGS) 85 | ]) 86 | 87 | AC_INIT(fitscut.c) 88 | 89 | AM_CONFIG_HEADER(config.h) 90 | AM_INIT_AUTOMAKE(fitscut,1.4.2) 91 | 92 | dnl Checks for programs. 93 | AC_PROG_CC 94 | AC_PROG_LN_S 95 | AC_PROG_INSTALL 96 | AC_PROG_CPP 97 | 98 | dnl Checks for header files. 99 | AC_STDC_HEADERS 100 | AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h) 101 | AC_CHECK_HEADERS(string.h) 102 | AC_CHECK_HEADERS(stdlib.h,) 103 | 104 | AC_CHECK_HEADERS(png.h,,AC_MSG_ERROR([png.h is required to build fitscut])) 105 | AC_CHECK_HEADERS(jpeglib.h,,AC_MSG_ERROR([jpeglib.h is required to build fitscut])) 106 | AC_CHECK_HEADERS(cfitsio/fitsio.h, have_cfitsio_fitsio_h=yes, have_cfitsio_fitsio_h=no) 107 | AC_CHECK_HEADERS(fitsio.h, have_fitsio_h=yes, have_fitsio_h=no) 108 | 109 | AM_CONDITIONAL(HAVE_CFITSIO_FITSIO_H, test "x$have_cfitsio_fitsio_h" = "xyes") 110 | AM_CONDITIONAL(HAVE_FITSIO_H, test "x$have_cfitsio_fitsio_h" = "xyes") 111 | 112 | if test "x$have_cfitsio_fitsio_h" != "xyes" -a "x$have_fitsio_h" != "xyes"; then 113 | AC_MSG_ERROR([fitsio.h is required to build fitscut]) 114 | fi 115 | 116 | dnl Checks for libraries. 117 | AC_CHECK_LIB(m, sin) 118 | AC_CHECK_LIB(socket, connect) 119 | AC_CHECK_LIB(nsl, main) 120 | AC_CHECK_LIB(png, png_read_info) 121 | AC_CHECK_LIB(jpeg, jpeg_destroy_decompress) 122 | AC_CHECK_LIB(cfitsio, ffvers) 123 | AC_CHECK_LIB(wcs, wcsinit, have_libwcs=yes, have_libwcs=no) 124 | 125 | AM_CONDITIONAL(HAVE_LIBWCS, test "x$have_libwcs" = "xyes") 126 | 127 | if test "x$have_libwcs" = "xyes"; then 128 | AC_DEFINE([HAVE_LIBWCS], 1, [Defined when libwcs is detected]) 129 | WCS_LIBS="-lwcs" 130 | AC_SUBST(WCS_LIBS) 131 | else 132 | AC_MSG_ERROR([libwcs is required to build fitscut]) 133 | fi 134 | 135 | COMPILE_WARNINGS(yes) 136 | CFLAGS="$CFLAGS $WARN_CFLAGS" 137 | AC_SUBST(CFLAGS) 138 | 139 | dnl Checks for library functions. 140 | AC_TYPE_SIGNAL 141 | 142 | AC_OUTPUT(Makefile) 143 | AC_OUTPUT(fitscut.spec) 144 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2004-07-27 William Jon McCann 2 | 3 | * NEWS: 4 | * revision.h (REVDATE): 5 | * configure.in: Update for release. 6 | 7 | * fitscut.c (check_input, main): Interpret warnings as errors. 8 | (check_output): Exit on error condition. 9 | 10 | * file_check.c (check_input_file): Don't issue a warning when the 11 | input file is a symbolic link. 12 | 13 | 2004-05-11 William Jon McCann 14 | 15 | * NEWS: Updated. 16 | 17 | * revision.h (REVDATE): Bump version for release. 18 | 19 | * configure.in: 20 | * extract.c: 21 | * fitscut.c: 22 | * resize.c: 23 | * output_fits.c: 24 | Look for fitsio.h with cfitsio prefix and without. 25 | 26 | * fitscut.spec.in: 27 | * Makefile.am (EXTRA_DIST): 28 | * configure.in: Add spec file. 29 | 30 | 2004-05-10 William Jon McCann 31 | 32 | * autogen.sh: New file. 33 | 34 | * revision.h: 35 | * configure.in: 36 | * NEWS: 37 | * README: Updated for 1.4.0 release. 38 | 39 | 2004-04-30 William Jon McCann 40 | 41 | * image_scale.[ch] (asinh_image2): Removed function. 42 | 43 | * fitscut.c (scale_image): Fix bug from missing break statements. 44 | 45 | * output_jpg.c (jpg_write_simple_image): 46 | * output_png.c (png_write_simple_image): Align verbose messages. 47 | 48 | * image_scale.c (autoscale_channel): Require higher verbosity for 49 | autoscale range messages. 50 | 51 | * histogram.c (compute_histogram): Require higher verbosity for 52 | histogram related messages. 53 | 54 | * fitscut.c (fitscut_initialize): Use 0,100 as defaults for autoscale. 55 | (main): Set scale mode to autoscale when autoscale-{min,max} are set. 56 | 57 | * Makefile.am (check): Use unambiguous autoscale option. 58 | 59 | * fitscut.c (main): Get autoscale-{min,max} from commandline. 60 | 61 | 2004-04-29 William Jon McCann 62 | 63 | * image_scale.c (autoscale_channel): Use autoscale low/high per channel. 64 | 65 | * fitscut.c (show_usage): Separate sections. Add some help text. 66 | 67 | * fitscut.h: Replace defines with enums. 68 | 69 | * output_fits.c (write_to_fits): Remove SCALE_NONE 70 | 71 | 2004-04-22 William Jon McCann 72 | 73 | * extract.c (extract_fits): Fix bug introduced by inappropriately 74 | initializing variables in a loop. 75 | 76 | * image_scale.c (autoscale_image): Set autoscale_performed flag. 77 | (asinh_image2, asinh_image): Rewrite algorithm so as not use any 78 | additional memory. Try to hook up user min/max values. 79 | 80 | * fitscut.c (fitscut_initialize): Use TRUE/FALSE where possible. 81 | 82 | * fitscut.h: Ensure TRUE/FALSE are defined. Add 83 | autoscale_performed flag to structure. 84 | 85 | * Makefile.am (check): Fix test names. Add asinh test. 86 | 87 | 2004-04-21 William Jon McCann 88 | 89 | * fitscut.c (fitscut_message, align_image, render_compass) 90 | (write_image, check_input): 91 | * wcs_align.c (wcs_initialize_channel, wcs_align_first) 92 | (wcs_remap_channel): 93 | * resize.c (resize_image_sample_reduce) 94 | (resize_image_sample_enlarge): 95 | * output_png.c (png_write_rgb_image, png_write_simple_image) 96 | (write_to_png): 97 | * output_jpg.c (jpg_write_rgb_image, jpg_write_simple_image) 98 | (write_to_jpg): 99 | * output_fits.c (write_to_fits): 100 | * image_scale.c (autoscale_channel, autoscale_image, log_image) 101 | (sqrt_image, asinh_image, scan_min_max, mult_image, rate_image): 102 | * histogram.c (compute_histogram): 103 | * extract.c (extract_fits, cutout_alloc, fits_get_exposure_time): 104 | * draw.c (draw_wcs_compass): 105 | Use new fitscut_message function. 106 | 107 | * test.fits: 108 | * Makefile.am (check): Change size of test file. 109 | 110 | 2004-04-21 William Jon McCann 111 | 112 | * AUTHORS: 113 | * NEWS: 114 | * Makefile.am: New file. 115 | 116 | * colormap.[ch]: 117 | * draw.[ch]: 118 | * extract.[ch]: 119 | * file_check.[ch]: 120 | * fitscut.[ch]: 121 | * getopt1.[ch]: 122 | * getopt.[ch]: 123 | * histogram.[ch]: 124 | * image_scale.[ch]: 125 | * output_fits.[ch]: 126 | * output_jpg.[ch]: 127 | * output_png.[ch]: 128 | * resize.[ch]: 129 | * util.[ch]: 130 | * wcs_align.[ch]: Add GPL license text. Change 131 | indentation to 8 chars. Add spacing around 132 | functions and operators. Fix compiler warnings. 133 | 134 | * configure.in: Add warnings. Define version 135 | here instead of in revision.h. Produce config.h. 136 | Report an error when required header is not found. 137 | Add WCS_LIBS variable. 138 | 139 | * THANKS: 140 | * TODO: 141 | * README: Updated. 142 | 143 | * COPYING: Added GPL license. 144 | 145 | 2003-11-25 William Jon McCann 146 | 147 | * revision.h: Increment version for test release. 148 | 149 | 2003-11-24 William Jon McCann 150 | 151 | * fitscut.[ch]: 152 | * image_scale.[ch]: added asinh scaling. 153 | 154 | -------------------------------------------------------------------------------- /getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc. 3 | 4 | This program is free software; you can redistribute it and/or modify it 5 | under the terms of the GNU General Public License as published by the 6 | Free Software Foundation; either version 2, or (at your option) any 7 | later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 17 | 18 | #ifndef _GETOPT_H 19 | #define _GETOPT_H 1 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /* For communication from `getopt' to the caller. 26 | When `getopt' finds an option that takes an argument, 27 | the argument value is returned here. 28 | Also, when `ordering' is RETURN_IN_ORDER, 29 | each non-option ARGV-element is returned here. */ 30 | 31 | extern char *optarg; 32 | 33 | /* Index in ARGV of the next element to be scanned. 34 | This is used for communication to and from the caller 35 | and for communication between successive calls to `getopt'. 36 | 37 | On entry to `getopt', zero means this is the first call; initialize. 38 | 39 | When `getopt' returns EOF, this is the index of the first of the 40 | non-option elements that the caller should itself scan. 41 | 42 | Otherwise, `optind' communicates from one call to the next 43 | how much of ARGV has been scanned so far. */ 44 | 45 | extern int optind; 46 | 47 | /* Callers store zero here to inhibit the error message `getopt' prints 48 | for unrecognized options. */ 49 | 50 | extern int opterr; 51 | 52 | /* Set to an option character which was unrecognized. */ 53 | 54 | extern int optopt; 55 | 56 | /* Describe the long-named options requested by the application. 57 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 58 | of `struct option' terminated by an element containing a name which is 59 | zero. 60 | 61 | The field `has_arg' is: 62 | no_argument (or 0) if the option does not take an argument, 63 | required_argument (or 1) if the option requires an argument, 64 | optional_argument (or 2) if the option takes an optional argument. 65 | 66 | If the field `flag' is not NULL, it points to a variable that is set 67 | to the value given in the field `val' when the option is found, but 68 | left unchanged if the option is not found. 69 | 70 | To have a long-named option do something other than set an `int' to 71 | a compiled-in constant, such as set a value from `optarg', set the 72 | option's `flag' field to zero and its `val' field to a nonzero 73 | value (the equivalent single-letter option character, if there is 74 | one). For long options that have a zero `flag' field, `getopt' 75 | returns the contents of the `val' field. */ 76 | 77 | struct option 78 | { 79 | #if __STDC__ 80 | const char *name; 81 | #else 82 | char *name; 83 | #endif 84 | /* has_arg can't be an enum because some compilers complain about 85 | type mismatches in all the code that assumes it is an int. */ 86 | int has_arg; 87 | int *flag; 88 | int val; 89 | }; 90 | 91 | /* Names for the values of the `has_arg' field of `struct option'. */ 92 | 93 | #define no_argument 0 94 | #define required_argument 1 95 | #define optional_argument 2 96 | 97 | #if __STDC__ 98 | #if defined(__GNU_LIBRARY__) 99 | /* Many other libraries have conflicting prototypes for getopt, with 100 | differences in the consts, in stdlib.h. To avoid compilation 101 | errors, only prototype getopt for the GNU C library. */ 102 | extern int getopt (int argc, char *const *argv, const char *shortopts); 103 | #else /* not __GNU_LIBRARY__ */ 104 | extern int getopt (); 105 | #endif /* not __GNU_LIBRARY__ */ 106 | extern int getopt_long (int argc, char *const *argv, const char *shortopts, 107 | const struct option *longopts, int *longind); 108 | extern int getopt_long_only (int argc, char *const *argv, 109 | const char *shortopts, 110 | const struct option *longopts, int *longind); 111 | 112 | /* Internal only. Users should not call this directly. */ 113 | extern int _getopt_internal (int argc, char *const *argv, 114 | const char *shortopts, 115 | const struct option *longopts, int *longind, 116 | int long_only); 117 | #else /* not __STDC__ */ 118 | extern int getopt (); 119 | extern int getopt_long (); 120 | extern int getopt_long_only (); 121 | 122 | extern int _getopt_internal (); 123 | #endif /* not __STDC__ */ 124 | 125 | #ifdef __cplusplus 126 | } 127 | #endif 128 | 129 | #endif /* _GETOPT_H */ 130 | -------------------------------------------------------------------------------- /getopt1.c: -------------------------------------------------------------------------------- 1 | /* getopt_long and getopt_long_only entry points for GNU getopt. 2 | Copyright (C) 1987, 88, 89, 90, 91, 92, 1993 3 | Free Software Foundation, Inc. 4 | 5 | This program is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU General Public License as published by the 7 | Free Software Foundation; either version 2, or (at your option) any 8 | later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 18 | 19 | #ifdef HAVE_CONFIG_H 20 | #include "config.h" 21 | #endif 22 | 23 | #include "getopt.h" 24 | 25 | #if !__STDC__ && !defined(const) && IN_GCC 26 | #define const 27 | #endif 28 | 29 | #include 30 | 31 | /* Comment out all this code if we are using the GNU C Library, and are not 32 | actually compiling the library itself. This code is part of the GNU C 33 | Library, but also included in many other GNU distributions. Compiling 34 | and linking in this code is a waste when using the GNU C library 35 | (especially if it is a shared library). Rather than having every GNU 36 | program understand `configure --with-gnu-libc' and omit the object files, 37 | it is simpler to just do this in the source for each such file. */ 38 | 39 | #if defined (_LIBC) || !defined (__GNU_LIBRARY__) 40 | 41 | 42 | /* This needs to come after some library #include 43 | to get __GNU_LIBRARY__ defined. */ 44 | #ifdef __GNU_LIBRARY__ 45 | #include 46 | #else 47 | char *getenv (); 48 | #endif 49 | 50 | #ifndef NULL 51 | #define NULL 0 52 | #endif 53 | 54 | int 55 | getopt_long (argc, argv, options, long_options, opt_index) 56 | int argc; 57 | char *const *argv; 58 | const char *options; 59 | const struct option *long_options; 60 | int *opt_index; 61 | { 62 | return _getopt_internal (argc, argv, options, long_options, opt_index, 0); 63 | } 64 | 65 | /* Like getopt_long, but '-' as well as '--' can indicate a long option. 66 | If an option that starts with '-' (not '--') doesn't match a long option, 67 | but does match a short option, it is parsed as a short option 68 | instead. */ 69 | 70 | int 71 | getopt_long_only (argc, argv, options, long_options, opt_index) 72 | int argc; 73 | char *const *argv; 74 | const char *options; 75 | const struct option *long_options; 76 | int *opt_index; 77 | { 78 | return _getopt_internal (argc, argv, options, long_options, opt_index, 1); 79 | } 80 | 81 | 82 | #endif /* _LIBC or not __GNU_LIBRARY__. */ 83 | 84 | #ifdef TEST 85 | 86 | #include 87 | 88 | int 89 | main (argc, argv) 90 | int argc; 91 | char **argv; 92 | { 93 | int c; 94 | int digit_optind = 0; 95 | 96 | while (1) 97 | { 98 | int this_option_optind = optind ? optind : 1; 99 | int option_index = 0; 100 | static struct option long_options[] = 101 | { 102 | {"add", 1, 0, 0}, 103 | {"append", 0, 0, 0}, 104 | {"delete", 1, 0, 0}, 105 | {"verbose", 0, 0, 0}, 106 | {"create", 0, 0, 0}, 107 | {"file", 1, 0, 0}, 108 | {0, 0, 0, 0} 109 | }; 110 | 111 | c = getopt_long (argc, argv, "abc:d:0123456789", 112 | long_options, &option_index); 113 | if (c == EOF) 114 | break; 115 | 116 | switch (c) 117 | { 118 | case 0: 119 | printf ("option %s", long_options[option_index].name); 120 | if (optarg) 121 | printf (" with arg %s", optarg); 122 | printf ("\n"); 123 | break; 124 | 125 | case '0': 126 | case '1': 127 | case '2': 128 | case '3': 129 | case '4': 130 | case '5': 131 | case '6': 132 | case '7': 133 | case '8': 134 | case '9': 135 | if (digit_optind != 0 && digit_optind != this_option_optind) 136 | printf ("digits occur in two different argv-elements.\n"); 137 | digit_optind = this_option_optind; 138 | printf ("option %c\n", c); 139 | break; 140 | 141 | case 'a': 142 | printf ("option a\n"); 143 | break; 144 | 145 | case 'b': 146 | printf ("option b\n"); 147 | break; 148 | 149 | case 'c': 150 | printf ("option c with value `%s'\n", optarg); 151 | break; 152 | 153 | case 'd': 154 | printf ("option d with value `%s'\n", optarg); 155 | break; 156 | 157 | case '?': 158 | break; 159 | 160 | default: 161 | printf ("?? getopt returned character code 0%o ??\n", c); 162 | } 163 | } 164 | 165 | if (optind < argc) 166 | { 167 | printf ("non-option ARGV-elements: "); 168 | while (optind < argc) 169 | printf ("%s ", argv[optind++]); 170 | printf ("\n"); 171 | } 172 | 173 | exit (0); 174 | } 175 | 176 | #endif /* TEST */ 177 | -------------------------------------------------------------------------------- /util.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * Utility functions 4 | * 5 | * Author: William Jon McCann 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * 21 | * $Id: util.c,v 1.4 2004/04/21 20:13:10 mccannwj Exp $ 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "getopt.h" 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | #ifdef STDC_HEADERS 41 | #include 42 | #else /* Not STDC_HEADERS */ 43 | extern void exit (); 44 | extern char *malloc (); 45 | #endif /* STDC_HEADERS */ 46 | 47 | #ifdef HAVE_STRING_H 48 | #include 49 | #else 50 | #include 51 | #endif 52 | 53 | #include "fitscut.h" 54 | #include "util.h" 55 | 56 | #ifdef DMALLOC 57 | #include 58 | #define DMALLOC_FUNC_CHECK 1 59 | #endif 60 | 61 | float * 62 | interpolate_points (long nresult, float *px, float *py, long npoints) 63 | { 64 | long i, j; 65 | long last_index, next_index; 66 | float *list; 67 | float m, x, y; 68 | 69 | /* x and y are normalized to unity */ 70 | list = (float *) malloc (sizeof (float) * nresult); 71 | last_index = 0; 72 | for (i = 0; i < npoints-1; i++) { 73 | next_index = ceil (nresult * px[i+1]); 74 | m = (py[i + 1] - py[i]) / (px[i + 1] - px[i]); 75 | for (j = last_index; j < next_index; j++) { 76 | /* point slope formula */ 77 | x = j / (float) nresult; 78 | y = m * (x - px[i]) + py[i]; 79 | list[j] = y; 80 | } 81 | last_index = next_index; 82 | } 83 | return list; 84 | } 85 | 86 | long 87 | parse_coordinates (char *str, float **x, float **y) 88 | { 89 | int count,i; 90 | char *sptr; 91 | char *tmpstr; 92 | float tx,ty; 93 | float *xp; 94 | float *yp; 95 | 96 | count = 0; 97 | for (i = 0; i < strlen (str); i++) { 98 | if (str[i] == ',') 99 | count++; 100 | } 101 | 102 | xp = (float *)malloc (sizeof (float) * count); 103 | yp = (float *)malloc (sizeof (float) * count); 104 | tmpstr = strdup(str); 105 | for (i = 0; i < count; i++) { 106 | if (i == 0) 107 | sptr = strtok (tmpstr, ")"); 108 | else 109 | sptr = strtok (NULL, ")"); 110 | sscanf (sptr, "(%f,%f", &tx, &ty); 111 | xp[i] = tx; 112 | yp[i] = ty; 113 | } 114 | 115 | *x = xp; 116 | *y = yp; 117 | free (tmpstr); 118 | return (count); 119 | } 120 | 121 | #if 0 122 | 123 | void 124 | byte_swap_vector (void *p, int n, int size) 125 | { 126 | char *a, *b, c; 127 | 128 | switch (size) { 129 | case 2: 130 | for (a = (char*)p ; n > 0; n--, a += 1) { 131 | b = a + 1; 132 | c = *a; *a++ = *b; *b = c; 133 | } 134 | break; 135 | case 4: 136 | for (a = (char*)p ; n > 0; n--, a += 2) { 137 | b = a + 3; 138 | c = *a; *a++ = *b; *b-- = c; 139 | c = *a; *a++ = *b; *b = c; 140 | } 141 | break; 142 | case 8: 143 | for (a = (char*)p ; n > 0; n--, a += 4) { 144 | b = a + 7; 145 | c = *a; *a++ = *b; *b-- = c; 146 | c = *a; *a++ = *b; *b-- = c; 147 | c = *a; *a++ = *b; *b-- = c; 148 | c = *a; *a++ = *b; *b = c; 149 | } 150 | break; 151 | default: 152 | break; 153 | } 154 | } 155 | #endif 156 | 157 | /* 158 | * Put string s in lower case, return s. 159 | */ 160 | char * 161 | strlwr (char *s) 162 | { 163 | char *t; 164 | for (t = s; *t; t++) 165 | *t = tolow(*t); 166 | return s; 167 | } 168 | -------------------------------------------------------------------------------- /histogram.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * Histogram functions 4 | * 5 | * Author: William Jon McCann 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * 21 | * $Id: histogram.c,v 1.7 2004/04/30 18:28:12 mccannwj Exp $ 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "getopt.h" 34 | #include 35 | #include 36 | 37 | #include 38 | #include 39 | 40 | #ifdef STDC_HEADERS 41 | #include 42 | #else /* Not STDC_HEADERS */ 43 | extern void exit (); 44 | extern char *malloc (); 45 | #endif /* STDC_HEADERS */ 46 | 47 | #include "fitscut.h" 48 | #include "histogram.h" 49 | 50 | #ifdef DMALLOC 51 | #include 52 | #define DMALLOC_FUNC_CHECK 1 53 | #endif 54 | 55 | /* 56 | ** returns a (length+1) bin histogram with one bin for objects below dmin, length-1 bins for objects 57 | ** between dmin and dmax, and one bin for objects above dmax 58 | **/ 59 | 60 | float * 61 | compute_histogram (float *arrayp, int length, double dmin, double dmax, long npix, float bad_data_value, long *pixcount, float *inmin, float *inmax) 62 | { 63 | float *hist; 64 | double binsize; 65 | long i, ind; 66 | float value; 67 | float fmin, fmax; 68 | long lpixcount; 69 | 70 | /* allocate histogram */ 71 | hist = (float*) malloc (sizeof (float) * (length + 1)); 72 | 73 | /* Initialize histogram */ 74 | for (i = 0; i <= length; i++) 75 | hist[i] = 0; 76 | 77 | /* Build histogram */ 78 | fitscut_message (3, "\tbuilding histogram...\n"); 79 | 80 | binsize = (dmax - dmin) / (length - 1); 81 | fitscut_message (4, "\tdmax: %lf dmin: %lf length: %d binsize: %lf npix: %ld...\n", 82 | dmax, dmin, length, binsize, npix); 83 | 84 | lpixcount = 0; 85 | fmin = FLT_MAX; 86 | fmax = -FLT_MAX; 87 | for (i = 0; i < npix; i++) { 88 | value = arrayp[i]; 89 | /* exclude blanked values */ 90 | if (finite(value) && (value != bad_data_value)) { 91 | if (value < dmin) { 92 | ind = 0; 93 | } else if (value > dmax) { 94 | ind = length-1; 95 | } else { 96 | ind = ceil ((value-dmin) / binsize); 97 | if (value > fmax) fmax = value; 98 | if (value < fmin) fmin = value; 99 | } 100 | hist[ind] += 1.0; 101 | lpixcount++; 102 | } 103 | } 104 | /* return total number of pixels excluding blanks in pixcount */ 105 | *pixcount = lpixcount; 106 | /* return min/max range for pixels within histogram bounds to allow refinement */ 107 | if (fmin > fmax) { 108 | /* no pixels in bounds */ 109 | *inmin = 0.5*(dmin+dmax); 110 | *inmax = *inmin; 111 | } else { 112 | *inmin = fmin; 113 | *inmax = fmax; 114 | } 115 | return (hist); 116 | } 117 | 118 | unsigned char * 119 | eq_histogram (float *hist, int length, long npix) 120 | { 121 | int i, j; 122 | int *part; 123 | unsigned char *lut; 124 | double pixels_per_value; 125 | double desired; 126 | double sum, dif; 127 | 128 | /* allocate partition */ 129 | part = (int*) malloc (sizeof (int) * 257); 130 | /* allocate look up table */ 131 | lut = (unsigned char*) malloc (sizeof (unsigned char) * (length + 1)); 132 | 133 | /* Find partition points */ 134 | pixels_per_value = ((double) npix) / 256.0; 135 | 136 | /* First and last points in partition */ 137 | part[0] = 0; 138 | part[256] = 256; 139 | 140 | /* Find intermediate points */ 141 | j = 0; 142 | sum = hist[0] + hist[1]; 143 | for (i = 1; i < 256; i++) { 144 | desired = i * pixels_per_value; 145 | while (sum <= desired) { 146 | j++; 147 | sum += hist[j+1]; 148 | } 149 | 150 | /* Nearest sum */ 151 | dif = sum - hist[j]; 152 | if ((sum - desired) > (dif / 2.0)) 153 | part[i] = j; 154 | else 155 | part[i] = j + 1; 156 | } 157 | 158 | /* Create equalization LUT */ 159 | for (j = 0; j < length; j++) { 160 | i = 0; 161 | 162 | while (part[i + 1] <= j) 163 | i++; 164 | if (i > 255) 165 | i = 255; 166 | 167 | lut[j] = i; 168 | } 169 | 170 | free (part); 171 | return (lut); 172 | } 173 | -------------------------------------------------------------------------------- /install-sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # install - install a program, script, or datafile 4 | # This comes from X11R5. 5 | # 6 | # Calling this script install-sh is preferred over install.sh, to prevent 7 | # `make' implicit rules from creating a file called install from it 8 | # when there is no Makefile. 9 | # 10 | # This script is compatible with the BSD install script, but was written 11 | # from scratch. 12 | # 13 | 14 | 15 | # set DOITPROG to echo to test this script 16 | 17 | # Don't use :- since 4.3BSD and earlier shells don't like it. 18 | doit="${DOITPROG-}" 19 | 20 | 21 | # put in absolute paths if you don't have them in your path; or use env. vars. 22 | 23 | mvprog="${MVPROG-mv}" 24 | cpprog="${CPPROG-cp}" 25 | chmodprog="${CHMODPROG-chmod}" 26 | chownprog="${CHOWNPROG-chown}" 27 | chgrpprog="${CHGRPPROG-chgrp}" 28 | stripprog="${STRIPPROG-strip}" 29 | rmprog="${RMPROG-rm}" 30 | mkdirprog="${MKDIRPROG-mkdir}" 31 | 32 | tranformbasename="" 33 | transform_arg="" 34 | instcmd="$mvprog" 35 | chmodcmd="$chmodprog 0755" 36 | chowncmd="" 37 | chgrpcmd="" 38 | stripcmd="" 39 | rmcmd="$rmprog -f" 40 | mvcmd="$mvprog" 41 | src="" 42 | dst="" 43 | dir_arg="" 44 | 45 | while [ x"$1" != x ]; do 46 | case $1 in 47 | -c) instcmd="$cpprog" 48 | shift 49 | continue;; 50 | 51 | -d) dir_arg=true 52 | shift 53 | continue;; 54 | 55 | -m) chmodcmd="$chmodprog $2" 56 | shift 57 | shift 58 | continue;; 59 | 60 | -o) chowncmd="$chownprog $2" 61 | shift 62 | shift 63 | continue;; 64 | 65 | -g) chgrpcmd="$chgrpprog $2" 66 | shift 67 | shift 68 | continue;; 69 | 70 | -s) stripcmd="$stripprog" 71 | shift 72 | continue;; 73 | 74 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` 75 | shift 76 | continue;; 77 | 78 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 79 | shift 80 | continue;; 81 | 82 | *) if [ x"$src" = x ] 83 | then 84 | src=$1 85 | else 86 | # this colon is to work around a 386BSD /bin/sh bug 87 | : 88 | dst=$1 89 | fi 90 | shift 91 | continue;; 92 | esac 93 | done 94 | 95 | if [ x"$src" = x ] 96 | then 97 | echo "install: no input file specified" 98 | exit 1 99 | else 100 | true 101 | fi 102 | 103 | if [ x"$dir_arg" != x ]; then 104 | dst=$src 105 | src="" 106 | 107 | if [ -d $dst ]; then 108 | instcmd=: 109 | else 110 | instcmd=mkdir 111 | fi 112 | else 113 | 114 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 115 | # might cause directories to be created, which would be especially bad 116 | # if $src (and thus $dsttmp) contains '*'. 117 | 118 | if [ -f $src -o -d $src ] 119 | then 120 | true 121 | else 122 | echo "install: $src does not exist" 123 | exit 1 124 | fi 125 | 126 | if [ x"$dst" = x ] 127 | then 128 | echo "install: no destination specified" 129 | exit 1 130 | else 131 | true 132 | fi 133 | 134 | # If destination is a directory, append the input filename; if your system 135 | # does not like double slashes in filenames, you may need to add some logic 136 | 137 | if [ -d $dst ] 138 | then 139 | dst="$dst"/`basename $src` 140 | else 141 | true 142 | fi 143 | fi 144 | 145 | ## this sed command emulates the dirname command 146 | dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 147 | 148 | # Make sure that the destination directory exists. 149 | # this part is taken from Noah Friedman's mkinstalldirs script 150 | 151 | # Skip lots of stat calls in the usual case. 152 | if [ ! -d "$dstdir" ]; then 153 | defaultIFS=' 154 | ' 155 | IFS="${IFS-${defaultIFS}}" 156 | 157 | oIFS="${IFS}" 158 | # Some sh's can't handle IFS=/ for some reason. 159 | IFS='%' 160 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 161 | IFS="${oIFS}" 162 | 163 | pathcomp='' 164 | 165 | while [ $# -ne 0 ] ; do 166 | pathcomp="${pathcomp}${1}" 167 | shift 168 | 169 | if [ ! -d "${pathcomp}" ] ; 170 | then 171 | $mkdirprog "${pathcomp}" 172 | else 173 | true 174 | fi 175 | 176 | pathcomp="${pathcomp}/" 177 | done 178 | fi 179 | 180 | if [ x"$dir_arg" != x ] 181 | then 182 | $doit $instcmd $dst && 183 | 184 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && 185 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && 186 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && 187 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi 188 | else 189 | 190 | # If we're going to rename the final executable, determine the name now. 191 | 192 | if [ x"$transformarg" = x ] 193 | then 194 | dstfile=`basename $dst` 195 | else 196 | dstfile=`basename $dst $transformbasename | 197 | sed $transformarg`$transformbasename 198 | fi 199 | 200 | # don't allow the sed command to completely eliminate the filename 201 | 202 | if [ x"$dstfile" = x ] 203 | then 204 | dstfile=`basename $dst` 205 | else 206 | true 207 | fi 208 | 209 | # Make a temp file name in the proper directory. 210 | 211 | dsttmp=$dstdir/#inst.$$# 212 | 213 | # Move or copy the file name to the temp name 214 | 215 | $doit $instcmd $src $dsttmp && 216 | 217 | trap "rm -f ${dsttmp}" 0 && 218 | 219 | # and set any options; do chmod last to preserve setuid bits 220 | 221 | # If any of these fail, we abort the whole thing. If we want to 222 | # ignore errors from any of these, just make sure not to ignore 223 | # errors from the above "$doit $instcmd $src $dsttmp" command. 224 | 225 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && 226 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && 227 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && 228 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && 229 | 230 | # Now rename the file to the real destination. 231 | 232 | $doit $rmcmd -f $dstdir/$dstfile && 233 | $doit $mvcmd $dsttmp $dstdir/$dstfile 234 | 235 | fi && 236 | 237 | 238 | exit 0 239 | -------------------------------------------------------------------------------- /colormap.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * Colormap functions 4 | * 5 | * Author: William Jon McCann 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * 21 | * $Id: colormap.c,v 1.5 2004/04/21 20:13:09 mccannwj Exp $ 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include "getopt.h" 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | #include "fitscut.h" 42 | #include "colormap.h" 43 | #include "util.h" 44 | 45 | #ifdef DMALLOC 46 | #include 47 | #define DMALLOC_FUNC_CHECK 1 48 | #endif 49 | 50 | static void 51 | load_color (char *str, long nresult, float **list) 52 | { 53 | float *x, *y; 54 | long npoints; 55 | 56 | npoints = parse_coordinates (str, &x, &y); 57 | *list = interpolate_points (nresult, x, y, npoints); 58 | } 59 | 60 | static void 61 | heat_color_map_def (char **red, char **green, char **blue) 62 | { 63 | char *redStr = "(0,0)(.34,1)(1,1)"; 64 | char *greenStr = "(0,0)(1,1)"; 65 | char *blueStr = "(0,0)(.65,0)(.98,1)(1,1)"; 66 | *red = redStr; 67 | *green = greenStr; 68 | *blue = blueStr; 69 | } 70 | 71 | static void 72 | cool_color_map_def (char **red, char **green, char **blue) 73 | { 74 | char *redStr = "(0,0)(.29,0)(.76,.1)(1,1)"; 75 | char *greenStr = "(0,0)(.22,0)(.96,1)(1,1)"; 76 | char *blueStr = "(0,0)(.53,1)(1,1)"; 77 | *red = redStr; 78 | *green = greenStr; 79 | *blue = blueStr; 80 | } 81 | 82 | static void 83 | rainbow_color_map_def (char **red, char **green, char **blue) 84 | { 85 | char *redStr = "(0,1)(.2,0)(.6,0)(.8,1)(1,1)"; 86 | char *greenStr = "(0,0)(.2,0)(.4,1)(.8,1)(1,0)"; 87 | char *blueStr = "(0,1)(.4,1)(.6,0)(1,0)"; 88 | *red=redStr; 89 | *green=greenStr; 90 | *blue=blueStr; 91 | } 92 | 93 | static void 94 | red_color_map_def (char **red, char **green, char **blue) 95 | { 96 | char *redStr = "(0,0)(1,1)"; 97 | char *greenStr = "(0,0)(0,0)"; 98 | char *blueStr = "(0,0)(0,0)"; 99 | *red = redStr; 100 | *green = greenStr; 101 | *blue = blueStr; 102 | } 103 | 104 | static void 105 | green_color_map_def (char **red, char **green, char **blue) 106 | { 107 | char *redStr = "(0,0)(0,0)"; 108 | char *greenStr = "(0,0)(1,1)"; 109 | char *blueStr = "(0,0)(0,0)"; 110 | *red = redStr; 111 | *green = greenStr; 112 | *blue = blueStr; 113 | } 114 | 115 | static void 116 | blue_color_map_def (char **red, char **green, char **blue) 117 | { 118 | char *redStr = "(0,0)(0,0)"; 119 | char *greenStr = "(0,0)(0,0)"; 120 | char *blueStr = "(0,0)(1,1)"; 121 | *red = redStr; 122 | *green = greenStr; 123 | *blue = blueStr; 124 | } 125 | 126 | static ColorMap * 127 | get_colormap (int type, long nvals) 128 | { 129 | float *red, *green, *blue; 130 | char *redStr, *greenStr, *blueStr; 131 | ColorMap *CM; 132 | 133 | CM = (ColorMap *) malloc (sizeof (ColorMap)); 134 | switch (type) { 135 | case CMAP_COOL: 136 | cool_color_map_def (&redStr, &greenStr, &blueStr); 137 | break; 138 | case CMAP_RAINBOW: 139 | rainbow_color_map_def (&redStr, &greenStr, &blueStr); 140 | break; 141 | case CMAP_RED: 142 | red_color_map_def (&redStr, &greenStr, &blueStr); 143 | break; 144 | case CMAP_GREEN: 145 | green_color_map_def (&redStr, &greenStr, &blueStr); 146 | break; 147 | case CMAP_BLUE: 148 | blue_color_map_def (&redStr, &greenStr, &blueStr); 149 | break; 150 | case CMAP_HEAT: 151 | default: 152 | heat_color_map_def (&redStr, &greenStr, &blueStr); 153 | break; 154 | } 155 | 156 | load_color (redStr, nvals, &red); 157 | load_color (greenStr, nvals, &green); 158 | load_color (blueStr, nvals, &blue); 159 | CM->red = red; 160 | CM->green = green; 161 | CM->blue = blue; 162 | 163 | /* always put white at the top */ 164 | CM->red[nvals-1] = 1; 165 | CM->blue[nvals-1] = 1; 166 | CM->green[nvals-1] = 1; 167 | 168 | return (CM); 169 | } 170 | 171 | png_color * 172 | get_png_palette (int type, long nvals) 173 | { 174 | int i; 175 | ColorMap *CM; 176 | png_color *palette; 177 | long max_val; 178 | float f; 179 | 180 | palette = (png_color *) malloc (sizeof (png_color) * nvals); 181 | 182 | CM = get_colormap (type, nvals); 183 | 184 | /* scale the map channels */ 185 | max_val = nvals - 1; 186 | for (i = 0; i < nvals; i++) { 187 | f = CM->red[i] * max_val; 188 | palette[i].red = (unsigned char) f; 189 | f = CM->green[i] * max_val; 190 | palette[i].green = (unsigned char) f; 191 | f = CM->blue[i] * max_val; 192 | palette[i].blue = (unsigned char) f; 193 | } 194 | 195 | return palette; 196 | } 197 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | This is a generic INSTALL file for utilities distributions. 2 | Some features specific to fitscut have been added. 3 | 4 | To compile this package: 5 | 6 | 1. Configure the package for your system. In the directory that this 7 | file is in, type `./configure'. If you're using `csh' on an old 8 | version of System V, you might need to type `sh configure' instead to 9 | prevent `csh' from trying to execute `configure' itself. If you 10 | are using Ultrix, you might need to type `sh5 configure' to avoid 11 | bugs in /bin/sh. Note that 'sh -x configure' may give different results 12 | than 'sh configure', making it difficult to debug configure scripts. 13 | 14 | The `configure' shell script attempts to guess correct values for 15 | various system-dependent variables used during compilation, and 16 | creates the Makefile(s) (one in each subdirectory of the source 17 | directory). In some packages it creates a C header file containing 18 | system-dependent definitions. It also creates a file `config.status' 19 | that you can run in the future to recreate the current configuration. 20 | 21 | Running `configure' takes a minute or two. While it is running, it 22 | prints some messages that tell what it is doing. If you don't want to 23 | see the messages, run `configure' with its standard output redirected 24 | to `/dev/null'; for example, `./configure >/dev/null'. 25 | 26 | To compile the package in a different directory from the one 27 | containing the source code, you must use a version of `make' that 28 | supports the VPATH variable, such as GNU `make'. `cd' to the directory 29 | where you want the object files and executables to go and run 30 | `configure'. `configure' automatically checks for the source code in 31 | the directory that `configure' is in and in `..'. If for some reason 32 | `configure' is not in the source code directory that you are 33 | configuring, then it will report that it can't find the source code. 34 | In that case, run `configure' with the option `--srcdir=DIR', where 35 | DIR is the directory that contains the source code. 36 | 37 | By default, `make install' will install the package's files in 38 | /usr/local/bin, /usr/local/lib, /usr/local/man, etc. You can specify an 39 | installation prefix other than /usr/local by giving `configure' the option 40 | `--prefix=PATH'. Alternately, you can do so by consistently giving a value 41 | for the `prefix' variable when you run `make', e.g., 42 | make prefix=/usr/gnu 43 | make prefix=/usr/gnu install 44 | 45 | You can specify separate installation prefixes for 46 | architecture-specific files and architecture-independent files. If 47 | you give `configure' the option `--exec-prefix=PATH' or set the 48 | `make' variable `exec_prefix' to PATH, the package will use PATH as 49 | the prefix for installing programs and libraries. Data files and 50 | documentation will still use the regular prefix. Normally, all files 51 | are installed using the regular prefix. 52 | 53 | Another `configure' option is useful mainly in `Makefile' rules for 54 | updating `config.status' and `Makefile'. The `--no-create' option 55 | figures out the configuration for your system and records it in 56 | `config.status', without actually configuring the package (creating 57 | `Makefile's and perhaps a configuration header file). Later, you can 58 | run `./config.status' to actually configure the package. You can also 59 | give `config.status' the `--recheck' option, which makes it re-run 60 | `configure' with the same arguments you used before. This option is 61 | useful if you change `configure'. 62 | 63 | `configure' ignores any other arguments that you give it. 64 | 65 | If your system requires unusual options for compilation or linking 66 | that `configure' doesn't know about, you can give `configure' initial 67 | values for some variables by setting them in the environment. In 68 | Bourne-compatible shells, you can do that on the command line like 69 | this: 70 | CC='gcc -traditional' DEFS=-D_POSIX_SOURCE ./configure 71 | 72 | For csh compatible shells, you can do something like this: 73 | 74 | (setenv CC 'gcc -traditional' ; ./configure) 75 | 76 | The `make' variables that you might want to override with environment 77 | variables when running `configure' are: 78 | 79 | (For these variables, any value given in the environment overrides the 80 | value that `configure' would choose:) 81 | CC C compiler program. 82 | Default is `cc', or `gcc' if `gcc' is in your PATH. 83 | INSTALL Program to use to install files. 84 | Default is `install' if you have it, `cp' otherwise. 85 | If you have an non-standard `install', use INSTALL="cp -p" 86 | 87 | (For these variables, any value given in the environment is added to 88 | the value that `configure' chooses:) 89 | DEFS Configuration options, in the form `-Dfoo -Dbar ...' 90 | CFLAGS Compiler options, such as `-O -g ...' 91 | LIBS Libraries to link with, in the form `-lfoo -lbar ...' 92 | 93 | If you need to do unusual things to compile the package, we encourage 94 | you to figure out how `configure' could check whether to do them, and 95 | mail diffs or instructions to the address given in the README so we 96 | can include them in the next release. 97 | 98 | Note: if your CFITSIO header files are not in a directory searched 99 | by default you will have to specify their location like this: 100 | 101 | setenv CFLAGS '-I/usr/local/include/cfitsio' 102 | 103 | Examine the Makefile that configure produces and uncomment lines as 104 | necessary. 105 | 106 | 2. Type `make' to compile the package. If you want, you can override 107 | the `make' variables CFLAGS and LDFLAGS like this: 108 | 109 | make CFLAGS=-O2 LDFLAGS=-s 110 | 111 | 3. The package comes with self-tests. If you want to run them, 112 | type `make check'. 113 | 114 | 4. Type `make install' to install programs, data files, and 115 | documentation. 116 | 117 | The man pages are installed by default with an extension `.1' (one). 118 | If you want the extension `.l' (lower case L) use: 119 | 120 | make manext=l install 121 | 122 | If you are using csh or tcsh, you must type `rehash' after `make install' 123 | to make sure that the command `fitscut' will invoke the new executable. 124 | 125 | 5. You can remove the program binaries and object files from the 126 | source directory by typing `make clean'. To also remove the 127 | Makefile(s), the header file containing system-dependent definitions 128 | (if the package uses one), and `config.status' (all the files that 129 | `configure' created), type `make distclean'. 130 | 131 | The file `configure.in' is used as a template to create `configure' by 132 | a program called `autoconf'. You will only need it if you want to 133 | regenerate `configure' using a newer version of `autoconf'. 134 | 135 | 6. Special targets 136 | 137 | -------------------------------------------------------------------------------- /fitscut.h: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * fitscut.h -- declarations for fitscut 4 | * Copyright (C) 1999 William Jon McCann 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | * 20 | * $Id: fitscut.h,v 1.26 2004/04/29 22:22:30 mccannwj Exp $ 21 | */ 22 | 23 | #include 24 | 25 | #if defined(__STDC__) || defined(PROTO) 26 | # define OF(args) args 27 | #else 28 | # define OF(args) () 29 | #endif 30 | 31 | #ifndef RETSIGTYPE 32 | # define RETSIGTYPE void 33 | #endif 34 | 35 | #define strequ(s1, s2) (strcmp((s1),(s2)) == 0) 36 | 37 | typedef RETSIGTYPE (*sig_type) OF((int)); 38 | 39 | #ifndef SET_BINARY_MODE 40 | # define SET_BINARY_MODE(fd) 41 | #endif 42 | 43 | #ifndef O_BINARY 44 | # define O_BINARY 0 /* creation mode for open() */ 45 | #endif 46 | 47 | #if !defined(S_ISDIR) && defined(S_IFDIR) 48 | # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 49 | #endif 50 | #if !defined(S_ISREG) && defined(S_IFREG) 51 | # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 52 | #endif 53 | 54 | #ifndef MAX_PATH_LEN 55 | # define MAX_PATH_LEN 1024 /* max pathname length */ 56 | #endif 57 | 58 | /* Separator for file name parts (see shorten_name()) */ 59 | #ifdef NO_MULTIPLE_DOTS 60 | # define PART_SEP "-" 61 | #else 62 | # define PART_SEP "." 63 | #endif 64 | 65 | #define BYTE unsigned char 66 | #define WORD unsigned short int 67 | #define LWORD unsigned long 68 | #define SPACE 32 69 | #define DEL 127 70 | #define ICSIZE 100 71 | 72 | /* NAN is already defined in C99 */ 73 | #ifndef NAN 74 | #define NAN (0.0/0.0) 75 | #endif 76 | 77 | #ifndef TRUE 78 | #define TRUE (1==1) 79 | #endif /* TRUE */ 80 | 81 | #ifndef FALSE 82 | #define FALSE !(TRUE) 83 | #endif /* FALSE */ 84 | 85 | /* Return codes */ 86 | #define OK 0 87 | #define ERROR 1 88 | #define WARNING 2 89 | 90 | #define tolow(c) (isupper(c) ? (c)-'A'+'a' : (c)) /* force to lower case */ 91 | 92 | #define WARN(msg) {if (!quiet) fprintf msg ; \ 93 | if (exit_code == OK) exit_code = WARNING;} 94 | 95 | #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) 96 | #define MAX(X,Y) ((X) < (Y) ? (Y) : (X)) 97 | 98 | typedef enum { 99 | OUTPUT_FITS = 0, 100 | OUTPUT_PNG, 101 | OUTPUT_JPG, 102 | OUTPUT_JSON, 103 | OUTPUT_RANGE 104 | } FitscutOutputFormat; 105 | 106 | typedef enum { 107 | SCALE_LINEAR = 0, 108 | SCALE_LOG, 109 | SCALE_SQRT, 110 | SCALE_HISTEQ, 111 | SCALE_FACTOR, 112 | SCALE_RATE, 113 | SCALE_ASINH 114 | } FitscutScaleType; 115 | 116 | typedef enum { 117 | SCALE_MODE_MINMAX = 0, 118 | SCALE_MODE_AUTO, 119 | SCALE_MODE_FULL, 120 | SCALE_MODE_USER 121 | } FitscutScaleMode; 122 | 123 | typedef enum { 124 | CMAP_GRAY = 0, 125 | CMAP_HEAT, 126 | CMAP_COOL, 127 | CMAP_RAINBOW, 128 | CMAP_RED, 129 | CMAP_GREEN, 130 | CMAP_BLUE 131 | } FitscutColormapType; 132 | 133 | typedef enum { 134 | ALIGN_NONE = 0, 135 | ALIGN_REF, 136 | ALIGN_NORTH, 137 | ALIGN_USER_WCS 138 | } FitscutAlignType; 139 | 140 | RETSIGTYPE abort_fitscut (void); 141 | void do_exit (int); 142 | void fitscut_error (char *); 143 | void fitscut_message (int level, const char *format, ...); 144 | 145 | #define NBINS 50000 146 | #define NSAMPLE 250000 147 | #define MINSAMPLEROWS 10 148 | 149 | extern int foreground; /* set if program run in foreground */ 150 | extern int force; /* don't ask questions, overwrite (-f) */ 151 | extern int to_stdout; /* output to stdout (-c) */ 152 | extern int verbose; /* be verbose (-v) */ 153 | extern int quiet; /* be very quiet (-q) */ 154 | extern int exit_code; /* program exit code */ 155 | 156 | #define MAX_CHANNELS 3 157 | 158 | #define MAGIC_SIZE_ALL_NUMBER 999999 159 | 160 | typedef struct fitscut_image { 161 | int output_type; 162 | int output_scale; 163 | int output_colormap; 164 | int output_scale_mode; 165 | int output_alignment; 166 | int output_compass; 167 | int output_marker; 168 | int output_invert; 169 | int output_add_blurb; 170 | int jpeg_quality; 171 | float output_zoom[MAX_CHANNELS]; 172 | int output_size; 173 | char *input_filename[MAX_CHANNELS]; 174 | char *input_blurbfile; 175 | int input_datatype[MAX_CHANNELS]; 176 | int input_wcscoords[MAX_CHANNELS]; 177 | int input_x_corner[MAX_CHANNELS], input_y_corner[MAX_CHANNELS]; 178 | double input_x[MAX_CHANNELS], input_y[MAX_CHANNELS]; 179 | char *output_filename; 180 | int channels; 181 | double x0[MAX_CHANNELS], y0[MAX_CHANNELS]; 182 | long ncols[MAX_CHANNELS], nrows[MAX_CHANNELS]; 183 | double user_min[MAX_CHANNELS]; 184 | int user_min_set; 185 | double user_max[MAX_CHANNELS]; 186 | int user_max_set; 187 | double user_scale_factor[MAX_CHANNELS]; 188 | int user_scale_factor_set; 189 | int qext[MAX_CHANNELS]; 190 | int qext_set; 191 | int qext_bad_value[MAX_CHANNELS]; 192 | int useBadpix; 193 | int useBsoften; 194 | float bad_data_value[MAX_CHANNELS]; 195 | float badmin[MAX_CHANNELS]; 196 | float badmax[MAX_CHANNELS]; 197 | double autoscale_percent_low[MAX_CHANNELS]; 198 | double autoscale_percent_high[MAX_CHANNELS]; 199 | double autoscale_min[MAX_CHANNELS], autoscale_max[MAX_CHANNELS]; 200 | int autoscale_performed; 201 | double data_min[MAX_CHANNELS], data_max[MAX_CHANNELS]; 202 | float *histogram[MAX_CHANNELS]; 203 | float *data[MAX_CHANNELS]; 204 | char *header[MAX_CHANNELS]; 205 | int header_cards[MAX_CHANNELS]; 206 | struct WorldCoor *wcs[MAX_CHANNELS]; 207 | /* reference coordinates for resampling image */ 208 | char *reference_filename; 209 | struct WorldCoor *wcsref; 210 | double x0ref, y0ref; 211 | double output_zoomref; 212 | long ncolsref, nrowsref; 213 | } FitsCutImage; 214 | -------------------------------------------------------------------------------- /tailor.h: -------------------------------------------------------------------------------- 1 | /* tailor.h -- target dependent definitions */ 2 | /* $Id: tailor.h,v 1.1 2001/11/06 00:36:46 mccannwj Exp $ */ 3 | 4 | #if defined(__MSDOS__) && !defined(MSDOS) 5 | # define MSDOS 6 | #endif 7 | 8 | #if defined(__OS2__) && !defined(OS2) 9 | # define OS2 10 | #endif 11 | 12 | #if defined(OS2) && defined(MSDOS) /* MS C under OS/2 */ 13 | # undef MSDOS 14 | #endif 15 | 16 | #ifdef MSDOS 17 | # ifdef __GNUC__ 18 | /* DJGPP version 1.09+ on MS-DOS. 19 | * The DJGPP 1.09 stat() function must be upgraded before gzip will 20 | * fully work. 21 | * No need for DIRENT, since defines POSIX_SOURCE which 22 | * implies DIRENT. 23 | */ 24 | # define near 25 | # else 26 | # define MAXSEG_64K 27 | # ifdef __TURBOC__ 28 | # define NO_OFF_T 29 | # ifdef __BORLANDC__ 30 | # define DIRENT 31 | # else 32 | # define NO_UTIME 33 | # endif 34 | # else /* MSC */ 35 | # define HAVE_SYS_UTIME_H 36 | # define NO_UTIME_H 37 | # endif 38 | # endif 39 | # define PATH_SEP2 '\\' 40 | # define PATH_SEP3 ':' 41 | # define MAX_PATH_LEN 128 42 | # define NO_MULTIPLE_DOTS 43 | # define MAX_EXT_CHARS 3 44 | # define FITS_SUFFIX "fit" 45 | # define NO_CHOWN 46 | # define PROTO 47 | # define STDC_HEADERS 48 | # define NO_SIZE_CHECK 49 | # define casemap(c) tolow(c) /* Force file names to lower case */ 50 | # include 51 | # define OS_CODE 0x00 52 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 53 | #else 54 | # define near 55 | #endif 56 | 57 | #ifdef OS2 58 | # define PATH_SEP2 '\\' 59 | # define PATH_SEP3 ':' 60 | # define MAX_PATH_LEN 260 61 | # ifdef OS2FAT 62 | # define NO_MULTIPLE_DOTS 63 | # define MAX_EXT_CHARS 3 64 | # define FITS_SUFFIX "fit" 65 | # define casemap(c) tolow(c) 66 | # endif 67 | # define NO_CHOWN 68 | # define PROTO 69 | # define STDC_HEADERS 70 | # include 71 | # define OS_CODE 0x06 72 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 73 | # ifdef _MSC_VER 74 | # define HAVE_SYS_UTIME_H 75 | # define NO_UTIME_H 76 | # define MAXSEG_64K 77 | # undef near 78 | # define near _near 79 | # endif 80 | # ifdef __EMX__ 81 | # define HAVE_SYS_UTIME_H 82 | # define NO_UTIME_H 83 | # define DIRENT 84 | # define EXPAND(argc,argv) \ 85 | {_response(&argc, &argv); _wildcard(&argc, &argv);} 86 | # endif 87 | # ifdef __BORLANDC__ 88 | # define DIRENT 89 | # endif 90 | # ifdef __ZTC__ 91 | # define NO_DIR 92 | # define NO_UTIME_H 93 | # include 94 | # define EXPAND(argc,argv) \ 95 | {response_expand(&argc, &argv);} 96 | # endif 97 | #endif 98 | 99 | #ifdef WIN32 /* Windows NT */ 100 | # define HAVE_SYS_UTIME_H 101 | # define NO_UTIME_H 102 | # define PATH_SEP2 '\\' 103 | # define PATH_SEP3 ':' 104 | # define MAX_PATH_LEN 260 105 | # define NO_CHOWN 106 | # define PROTO 107 | # define STDC_HEADERS 108 | # define SET_BINARY_MODE(fd) setmode(fd, O_BINARY) 109 | # include 110 | # include 111 | # ifdef NTFAT 112 | # define NO_MULTIPLE_DOTS 113 | # define MAX_EXT_CHARS 3 114 | # define FITS_SUFFIX "fit" 115 | # define casemap(c) tolow(c) /* Force file names to lower case */ 116 | # endif 117 | # define OS_CODE 0x0b 118 | #endif 119 | 120 | #ifdef MSDOS 121 | # ifdef __TURBOC__ 122 | # include 123 | # define DYN_ALLOC 124 | /* Turbo C 2.0 does not accept static allocations of large arrays */ 125 | void * fcalloc (unsigned items, unsigned size); 126 | void fcfree (void *ptr); 127 | # else /* MSC */ 128 | # include 129 | # define fcalloc(nitems,itemsize) halloc((long)(nitems),(itemsize)) 130 | # define fcfree(ptr) hfree(ptr) 131 | # endif 132 | #else 133 | # ifdef MAXSEG_64K 134 | # define fcalloc(items,size) calloc((items),(size)) 135 | # else 136 | # define fcalloc(items,size) malloc((size_t)(items)*(size_t)(size)) 137 | # endif 138 | # define fcfree(ptr) free(ptr) 139 | #endif 140 | 141 | #if defined(VAXC) || defined(VMS) 142 | # define PATH_SEP ']' 143 | # define PATH_SEP2 ':' 144 | # define SUFFIX_SEP ';' 145 | # define NO_MULTIPLE_DOTS 146 | # define FITS_SUFFIX "-fits" 147 | # define RECORD_IO 1 148 | # define casemap(c) tolow(c) 149 | # define OS_CODE 0x02 150 | # define STDC_HEADERS 151 | # define NO_UTIME 152 | # define EXPAND(argc,argv) vms_expand_args(&argc,&argv); 153 | # include 154 | # define unlink delete 155 | # ifdef VAXC 156 | # define NO_FCNTL_H 157 | # include 158 | # endif 159 | #endif 160 | 161 | #ifdef AMIGA 162 | # define PATH_SEP2 ':' 163 | # define STDC_HEADERS 164 | # define OS_CODE 0x01 165 | # ifdef __GNUC__ 166 | # define DIRENT 167 | # define HAVE_UNISTD_H 168 | # else /* SASC */ 169 | # define NO_STDIN_FSTAT 170 | # define SYSDIR 171 | # define NO_SYMLINK 172 | # define NO_CHOWN 173 | # define NO_FCNTL_H 174 | # include /* for read() and write() */ 175 | # define direct dirent 176 | extern void _expand_args(int *argc, char ***argv); 177 | # define EXPAND(argc,argv) _expand_args(&argc,&argv); 178 | # undef O_BINARY /* disable useless --ascii option */ 179 | # endif 180 | #endif 181 | 182 | #if defined(ATARI) || defined(atarist) 183 | # ifndef STDC_HEADERS 184 | # define STDC_HEADERS 185 | # define HAVE_UNISTD_H 186 | # define DIRENT 187 | # endif 188 | # define OS_CODE 0x05 189 | # ifdef TOSFS 190 | # define PATH_SEP2 '\\' 191 | # define PATH_SEP3 ':' 192 | # define MAX_PATH_LEN 128 193 | # define NO_MULTIPLE_DOTS 194 | # define MAX_EXT_CHARS 3 195 | # define FITS_SUFFIX "fit" 196 | # define NO_CHOWN 197 | # define casemap(c) tolow(c) /* Force file names to lower case */ 198 | # define NO_SYMLINK 199 | # endif 200 | #endif 201 | 202 | #ifdef MACOS 203 | # define PATH_SEP ':' 204 | # define DYN_ALLOC 205 | # define PROTO 206 | # define NO_STDIN_FSTAT 207 | # define NO_CHOWN 208 | # define NO_UTIME 209 | # define chmod(file, mode) (0) 210 | # define OPEN(name, flags, mode) open(name, flags) 211 | # define OS_CODE 0x07 212 | # ifdef MPW 213 | # define isatty(fd) ((fd) <= 2) 214 | # endif 215 | #endif 216 | 217 | #ifdef __50SERIES /* Prime/PRIMOS */ 218 | # define PATH_SEP '>' 219 | # define STDC_HEADERS 220 | # define NO_MEMORY_H 221 | # define NO_UTIME_H 222 | # define NO_UTIME 223 | # define NO_CHOWN 224 | # define NO_STDIN_FSTAT 225 | # define NO_SIZE_CHECK 226 | # define NO_SYMLINK 227 | # define RECORD_IO 1 228 | # define casemap(c) tolow(c) /* Force file names to lower case */ 229 | # define put_char(c) put_byte((c) & 0x7F) 230 | # define get_char(c) ascii2pascii(get_byte()) 231 | # define OS_CODE 0x0F /* temporary, subject to change */ 232 | # ifdef SIGTERM 233 | # undef SIGTERM /* We don't want a signal handler for SIGTERM */ 234 | # endif 235 | #endif 236 | 237 | #if defined(pyr) && !defined(NOMEMCPY) /* Pyramid */ 238 | # define NOMEMCPY /* problem with overlapping copies */ 239 | #endif 240 | 241 | #ifdef TOPS20 242 | # define OS_CODE 0x0a 243 | #endif 244 | 245 | #ifndef unix 246 | # define NO_ST_INO /* don't rely on inode numbers */ 247 | #endif 248 | 249 | 250 | /* Common defaults */ 251 | 252 | #ifndef OS_CODE 253 | # define OS_CODE 0x03 /* assume Unix */ 254 | #endif 255 | 256 | #ifndef PATH_SEP 257 | # define PATH_SEP '/' 258 | #endif 259 | 260 | #ifndef casemap 261 | # define casemap(c) (c) 262 | #endif 263 | 264 | #ifndef FITS_SUFFIX 265 | # define FITS_SUFFIX ".fits" 266 | #endif 267 | 268 | #ifdef MAX_EXT_CHARS 269 | # define MAX_SUFFIX MAX_EXT_CHARS 270 | #else 271 | # define MAX_SUFFIX 30 272 | #endif 273 | 274 | #ifndef MAKE_LEGAL_NAME 275 | # ifdef NO_MULTIPLE_DOTS 276 | # define MAKE_LEGAL_NAME(name) make_simple_name(name) 277 | # else 278 | # define MAKE_LEGAL_NAME(name) 279 | # endif 280 | #endif 281 | 282 | #ifndef MIN_PART 283 | # define MIN_PART 3 284 | /* keep at least MIN_PART chars between dots in a file name. */ 285 | #endif 286 | 287 | #ifndef EXPAND 288 | # define EXPAND(argc,argv) 289 | #endif 290 | 291 | #ifndef RECORD_IO 292 | # define RECORD_IO 0 293 | #endif 294 | 295 | #ifndef SET_BINARY_MODE 296 | # define SET_BINARY_MODE(fd) 297 | #endif 298 | 299 | #ifndef OPEN 300 | # define OPEN(name, flags, mode) open(name, flags, mode) 301 | #endif 302 | 303 | #ifndef get_char 304 | # define get_char() get_byte() 305 | #endif 306 | 307 | #ifndef put_char 308 | # define put_char(c) put_byte(c) 309 | #endif 310 | -------------------------------------------------------------------------------- /resize.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * Image resizing functions 4 | * 5 | * Author: William Jon McCann 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * 21 | * $Id: resize.c,v 1.9 2004/05/11 22:05:06 mccannwj Exp $ 22 | * 23 | * Extensively modified 2006 October 11 by R. White (including 24 | * both interface and algorithm changes) 25 | * Added exact_resize_image_channel, RLW, 2007 March 6 26 | * Skip zero pixels in resize_image_channel_reduce, RLW, 2008 January 9 27 | */ 28 | 29 | /* make lround work ok with old gcc on linux */ 30 | #define _ISOC99_SOURCE 31 | 32 | #ifdef HAVE_CONFIG_H 33 | #include 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #ifdef HAVE_STRING_H 45 | #include 46 | #else 47 | #include 48 | #endif 49 | 50 | #ifdef HAVE_CFITSIO_FITSIO_H 51 | #include 52 | #else 53 | #include 54 | #endif 55 | 56 | #include "fitscut.h" 57 | #include "resize.h" 58 | 59 | #ifdef DMALLOC 60 | #include 61 | #define DMALLOC_FUNC_CHECK 1 62 | #endif 63 | 64 | /* get the size for (possibly intermediate) integral zoom scaling of the image */ 65 | 66 | void 67 | get_zoom_size_channel (int ncols, int nrows, float zoom_factor, int output_size, 68 | int *pixfac, int *zoomcols, int *zoomrows, int *doshrink) 69 | { 70 | int maxsize; 71 | 72 | if (output_size > 0) { 73 | 74 | /* fixed output size */ 75 | 76 | maxsize = (ncols > nrows) ? ncols : nrows; 77 | *pixfac = maxsize/output_size; 78 | if (*pixfac > 1) { 79 | *zoomcols = (ncols-1) / (*pixfac) + 1; 80 | if (*zoomcols<1) *zoomcols = 1; 81 | *zoomrows = (nrows-1) / (*pixfac) + 1; 82 | if (*zoomrows<1) *zoomrows = 1; 83 | *doshrink = 1; 84 | } else { 85 | /* no rebinning if output is larger than input */ 86 | *pixfac = 1; 87 | *zoomcols = ncols; 88 | *zoomrows = nrows; 89 | *doshrink = 0; 90 | } 91 | } else { 92 | if (zoom_factor <=0 || zoom_factor == 1) { 93 | /* no zoom */ 94 | *pixfac = 1; 95 | *zoomcols = ncols; 96 | *zoomrows = nrows; 97 | *doshrink = 0; 98 | } else if (zoom_factor > 1) { 99 | /* zoom expanding */ 100 | *pixfac = lround(zoom_factor); 101 | *zoomcols = ncols * (*pixfac); 102 | *zoomrows = nrows * (*pixfac); 103 | *doshrink = 0; 104 | } else { 105 | /* zoom shrinking */ 106 | *pixfac = lround(1./zoom_factor); 107 | *zoomcols = (ncols-1) / (*pixfac) + 1; 108 | if (*zoomcols<1) *zoomcols = 1; 109 | *zoomrows = (nrows-1) / (*pixfac) + 1; 110 | if (*zoomrows<1) *zoomrows = 1; 111 | *doshrink = 1; 112 | } 113 | } 114 | } 115 | 116 | void 117 | exact_resize_image_channel (FitsCutImage *srcImagePtr, int k, int output_size) 118 | { 119 | FitsCutImage destImage; 120 | int orig_width, orig_height, maxsize; 121 | 122 | orig_width = srcImagePtr->ncols[k]; 123 | orig_height = srcImagePtr->nrows[k]; 124 | maxsize = (orig_width > orig_height) ? orig_width : orig_height; 125 | 126 | /* we're done if size matches */ 127 | if (maxsize == output_size) return; 128 | 129 | /* use simple interpolation to get desired size */ 130 | interpolate_image (srcImagePtr, &destImage, k, output_size); 131 | free (srcImagePtr->data[k]); 132 | srcImagePtr->data[k] = destImage.data[k]; 133 | destImage.data[k] = NULL; 134 | srcImagePtr->ncols[k] = destImage.ncols[k]; 135 | srcImagePtr->nrows[k] = destImage.nrows[k]; 136 | srcImagePtr->output_zoom[k] = destImage.output_zoom[k]; 137 | } 138 | 139 | /* modify reference header parameters for exact-resize scaling */ 140 | 141 | void 142 | exact_resize_reference (FitsCutImage *Image, int output_size) 143 | { 144 | int width, height, orig_width, orig_height, maxsize; 145 | double zoom_factor, orig_zoom; 146 | 147 | orig_width = Image->ncolsref; 148 | orig_height = Image->nrowsref; 149 | orig_zoom = Image->output_zoomref; 150 | if (orig_zoom == 0) orig_zoom = 1.0; 151 | 152 | if (orig_width > orig_height) { 153 | maxsize = orig_width; 154 | width = output_size; 155 | zoom_factor = ((double) width)/orig_width; 156 | height = lround(zoom_factor*orig_height); 157 | if (height<1) height = 1; 158 | } else { 159 | maxsize = orig_height; 160 | height = output_size; 161 | zoom_factor = ((double) height)/orig_height; 162 | width = lround(zoom_factor*orig_width); 163 | if (width<1) width = 1; 164 | } 165 | 166 | /* we're done if size matches */ 167 | if (maxsize == output_size) return; 168 | 169 | Image->output_zoomref = zoom_factor * orig_zoom; 170 | Image->ncolsref = width; 171 | Image->nrowsref = height; 172 | } 173 | 174 | void 175 | reduce_array (float *input, float *output, int orig_width, int orig_height, int pixfac, float bad_data_value) 176 | { 177 | float *src; 178 | float *dest; 179 | int width, height; 180 | int x, y, i, j, jmin, jmax; 181 | int *count; 182 | 183 | width = (orig_width-1)/pixfac + 1; 184 | if (width<1) width = 1; 185 | height = (orig_height-1)/pixfac + 1; 186 | if (height<1) height = 1; 187 | 188 | count = (int *) malloc (width * sizeof (int)); 189 | 190 | for (y=0; y orig_height) jmax = orig_height; 199 | for (j=jmin; j 0) { 211 | dest[x] /= count[x]; 212 | } else { 213 | dest[x] = NAN; 214 | } 215 | } 216 | } 217 | free(count); 218 | } 219 | 220 | void 221 | enlarge_array (float *input, float *output, int orig_width, int orig_height, int pixfac) 222 | { 223 | float *src; 224 | float *dest; 225 | int width, height; 226 | int x, y, j; 227 | 228 | width = orig_width*pixfac; 229 | height = orig_height*pixfac; 230 | 231 | for (j=0; jncols[k]; 259 | orig_height = srcImagePtr->nrows[k]; 260 | if (orig_width > orig_height) { 261 | width = output_size; 262 | zoom_factor = ((double) width)/orig_width; 263 | height = lround(zoom_factor*orig_height); 264 | if (height<1) height = 1; 265 | } else { 266 | height = output_size; 267 | zoom_factor = ((double) height)/orig_height; 268 | width = lround(zoom_factor*orig_width); 269 | if (width<1) width = 1; 270 | } 271 | 272 | destImagePtr->output_zoom[k] = zoom_factor * srcImagePtr->output_zoom[k]; 273 | destImagePtr->ncols[k] = width; 274 | destImagePtr->nrows[k] = height; 275 | destImagePtr->data[k] = (float *) malloc (width * height * sizeof (float)); 276 | 277 | fitscut_message (2, "\tresizing channel to x=%d y=%d from x=%d y=%d\n", 278 | width, height, orig_width, orig_height); 279 | 280 | /* nearest neighbor interpolation */ 281 | for (y=0; ydata[k] + y*width; 285 | src1 = srcImagePtr->data[k] + j*orig_width; 286 | for (x=0; xdata[k] + y*width; 301 | src1 = srcImagePtr->data[k] + j*orig_width; 302 | src2 = src1 + orig_width; 303 | for (x=0; x 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "getopt.h" 34 | #include 35 | #include 36 | 37 | #ifdef HAVE_STRING_H 38 | #include 39 | #else 40 | #include 41 | #endif 42 | 43 | #ifdef HAVE_UNISTD_H 44 | # include 45 | #endif 46 | 47 | #include "fitscut.h" 48 | #include "tailor.h" 49 | #include "file_check.h" 50 | 51 | #include "util.h" 52 | 53 | extern char *progname; 54 | extern int foreground; 55 | 56 | char fits_suffix[MAX_SUFFIX+1]; /* default suffix */ 57 | int suffix_len; /* strlen(fits_suffix) */ 58 | struct stat istat; /* status for input file */ 59 | 60 | /* 61 | * Use lstat if available, except for -c or -f. Use stat otherwise. 62 | * This allows links when not removing the original file. 63 | */ 64 | static int 65 | do_stat (char *name, struct stat *sbuf) 66 | { 67 | errno = 0; 68 | #if (defined(S_IFLNK) || defined (S_ISLNK)) && !defined(NO_SYMLINK) 69 | if (!to_stdout && !force) { 70 | return lstat (name, sbuf); 71 | } 72 | #endif 73 | return stat (name, sbuf); 74 | } 75 | 76 | static int 77 | get_istat (char *iname, struct stat *sbuf) 78 | { 79 | /* If input file exists, return OK. */ 80 | if (do_stat (iname, sbuf) == 0) 81 | return OK; 82 | 83 | if (errno != ENOENT) { 84 | perror (iname); 85 | exit_code = ERROR; 86 | return ERROR; 87 | } 88 | 89 | perror (iname); 90 | exit_code = ERROR; 91 | return ERROR; 92 | } 93 | 94 | /* 95 | * Generate ofname. Return OK, or WARNING if file must be skipped. 96 | * Sets save_orig_name to true if the file name has been truncated. 97 | */ 98 | int 99 | make_output_name (char *ofname, char *oname) 100 | { 101 | sprintf (ofname, "%s", oname); 102 | return OK; 103 | } 104 | 105 | /* 106 | * Return true if the two stat structures correspond to the same file. 107 | */ 108 | static int 109 | same_file (struct stat *stat1, struct stat *stat2) 110 | { 111 | return stat1->st_ino == stat2->st_ino 112 | && stat1->st_dev == stat2->st_dev 113 | #ifdef NO_ST_INO 114 | /* Can't rely on st_ino and st_dev, use other fields: */ 115 | && stat1->st_mode == stat2->st_mode 116 | && stat1->st_uid == stat2->st_uid 117 | && stat1->st_gid == stat2->st_gid 118 | && stat1->st_size == stat2->st_size 119 | && stat1->st_atime == stat2->st_atime 120 | && stat1->st_mtime == stat2->st_mtime 121 | && stat1->st_ctime == stat2->st_ctime 122 | #endif 123 | ; 124 | } 125 | 126 | /* 127 | * Return true if a file name is ambiguous because the operating system 128 | * truncates file names. 129 | */ 130 | static int 131 | name_too_long (char *name, struct stat *statb) 132 | { 133 | int s = strlen (name); 134 | char c = name[s-1]; 135 | struct stat tstat; /* stat for truncated name */ 136 | int res; 137 | 138 | tstat = *statb; /* Just in case OS does not fill all fields */ 139 | name[s-1] = '\0'; 140 | res = stat (name, &tstat) == 0 && same_file (statb, &tstat); 141 | name[s-1] = c; 142 | 143 | return res; 144 | } 145 | 146 | static void 147 | shorten_name (char *name) 148 | { 149 | fprintf (stderr, "%s: error: output file name too long: %s\n", 150 | progname, name); 151 | do_exit (ERROR); 152 | } 153 | 154 | /* 155 | * Check if ofname is not ambiguous 156 | * because the operating system truncates names. Otherwise, generate 157 | * a new ofname and save the original name in the compressed file. 158 | * If the compressed file already exists, ask for confirmation. 159 | * The check for name truncation is made dynamically, because different 160 | * file systems on the same OS might use different truncation rules (on SVR4 161 | * s5 truncates to 14 chars and ufs does not truncate). 162 | * This function returns -1 if the file must be skipped, and 163 | * updates save_orig_name if necessary. 164 | * IN assertions: save_orig_name is already set if ofname has been 165 | * already truncated because of NO_MULTIPLE_DOTS. The input file has 166 | * already been open and istat is set. 167 | */ 168 | int 169 | check_output_file (char *ofname, char *ifname) 170 | { 171 | struct stat ostat; /* stat for ofname */ 172 | 173 | #ifdef ENAMETOOLONG 174 | /* Check for strictly conforming Posix systems (which return ENAMETOOLONG 175 | * instead of silently truncating filenames). 176 | */ 177 | errno = 0; 178 | while (stat (ofname, &ostat) != 0) { 179 | if (errno != ENAMETOOLONG) return 0; /* ofname does not exist */ 180 | shorten_name (ofname); 181 | } 182 | #else 183 | if (stat (ofname, &ostat) != 0) { 184 | return 0; 185 | } 186 | #endif 187 | 188 | /* Check for name truncation on existing file. Do this even on systems 189 | * defining ENAMETOOLONG, because on most systems the strict Posix 190 | * behavior is disabled by default (silent name truncation allowed). 191 | */ 192 | if (name_too_long (ofname, &ostat)) { 193 | shorten_name (ofname); 194 | if (stat (ofname, &ostat) != 0) 195 | return 0; 196 | } 197 | /* Check that the input and output files are different (could be 198 | * the same by name truncation or links). 199 | */ 200 | if (same_file (&istat, &ostat)) { 201 | if (strequ (ifname, ofname)) { 202 | fprintf (stderr, "%s: %s: cannot convert onto itself\n", 203 | progname, ifname ); 204 | } else { 205 | fprintf (stderr, "%s: %s and %s are the same file\n", 206 | progname, ifname, ofname); 207 | } 208 | exit_code = ERROR; 209 | return ERROR; 210 | } 211 | /* Ask permission to overwrite the existing file */ 212 | if (!force) { 213 | char response[80]; 214 | strcpy (response,"n"); 215 | fprintf (stderr, "%s: %s already exists;", progname, ofname); 216 | if (foreground && isatty (fileno (stdin))) { 217 | fprintf (stderr, " do you wish to overwrite (y or n)? "); 218 | fflush (stderr); 219 | (void)fgets (response, sizeof (response)-1, stdin); 220 | } 221 | if (tolow (*response) != 'y') { 222 | fprintf (stderr, "\tnot overwritten\n"); 223 | if (exit_code == OK) 224 | exit_code = WARNING; 225 | return ERROR; 226 | } 227 | } 228 | (void) chmod (ofname, 0777); 229 | if (unlink (ofname)) { 230 | fprintf (stderr, "%s: ", progname); 231 | perror (ofname); 232 | exit_code = ERROR; 233 | return ERROR; 234 | } 235 | return OK; 236 | } 237 | 238 | int 239 | check_input_file (char *iname) 240 | { 241 | char tmpname[1024]; 242 | int i, ltmpname; 243 | 244 | if (strlen(iname) >= sizeof(tmpname)) { 245 | WARN ((stderr, "%s: filename is >= 1024 characters long\n", progname)); 246 | } 247 | (void) strncpy(tmpname, iname, sizeof(tmpname) - 1); 248 | tmpname[sizeof(tmpname) - 1] = '\0'; 249 | 250 | /* Omit any extension that was specified */ 251 | ltmpname = strlen(tmpname); 252 | for (i=0; i 1 && !to_stdout && !force) { 276 | WARN ((stderr, "%s: %s has %d other link%c\n", 277 | progname, tmpname, 278 | (int)istat.st_nlink - 1, istat.st_nlink > 2 ? 's' : ' ')); 279 | return WARNING; 280 | } 281 | 282 | return OK; 283 | } 284 | -------------------------------------------------------------------------------- /missing: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Common stub for a few missing GNU programs while installing. 3 | # Copyright (C) 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. 4 | # Originally by Fran,cois Pinard , 1996. 5 | 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2, or (at your option) 9 | # any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | # 02111-1307, USA. 20 | 21 | # As a special exception to the GNU General Public License, if you 22 | # distribute this file as part of a program that contains a 23 | # configuration script generated by Autoconf, you may include it under 24 | # the same distribution terms that you use for the rest of that program. 25 | 26 | if test $# -eq 0; then 27 | echo 1>&2 "Try \`$0 --help' for more information" 28 | exit 1 29 | fi 30 | 31 | run=: 32 | 33 | # In the cases where this matters, `missing' is being run in the 34 | # srcdir already. 35 | if test -f configure.ac; then 36 | configure_ac=configure.ac 37 | else 38 | configure_ac=configure.in 39 | fi 40 | 41 | case "$1" in 42 | --run) 43 | # Try to run requested program, and just exit if it succeeds. 44 | run= 45 | shift 46 | "$@" && exit 0 47 | ;; 48 | esac 49 | 50 | # If it does not exist, or fails to run (possibly an outdated version), 51 | # try to emulate it. 52 | case "$1" in 53 | 54 | -h|--h|--he|--hel|--help) 55 | echo "\ 56 | $0 [OPTION]... PROGRAM [ARGUMENT]... 57 | 58 | Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an 59 | error status if there is no known handling for PROGRAM. 60 | 61 | Options: 62 | -h, --help display this help and exit 63 | -v, --version output version information and exit 64 | --run try to run the given command, and emulate it if it fails 65 | 66 | Supported PROGRAM values: 67 | aclocal touch file \`aclocal.m4' 68 | autoconf touch file \`configure' 69 | autoheader touch file \`config.h.in' 70 | automake touch all \`Makefile.in' files 71 | bison create \`y.tab.[ch]', if possible, from existing .[ch] 72 | flex create \`lex.yy.c', if possible, from existing .c 73 | help2man touch the output file 74 | lex create \`lex.yy.c', if possible, from existing .c 75 | makeinfo touch the output file 76 | tar try tar, gnutar, gtar, then tar without non-portable flags 77 | yacc create \`y.tab.[ch]', if possible, from existing .[ch]" 78 | ;; 79 | 80 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version) 81 | echo "missing 0.4 - GNU automake" 82 | ;; 83 | 84 | -*) 85 | echo 1>&2 "$0: Unknown \`$1' option" 86 | echo 1>&2 "Try \`$0 --help' for more information" 87 | exit 1 88 | ;; 89 | 90 | aclocal*) 91 | if test -z "$run" && ($1 --version) > /dev/null 2>&1; then 92 | # We have it, but it failed. 93 | exit 1 94 | fi 95 | 96 | echo 1>&2 "\ 97 | WARNING: \`$1' is missing on your system. You should only need it if 98 | you modified \`acinclude.m4' or \`${configure_ac}'. You might want 99 | to install the \`Automake' and \`Perl' packages. Grab them from 100 | any GNU archive site." 101 | touch aclocal.m4 102 | ;; 103 | 104 | autoconf) 105 | if test -z "$run" && ($1 --version) > /dev/null 2>&1; then 106 | # We have it, but it failed. 107 | exit 1 108 | fi 109 | 110 | echo 1>&2 "\ 111 | WARNING: \`$1' is missing on your system. You should only need it if 112 | you modified \`${configure_ac}'. You might want to install the 113 | \`Autoconf' and \`GNU m4' packages. Grab them from any GNU 114 | archive site." 115 | touch configure 116 | ;; 117 | 118 | autoheader) 119 | if test -z "$run" && ($1 --version) > /dev/null 2>&1; then 120 | # We have it, but it failed. 121 | exit 1 122 | fi 123 | 124 | echo 1>&2 "\ 125 | WARNING: \`$1' is missing on your system. You should only need it if 126 | you modified \`acconfig.h' or \`${configure_ac}'. You might want 127 | to install the \`Autoconf' and \`GNU m4' packages. Grab them 128 | from any GNU archive site." 129 | files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` 130 | test -z "$files" && files="config.h" 131 | touch_files= 132 | for f in $files; do 133 | case "$f" in 134 | *:*) touch_files="$touch_files "`echo "$f" | 135 | sed -e 's/^[^:]*://' -e 's/:.*//'`;; 136 | *) touch_files="$touch_files $f.in";; 137 | esac 138 | done 139 | touch $touch_files 140 | ;; 141 | 142 | automake*) 143 | if test -z "$run" && ($1 --version) > /dev/null 2>&1; then 144 | # We have it, but it failed. 145 | exit 1 146 | fi 147 | 148 | echo 1>&2 "\ 149 | WARNING: \`$1' is missing on your system. You should only need it if 150 | you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. 151 | You might want to install the \`Automake' and \`Perl' packages. 152 | Grab them from any GNU archive site." 153 | find . -type f -name Makefile.am -print | 154 | sed 's/\.am$/.in/' | 155 | while read f; do touch "$f"; done 156 | ;; 157 | 158 | autom4te) 159 | if test -z "$run" && ($1 --version) > /dev/null 2>&1; then 160 | # We have it, but it failed. 161 | exit 1 162 | fi 163 | 164 | echo 1>&2 "\ 165 | WARNING: \`$1' is needed, and you do not seem to have it handy on your 166 | system. You might have modified some files without having the 167 | proper tools for further handling them. 168 | You can get \`$1Help2man' as part of \`Autoconf' from any GNU 169 | archive site." 170 | 171 | file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` 172 | test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` 173 | if test -f "$file"; then 174 | touch $file 175 | else 176 | test -z "$file" || exec >$file 177 | echo "#! /bin/sh" 178 | echo "# Created by GNU Automake missing as a replacement of" 179 | echo "# $ $@" 180 | echo "exit 0" 181 | chmod +x $file 182 | exit 1 183 | fi 184 | ;; 185 | 186 | bison|yacc) 187 | echo 1>&2 "\ 188 | WARNING: \`$1' is missing on your system. You should only need it if 189 | you modified a \`.y' file. You may need the \`Bison' package 190 | in order for those modifications to take effect. You can get 191 | \`Bison' from any GNU archive site." 192 | rm -f y.tab.c y.tab.h 193 | if [ $# -ne 1 ]; then 194 | eval LASTARG="\${$#}" 195 | case "$LASTARG" in 196 | *.y) 197 | SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` 198 | if [ -f "$SRCFILE" ]; then 199 | cp "$SRCFILE" y.tab.c 200 | fi 201 | SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` 202 | if [ -f "$SRCFILE" ]; then 203 | cp "$SRCFILE" y.tab.h 204 | fi 205 | ;; 206 | esac 207 | fi 208 | if [ ! -f y.tab.h ]; then 209 | echo >y.tab.h 210 | fi 211 | if [ ! -f y.tab.c ]; then 212 | echo 'main() { return 0; }' >y.tab.c 213 | fi 214 | ;; 215 | 216 | lex|flex) 217 | echo 1>&2 "\ 218 | WARNING: \`$1' is missing on your system. You should only need it if 219 | you modified a \`.l' file. You may need the \`Flex' package 220 | in order for those modifications to take effect. You can get 221 | \`Flex' from any GNU archive site." 222 | rm -f lex.yy.c 223 | if [ $# -ne 1 ]; then 224 | eval LASTARG="\${$#}" 225 | case "$LASTARG" in 226 | *.l) 227 | SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` 228 | if [ -f "$SRCFILE" ]; then 229 | cp "$SRCFILE" lex.yy.c 230 | fi 231 | ;; 232 | esac 233 | fi 234 | if [ ! -f lex.yy.c ]; then 235 | echo 'main() { return 0; }' >lex.yy.c 236 | fi 237 | ;; 238 | 239 | help2man) 240 | if test -z "$run" && ($1 --version) > /dev/null 2>&1; then 241 | # We have it, but it failed. 242 | exit 1 243 | fi 244 | 245 | echo 1>&2 "\ 246 | WARNING: \`$1' is missing on your system. You should only need it if 247 | you modified a dependency of a manual page. You may need the 248 | \`Help2man' package in order for those modifications to take 249 | effect. You can get \`Help2man' from any GNU archive site." 250 | 251 | file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` 252 | if test -z "$file"; then 253 | file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` 254 | fi 255 | if [ -f "$file" ]; then 256 | touch $file 257 | else 258 | test -z "$file" || exec >$file 259 | echo ".ab help2man is required to generate this page" 260 | exit 1 261 | fi 262 | ;; 263 | 264 | makeinfo) 265 | if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then 266 | # We have makeinfo, but it failed. 267 | exit 1 268 | fi 269 | 270 | echo 1>&2 "\ 271 | WARNING: \`$1' is missing on your system. You should only need it if 272 | you modified a \`.texi' or \`.texinfo' file, or any other file 273 | indirectly affecting the aspect of the manual. The spurious 274 | call might also be the consequence of using a buggy \`make' (AIX, 275 | DU, IRIX). You might want to install the \`Texinfo' package or 276 | the \`GNU make' package. Grab either from any GNU archive site." 277 | file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` 278 | if test -z "$file"; then 279 | file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` 280 | file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` 281 | fi 282 | touch $file 283 | ;; 284 | 285 | tar) 286 | shift 287 | if test -n "$run"; then 288 | echo 1>&2 "ERROR: \`tar' requires --run" 289 | exit 1 290 | fi 291 | 292 | # We have already tried tar in the generic part. 293 | # Look for gnutar/gtar before invocation to avoid ugly error 294 | # messages. 295 | if (gnutar --version > /dev/null 2>&1); then 296 | gnutar "$@" && exit 0 297 | fi 298 | if (gtar --version > /dev/null 2>&1); then 299 | gtar "$@" && exit 0 300 | fi 301 | firstarg="$1" 302 | if shift; then 303 | case "$firstarg" in 304 | *o*) 305 | firstarg=`echo "$firstarg" | sed s/o//` 306 | tar "$firstarg" "$@" && exit 0 307 | ;; 308 | esac 309 | case "$firstarg" in 310 | *h*) 311 | firstarg=`echo "$firstarg" | sed s/h//` 312 | tar "$firstarg" "$@" && exit 0 313 | ;; 314 | esac 315 | fi 316 | 317 | echo 1>&2 "\ 318 | WARNING: I can't seem to be able to run \`tar' with the given arguments. 319 | You may want to install GNU tar or Free paxutils, or check the 320 | command line arguments." 321 | exit 1 322 | ;; 323 | 324 | *) 325 | echo 1>&2 "\ 326 | WARNING: \`$1' is needed, and you do not seem to have it handy on your 327 | system. You might have modified some files without having the 328 | proper tools for further handling them. Check the \`README' file, 329 | it often tells you about the needed prerequirements for installing 330 | this package. You may also peek at any GNU archive site, in case 331 | some other package would contain this missing \`$1' program." 332 | exit 1 333 | ;; 334 | esac 335 | 336 | exit 0 337 | -------------------------------------------------------------------------------- /depcomp: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # depcomp - compile a program generating dependencies as side-effects 4 | # Copyright 1999, 2000 Free Software Foundation, Inc. 5 | 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2, or (at your option) 9 | # any later version. 10 | 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 19 | # 02111-1307, USA. 20 | 21 | # As a special exception to the GNU General Public License, if you 22 | # distribute this file as part of a program that contains a 23 | # configuration script generated by Autoconf, you may include it under 24 | # the same distribution terms that you use for the rest of that program. 25 | 26 | # Originally written by Alexandre Oliva . 27 | 28 | if test -z "$depmode" || test -z "$source" || test -z "$object"; then 29 | echo "depcomp: Variables source, object and depmode must be set" 1>&2 30 | exit 1 31 | fi 32 | # `libtool' can also be set to `yes' or `no'. 33 | 34 | if test -z "$depfile"; then 35 | base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'` 36 | dir=`echo "$object" | sed 's,/.*$,/,'` 37 | if test "$dir" = "$object"; then 38 | dir= 39 | fi 40 | # FIXME: should be _deps on DOS. 41 | depfile="$dir.deps/$base" 42 | fi 43 | 44 | tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} 45 | 46 | rm -f "$tmpdepfile" 47 | 48 | # Some modes work just like other modes, but use different flags. We 49 | # parameterize here, but still list the modes in the big case below, 50 | # to make depend.m4 easier to write. Note that we *cannot* use a case 51 | # here, because this file can only contain one case statement. 52 | if test "$depmode" = hp; then 53 | # HP compiler uses -M and no extra arg. 54 | gccflag=-M 55 | depmode=gcc 56 | fi 57 | 58 | if test "$depmode" = dashXmstdout; then 59 | # This is just like dashmstdout with a different argument. 60 | dashmflag=-xM 61 | depmode=dashmstdout 62 | fi 63 | 64 | case "$depmode" in 65 | gcc3) 66 | ## gcc 3 implements dependency tracking that does exactly what 67 | ## we want. Yay! Note: for some reason libtool 1.4 doesn't like 68 | ## it if -MD -MP comes after the -MF stuff. Hmm. 69 | "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" 70 | stat=$? 71 | if test $stat -eq 0; then : 72 | else 73 | rm -f "$tmpdepfile" 74 | exit $stat 75 | fi 76 | mv "$tmpdepfile" "$depfile" 77 | ;; 78 | 79 | gcc) 80 | ## There are various ways to get dependency output from gcc. Here's 81 | ## why we pick this rather obscure method: 82 | ## - Don't want to use -MD because we'd like the dependencies to end 83 | ## up in a subdir. Having to rename by hand is ugly. 84 | ## (We might end up doing this anyway to support other compilers.) 85 | ## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like 86 | ## -MM, not -M (despite what the docs say). 87 | ## - Using -M directly means running the compiler twice (even worse 88 | ## than renaming). 89 | if test -z "$gccflag"; then 90 | gccflag=-MD, 91 | fi 92 | "$@" -Wp,"$gccflag$tmpdepfile" 93 | stat=$? 94 | if test $stat -eq 0; then : 95 | else 96 | rm -f "$tmpdepfile" 97 | exit $stat 98 | fi 99 | rm -f "$depfile" 100 | echo "$object : \\" > "$depfile" 101 | alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 102 | ## The second -e expression handles DOS-style file names with drive letters. 103 | sed -e 's/^[^:]*: / /' \ 104 | -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" 105 | ## This next piece of magic avoids the `deleted header file' problem. 106 | ## The problem is that when a header file which appears in a .P file 107 | ## is deleted, the dependency causes make to die (because there is 108 | ## typically no way to rebuild the header). We avoid this by adding 109 | ## dummy dependencies for each header file. Too bad gcc doesn't do 110 | ## this for us directly. 111 | tr ' ' ' 112 | ' < "$tmpdepfile" | 113 | ## Some versions of gcc put a space before the `:'. On the theory 114 | ## that the space means something, we add a space to the output as 115 | ## well. 116 | ## Some versions of the HPUX 10.20 sed can't process this invocation 117 | ## correctly. Breaking it into two sed invocations is a workaround. 118 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 119 | rm -f "$tmpdepfile" 120 | ;; 121 | 122 | hp) 123 | # This case exists only to let depend.m4 do its work. It works by 124 | # looking at the text of this script. This case will never be run, 125 | # since it is checked for above. 126 | exit 1 127 | ;; 128 | 129 | sgi) 130 | if test "$libtool" = yes; then 131 | "$@" "-Wp,-MDupdate,$tmpdepfile" 132 | else 133 | "$@" -MDupdate "$tmpdepfile" 134 | fi 135 | stat=$? 136 | if test $stat -eq 0; then : 137 | else 138 | rm -f "$tmpdepfile" 139 | exit $stat 140 | fi 141 | rm -f "$depfile" 142 | 143 | if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files 144 | echo "$object : \\" > "$depfile" 145 | 146 | # Clip off the initial element (the dependent). Don't try to be 147 | # clever and replace this with sed code, as IRIX sed won't handle 148 | # lines with more than a fixed number of characters (4096 in 149 | # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; 150 | # the IRIX cc adds comments like `#:fec' to the end of the 151 | # dependency line. 152 | tr ' ' ' 153 | ' < "$tmpdepfile" \ 154 | | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ 155 | tr ' 156 | ' ' ' >> $depfile 157 | echo >> $depfile 158 | 159 | # The second pass generates a dummy entry for each header file. 160 | tr ' ' ' 161 | ' < "$tmpdepfile" \ 162 | | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ 163 | >> $depfile 164 | else 165 | # The sourcefile does not contain any dependencies, so just 166 | # store a dummy comment line, to avoid errors with the Makefile 167 | # "include basename.Plo" scheme. 168 | echo "#dummy" > "$depfile" 169 | fi 170 | rm -f "$tmpdepfile" 171 | ;; 172 | 173 | aix) 174 | # The C for AIX Compiler uses -M and outputs the dependencies 175 | # in a .u file. This file always lives in the current directory. 176 | # Also, the AIX compiler puts `$object:' at the start of each line; 177 | # $object doesn't have directory information. 178 | stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` 179 | tmpdepfile="$stripped.u" 180 | outname="$stripped.o" 181 | if test "$libtool" = yes; then 182 | "$@" -Wc,-M 183 | else 184 | "$@" -M 185 | fi 186 | 187 | stat=$? 188 | if test $stat -eq 0; then : 189 | else 190 | rm -f "$tmpdepfile" 191 | exit $stat 192 | fi 193 | 194 | if test -f "$tmpdepfile"; then 195 | # Each line is of the form `foo.o: dependent.h'. 196 | # Do two passes, one to just change these to 197 | # `$object: dependent.h' and one to simply `dependent.h:'. 198 | sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" 199 | sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" 200 | else 201 | # The sourcefile does not contain any dependencies, so just 202 | # store a dummy comment line, to avoid errors with the Makefile 203 | # "include basename.Plo" scheme. 204 | echo "#dummy" > "$depfile" 205 | fi 206 | rm -f "$tmpdepfile" 207 | ;; 208 | 209 | tru64) 210 | # The Tru64 compiler uses -MD to generate dependencies as a side 211 | # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. 212 | # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put 213 | # dependencies in `foo.d' instead, so we check for that too. 214 | # Subdirectories are respected. 215 | dir=`echo "$object" | sed -e 's|/[^/]*$|/|'` 216 | test "x$dir" = "x$object" && dir= 217 | base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'` 218 | 219 | if test "$libtool" = yes; then 220 | tmpdepfile1="$dir.libs/$base.lo.d" 221 | tmpdepfile2="$dir.libs/$base.d" 222 | "$@" -Wc,-MD 223 | else 224 | tmpdepfile1="$dir$base.o.d" 225 | tmpdepfile2="$dir$base.d" 226 | "$@" -MD 227 | fi 228 | 229 | stat=$? 230 | if test $stat -eq 0; then : 231 | else 232 | rm -f "$tmpdepfile1" "$tmpdepfile2" 233 | exit $stat 234 | fi 235 | 236 | if test -f "$tmpdepfile1"; then 237 | tmpdepfile="$tmpdepfile1" 238 | else 239 | tmpdepfile="$tmpdepfile2" 240 | fi 241 | if test -f "$tmpdepfile"; then 242 | sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" 243 | # That's a space and a tab in the []. 244 | sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" 245 | else 246 | echo "#dummy" > "$depfile" 247 | fi 248 | rm -f "$tmpdepfile" 249 | ;; 250 | 251 | #nosideeffect) 252 | # This comment above is used by automake to tell side-effect 253 | # dependency tracking mechanisms from slower ones. 254 | 255 | dashmstdout) 256 | # Important note: in order to support this mode, a compiler *must* 257 | # always write the proprocessed file to stdout, regardless of -o. 258 | "$@" || exit $? 259 | 260 | # Remove the call to Libtool. 261 | if test "$libtool" = yes; then 262 | while test $1 != '--mode=compile'; do 263 | shift 264 | done 265 | shift 266 | fi 267 | 268 | # Remove `-o $object'. We will use -o /dev/null later, 269 | # however we can't do the remplacement now because 270 | # `-o $object' might simply not be used 271 | IFS=" " 272 | for arg 273 | do 274 | case $arg in 275 | -o) 276 | shift 277 | ;; 278 | $object) 279 | shift 280 | ;; 281 | *) 282 | set fnord "$@" "$arg" 283 | shift # fnord 284 | shift # $arg 285 | ;; 286 | esac 287 | done 288 | 289 | test -z "$dashmflag" && dashmflag=-M 290 | "$@" -o /dev/null $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" 291 | rm -f "$depfile" 292 | cat < "$tmpdepfile" > "$depfile" 293 | tr ' ' ' 294 | ' < "$tmpdepfile" | \ 295 | ## Some versions of the HPUX 10.20 sed can't process this invocation 296 | ## correctly. Breaking it into two sed invocations is a workaround. 297 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 298 | rm -f "$tmpdepfile" 299 | ;; 300 | 301 | dashXmstdout) 302 | # This case only exists to satisfy depend.m4. It is never actually 303 | # run, as this mode is specially recognized in the preamble. 304 | exit 1 305 | ;; 306 | 307 | makedepend) 308 | "$@" || exit $? 309 | # X makedepend 310 | shift 311 | cleared=no 312 | for arg in "$@"; do 313 | case $cleared in 314 | no) 315 | set ""; shift 316 | cleared=yes ;; 317 | esac 318 | case "$arg" in 319 | -D*|-I*) 320 | set fnord "$@" "$arg"; shift ;; 321 | -*) 322 | ;; 323 | *) 324 | set fnord "$@" "$arg"; shift ;; 325 | esac 326 | done 327 | obj_suffix="`echo $object | sed 's/^.*\././'`" 328 | touch "$tmpdepfile" 329 | ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@" 330 | rm -f "$depfile" 331 | cat < "$tmpdepfile" > "$depfile" 332 | sed '1,2d' "$tmpdepfile" | tr ' ' ' 333 | ' | \ 334 | ## Some versions of the HPUX 10.20 sed can't process this invocation 335 | ## correctly. Breaking it into two sed invocations is a workaround. 336 | sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" 337 | rm -f "$tmpdepfile" "$tmpdepfile".bak 338 | ;; 339 | 340 | cpp) 341 | # Important note: in order to support this mode, a compiler *must* 342 | # always write the proprocessed file to stdout. 343 | "$@" || exit $? 344 | 345 | # Remove the call to Libtool. 346 | if test "$libtool" = yes; then 347 | while test $1 != '--mode=compile'; do 348 | shift 349 | done 350 | shift 351 | fi 352 | 353 | # Remove `-o $object'. 354 | IFS=" " 355 | for arg 356 | do 357 | case $arg in 358 | -o) 359 | shift 360 | ;; 361 | $object) 362 | shift 363 | ;; 364 | *) 365 | set fnord "$@" "$arg" 366 | shift # fnord 367 | shift # $arg 368 | ;; 369 | esac 370 | done 371 | 372 | "$@" -E | 373 | sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | 374 | sed '$ s: \\$::' > "$tmpdepfile" 375 | rm -f "$depfile" 376 | echo "$object : \\" > "$depfile" 377 | cat < "$tmpdepfile" >> "$depfile" 378 | sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" 379 | rm -f "$tmpdepfile" 380 | ;; 381 | 382 | msvisualcpp) 383 | # Important note: in order to support this mode, a compiler *must* 384 | # always write the proprocessed file to stdout, regardless of -o, 385 | # because we must use -o when running libtool. 386 | "$@" || exit $? 387 | IFS=" " 388 | for arg 389 | do 390 | case "$arg" in 391 | "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") 392 | set fnord "$@" 393 | shift 394 | shift 395 | ;; 396 | *) 397 | set fnord "$@" "$arg" 398 | shift 399 | shift 400 | ;; 401 | esac 402 | done 403 | "$@" -E | 404 | sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" 405 | rm -f "$depfile" 406 | echo "$object : \\" > "$depfile" 407 | . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" 408 | echo " " >> "$depfile" 409 | . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" 410 | rm -f "$tmpdepfile" 411 | ;; 412 | 413 | none) 414 | exec "$@" 415 | ;; 416 | 417 | *) 418 | echo "Unknown depmode $depmode" 1>&2 419 | exit 1 420 | ;; 421 | esac 422 | 423 | exit 0 424 | -------------------------------------------------------------------------------- /wcs_align.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * Functions for remapping an image based on WCS info 4 | * 5 | * Author: William Jon McCann 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * 21 | * $Id: wcs_align.c,v 1.7 2004/04/21 21:28:47 mccannwj Exp $ 22 | */ 23 | 24 | /* make lround work ok with old gcc on linux */ 25 | #define _ISOC99_SOURCE 26 | 27 | #ifdef HAVE_CONFIG_H 28 | #include 29 | #endif 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "getopt.h" 38 | #include 39 | #include 40 | 41 | #ifdef HAVE_CFITSIO_FITSIO_H 42 | #include 43 | #else 44 | #include 45 | #endif 46 | 47 | #include "fitscut.h" 48 | #include "extract.h" 49 | #include 50 | #include "wcs_align.h" 51 | 52 | #ifdef STDC_HEADERS 53 | #include 54 | #else /* Not STDC_HEADERS */ 55 | extern void exit (); 56 | #endif /* STDC_HEADERS */ 57 | 58 | #ifdef HAVE_STRING_H 59 | #include 60 | #else 61 | #include 62 | #endif 63 | 64 | #ifdef DMALLOC 65 | #include 66 | #define DMALLOC_FUNC_CHECK 1 67 | #endif 68 | 69 | void 70 | wcs_initialize_channel (FitsCutImage *Image, int k) 71 | { 72 | if (Image->header[k] != NULL) { 73 | struct WorldCoor *wcs; 74 | 75 | wcs = wcsninit (Image->header[k], Image->header_cards[k]*80); 76 | if (iswcs (wcs)) { 77 | Image->wcs[k] = wcs; 78 | } 79 | } 80 | } 81 | 82 | void 83 | wcs_initialize (FitsCutImage *Image) 84 | { 85 | int k; 86 | 87 | for (k = 0; k < Image->channels; k++) 88 | wcs_initialize_channel (Image, k); 89 | } 90 | 91 | /* open FITS file, extract the WCS, and close it 92 | * also returns the image dimensions in naxes array 93 | */ 94 | 95 | struct WorldCoor *wcs_read(char *filename, long *naxes) 96 | { 97 | fitsfile *fptr; 98 | char *header; 99 | int status = 0; 100 | struct WorldCoor *wcs; 101 | 102 | if (fits_open_image (&fptr, filename, READONLY, &status)) 103 | printerror (status); 104 | 105 | /* let cfitsio extract the entire header as a string */ 106 | if (fits_get_image_wcs_keys (fptr, &header, &status)) 107 | printerror (status); 108 | 109 | if (fits_get_img_size (fptr, 2, naxes, &status)) 110 | printerror (status); 111 | 112 | if (fits_close_file(fptr, &status)) 113 | printerror (status); 114 | 115 | /* get world coordinate system info from header */ 116 | wcs = wcsinit (header); 117 | 118 | if (nowcs(wcs)) { 119 | fitscut_message (1, 120 | "fitscut: warning: no WCS info for file %s\n", filename); 121 | } 122 | 123 | free(header); 124 | return (wcs); 125 | } 126 | 127 | void 128 | wcs_initialize_ref (FitsCutImage *Image, long *naxes) 129 | { 130 | Image->wcsref = wcs_read(Image->reference_filename, naxes); 131 | } 132 | 133 | void 134 | wcs_align_ref (FitsCutImage *Image) 135 | { 136 | int k; 137 | 138 | if (Image->wcsref == NULL) 139 | return; 140 | 141 | if (nowcs (Image->wcsref)) 142 | return; 143 | 144 | for (k = 0; k < Image->channels; k++) { 145 | if (Image->data[k] != NULL) { 146 | fitscut_message (2, "\t\tremapping channel %d\n", k); 147 | wcs_remap_channel (Image, k); 148 | } 149 | } 150 | } 151 | 152 | /* returns true if 2 WCS systems are the same */ 153 | 154 | static int 155 | wcs_equal(struct WorldCoor *wcs1, struct WorldCoor *wcs2) 156 | { 157 | return ( wcs1 == wcs2 || ( 158 | wcs1->nxpix == wcs2->nxpix && 159 | wcs1->nypix == wcs2->nypix && 160 | wcs1->yref == wcs2->yref && 161 | wcs1->xrefpix == wcs2->xrefpix && 162 | wcs1->yrefpix == wcs2->yrefpix && 163 | wcs1->xinc == wcs2->xinc && 164 | wcs1->yinc == wcs2->yinc && 165 | wcs1->rot == wcs2->rot && 166 | wcs1->equinox == wcs2->equinox && 167 | wcs1->cd[0] == wcs2->cd[0] && 168 | wcs1->cd[1] == wcs2->cd[1] && 169 | wcs1->cd[2] == wcs2->cd[2] && 170 | wcs1->cd[3] == wcs2->cd[3] && 171 | wcs1->wcsproj == wcs2->wcsproj 172 | )); 173 | } 174 | 175 | /* convert pixel coordinates in wcs_in to pixel coordinates in wcs_out */ 176 | 177 | static void 178 | pix2pix(struct WorldCoor *wcs_in, double x_in, double y_in, struct WorldCoor *wcs_out, double *x_out, double *y_out, int *offscl) 179 | { 180 | double xpos, ypos; 181 | 182 | pix2wcs (wcs_in, x_in, y_in, &xpos, &ypos); 183 | wcs2pix (wcs_out, xpos, ypos, x_out, y_out, offscl); 184 | } 185 | 186 | int 187 | wcs_remap_channel (FitsCutImage *Image, int channel) 188 | { 189 | struct WorldCoor *wcs_in, *wcs_out; 190 | int wpin, hpin; 191 | int offscl; 192 | int iin, iout, jin, jout; 193 | int iout1, iout2, jout1, jout2; 194 | 195 | double xout, yout, xin, yin; 196 | double xmin, xmax, ymin, ymax; 197 | double x0, y0, x1, y1; 198 | 199 | int ncols_in, nrows_in; 200 | int ncols_out, nrows_out; 201 | 202 | float *image_out, *image; 203 | 204 | wcs_out = Image->wcsref; 205 | wcs_in = Image->wcs[channel]; 206 | if (wcs_equal(wcs_in, wcs_out)) { 207 | fitscut_message (3, "\t\tWCS for channel %d matches reference image\n", channel); 208 | return(0); 209 | } 210 | 211 | image = Image->data[channel]; 212 | ncols_in = Image->ncols[channel]; 213 | nrows_in = Image->nrows[channel]; 214 | 215 | /* Allocate space for output image */ 216 | ncols_out = Image->ncolsref; 217 | nrows_out = Image->nrowsref; 218 | 219 | fitscut_message (3, "\t\tCreating temp image [%d,%d]\n", ncols_out, nrows_out); 220 | 221 | image_out = cutout_alloc(ncols_out, nrows_out, NAN); 222 | 223 | /* Set input WCS output coordinate system to output coordinate system */ 224 | wcs_in->sysout = wcs_out->syswcs; 225 | strcpy (wcs_in->radecout, wcs_out->radecsys); 226 | wpin = wcs_in->nxpix; 227 | hpin = wcs_in->nypix; 228 | 229 | /* Set output WCS output coordinate system to input coordinate system */ 230 | wcs_out->sysout = wcs_in->syswcs; 231 | 232 | /* Find limiting edges of input image in output image */ 233 | x0 = 0.5; 234 | y0 = 0.5; 235 | x1 = wcs_in->nxpix+0.5; 236 | y1 = wcs_in->nypix+0.5; 237 | 238 | pix2pix(wcs_in, x0, y0, wcs_out, &xout, &yout, &offscl); 239 | xmin = xout; 240 | xmax = xout; 241 | ymin = yout; 242 | ymax = yout; 243 | pix2pix(wcs_in, x0, y1, wcs_out, &xout, &yout, &offscl); 244 | if (xout < xmin) { xmin = xout; } else if (xout > xmax) { xmax = xout; } 245 | if (yout < ymin) { ymin = yout; } else if (yout > ymax) { ymax = yout; } 246 | pix2pix(wcs_in, x1, y0, wcs_out, &xout, &yout, &offscl); 247 | if (xout < xmin) { xmin = xout; } else if (xout > xmax) { xmax = xout; } 248 | if (yout < ymin) { ymin = yout; } else if (yout > ymax) { ymax = yout; } 249 | pix2pix(wcs_in, x1, y1, wcs_out, &xout, &yout, &offscl); 250 | if (xout < xmin) { xmin = xout; } else if (xout > xmax) { xmax = xout; } 251 | if (yout < ymin) { ymin = yout; } else if (yout > ymax) { ymax = yout; } 252 | iout1 = (int) ceil(ymin); 253 | iout2 = (int) floor(ymax); 254 | jout1 = (int) ceil(xmin); 255 | jout2 = (int) floor(xmax); 256 | if (iout1 < 1) iout1 = 1; 257 | if (iout2 > nrows_out) iout2 = nrows_out; 258 | if (jout1 < 1) jout1 = 1; 259 | if (jout2 > ncols_out) jout2 = ncols_out; 260 | 261 | fitscut_message (3, "REMAP: Output x: %d-%d, y: %d-%d\n", 262 | jout1, jout2, iout1, iout2); 263 | 264 | /* Loop through vertical pixels (output image lines) */ 265 | for (iout = iout1; iout <= iout2; iout++) { 266 | yout = (double) iout; 267 | 268 | /* Loop through horizontal pixels (output image columns) */ 269 | for (jout = jout1; jout <= jout2; jout++) { 270 | xout = (double) jout; 271 | 272 | /* Get image coordinates of this pixel in input image */ 273 | pix2pix(wcs_out, xout, yout, wcs_in, &xin, &yin, &offscl); 274 | 275 | if (!offscl) { 276 | iin = lround(yin); 277 | jin = lround(xin); 278 | if (iin >= 1 && iin <= nrows_in && jin >= 1 && jin <= ncols_in) { 279 | /* Copy pixel from input to output */ 280 | image_out[(jout-1)+(iout-1)*ncols_out] = image[(jin-1)+(iin-1)*ncols_in]; 281 | } 282 | } 283 | } 284 | } 285 | 286 | free (Image->data[channel]); 287 | Image->data[channel] = (float *) image_out; 288 | Image->ncols[channel] = ncols_out; 289 | Image->nrows[channel] = nrows_out; 290 | 291 | /* update the wcs for this channel */ 292 | Image->wcs[channel] = Image->wcsref; 293 | Image->output_zoom[channel] = Image->output_zoomref; 294 | Image->x0[channel] = Image->x0ref; 295 | Image->y0[channel] = Image->y0ref; 296 | 297 | return (0); 298 | } 299 | 300 | /* modify image section for channel to match reference image using WCS */ 301 | 302 | int 303 | wcs_match_channel (FitsCutImage *Image, int channel) 304 | { 305 | struct WorldCoor *wcs_chan, *wcs_ref; 306 | int offscl; 307 | int iout1, iout2, jout1, jout2; 308 | 309 | double xout, yout; 310 | double xmin, xmax, ymin, ymax; 311 | double x0, y0, x1, y1; 312 | 313 | wcs_chan = Image->wcs[channel]; 314 | wcs_ref = Image->wcsref; 315 | if (wcs_equal(wcs_ref, wcs_chan)) { 316 | fitscut_message (3, "\t\tWCS for channel %d matches reference image\n", channel); 317 | return(0); 318 | } 319 | 320 | /* Set reference WCS output coordinate system to channel coordinate system*/ 321 | wcs_ref->sysout = wcs_chan->syswcs; 322 | strcpy (wcs_ref->radecout, wcs_chan->radecsys); 323 | 324 | /* Set channel WCS output coordinate system to reference coordinate system*/ 325 | wcs_chan->sysout = wcs_ref->syswcs; 326 | 327 | /* Find limiting edges of reference image in channel image */ 328 | x0 = 0.5; 329 | y0 = 0.5; 330 | x1 = Image->ncolsref+0.5; 331 | y1 = Image->nrowsref+0.5; 332 | pix2pix(wcs_ref, x0, y0, wcs_chan, &xout, &yout, &offscl); 333 | xmin = xout; 334 | xmax = xout; 335 | ymin = yout; 336 | ymax = yout; 337 | pix2pix(wcs_ref, x0, y1, wcs_chan, &xout, &yout, &offscl); 338 | if (xout < xmin) { xmin = xout; } else if (xout > xmax) { xmax = xout; } 339 | if (yout < ymin) { ymin = yout; } else if (yout > ymax) { ymax = yout; } 340 | pix2pix(wcs_ref, x1, y0, wcs_chan, &xout, &yout, &offscl); 341 | if (xout < xmin) { xmin = xout; } else if (xout > xmax) { xmax = xout; } 342 | if (yout < ymin) { ymin = yout; } else if (yout > ymax) { ymax = yout; } 343 | pix2pix(wcs_ref, x1, y1, wcs_chan, &xout, &yout, &offscl); 344 | if (xout < xmin) { xmin = xout; } else if (xout > xmax) { xmax = xout; } 345 | if (yout < ymin) { ymin = yout; } else if (yout > ymax) { ymax = yout; } 346 | iout1 = (int) ceil(ymin); 347 | iout2 = (int) floor(ymax); 348 | jout1 = (int) ceil(xmin); 349 | jout2 = (int) floor(xmax); 350 | 351 | fitscut_message (3, "REMAP: Channel %d Output x: %d-%d, y: %d-%d\n", 352 | channel, jout1, jout2, iout1, iout2); 353 | 354 | Image->ncols[channel] = jout2-jout1+1; 355 | Image->nrows[channel] = iout2-iout1+1; 356 | Image->input_x_corner[channel] = 1; 357 | Image->input_y_corner[channel] = 1; 358 | Image->input_x[channel] = jout1-1; 359 | Image->input_y[channel] = iout1-1; 360 | 361 | return (0); 362 | } 363 | 364 | 365 | /* modify world coordinate system for cutout position and rebinning */ 366 | 367 | void 368 | wcs_update (FitsCutImage *Image) 369 | { 370 | int k; 371 | 372 | for (k = 0; k < Image->channels; k++) 373 | wcs_update_channel (Image, k); 374 | } 375 | 376 | void 377 | wcs_apply_update (struct WorldCoor *wcs, double x0, double y0, double zoom, int ncols, int nrows) 378 | { 379 | double cd[4], *cdptr = NULL, cdelt1 = 0, cdelt2 = 0, crota = 0; 380 | double crpix1, crpix2, crval1, crval2; 381 | int i; 382 | 383 | if (wcs == NULL) return; 384 | 385 | if (zoom == 0) zoom = 1; 386 | 387 | /* return if no change */ 388 | if (x0 == 0 && y0 == 0 && zoom == 1) return; 389 | 390 | crpix1 = zoom*(wcs->crpix[0] - x0) - 0.5*(zoom-1); 391 | crpix2 = zoom*(wcs->crpix[1] - y0) - 0.5*(zoom-1); 392 | crval1 = wcs->crval[0]; 393 | crval2 = wcs->crval[1]; 394 | if (wcs->rotmat) { 395 | /* using rotation matrix */ 396 | for (i=0; i<4; i++) cd[i] = wcs->cd[i]/zoom; 397 | cdptr = cd; 398 | } else { 399 | /* using CROTA, CDELT */ 400 | cdelt1 = wcs->cdelt[0]/zoom; 401 | cdelt2 = wcs->cdelt[1]/zoom; 402 | crota = wcs->rot; 403 | } 404 | 405 | if (wcs->prjcode == WCS_DSS) { 406 | /* special code for DSS polynomial coordinate system 407 | * XXX Offsets could have an off-by-1/2 error, haven't figured out the details 408 | */ 409 | wcs->x_pixel_offset = -zoom*(wcs->x_pixel_offset - x0); 410 | wcs->y_pixel_offset = -zoom*(wcs->y_pixel_offset - y0); 411 | wcs->x_pixel_size = wcs->x_pixel_size/zoom; 412 | wcs->y_pixel_size = wcs->y_pixel_size/zoom; 413 | wcs->crpix[0] = crpix1; 414 | wcs->crpix[1] = crpix2; 415 | } else { 416 | wcsreset(wcs, crpix1, crpix2, crval1, crval2, cdelt1, cdelt2, crota, cdptr); 417 | } 418 | wcs->nxpix = ncols; 419 | wcs->nypix = nrows; 420 | } 421 | 422 | void 423 | wcs_update_channel (FitsCutImage *Image, int k) 424 | { 425 | wcs_apply_update(Image->wcs[k], Image->x0[k], Image->y0[k], Image->output_zoom[k], Image->ncols[k], Image->nrows[k]); 426 | } 427 | 428 | void 429 | wcs_update_ref (FitsCutImage *Image) 430 | { 431 | wcs_apply_update(Image->wcsref, Image->x0ref, Image->y0ref, Image->output_zoomref, Image->ncolsref, Image->nrowsref); 432 | } 433 | -------------------------------------------------------------------------------- /output_fits.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * FITS output functions 4 | * 5 | * Author: William Jon McCann 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | * 21 | * $Id: output_fits.c,v 1.11 2004/05/11 22:05:06 mccannwj Exp $ 22 | */ 23 | 24 | #ifdef HAVE_CONFIG_H 25 | #include 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "getopt.h" 34 | #include 35 | #include 36 | 37 | #ifdef STDC_HEADERS 38 | #include 39 | #else /* Not STDC_HEADERS */ 40 | extern void exit (); 41 | extern char *malloc (); 42 | #endif /* STDC_HEADERS */ 43 | 44 | #ifdef HAVE_STRING_H 45 | #include 46 | #else 47 | #include 48 | #endif 49 | 50 | #ifdef HAVE_CFITSIO_FITSIO_H 51 | #include 52 | #else 53 | #include 54 | #endif 55 | 56 | #include "fitscut.h" 57 | #include "output_fits.h" 58 | #include "blurb.h" 59 | #include "extract.h" 60 | #include "revision.h" 61 | 62 | static void 63 | fitscut_create_primary (fitsfile *fptr, 64 | int bitpix, 65 | int nrows, 66 | int ncols, 67 | int channels) 68 | { 69 | int status = 0; 70 | long naxis; 71 | long naxes[3]; 72 | 73 | naxis = (channels == 1) ? 2 : 3; 74 | naxes[0] = ncols; 75 | naxes[1] = nrows; 76 | naxes[2] = channels; 77 | 78 | /* Create the primary array image */ 79 | if (fits_create_img (fptr, bitpix, naxis, naxes, &status)) 80 | printerror (status); /* note printerror exits with error status */ 81 | } 82 | 83 | static void 84 | fitscut_write_data (fitsfile *fptr, 85 | float **dataptr, 86 | int nrows, 87 | int ncols, 88 | int channels) 89 | { 90 | int status = 0; 91 | long naxes[3], fpixel[3], nelements; 92 | long ii, jj, k; 93 | float *avgrow; 94 | 95 | naxes[0] = ncols; 96 | naxes[1] = nrows; 97 | naxes[2] = channels; 98 | nelements = naxes[0]*naxes[1]; 99 | for (k=0; k < channels; k++) { 100 | fpixel[0] = 1; 101 | fpixel[1] = 1; 102 | fpixel[2] = k + 1; 103 | if (dataptr[k] != NULL) { 104 | if (fits_write_pix(fptr, TFLOAT, fpixel, nelements, dataptr[k], &status)) 105 | printerror (status); 106 | } else { 107 | 108 | /* write mean green channel if possible */ 109 | if (k==1 && channels==3 && dataptr[0] != NULL && dataptr[2] != NULL) { 110 | avgrow = (float *) malloc(ncols*sizeof(float)); 111 | for (ii = 0; ii < nrows; ii++) { 112 | for (jj = 0; jj < ncols; jj++) { 113 | avgrow[jj] = 0.5*(dataptr[0][ncols*ii+jj] + dataptr[2][ncols*ii+jj]); 114 | } 115 | fpixel[1] = ii+1; 116 | if (fits_write_pix(fptr, TFLOAT, fpixel, ncols, avgrow, &status)) 117 | printerror (status); 118 | } 119 | free(avgrow); 120 | } 121 | } 122 | } 123 | } 124 | 125 | static void 126 | fitscut_create_fits (char *ofname, fitsfile **fptrptr) 127 | { 128 | int status = 0; 129 | 130 | if (strlen (ofname) <= 0) { 131 | fitscut_error ("output filename is null."); 132 | } 133 | 134 | if (fits_create_file (fptrptr, ofname, &status)) /* create new file */ 135 | printerror (status); /* call printerror if error occurs */ 136 | } 137 | 138 | static void 139 | fitscut_write_header (fitsfile *fptr, char *header, int num_cards) 140 | { 141 | int status = 0; 142 | char keyname[FLEN_KEYWORD]; 143 | int i, namelen; 144 | char card[FLEN_CARD]; 145 | 146 | /* Write a keyword; must pass the ADDRESS of the value */ 147 | if (header != NULL) { 148 | keyname[0] = '\0'; 149 | if (fits_write_date (fptr, &status)) 150 | printerror (status); 151 | 152 | for (i = 0; i < num_cards; i++) { 153 | strncpy (card, header + i * (FLEN_CARD - 1), FLEN_CARD - 1); 154 | if (fits_get_keyname (card, keyname, &namelen, &status)) 155 | printerror (status); 156 | /*fprintf(stderr," keyname: %s \n",keyname);*/ 157 | if (strequ(keyname,"END")) break; 158 | if ( (!strequ (keyname,"SIMPLE")) && 159 | (!strequ (keyname,"BITPIX")) && 160 | (!strequ (keyname,"NAXIS")) && 161 | (!strequ (keyname,"NAXIS1")) && 162 | (!strequ (keyname,"NAXIS2")) && 163 | (!strequ (keyname,"NAXIS3")) && 164 | (!strequ (keyname,"NAXIS4")) && 165 | (!strequ (keyname,"NAXIS5")) && 166 | (!strequ (keyname,"NAXIS6")) && 167 | (!strequ (keyname,"NAXIS7")) && 168 | (!strequ (keyname,"EXTEND")) && 169 | (!strequ (keyname,"DATE")) ) { 170 | if (fits_write_record (fptr, card, &status)) 171 | printerror(status); 172 | } 173 | } 174 | } 175 | } 176 | 177 | static void 178 | fitscut_close_fits (fitsfile *fptr) 179 | { 180 | int status = 0; 181 | 182 | if (fits_close_file (fptr, &status)) 183 | printerror (status); 184 | } 185 | 186 | /* 187 | * delete FITS keyword from header 188 | * it's OK if the keyword does not exist 189 | */ 190 | static void 191 | fitscut_delete_key(fitsfile *fptr, char *keyword, int *status) { 192 | if (*status) return; 193 | fits_delete_key(fptr, keyword, status); 194 | if (*status == KEY_NO_EXIST) *status = 0; 195 | } 196 | 197 | /* 198 | * clean extraneous keywords out of the header 199 | */ 200 | static void 201 | fitscut_clean_header(fitsfile *fptr, FitsCutImage *Image, int *status) { 202 | 203 | /* integer scaling */ 204 | fitscut_delete_key(fptr, "BZERO", status); 205 | fitscut_delete_key(fptr, "BSCALE", status); 206 | fitscut_delete_key(fptr, "BLANK", status); 207 | 208 | /* compression */ 209 | fitscut_delete_key(fptr, "ZBLANK", status); 210 | fitscut_delete_key(fptr, "TFIELDS", status); 211 | fitscut_delete_key(fptr, "TTYPE1", status); 212 | fitscut_delete_key(fptr, "TFORM1", status); 213 | fitscut_delete_key(fptr, "ZIMAGE", status); 214 | fitscut_delete_key(fptr, "ZSIMPLE", status); 215 | fitscut_delete_key(fptr, "ZBITPIX", status); 216 | fitscut_delete_key(fptr, "ZNAXIS", status); 217 | fitscut_delete_key(fptr, "ZNAXIS1", status); 218 | fitscut_delete_key(fptr, "ZNAXIS2", status); 219 | fitscut_delete_key(fptr, "ZTILE1", status); 220 | fitscut_delete_key(fptr, "ZTILE2", status); 221 | fitscut_delete_key(fptr, "ZCMPTYPE", status); 222 | fitscut_delete_key(fptr, "ZNAME1", status); 223 | fitscut_delete_key(fptr, "ZVAL1", status); 224 | fitscut_delete_key(fptr, "ZNAME2", status); 225 | fitscut_delete_key(fptr, "ZVAL2", status); 226 | 227 | /* extension info */ 228 | fitscut_delete_key(fptr, "XTENSION", status); 229 | fitscut_delete_key(fptr, "EXTNAME", status); 230 | fitscut_delete_key(fptr, "EXTVER", status); 231 | fitscut_delete_key(fptr, "INHERIT", status); 232 | fitscut_delete_key(fptr, "PCOUNT", status); 233 | fitscut_delete_key(fptr, "GCOUNT", status); 234 | 235 | /* asinh scaling */ 236 | if (Image->useBsoften) { 237 | fitscut_delete_key(fptr, "BSOFTEN", status); 238 | fitscut_delete_key(fptr, "BOFFSET", status); 239 | } 240 | 241 | /* catch all errors in above section */ 242 | if (*status) printerror (*status); 243 | } 244 | 245 | void 246 | write_to_fits(FitsCutImage *Image) 247 | { 248 | fitsfile *fptr; 249 | int bitpix; 250 | int status = 0; 251 | char *last; 252 | int i, len; 253 | char history[64], retval[512]; 254 | char *blurb = NULL; 255 | double crpix, cd1, cd2, zoom; 256 | 257 | fitscut_message (1, "\tCreating FITS...\n"); 258 | fitscut_create_fits (Image->output_filename, &fptr); 259 | 260 | fitscut_message (2, "\tWriting primary...\n"); 261 | 262 | /* 263 | * Force the bitpix to float regardless of the input image type. 264 | * This is necessary because the image rebinning could cause 265 | * integer values to overflow. There are also complicated issues 266 | * with the handling of blanks for non-float images. 267 | */ 268 | bitpix = FLOAT_IMG; 269 | /* 270 | * clean scaling, compression & other keywords out of header 271 | */ 272 | fitscut_clean_header (fptr, Image, &status); 273 | 274 | fitscut_create_primary (fptr, bitpix, 275 | Image->nrowsref, Image->ncolsref, Image->channels); 276 | 277 | /* write header */ 278 | /* for now I'm not going to try to merge the headers 279 | * just use the first one */ 280 | fitscut_write_header (fptr, Image->header[0], Image->header_cards[0]); 281 | 282 | if (Image->output_add_blurb) { /* add text message as HISTORY cards */ 283 | if ((blurb = blurb_read (Image->input_blurbfile)) == NULL) { 284 | fitscut_message (2, "\tProblem reading blurb file, header not updated\n"); 285 | } else { 286 | 287 | len = strlen (blurb); 288 | for (i = 0, last = blurb; i < len ; ++i) { 289 | if (blurb[i] == '\n') { 290 | blurb[i] = '\0'; 291 | if (last == blurb + i) { 292 | fits_write_history (fptr, " ", &status); // treat back-to-back carriage returns as blank lines 293 | } else { 294 | fits_write_history (fptr, last, &status); 295 | } 296 | last = blurb + i + 1; 297 | } 298 | } 299 | free (blurb); 300 | } 301 | } 302 | 303 | sprintf (history, "Created by fitscut %s (William Jon McCann)", VERSION); 304 | 305 | fits_write_history (fptr, history, &status); 306 | 307 | /* update WCS info */ 308 | 309 | zoom = Image->output_zoom[0]; 310 | 311 | fits_read_key(fptr, TDOUBLE, "CRPIX1", &crpix, NULL, &status); 312 | if (status == 0) { 313 | crpix = crpix - Image->x0[0]; 314 | if (zoom != 0 && zoom != 1) { 315 | crpix = zoom*crpix - 0.5*(zoom-1); 316 | fits_read_key(fptr, TDOUBLE, "CD1_1", &cd1, NULL, &status); 317 | fits_read_key(fptr, TDOUBLE, "CD1_2", &cd2, NULL, &status); 318 | if (status == 0) { 319 | cd1 = cd1/zoom; 320 | cd2 = cd2/zoom; 321 | fits_update_key(fptr, TDOUBLE, "CD1_1", &cd1, NULL, &status); 322 | fits_update_key(fptr, TDOUBLE, "CD1_2", &cd2, NULL, &status); 323 | } else if (status == VALUE_UNDEFINED || status == KEY_NO_EXIST) { 324 | /* no CRPIX, so look for CDELT1 */ 325 | status = 0; 326 | fits_read_key(fptr, TDOUBLE, "CDELT1", &cd1, NULL, &status); 327 | if (status == 0) { 328 | cd1 = cd1/zoom; 329 | if (fits_update_key(fptr, TDOUBLE, "CDELT1", &cd1, NULL, &status)) 330 | printerror (status); 331 | } else if (status == VALUE_UNDEFINED || status == KEY_NO_EXIST) { 332 | status = 0; 333 | fitscut_message (2, 334 | "\tNo CD1 or CDELT1 found, header scale not updated\n"); 335 | } 336 | } 337 | } 338 | fits_update_key(fptr, TDOUBLE, "CRPIX1", &crpix, 339 | "Reference pixel shifted for cutout", &status); 340 | fitscut_message (2, "\tUpdated CRPIX1 to %f\n", crpix); 341 | } else if (status == VALUE_UNDEFINED || status == KEY_NO_EXIST) { 342 | /* no CRPIX, so skip updating WCS */ 343 | fitscut_message (2, "\tNo CRPIX1 found, header not updated\n"); 344 | status = 0; 345 | } 346 | /* catch all errors in above section */ 347 | if (status) printerror (status); 348 | 349 | fits_read_key(fptr, TDOUBLE, "CRPIX2", &crpix, NULL, &status); 350 | if (status == 0) { 351 | crpix = crpix - Image->y0[0]; 352 | if (zoom != 0 && zoom != 1) { 353 | crpix = zoom*crpix - 0.5*(zoom-1); 354 | fits_read_key(fptr, TDOUBLE, "CD2_1", &cd1, NULL, &status); 355 | fits_read_key(fptr, TDOUBLE, "CD2_2", &cd2, NULL, &status); 356 | if (status == 0) { 357 | cd1 = cd1/zoom; 358 | cd2 = cd2/zoom; 359 | fits_update_key(fptr, TDOUBLE, "CD2_1", &cd1, NULL, &status); 360 | fits_update_key(fptr, TDOUBLE, "CD2_2", &cd2, NULL, &status); 361 | } else if (status == VALUE_UNDEFINED || status == KEY_NO_EXIST) { 362 | /* no CRPIX, so look for CDELT2 */ 363 | status = 0; 364 | fits_read_key(fptr, TDOUBLE, "CDELT2", &cd1, NULL, &status); 365 | if (status == 0) { 366 | cd1 = cd1/zoom; 367 | if (fits_update_key(fptr, TDOUBLE, "CDELT2", &cd1, NULL, &status)) 368 | printerror (status); 369 | } else if (status == VALUE_UNDEFINED || status == KEY_NO_EXIST) { 370 | status = 0; 371 | fitscut_message (2, 372 | "\tNo CD2 or CDELT2 found, header scale not updated\n"); 373 | } 374 | } 375 | } 376 | fits_update_key(fptr, TDOUBLE, "CRPIX2", &crpix, 377 | "Reference pixel shifted for cutout", &status); 378 | fitscut_message (2, "\tUpdated CRPIX2 to %f\n", crpix); 379 | } else if (status == VALUE_UNDEFINED || status == KEY_NO_EXIST) { 380 | /* no CRPIX, so skip updating WCS */ 381 | fitscut_message (2, "\tNo CRPIX2 found, header not updated\n"); 382 | status = 0; 383 | } 384 | 385 | /* 386 | * clean the extension header too 387 | */ 388 | fitscut_clean_header (fptr, Image, &status); 389 | 390 | if (Image->channels > 1) { 391 | /* add CTYPE3 = "RGB" for color images just after CTYPE2 */ 392 | fits_read_key(fptr, TSTRING, "CTYPE2", retval, NULL, &status); 393 | if (status) { 394 | /* append key at end if CTYPE2 was not found */ 395 | status = 0; 396 | fits_update_key(fptr, TSTRING, "CTYPE3", "RGB", "RGB color image", &status); 397 | } else { 398 | fits_insert_key_str(fptr, "CTYPE3", "RGB", "RGB color image", &status); 399 | } 400 | if (status) printerror (status); 401 | } 402 | 403 | fitscut_message(2, "\tWriting pixel data\n"); 404 | fitscut_write_data (fptr, Image->data, 405 | Image->nrowsref, Image->ncolsref, Image->channels); 406 | 407 | 408 | fitscut_message (1, "\tClosing file...\n"); 409 | fitscut_close_fits (fptr); 410 | } 411 | -------------------------------------------------------------------------------- /draw.c: -------------------------------------------------------------------------------- 1 | /* -*- mode:C; indent-tabs-mode:nil; tab-width:8; c-basic-offset:8; -*- 2 | * 3 | * Fitscut drawing functions 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | * 19 | * $Id: draw.c,v 1.6 2004/04/21 21:28:47 mccannwj Exp $ 20 | */ 21 | 22 | #ifdef HAVE_CONFIG_H 23 | #include 24 | #endif 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include "getopt.h" 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | #ifdef STDC_HEADERS 39 | #include 40 | #else /* Not STDC_HEADERS */ 41 | extern void exit (); 42 | extern char *malloc (); 43 | #endif /* STDC_HEADERS */ 44 | 45 | #ifdef HAVE_UNISTD_H 46 | # include 47 | #endif 48 | 49 | #include "fitscut.h" 50 | #include "image_scale.h" 51 | #include "draw.h" 52 | 53 | #ifndef DEGTORAD 54 | #define DEGTORAD(x) ((x)*M_PI/180.0) 55 | #endif 56 | 57 | static void 58 | rotate_vector (float *invec, float angle, float *outvec) 59 | { 60 | float cosa, sina; 61 | float temp; 62 | 63 | cosa = cos (DEGTORAD (angle)); 64 | sina = sin (DEGTORAD (angle)); 65 | 66 | /* use a temp variable in case invec and outvec are the same */ 67 | temp = invec[0] * cosa + invec[1] * sina; 68 | outvec[1] = -invec[0] * sina + invec[1] * cosa; 69 | outvec[0] = temp; 70 | } 71 | 72 | static void 73 | ImageSetPixel (FitsCutImage *Image, int channel, int x, int y, float value) 74 | { 75 | float *arrayp; 76 | int ncols = Image->ncols[channel]; 77 | 78 | arrayp = Image->data[channel]; 79 | 80 | if (arrayp[ncols * y + x] < value/2) { 81 | /* line is normally light over dark background */ 82 | arrayp[ncols * y + x] = value; 83 | } else { 84 | /* line is black over light background */ 85 | arrayp[ncols * y + x] = 0.0; 86 | } 87 | } 88 | 89 | static int 90 | drawCompareInt (const void *a, const void *b) 91 | { 92 | return (*(const int *)a) - (*(const int *)b); 93 | } 94 | 95 | void 96 | draw_filled_polygon (FitsCutImage *Image, int channel, drawPointPtr p, int n, int c) 97 | { 98 | /* adapted from gdImageFilledPolygon */ 99 | int i; 100 | int y; 101 | int miny, maxy; 102 | int x1, y1; 103 | int x2, y2; 104 | int ind1, ind2; 105 | int ints; 106 | int *polyInts; 107 | 108 | if (!n) 109 | return; 110 | 111 | polyInts = (int *) malloc (sizeof (int) * n); 112 | 113 | miny = p[0].y; 114 | maxy = p[0].y; 115 | for (i = 1; i < n; i++) { 116 | if (p[i].y < miny) 117 | miny = p[i].y; 118 | if (p[i].y > maxy) 119 | maxy = p[i].y; 120 | } 121 | /* Fix in 1.3: count a vertex only once */ 122 | for (y = miny; y <= maxy; y++) { 123 | /*1.4 int interLast = 0; */ 124 | /* int dirLast = 0; */ 125 | /* int interFirst = 1; */ 126 | ints = 0; 127 | for (i = 0; (i < n); i++) { 128 | if (!i) { 129 | ind1 = n - 1; 130 | ind2 = 0; 131 | } else { 132 | ind1 = i - 1; 133 | ind2 = i; 134 | } 135 | y1 = p[ind1].y; 136 | y2 = p[ind2].y; 137 | if (y1 < y2) { 138 | x1 = p[ind1].x; 139 | x2 = p[ind2].x; 140 | } else if (y1 > y2) { 141 | y2 = p[ind1].y; 142 | y1 = p[ind2].y; 143 | x2 = p[ind1].x; 144 | x1 = p[ind2].x; 145 | } else { 146 | continue; 147 | } 148 | if ((y >= y1) && (y < y2)) { 149 | polyInts[ints++] = (y-y1) * (x2-x1) / (y2-y1) + x1; 150 | } else if ((y == maxy) && (y > y1) && (y <= y2)) { 151 | polyInts[ints++] = (y-y1) * (x2-x1) / (y2-y1) + x1; 152 | } 153 | } 154 | qsort (polyInts, ints, sizeof (int), drawCompareInt); 155 | 156 | for (i = 0; (i < (ints)); i += 2) { 157 | draw_line (Image, channel, polyInts[i], y, 158 | polyInts[i+1], y, c); 159 | } 160 | } 161 | } 162 | 163 | void 164 | draw_line (FitsCutImage *Image, int channel, int x1, int y1, int x2, int y2, int value) 165 | { 166 | /* adapted from GD gdImageLine */ 167 | int dx, dy, incr1, incr2, d, x, y, xend, yend, xdirflag, ydirflag; 168 | dx = abs (x2-x1); 169 | dy = abs (y2-y1); 170 | if (dy <= dx) { 171 | d = 2 * dy - dx; 172 | incr1 = 2 * dy; 173 | incr2 = 2 * (dy - dx); 174 | if (x1 > x2) { 175 | x = x2; 176 | y = y2; 177 | ydirflag = (-1); 178 | xend = x1; 179 | } else { 180 | x = x1; 181 | y = y1; 182 | ydirflag = 1; 183 | xend = x2; 184 | } 185 | ImageSetPixel (Image, channel, x, y, value); 186 | if (((y2 - y1) * ydirflag) > 0) { 187 | while (x < xend) { 188 | x++; 189 | if (d <0) { 190 | d += incr1; 191 | } else { 192 | y++; 193 | d+=incr2; 194 | } 195 | ImageSetPixel (Image, channel, x, y, value); 196 | } 197 | } else { 198 | while (x < xend) { 199 | x++; 200 | if (d <0) { 201 | d+=incr1; 202 | } else { 203 | y--; 204 | d+=incr2; 205 | } 206 | ImageSetPixel (Image, channel, x, y, value); 207 | } 208 | } 209 | } else { 210 | d = 2 * dx - dy; 211 | incr1 = 2 * dx; 212 | incr2 = 2 * (dx - dy); 213 | if (y1 > y2) { 214 | y = y2; 215 | x = x2; 216 | yend = y1; 217 | xdirflag = (-1); 218 | } else { 219 | y = y1; 220 | x = x1; 221 | yend = y2; 222 | xdirflag = 1; 223 | } 224 | ImageSetPixel (Image, channel, x, y, value); 225 | if (((x2 - x1) * xdirflag) > 0) { 226 | while (y < yend) { 227 | y++; 228 | if (d <0) { 229 | d+=incr1; 230 | } else { 231 | x++; 232 | d+=incr2; 233 | } 234 | ImageSetPixel (Image, channel, x, y, value); 235 | } 236 | } 237 | else { 238 | while (y < yend) { 239 | y++; 240 | if (d <0) { 241 | d+=incr1; 242 | } else { 243 | x--; 244 | d+=incr2; 245 | } 246 | ImageSetPixel (Image, channel, x, y, value); 247 | } 248 | } 249 | } 250 | } 251 | 252 | static void 253 | draw_arrow (FitsCutImage *Image, 254 | int channel, 255 | int x, 256 | int y, 257 | float angle, 258 | int length, 259 | int width, 260 | int tip_length, 261 | int value) 262 | { 263 | float tip_angle; 264 | float vec[2], outvec[2]; 265 | int num_tip_points; 266 | int x0, y0, x1, y1, tipx, tipy; 267 | drawPointPtr arrow; 268 | drawPointPtr shaft; 269 | 270 | tip_angle = 20.0; 271 | 272 | /* rotate from horizontal */ 273 | vec[0] = length; 274 | vec[1] = 0; 275 | rotate_vector (vec,angle,outvec); 276 | tipx = floor (x + outvec[0] + 0.5); 277 | tipy = floor (y + outvec[1] + 0.5); 278 | 279 | /* find arrow tips */ 280 | vec[0] = -tip_length; 281 | vec[1] = 0; 282 | rotate_vector (vec, angle + tip_angle, outvec); 283 | x0 = floor (tipx + outvec[0] + 0.5); 284 | y0 = floor (tipy + outvec[1] + 0.5); 285 | rotate_vector (vec, angle - tip_angle, outvec); 286 | x1 = floor (tipx + outvec[0] + 0.5); 287 | y1 = floor (tipy + outvec[1] + 0.5); 288 | if (tip_length > 10) { 289 | num_tip_points = (tip_length > 10) ? 4 : 3; 290 | 291 | arrow = (drawPoint *) malloc (sizeof (drawPoint) * num_tip_points); 292 | 293 | arrow[0].x = tipx; 294 | arrow[0].y = tipy; 295 | arrow[1].x = x0; 296 | arrow[1].y = y0; 297 | 298 | arrow[num_tip_points-1].x = x1; 299 | arrow[num_tip_points-1].y = y1; 300 | 301 | if (num_tip_points > 3) { 302 | /* find the new tip of the arrow shaft */ 303 | vec[0] = length - tip_length * 0.8; 304 | vec[1] = 0; 305 | rotate_vector (vec,angle,outvec); 306 | tipx = floor (x + outvec[0] + 0.5); 307 | tipy = floor (y + outvec[1] + 0.5); 308 | arrow[2].x = tipx; 309 | arrow[2].y = tipy; 310 | } 311 | 312 | /* draw the arrow head */ 313 | draw_filled_polygon (Image, channel, arrow, num_tip_points, value); 314 | free (arrow); 315 | } 316 | else { 317 | draw_line (Image, channel, x0, y0, tipx, tipy, value); 318 | draw_line (Image, channel, x1, y1, tipx, tipy, value); 319 | } 320 | 321 | /* draw arrow shaft */ 322 | if (width > 2) { 323 | shaft = (drawPoint *) malloc (sizeof (drawPoint) * 4); 324 | vec[0] = 0; 325 | vec[1] = width / 2; 326 | rotate_vector (vec, angle, outvec); 327 | shaft[0].x = x + outvec[0]; 328 | shaft[0].y = y + outvec[1]; 329 | shaft[1].x = tipx + outvec[0]; 330 | shaft[1].y = tipy + outvec[1]; 331 | vec[0] = 0; 332 | vec[1] = -width / 2; 333 | rotate_vector (vec, angle, outvec); 334 | shaft[3].x = x + outvec[0]; 335 | shaft[3].y = y + outvec[1]; 336 | shaft[2].x = tipx + outvec[0]; 337 | shaft[2].y = tipy + outvec[1]; 338 | draw_filled_polygon (Image, channel, shaft, 4, value); 339 | free (shaft); 340 | } 341 | else { 342 | draw_line (Image, channel, x, y, tipx, tipy, value); 343 | } 344 | 345 | } 346 | 347 | void 348 | draw_wcs_compass (FitsCutImage *Image, float north_pa, float east_pa) 349 | { 350 | float arrow_length; 351 | long center[2]; 352 | int channel = 0; 353 | float east_size_factor = 0.6; 354 | float line_value = 255; 355 | float arrow_size_factor; 356 | int thickness; 357 | int tip_size; 358 | int min_size; 359 | 360 | min_size = (Image->ncolsref > Image->nrowsref) ? Image->nrowsref : Image->ncolsref; 361 | 362 | if (min_size > 1024) 363 | arrow_size_factor = 0.05; 364 | else if (min_size > 512) 365 | arrow_size_factor = 0.10; 366 | else if (min_size > 128) 367 | arrow_size_factor = 0.20; 368 | else 369 | arrow_size_factor = 0.30; 370 | 371 | arrow_length = arrow_size_factor * min_size; 372 | 373 | center[0] = Image->ncolsref - arrow_length - 2; 374 | center[1] = Image->nrowsref - arrow_length - 2; 375 | 376 | thickness = 2; /*floor(arrow_length * 0.05 + 0.5);*/ 377 | if (thickness < 1) 378 | thickness = 1; 379 | 380 | fitscut_message (1, "drawing WCS compass north: %f east: %f thickness: %d\n", 381 | north_pa, east_pa, thickness); 382 | 383 | tip_size = floor (arrow_length * 0.2 + 0.5); 384 | 385 | for (channel = 0; channel < Image->channels; channel++) { 386 | if (Image->data[channel] != NULL) { 387 | /* draw north line */ 388 | draw_arrow (Image, channel, center[0], center[1], north_pa, 389 | arrow_length, thickness, tip_size, line_value); 390 | 391 | /* draw east line */ 392 | draw_arrow (Image, channel, center[0], center[1], east_pa, 393 | arrow_length * east_size_factor, thickness, tip_size, line_value); 394 | } 395 | } 396 | } 397 | 398 | /* draw crosshair marker around center of image */ 399 | 400 | void 401 | draw_center_marker (FitsCutImage *Image) 402 | { 403 | long xcenter, ycenter, insidegap, outsidegap; 404 | int channel = 0; 405 | float line_value = 255; 406 | int min_size; 407 | 408 | xcenter = Image->ncolsref / 2; 409 | ycenter = Image->nrowsref / 2; 410 | min_size = (Image->ncolsref > Image->nrowsref) ? Image->nrowsref : Image->ncolsref; 411 | 412 | if (min_size < 30) { 413 | /* no room for marker */ 414 | fitscut_message (1, "no room for center marker in %d x %d pixel image\n", 415 | Image->ncolsref, Image->nrowsref); 416 | return; 417 | } else if (min_size < 60) { 418 | insidegap = 5; 419 | outsidegap = 5; 420 | } else if (min_size < 100) { 421 | insidegap = 10; 422 | outsidegap = 10; 423 | } else if (min_size < 200) { 424 | insidegap = 10; 425 | outsidegap = 20; 426 | } else if (min_size < 300) { 427 | insidegap = 20; 428 | outsidegap = 40; 429 | } else { 430 | insidegap = 30; 431 | outsidegap = 60; 432 | } 433 | 434 | fitscut_message (1, "drawing center marker with inside gap %d outside gap %d\n", 435 | insidegap, outsidegap); 436 | for (channel = 0; channel < Image->channels; channel++) { 437 | if (Image->data[channel] != NULL) { 438 | draw_line (Image, channel, outsidegap, ycenter, xcenter-insidegap, ycenter, line_value); 439 | draw_line (Image, channel, xcenter+insidegap, ycenter, Image->ncolsref-outsidegap, ycenter, line_value); 440 | draw_line (Image, channel, xcenter, outsidegap, xcenter, ycenter-insidegap, line_value); 441 | draw_line (Image, channel, xcenter, ycenter+insidegap, xcenter, Image->nrowsref-outsidegap, line_value); 442 | } 443 | } 444 | } 445 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. 341 | --------------------------------------------------------------------------------