[fitsbits] converting to fits format
William Pence
pence at tetra.gsfc.nasa.gov
Tue Aug 1 10:37:56 EDT 2000
"Motallebi, Habib" wrote:
>
> I have a PC image files with flf extension,i.e. myimage.flf.
> I like to convert these to fits format. The first two integers
> each are two byte widht and height representation resepctively.
> The file is 16 bit binary file.
>
> Can i append the contents of this image file to a fits header and
> create a fits image file in that way?.
>
> How can i do this is unix environment?. can cat command help?.
> How can i do this in PC environment?.
If you can program in C or Fortran, it would be easy to write a little
conversion program that would run in unix or on PCs. Just read the binary
image data into a program array, then call 4 CFITSIO subroutines in
succession:
fits_create_file(..., filename, ...);
fits_create_img(..., SHORT_IMG, naxis, naxes, ...);
fits_write_img(..., npixels, array, ....);
fits_close_file(...);
where I've only listed the key arguments in each routine. CFITSIO is
available for Unix and PCs from http://heasarc.gsfc.nasa.gov/fitsio
Alternatively, it is possible (but messy) to use basic Unix commands to do
this, at least for simple FITS images. First you'd have to construct a
valid FITS header with NAXIS1 and NAXIS2 keyword values that match the pixel
size of the image. The header must be exactly 2880 bytes long (padded with
space characters if necessary) and not contain any CR or LF characters.
You could then use the 'dd' unix command to strip the 1st 2 integers off of
your binary data file, and byteswap the remaining pixel values (byteswapping
is required on PCs and DEC OSF unix, but not on Macs, or SUN workstations):
dd if=in.file of=out.file ibs=4 skip=1 conv=swab (byteswapped)
or
dd if=in.file of=out.file ibs=4 skip=1 (not byteswapped)
Then use 'cat' to concatinate the header and data.
-Bill Pence
--
____________________________________________________________________
Dr. William Pence pence at tetra.gsfc.nasa.gov
NASA/GSFC Code 662 HEASARC +1-301-286-4599 (voice)
Greenbelt MD 20771 +1-301-286-1684 (fax)
More information about the fitsbits
mailing list