next up previous FITS Documents
Next: Alternate Checksum Algorithms Up: Discussion Previous: Checksum Keyword Alignment

Checksum Keyword Example

The following is an example of how the CHECKSUM, DATASUM, and CHECKVER keywords are used. For the default case of the ASCII coded 32-bit 1's complement checksum, omitting the CHECKVER keyword is preferred, but it is included here for the sake of completeness. The example uses a primary FITS header, but the identical usage applies for extension headers.

         1         2         3         4         5         6
12345678901234567890123456789012345678901234567890123456789012345...
SIMPLE  =                    T  /  standard FITS format
...
CHECKSUM= 'hcHjjc9ghcEghc9g'    /  ASCII 1's complement checksum
DATASUM = '2503531142'          /  checksum of data records
CHECKVER= 'COMPLEMENT'          /  checksum version ID
END

To calculate the two checksums, first accumulate the checksum of the data records, format this unsigned integer into a character string (for portability) and update the DATASUM keyword. Next, set the CHECKSUM keyword value to '0000000000000000' and calculate the checksum of the header records. Add the DATASUM to the header checksum and bit complement the total. This is the 1's complement additive inverse of the total. ASCII encode this value and write it into the CHECKSUM keyword, replacing the 0's. The checksum of the FITS HDU is now zeroed. A few points:


next up previous FITS Documents
Next: Alternate Checksum Algorithms Up: Discussion Previous: Checksum Keyword Alignment