spacer link to MAST page spacer logo image spacer
 
link to STScI page


Reading BEFS FITS files in IDL



BEFS FITS arrays may be read into IDL using the IUEDAC routine IFITSRD, or the FITS binary table routines of the IDL Astronomy User's Library, available at http://idlastro.gsfc.nasa.gov/homepage.html.

In the binary table extensions containing our first- and second-order spectra, the data are written as a series of 12 22,000-point vectors. The wavelength vector is first, followed by calibrated flux in photon units, followed by calibrated flux in energy units, etc. (Because the computer must calculate the location of only the first element of each vector, it can read the files much faster than if the table were written as 22,000 rows, each twelve entries across.)

Here are a few examples of reading the BEFS FITS arrays into IDL variables:

1.   IFITSRD.pro: is a general FITS reader written by the IUE project.

IDL>     ifitsrd,'BEFS1002.SPD1',1,mheader,exheader,wave,fphoton, flux,err

The above command will store wavelengths in the IDL variable "wave", calibrated fluxes in "flux", and the error estimates (defined as the "sigma of flux" / "flux") in "err". The primary header is stored as a string array called mheader, and the extension header is exheader. This program has the virtue of writing binary table fields directly into individual IDL variables in one command. Ifitsrd (unless commanded off by keyword '/silent') will also print out the names of the table columns, such as:
    WAVELENGTH,FLUX_PHOT,FLUX_ERGS,FRAC_ERR, etc.

While this is a good routine for reading single table extension files, the most widely distributed version of ifitsrd can be a little awkward for reading the second extension containing the 2nd-order fluxes (fluxes adapted from the EUVE) which a small fraction of the BEFS database contain in the *.SPD1 (FUV) files. To read this second extension, one must know the record number in which the second extension data begins. The record number can be determined by first reading the header array using the routine IUEFHRD, and using the parms output vector to calculate the record number. The commands to read the 2nd order data would be:

IDL>   iuefhrd,'BEFS1020.SPD1',parms,mhead,exthead
IDL>   extnum=2
IDL>    nrec= total(parms(0:2*extnum)) + 1
IDL>    ifitsrd,'BEFS1020.SPD1',1,mh,eh,wave,cnts,err,erec=nrec

(Note the 2nd order fluxes are only given in units of counts) The latest version of ifitsrd includes a keyword enum for specifying the number of the extension to read, so reading the data as above would be simply:

IDL>    ifitsrd,'BEFS1020.SPD1',1,mh,eh,wave,cnts,err,enum=2

It should be pointed out that the above examples require the user to know the order in which the data entries are stored in the binary table. An alternative way, (also used by MRDFITS below) is to store all the fields in an IDL structure (see below). To read all the data from the first binary table as a structure called dst with ifitsrd:

IDL>    ifitsrd,'BEFS1020.SPD1',1,mh,eh,dst,/structure


2.   FXBREAD.pro: is another general FITS reader. To extract wavelength, flux (in photon units), and error bars, type:

IDL>  fxbopen, unit, 'BEFS1002.SPD1', 'SPECTRUM', header
IDL>  fxbread, unit, wave, 'WAVELENGTH'
IDL>  fxbread, unit, flux, 'FLUX_PHOT'
IDL>  fxbread, unit, error, 'FRAC_ERR'
IDL>  fxbclose, unit
IDL>  error = error * flux
IDL>  print, header

To extract the corresponding second-order spectrum, type:

IDL>  fxbopen, unit, 'BEFS1002.SPD1', '2NDORDER', header
IDL>  fxbread, unit, wave2, 'WAVELENGTH'
IDL>  fxbread, unit, counts2, '2ND_COUNTS'
IDL>  fxbclose, unit

3.   MRDFITS.pro can read both extensions, this time without foreknowledge of the table row names:

IDL>   a1 = mrdfits('BEFS1020.SPD1',1,h1)
IDL>   a2 = mrdfits('BEFS1020.SPD1',1,h1)

The resulting arrays a1 and a2 are structures. To determine the structure names, type   help,/struc,a1. For a tutorial in IDL structures, consult < using IDL structures >. More examples of reading FITS files using IDL are given in the Analysis of Copernicus Scans   (Exs. 1 & 2 only), How to read Copernicus files, and in How to read IMAPS files.