Monday, June 3, 2013

RATRAN : get RESTFREQ written to FITS file

Current versions of RATRAN (http://www.sron.rug.nl/~vdtak/ratran/) does not put the FITS keyword RESTFREQ and the corresponding value in the output FITS-files by default. Below is a quick fix that I forgot to note down when I figured it out and thus had to rediscover twice...

Note about getting FITS output working:
make sure your shell variable CFITSIO is set to the path where it is installed, on my Ubuntu 13.04 this is CFITSIO=/usr/include:/usr/lib/x86_64-linux-gnu/:/usr/lib (several paths to make sure its correct) and also the LD_LIBRARY_PATH path (e.g. LD_LIBRARY_PATH=$LD_LIBRARY_PATH/usr/include)

So for the RESTFREQ to be printed we need to add it to the routine 'openfits', so edit 'Ratran_install_dir/sky/openfits.f'

first add restfreq to the definition of the routine
change
SUBROUTINE openfits(lout,outname,naxis,naxes,status)
to
SUBROUTINE openfits(lout,outname,naxis,naxes,status,restfreq)
 then define the type
DOUBLE PRECISION restfreq
this should be added after the declaration of the other variables, i.e. after these lines

      INTEGER lout,blocksize,bitpix,status,naxis,naxes(3)
    LOGICAL simple,extend
    CHARACTER outname*60

then we need to tell it when and how to write it to the fits, so just after all the other header keywords are written, i.e.
...
call ftpkyd(lout,'CDELT3',dble(velres),-8,'',status)
call ftpkyd(lout,'CRPIX3',dble(nchan/2+1),-8,'',status)
call ftpkyd(lout,'CRVAL3',0.d0,-8,'',status)
we add
call ftpkyd(lout,'RESTFREQ',dble(restfreq),-8,'',status)

So now the function openfits can add the restfeq keyword, but now we also need to add this input argument to the call of that routine.
Save and close openfits.f, and open 'Ratran_install_dir/sky/fmain.f' and in this file, find the line that call the openfits rouitine, i.e. use the find function of your editor and search for 'openfits'
Change the line
call openfits(lout(iline),outname,naxis,naxes,status)
to
call openfits(lout(iline),outname,naxis,naxes,status,nu(iline))

and done!