Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions INSTALL_HLAWEB

This file was deleted.

22 changes: 0 additions & 22 deletions INSTALL_SOLARIS

This file was deleted.

34 changes: 0 additions & 34 deletions INSTALL_WITH_SCISOFT

This file was deleted.

36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ General Information
===================

fitscut is designed to extract cutouts from FITS image format files.
FITS, PNG, and JPEG output types are supported.
FITS, PNG, and JPEG output types are supported.

When multiple input files are specified and the output type is PNG or
JPEG the resulting image is an RGB color image.
Expand All @@ -12,37 +12,32 @@ Information on the FITS file format is available from
http://fits.gsfc.nasa.gov/.


A cgi interface to fiscut is avilable here: https://hla.stsci.edu/fitscutcgi_interface.html
A cgi interface to fitscut is available here: https://hla.stsci.edu/fitscutcgi_interface.html

Dependencies
============

In order to build fitscut you will need:

CFITSIO library
<http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html>
- CFITSIO library: <http://heasarc.gsfc.nasa.gov/docs/software/fitsio/fitsio.html>

LIBPNG
<http://www.libpng.org/pub/png/libpng.html>
- LIBPNG: <http://www.libpng.org/pub/png/libpng.html>

JPEG library
<http://www.ijg.org/>
- JPEG library: <http://www.ijg.org/>

And optionally:

WCS Subroutine library
<ftp://cfa-ftp.harvard.edu/pub/gsc/WCSTools/>

- WCS Subroutine library: <http://tdc-www.harvard.edu/software/wcstools/>\
(The WCS library was originally optional but is required in this version of fitscut.)

Supported Platforms
===================

fitscut has been tested and is known to work on:

RedHat Linux 8, 9
RedHat Enterprise Linux 3
Fedora Core 1
Solaris 8, 9
RedHat Linux 8, 9\
RedHat Enterprise Linux 3\
Fedora Core 1\
Solaris 8, 9
MacOS 10.12 (and other OSX versions)

Installation
============
Expand All @@ -51,13 +46,18 @@ Please see the INSTALL file.

This usually consists of:

% gzip -cd fitscut-1.4.0.tar.gz | tar xvf - # unpack the sources
```
% tar xzvf fitscut-1.4.0.tar.gz # unpack the sources
% cd fitscut-1.4.0 # change to the directory
% ./configure # run the 'configure' script
% make # build fitscut
[ Become root if necessary ]
% make install # install fitscut
```

The usual configure options are available (e.g., `--prefix=/your/install/location` to specify where the binary executable should be installed).
You can define the `CFLAGS` and `LDFLAGS` environment variables to specify the locations of include files and libraries before running
`./configure`.

-----
Copyright (C) 2001 William Jon McCann
Expand Down
14 changes: 12 additions & 2 deletions extract.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,15 @@ extract_fits (FitsCutImage *Image)

/* determine zoomed image size */

if (Image->output_zoom[k] > 0) {
if (Image->output_alignment == ALIGN_REF) {
/* estimate zoom factor based on image region and output sizes */
zoom_factor = ((float) Image->nrowsref)/((float) nrows);
if (zoom_factor > 1) {
zoom_factor = 1.0;
} else {
zoom_factor = 1.0/lround(1.0/zoom_factor);
}
} else if (Image->output_zoom[k] > 0) {
zoom_factor = Image->output_zoom[k];
}
else {
Expand All @@ -658,6 +666,7 @@ extract_fits (FitsCutImage *Image)
get_zoom_size_channel (ncols, nrows, zoom_factor, Image->output_size,
&pixfac, &zoomcols, &zoomrows, &doshrink);
fitscut_message (1, "\tZoomed output size is %d x %d\n", zoomcols, zoomrows);
fitscut_message(2, "\tpixfac = %d\n", pixfac);

/* CFITSIO starts indexing at 1 */
x0 += 1;
Expand Down Expand Up @@ -731,6 +740,7 @@ extract_fits (FitsCutImage *Image)
zoomcols, zoomrows);
arrayptr = cutout_alloc (zoomcols, zoomrows, NAN);

nbad = 0;
if (cols_read > 0 && rows_read > 0) {
if (pixfac > 1) {
fitscut_message (2, "\tAllocating space for %d x %d buffer\n",
Expand Down Expand Up @@ -845,7 +855,7 @@ extract_fits (FitsCutImage *Image)
Image->output_zoom[k] = 1.0;
}

if (pixfac > 1) {
if (pixfac > 1 && cols_read > 0 && rows_read > 0) {
free(bufferptr);
}

Expand Down
42 changes: 42 additions & 0 deletions output_fits.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,26 @@ fitscut_clean_header(fitsfile *fptr, FitsCutImage *Image, int *status) {
if (*status) printerror (*status);
}


/* return true if the keyword exists in the header */
static int
header_has_key(fitsfile *fptr, char *keyname, int *status)
{
char value[81];

if (*status == 0) {
fits_read_keyword(fptr, keyname, value, NULL, status);
if (*status == VALUE_UNDEFINED || *status == KEY_NO_EXIST) {
*status = 0;
return 0; /* no such keyword */
} else if (*status == 0) {
return 1; /* keyword found */
}
}
/* error in status */
return 0;
}

void
write_to_fits(FitsCutImage *Image)
{
Expand Down Expand Up @@ -338,6 +358,28 @@ write_to_fits(FitsCutImage *Image)
fits_update_key(fptr, TDOUBLE, "CRPIX1", &crpix,
"Reference pixel shifted for cutout", &status);
fitscut_message (2, "\tUpdated CRPIX1 to %f\n", crpix);
/*
* add RADESYS keyword if it is missing (for PS1 images)
* only do this if both RADESYS and EQUINOX are missing and the
* image has the old PC001001 keyword
*/
if (status == 0) {
if ((! header_has_key(fptr, "RADESYS", &status))
& (! header_has_key(fptr, "EQUINOX", &status))
& header_has_key(fptr, "PC001001", &status) ) {
/* keyword not found, add it */
if (fits_write_key(fptr, TSTRING, "RADESYS", "FK5", "added by fitscut", &status))
printerror (status);
fitscut_message (2, "\tAdded RADESYS keyword\n");
/* also add the TIMESYS keyword for PS1 images (which are the source of the RADESYS problem) */
if (! header_has_key(fptr, "TIMESYS", &status)) {
/* keyword not found, add it */
if (fits_write_key(fptr, TSTRING, "TIMESYS", "TAI", "added by fitscut", &status))
printerror (status);
fitscut_message (2, "\tAdded TIMESYS keyword\n");
}
}
}
} else if (status == VALUE_UNDEFINED || status == KEY_NO_EXIST) {
/* no CRPIX, so skip updating WCS */
fitscut_message (2, "\tNo CRPIX1 found, header not updated\n");
Expand Down
76 changes: 57 additions & 19 deletions output_graphic.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,13 @@ static void
jpg_add_header_info(FitsCutImage *Image, GraphicsInfo *info)
{
struct jpeg_compress_struct *cinfo_ptr = &(info->jpeg_info);
char output_text[11*80];
char output_text[15*80];
/* initialize these to eliminate compiler warnings */
double crval1=0, crval2=0, crpix1=0, crpix2=0, cd1_1=1, cd1_2=0, cd2_1=0, cd2_2=1, cdelt1=1, cdelt2=1, crota2=0, zoom=1;
double crval1=0, crval2=0, crpix1=0, crpix2=0, cd1_1=1, cd1_2=0, cd2_1=0, cd2_2=1,
cdelt1=1, cdelt2=1, crota2=0, pc1_1=0, pc1_2=0, pc2_1=0, pc2_2=0, zoom=1;
char ctype1[FLEN_VALUE], ctype2[FLEN_VALUE];
/* counts for various classes of keywords */
int crcount = 0, cdcount = 0, delcount = 0, rotcount = 0;
int crcount = 0, cdcount = 0, delcount = 0, rotcount = 0, pccount=0;

int status = 0;
char *header, keyname[FLEN_KEYWORD];
Expand Down Expand Up @@ -422,6 +423,22 @@ jpg_add_header_info(FitsCutImage *Image, GraphicsInfo *info)
fits_parse_value (card, value_string, comment, &status);
cd2_2 = strtod (value_string, (char **)NULL);
cdcount += 1;
} else if (strequ (keyname, "PC001001") || strequ(keyname, "PC1_1")) {
fits_parse_value (card, value_string, comment, &status);
pc1_1 = strtod (value_string, (char **)NULL);
pccount += 1;
} else if (strequ (keyname, "PC001002") || strequ(keyname, "PC1_2")) {
fits_parse_value (card, value_string, comment, &status);
pc1_2 = strtod (value_string, (char **)NULL);
pccount += 1;
} else if (strequ (keyname, "PC002001") || strequ(keyname, "PC2_1")) {
fits_parse_value (card, value_string, comment, &status);
pc2_1 = strtod (value_string, (char **)NULL);
pccount += 1;
} else if (strequ (keyname, "PC002002") || strequ(keyname, "PC2_2")) {
fits_parse_value (card, value_string, comment, &status);
pc2_2 = strtod (value_string, (char **)NULL);
pccount += 1;
} else if (strequ (keyname, "CDELT1")) {
fits_parse_value (card, value_string, comment, &status);
cdelt1 = strtod (value_string, (char **)NULL);
Expand Down Expand Up @@ -449,8 +466,8 @@ jpg_add_header_info(FitsCutImage *Image, GraphicsInfo *info)

/* update WCS info */

fitscut_message (3, "\tWCS counts: crval/pix/type %d cd1_1 %d cdelt %d rota %d\n",
crcount, cdcount, delcount, rotcount);
fitscut_message (3, "\tWCS counts: crval/pix/type %d cd1_1 %d pc1_1 %d cdelt %d rota %d\n",
crcount, cdcount, pccount, delcount, rotcount);
if (crcount == 6 && (cdcount == 4 || delcount == 2)) {
zoom = Image->output_zoom[0];
if (zoom == 0.0) zoom = 1.0;
Expand Down Expand Up @@ -483,20 +500,41 @@ jpg_add_header_info(FitsCutImage *Image, GraphicsInfo *info)
cdelt2 = cdelt2/zoom;
/* CROTA2 is optional */
if (rotcount == 0) crota2 = 0.0;
sprintf(output_text,
"CTYPE1 = %s\n"
"CTYPE2 = %s\n"
"CRPIX1 = %.15g\n"
"CRPIX2 = %.15g\n"
"CRVAL1 = %.15g\n"
"CRVAL2 = %.15g\n"
"CDELT1 = %.15g\n"
"CDELT2 = %.15g\n"
"CROTA2 = %.15g\n"
"COMMENT Created by fitscut %s (William Jon McCann)\n",
ctype1, ctype2, crpix1, crpix2, crval1, crval2,
cdelt1, cdelt2, crota2, VERSION);
fitscut_message (2, "\tAdded CDELT1 format WCS to JPEG comment\n");
if (pccount == 4) {
sprintf(output_text,
"CTYPE1 = %s\n"
"CTYPE2 = %s\n"
"CRPIX1 = %.15g\n"
"CRPIX2 = %.15g\n"
"CRVAL1 = %.15g\n"
"CRVAL2 = %.15g\n"
"CDELT1 = %.15g\n"
"CDELT2 = %.15g\n"
"CROTA2 = %.15g\n"
"PC1_1 = %.15g\n"
"PC1_2 = %.15g\n"
"PC2_1 = %.15g\n"
"PC2_2 = %.15g\n"
"COMMENT Created by fitscut %s (William Jon McCann)\n",
ctype1, ctype2, crpix1, crpix2, crval1, crval2,
cdelt1, cdelt2, crota2, pc1_1, pc1_2, pc2_1, pc2_2, VERSION);
fitscut_message (2, "\tAdded PC/CDELT1 format WCS to JPEG comment\n");
} else {
sprintf(output_text,
"CTYPE1 = %s\n"
"CTYPE2 = %s\n"
"CRPIX1 = %.15g\n"
"CRPIX2 = %.15g\n"
"CRVAL1 = %.15g\n"
"CRVAL2 = %.15g\n"
"CDELT1 = %.15g\n"
"CDELT2 = %.15g\n"
"CROTA2 = %.15g\n"
"COMMENT Created by fitscut %s (William Jon McCann)\n",
ctype1, ctype2, crpix1, crpix2, crval1, crval2,
cdelt1, cdelt2, crota2, VERSION);
fitscut_message (2, "\tAdded CDELT1 format WCS to JPEG comment\n");
}
}
} else {
/* no WCS found, so just add the comment */
Expand Down
Loading