-
Notifications
You must be signed in to change notification settings - Fork 0
/
writeFITS.f
56 lines (45 loc) · 1.29 KB
/
writeFITS.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
subroutine writefitsfile(filename,im,nlam,n)
IMPLICIT NONE
character*500 filename
integer n,nlam
real*8 im(n,n,nlam)
integer status,unit,blocksize,bitpix,naxis,naxes(3)
integer i,j,group,fpixel,nelements
logical simple,extend,truefalse
inquire(file=filename,exist=truefalse)
if(truefalse) then
call output("FITS file already exists, overwriting")
open(unit=90,file=filename)
close(unit=90,status='delete')
endif
status=0
C Get an unused Logical Unit Number to use to create the FITS file
call ftgiou(unit,status)
C create the new empty FITS file
blocksize=1
call ftinit(unit,filename,blocksize,status)
C initialize parameters about the FITS image (IMDIM x IMDIM 64-bit reals)
simple=.true.
bitpix=-64
naxes(1)=n
naxes(2)=n
if(nlam.gt.1) then
naxis=3
naxes(3)=nlam
else
naxis=2
naxes(3)=1
endif
extend=.true.
C write the required header keywords
call ftphpr(unit,simple,bitpix,naxis,naxes,0,1,extend,status)
C write the array to the FITS file
group=1
fpixel=1
nelements=naxes(1)*naxes(2)*naxes(3)
call ftpprd(unit,group,fpixel,nelements,im,status)
C close the file and free the unit number
call ftclos(unit, status)
call ftfiou(unit, status)
return
end