Nandan Joshi
Nandan Joshi
~1 min read

Categories

Tags

There are many IDL routines available for reading FITS file, a standard for astronomical data, but I have never been happy with their use for pretty simple thing of displaying the spectrum of the object. fits_read gives you the header and flux, but never the wavelength scale. readfits can also be useful, but it does so many other things, that I decided to write reading routine on my own.

Of course, I had to make use of fits_read to get the header and flux information from the FITS file. What is actually missing is the wavelength scale. So I create a wavelength array by taking header information from the FITS file. Header saves the value of the starting wavelength as CRVAL1 and the size of the increment as CDELT1. Now creating the wavelength array is not that difficult. My IDL routine is called myreadfits.pro and the source code is given below.

pro myreadfits, file, wavel, flux

fits_read, file, flux, header
crpos=where(strmid(header,0,6) eq "CRVAL1")
cr=strmid(header[crpos[0]],9,60)+0.
cdeltpos=where(strmid(header,0,6) eq "CDELT1")
cdelt=strmid(header[cdeltpos[0]],9,60)+0.
wavel=findgen(n_elements(flux))*cdelt+cr

end