Subject: program to copy a FITS image (request)

From: dmehring at zia.aoc.nrao.edu (David Mehringer)
Date: 22 Oct 91 20:40:26 GMT

Sorry if this is a FAQ, but does someone have a program whose sole
purpose is to copy a FITS image at disk level and if so, may I have a
copy?  I am trying to manipulate images at disk level and am in need
of such a program.  Since I will be changing the pixel values, a
program that also checks for the max and min pixel values and
incorporates them into the header would be great.
Thanks in advance.

-- 
Dave Mehringer            | "Every so often someone comes along and tries
dmehring at zia.aoc.nrao.edu | to re-invent the wheel, but usually ends up 
National Radio Astronomy  | with an octogon that has an off-center hole."
Observatory, Socorro, NM  |    -- E.N. Parker (the solar wind guy)

---

From: pence at heawk1.gsfc.nasa.gov ( William Pence)
Date: 23 Oct 91 16:49:56 GMT

>incorporates them into the header would be great.

David

I am not exactly clear what you want the program to do, but the following
fortran program is an example of how you could read a FITS image
with 3 calls to the FITSIO subroutine package.

-Bill Pence

C----------------------------------------------------------------------
	program rdimag

C	simple program to open and read a FITS image

C	this assumes that the image is in INTEGER*4 format, and is no
C	larger than 100 X 100 pixels.  Would need to change the following
C	declaration statements if this is not the case...
	parameter (ndim1=100)
	parameter (ndim2=100)
	integer image(ndim1,ndim2),nulval

	character*40 name
	integer iunit,rwmode,block,status
	integer bitpix,naxis,naxes(99),pcount,gcount
	logical simple,extend,anyflg

	print *,'enter name of FITS file:'
	read(*,1000)name
1000	format(a)

C	use fortran unit number 12
	iunit=12
C	open the FITS file with readonly access:
	rwmode=0
	call ftopen(iunit,name,rwmode,block,status)

C	read the important primary array header keywords:
	call ftgprh(iunit,simple,bitpix,naxis,naxes,pcount,gcount,
     &              extend,status)

C	should check that this is really a 2-D array, and that the
C	FITS array size does not exceed the IMAGE array dimensions,
C       but we will just assume that everything is OK...

C	assign the value to be used to represent undefined pixels:
	nulval=-999

C	now read the array
	call ftg2dj(iunit,0,nulval,ndim1,naxes(1),naxes(2),
     &              image,anyflg,status)

C	Now do whatever you want with the IMAGE array....

	end
C---------------------------------------------------------------------------