[AIT logo]

Institut für Astronomie und Astrophysik

Abteilung Astronomie

Sand 1, D-72076 Tübingen, Germany
[Uni logo]


CHECKSUM32 Source code in checksum32.pro

CHECKSUM32

Name
       CHECKSUM32
Purpose
       To compute the 32bit checksum of an array (ones-complement arithmetic)
Explanation
       The 32bit checksum is adopted in the FITS Checksum convention
       http://heasarc.gsfc.nasa.gov/docs/heasarc/fits/checksum.html
Calling Sequence
       CHECKSUM32, array, checksum, [/FROM_IEEE, /NoSAVE]
Input Parameters
       array - any numeric idl array.  If the number of bytes in the array is
               not a multiple of four then it is padded with zeros internally
               (the array is returned unchanged).   Convert a string array
               (e.g. a FITS header) to bytes prior to calling CHECKSUM32.
Output Parameters
       checksum - unsigned long scalar, giving sum of array elements using
                  ones-complement arithmetic
Keyword Parameters
      /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. Linux boxes).
      /NoSAVE - if set, then the input array is not saved upon exiting.   Use
           the /NoSave keyword to save time if the input array is not needed
           in further computations.
Procedure
       Uses TOTAL() to sum the array into a double precision variable.  The
       overflow bits beyond 2^32 are then shifted back to the least significant
       bits.    Due to the limited precision of a DOUBLE variable, the summing
       is done in chunks determined by MACHAR(). Adapted from FORTRAN code in
      heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/checksum/node30.html
      Could probably be done in a cleverer way (similar to the C
      implementation) but then the array-oriented TOTAL() function could not
      be used.
Restrictions
       (1) Requires V5.2 or later (uses unsigned integers)
       (2) Not valid for object or pointer data types
Example
       Find the 32 bit checksum of the array x = findgen(35)
       IDL> checksum32, x, s    ===> s =  2920022024
Procedures Used
       IS_IEEE_BIG(), N_BYTES()
Revision History
       Written    W. Landsman          June 2001
       Work correctly on little endian machines, added /FROM_IEEE and /NoSave
                  W. Landsman          November 2002
       Pad with zeros when array size not a multiple of 4 W.Landsman Aug 2003
       Always copy to new array, somewhat slower but more robust algorithm
           especially for Linux boxes   W. Landsman Sep. 2004
       Sep. 2004 update not implemented correctly (sigh) W. Landsman Dec 2004

Last modified by pro2html on 2004 December 11 at 05:01 UTC

[Home Page] [Software, Documentation] [IDL Documentation] [Quick Reference] [Feedback]

Jörn Wilms (wilms@astro.uni-tuebingen.de)
Updated automatically