From fitsbits-request Tue Dec 20 19:36:43 1994 X-VM-v5-Data: ([t nil nil nil nil nil nil nil nil] ["3291" "" "20" "December" "1994" "23:55:49" "GMT" "Rob Seaman" "seaman@noao.edu" nil "101" "FITS checksum proposal" "^From:" nil nil "12" nil nil nil nil] nil) Received: by fits.cv.nrao.edu (4.1/DDN-DLB/1.5) id AA27601; Tue, 20 Dec 94 19:36:43 EST Return-Path: Message-Id: <3d7qu5$6ol@noao.edu> Organization: National Optical Astronomy Observatories, Tucson, AZ, USA Path: solitaire.cv.nrao.edu!hearst.acc.Virginia.EDU!caen!newsxfer.itd.umich.edu!europa.eng.gtefsd.com!library.ucla.edu!csulb.edu!nic-nac.CSU.net!news.Cerritos.edu!news.Arizona.EDU!CS.Arizona.EDU!noao!seaman Newsgroups: sci.astro.fits From: seaman@noao.edu (Rob Seaman) Sender: fitsbits-request@fits.CV.NRAO.EDU To: fitsbits@fits.CV.NRAO.EDU Subject: FITS checksum proposal Date: 20 Dec 1994 23:55:49 GMT FITS Checksum Proposal R.L. Seaman and W.D. Pence 20 December 1994 ABSTRACT This paper describes a simple means for embedding a checksum within a FITS header, providing a mechanism for later verifying the integrity of the FITS file. The method uses ASCII coded 32 bit 1's complement arithmetic to force the checksum of each FITS HDU to zero. This technique requires no extension of the FITS standard to be used by any given project, in fact the technique may be used to zero the checksum of any ASCII file. The purpose of this proposal is simply to reserve keywords that will allow projects and software packages to seamlessly verify and update each other's data. -------- A copy of the proposal is available via anonymous ftp from iraf.noao.edu in the /misc/checksum directory, where you will find the following files: README this file checksum.ps FITS Checksum Proposal, Seaman & Pence stb249851.fits FITS file w/ CHECKSUM and DATASUM keywords sum32.tar simple C program to calculate the 32 bit 1's complement checksum and to ASCII encode the checksum (w/ SunOS binary) FITS.sum.example pseudo FITS header with CHECKSUM keyword FITS.sum.zeroed same header with the checksum zeroed -------- The two files, FITS.sum.example and FITS.sum.zeroed, are an example of how the technique works. Before accumulating the checksum for a FITS file, set the value of the CHECKSUM keyword to all 0's: SIMPLE = T / BITPIX = 8 / NAXIS = 0 / to align the next keyword CHECKSUM= '0000000000000000' / ASCII 1's complement checksum DATASUM = '0000000000000000' / checksum of data records END (The comment for the NAXIS keyword shifts the alignment of the CHECKSUM keyword to impersonate real FITS - these are not 80 character cardimages.) For this example, calculate the checksum using the sum32 program: % sum32 -p FITS.sum.example checksum16: 23910 = IHKGIGIG complement: 41625 = VZWXVXVX checksum32: 3708584025 = Fh3PGg3PFg3PFg3P complement: 0586383270 = YAoRa1lOS8lOY8lO file size: 255 bytes (The -p tells the program to permute the ASCII encoding for the odd byte alignment required by placement of the FITS keyword value.) Edit the header to replace the 0's with the complement of the checksum (32 bit version): SIMPLE = T / BITPIX = 8 / NAXIS = 0 / to align the next keyword CHECKSUM= 'YAoRa1lOS8lOY8lO' / ASCII 1's complement checksum DATASUM = '0000000000000000' / checksum of data records END with the result that the checksum of the FITS header (or file, or extension) is set to zero: % sum32 FITS.sum.zeroed checksum16: 65535 = rroooooo complement: 00000 = 00000000 checksum32: 4294967295 = rrrroooooooooooo complement: 0000000000 = 0000000000000000 file size: 255 bytes To later verify the file, accumulate the checksum and see if the checksum is still zero. Rob Seaman seaman@noao.edu Bill Pence pence@tetra.gsfc.nasa.gov -- Rob Seaman: seaman@noao.edu/602-325-9248 National Optical Astronomy Observatories 950 North Cherry Avenue, Tucson AZ 85719