idlastro / FITS I/O: FITS_TEST_CHECKSUM

[Source code]

NAME
FITS_TEST_CHECKSUM()
PURPOSE
Verify the values of the CHECKSUM and DATASUM keywords in a FITS header 
EXPLANATION
Follows the 2007 version of the FITS checksum proposal at 
http://fits.gsfc.nasa.gov/registry/checksum.html
CALLING SEQUENCE
result = FITS_TEST_CHECKSUM(HDR, [ DATA, ERRMSG=, /FROM_IEEE ])
INPUTS
HDR - FITS header (vector string)
OPTIONAL DATA
DATA - data array associated with the FITS header.   An IDL structure is 
       not allowed.    If not supplied, or
       set to a scalar, then there is assumed to be no data array 
       associated with the FITS header.
RESULT
An integer -1, 0 or 1 indicating the following conditions:
      1 - CHECKSUM (and DATASUM) keywords are present with correct values
      0 - CHECKSUM keyword is not present
     -1 - CHECKSUM or DATASUM keyword does not have the correct value
          indicating possible data corruption.
OPTIONAL INPUT KEYWORD
/FROM_IEEE - If this keyword is set, then the input is assumed to be in 
         big endian format (e.g. an untranslated FITS array).    This 
         keyword only has an effect on little endian machines (e.g. 
         a Linux box).
/TRUST_DATASUM - If this keyword is set, then the DATA input
         parameter is ignored and the DATASUM keyword in the HDR
         is assumed to be correct. (If there is no DATASUM
         keyword, /TRUST_DATASUM has no effect.)    Useful if data is too
         large to store entirely in memory at one time.
OPTIONAL OUTPUT KEYWORD
ERRMSG - will contain a scalar string giving the error condition.   If
         RESULT = 1 then ERRMSG will be an empty string.   If this 
         output keyword is not supplied, then the error message will be
         printed at the terminal.
NOTES
The header and data must be *exactly* as originally written in the FITS 
file.  By default, some FITS readers may alter keyword values (e.g. 
BSCALE) or append information (e.g. HISTORY or an inherited primary 
header) and this will alter the checksum value.           
PROCEDURES USED
CHECKSUM32, FITS_ASCII_ENCODE(), SXPAR()
EXAMPLE
Verify the CHECKSUM keywords in the primary header/data unit of a FITS 
file 'test.fits'
FITS_READ,'test.fits',data,hdr,/no_PDU,/NoSCALE
print,FITS_TEST_CHECKSUM(hdr,data)
Note the use of the /No_PDU and /NoSCALE keywords to avoid any alteration 
of the FITS header
REVISION HISTORY
W. Landsman  SSAI               December 2002
Return quietly if CHECKSUM keywords not found W. Landsman May 2003
Add /NOSAVE to CHECKSUM32 calls when possible W. Landsman Sep 2004
New option /TRUST_DATASUM. Mats Löfdahl July 2020