[fitsbits] top or bottom

Clive Page cgp at nospam.le.ac.uk
Mon May 8 08:33:57 EDT 2000


In article <Pine.HPX.4.03.10005051549130.22873-100000 at galileo.csun.edu>,
Stephen Walton  <swalton at galileo.csun.edu> wrote:
>> call FITSIO is that you can set up a module containing interface
>> definitions of all the FITSIO routines you ever use...
>
>Can you put these up on the Web somewhere and/or contribute them to Bill
>Pence?  It would be even better to have a Fortran-90-style interface to
>FITSIO which would take advantage of things like optional arguments and
>the SIZE intrinsic.  

I had thought of doing that, but the set of interfaces I had created for
my own use is only a small subset of all the routines in the FITSIO
library, and I thought that (apart from all those writing code for
XMM-Newton) hardly anyone called FITSIO from Fortran90.  But I'm pleased to
hear your suggestion to the contrary.

> I think I remember reading in a NAG press release
>that the average number of (required) arguments for NAG Fortran library
>routines was 9 for the Fortran-77 version and 2 for the Fortran-90
>version.

If you take advantage of optional arguments it can indeed greatly simplify
many calls, but with FITSIO there is a mild difficulty: the rules of
Fortran specify that after you omit any optional argument in a call,
either all the rest of the arguments must also be optional and omitted, or
keywords have to be used for the rest.  (Some F77 compilers allowed you to
omit args by having two or more adjacent commas, but this isn't part of any
Fortran Standard).

The STATUS argument at the end is then a problem: either you move it to
some other position, or you have to refer to it with a keyword if you omit
earlier optional arguments.

In case what I have just said seems clear as mud, perhaps an example will
help.  Let's use as a very simple example the routine FTMAHD, defined as:  
      FTMAHD(unit, nhdu, >hdutype, status)

Since in many cases you won't care what hdutype is found when moving to an
absolute nhud, you might chose to make hdutype an optional argument.
There are then two obvious ways of doing this:

(a) keep the existing argument order; in this case you can legally use
      call ftmahd(myunit, myhdu, myhdutype, mystat)
but if you want to omit the optional argument, you will need this:
      call ftmahd(myunit, myhdu, status=mystat)

(b) move the status arg earlier, say to the beginning, then you can use
either of these forms:
      call ftmahd(mystat, myunit, myhdu, myhdutype)
      call ftmahd(mystat, myunit, myhdu)
which is obviously a bit neater for the simpler case.

Any preferences?

-- 
-- 
Clive Page,
Dept of Physics & Astronomy,               
University of Leicester.                   



More information about the fitsbits mailing list