FITS long integer support (was Re: [fitsbits] ADASS FITS BoF on Sunday)

Clive Page cgp at star.le.ac.uk
Sat Oct 23 06:52:40 EDT 2004


On Fri, 22 Oct 2004, Thomas McGlynn wrote:

> The notations integer*2, integer*4 and integer*8 are all non-standard
> Fortran and are not included in any of the Fortran standards F66, F77, F90, F95 or
> the impending F2003.  Integer*2 has never been standard Fortran.

Correct.  In practice, however, their use is so widespread that
compiler-writers have been forced to support them.  I have used quite a
wide range of Fortran compilers and never in recent years come across any
which don't support all these.  The open source compilers g77 and g95 both
support all these, despite in other respects restricting themselves pretty
much to the respective official Fortran Standards.  The g77 documentation
says that INTEGER*8 may not be fully supported, but in practice I haven't
found any problems.


> Fortran (i.e., the standard) has no mechanism to specify the length in
> bytes of the desired variable.  The standard way to get different
> kinds of integers is something like
>
>        integer (kind=n) i,j,k

That's only half the story, as Tom probably knows, as the mapping from the
kind-selector n to a number of bytes is intentionally unspecified by the
Fortran90/95/2003 standards, and in practice it varies.  What you do
instead is select the number of *decimal* digits you need, so that, say

    integer (kind=select_int_kind(12)) :: i, j, k

will force the compiler to give you storage capable of storing an integer
of up to 12 digits, which may in practice mean 8 bytes (or if that's
impossible is guaranteed to give you a compiler-time error).  That doesn't
map very well to our image of storage as always an integer number of
bytes, but then Fortran was first standardised in the era when we, at
least, were using 12-bit and 60-bit computers, both of which had Fortran
compilers, and neither had any notion of bytes.

Now that byte-based storage is ubiquitous, these extreme portability
measures in Fortran seem a bit superfluous.  But since FITS goes back to
the same vintage, perhaps we shouldn't criticise.


-- 
Clive Page
Dept of Physics & Astronomy,
University of Leicester,
Leicester, LE1 7RH,  U.K.




More information about the fitsbits mailing list