Skip to content

Commit

Permalink
Merge pull request #14020 from saimn/cfitsio-4.2.0
Browse files Browse the repository at this point in the history
Update cfitsio to 4.2.0
  • Loading branch information
astrofrog committed Nov 29, 2022
2 parents 591bd17 + ae45a90 commit 93a243d
Show file tree
Hide file tree
Showing 45 changed files with 22,064 additions and 6,683 deletions.
2 changes: 1 addition & 1 deletion astropy/io/fits/setup_package.py
Expand Up @@ -43,7 +43,7 @@ def _get_compression_extension():
"/D",
"_CRT_SECURE_NO_DEPRECATE",
"/D",
"FF_NO_UNISTD_H",
"YY_NO_UNISTD_H",
]
)
else:
Expand Down
55 changes: 55 additions & 0 deletions cextern/cfitsio/docs/changes.txt
@@ -1,5 +1,60 @@
Log of Changes Made to CFITSIO

Version 4.2.0 - Nov 2022

- This release includes patches to security vulnerabilities. We
strongly encourage this upgrade, particularly for those running
CFITSIO in web accessible applications.

- Fix to fits_read_key function, which was failing to properly read
keywords declared type TUINT on compilers where sizeof(int) =
sizeof(long).

- Added new functions fits_read_cols and fits_write_cols to efficiently
read or write multiple columns in a single function call

- Added new function fits_copy_selrows to copy only selected rows, such
as the selected rows returned by fits_find_rows

- Added new calculator functions ERF(X), ERFC(X) and GAMMA(X), which are
mathematical special functions of the same name

- Added new calculator function GTIFIND() which reports which GTI row
brackets a given time sample

- Added new calculator functions which operate upon vector table
values NAXIS(V), NAXES(V,n), ELEMENTNUM(V) and AXISELEM(V,n),
and ARRAY(X,d) which promotes scalar X to a vector or array
with given dimensions.

- The CFITSIO histogramming code now handles binning by any
arbitrary calculator expression rather than just a column name.
Both the binned columns as well as the optional weights may be
calculator expressions, enclosed in parentheses.

- Binning of vector columns or expressions is now supported, as long
as all binned inputs (as well as the optional weighting) have the
same vector dimensions. Binning of variable-length columns remains
unsupported.

- A bug that caused histogram weights from columns that are null values
to be tallied along with non-null values has been fixed.

- The CFITSIO calculator and histogramming functionality is now
fully reentrant and does not require multithreading interlocks.

- A long-standing segmentation fault bug in the histogramming code
related to binning any value using the "reciprocal" /XXXX notation
has been fixed.

- Added mutex locks for thread safety in ftgiou and ftfiou.

- Added several Fortran wrappers to support image read/write when
'fpixel' and 'nelements' are 8-byte integers.

- Fixed bug which was adding spaces to some cases of long string key
value output.

Version 4.1.0 - Feb 2022

- Calls to the zlib inflate() function in zcompress.c now handle
Expand Down
71 changes: 58 additions & 13 deletions cextern/cfitsio/lib/cfileio.c
Expand Up @@ -1306,23 +1306,28 @@ int ffopen(fitsfile **fptr, /* O - FITS file pointer */

if (*binspec)
{
char **exprs = 0;
if (*histfilename && !(*pixfilter) )
strcpy(outfile, histfilename); /* the original outfile name */
else
strcpy(outfile, "mem://_3"); /* create histogram in memory */
/* if not already copied the file */

/* parse the binning specifier into individual parameters */
ffbins(binspec, &imagetype, &haxis, colname,
minin, maxin, binsizein,
minname, maxname, binname,
&weight, wtcol, &recip, status);

ffbinse(binspec, &imagetype, &haxis, colname,
minin, maxin, binsizein,
minname, maxname, binname,
&weight, wtcol, &recip, &(exprs), status);
/* Create the histogram primary array and open it as the current fptr */
/* This will close the table that was used to create the histogram. */
ffhist2(fptr, outfile, imagetype, haxis, colname, minin, maxin,
binsizein, minname, maxname, binname,
weight, wtcol, recip, rowselect, status);
ffhist2e(fptr, outfile, imagetype, haxis,
colname, exprs, minin, maxin, binsizein,
minname, maxname, binname,
weight, wtcol, (exprs?exprs[4]:0),
recip, rowselect, status);

if (exprs) free(exprs);

if (rowselect)
free(rowselect);
Expand Down Expand Up @@ -1736,6 +1741,38 @@ static int find_quote(char **string)
}
return(1); /* opps, didn't find the closing character */
}

/*--------------------------------------------------------------------------*/
char *fits_find_match_delim(char *string, char delim)
/*
Find matching delimiter, respecting quoting and (potentially nested) parentheses
char *string - null-terminated string to be searched for delimiter
char delim - single delimiter to search for (one of '")]} )
returns: pointer to character after delimiter, or 0 if not found
*/
{
char *tstr = string;
int retval = 0;

if (!string) return 0;
switch (delim) {
case '\'': retval = find_quote(&tstr); break;
case '"': retval = find_doublequote(&tstr); break;
case '}': retval = find_curlybracket(&tstr); break;
case ']': retval = find_bracket(&tstr); break;
case ')': retval = find_paren(&tstr); break;
default: return 0; /* Invalid delimeter, return failure */
}

/* Delimeter not found, return failure */
if (retval) return 0;

/* Delimeter was found, return next position */
return (tstr);
}

/*--------------------------------------------------------------------------*/
static int find_doublequote(char **string)

Expand Down Expand Up @@ -6121,11 +6158,12 @@ int ffifile2(char *url, /* input filename */
return(*status = URL_PARSE_ERROR);
}

strcpy(binspec, ptr1 + 1);
ptr2 = strchr(binspec, ']');
strcpy(binspec, ptr1 + 1);
ptr2 = fits_find_match_delim(binspec, ']');

if (ptr2) /* terminate the binning filter */
{
--ptr2; /* points beyond delimeter, so rewind by 1 */
*ptr2 = '\0';

if ( *(--ptr2) == ' ') /* delete trailing spaces */
Expand All @@ -6141,9 +6179,16 @@ int ffifile2(char *url, /* input filename */
}

/* delete the binning spec from the row filter string */
ptr2 = strchr(ptr1, ']');
strcpy(tmpstr, ptr2+1); /* copy any chars after the binspec */
strcpy(ptr1, tmpstr); /* overwrite binspec */
ptr2 = fits_find_match_delim(ptr1+1, ']');
if (ptr2) {
strcpy(tmpstr, ptr2); /* copy any chars after the binspec */
strcpy(ptr1, tmpstr); /* overwrite binspec */
} else {
ffpmsg("input file URL is missing closing bracket ']'");
ffpmsg(rowfilter);
free(infile);
return(*status = URL_PARSE_ERROR); /* error, no closing ] */
}
}

/* --------------------------------------------------------- */
Expand Down
31 changes: 31 additions & 0 deletions cextern/cfitsio/lib/drvrmem.c
Expand Up @@ -1237,6 +1237,37 @@ int mem_write(int hdl, void *buffer, long nbytes)
return(0);
}

/*--------------------------------------------------------------------------*/
int mem_zuncompress_and_write(int hdl, void *buffer, long nbytes)
/*
uncompress input buffer, length nbytes and write bytes to current
position in file. output buffer needs to be at position 0 to start.
*/
{
size_t newsize;
int status = 0;

if (memTable[hdl].currentpos != 0) {
ffpmsg("cannot append uncompressed data (mem_uncompress_and_write)");
return(WRITE_ERROR);
}

uncompress2mem_from_mem(buffer, nbytes,
memTable[hdl].memaddrptr,
memTable[hdl].memsizeptr,
memTable[hdl].mem_realloc,
&newsize, &status);

if (status) {
ffpmsg("unabled to uncompress memory file (mem_uncompress_and_write)");
return(WRITE_ERROR);
}

memTable[hdl].currentpos += newsize;
memTable[hdl].fitsfilesize = newsize;
return(0);
}


#if HAVE_BZIP2
void bzip2uncompress2mem(char *filename, FILE *diskfile, int hdl,
Expand Down

0 comments on commit 93a243d

Please sign in to comment.