C---------------------------------------------------------------------- subroutine ftchdu(iunit,status) C Close Header Data Unit C If we have write access to the file, then close the current HDU by: C -padding remaining space in the header with blanks C -writing the END keyword in the CHU C -check the data fill values, and rewrite them if not correct C -flushing the current buffer to disk C -recover common block space containing column descriptors C iunit i fortran unit number C status i output error status C C written by Wm Pence, HEASARC/GSFC, June, 1991 integer iunit,status C COMMON BLOCK DEFINITIONS:-------------------------------------------- integer nb,ne,nf parameter (nb = 20) parameter (ne = 512) parameter (nf = 3000) integer bufnum,chdu,hdutyp,maxhdu,hdstrt,hdend,nxthdr,dtstrt integer nxtfld logical wrmode common/ft0001/bufnum(199),chdu(nb),hdutyp(nb),maxhdu(nb), & wrmode(nb),hdstrt(nb,ne),hdend(nb),nxthdr(nb),dtstrt(nb),nxtfld integer tfield,tstart,tbcol,rowlen,tdtype,trept,tnull,heapsz integer theap double precision tscale,tzero common/ft0002/tfield(nb),tstart(nb),tbcol(nf),rowlen(nb), & tdtype(nf),trept(nf),tscale(nf),tzero(nf),tnull(nf),heapsz(nb) & ,theap(nb) C END OF COMMON BLOCK DEFINITIONS----------------------------------- integer ibuff,pcount character*8 comm C ignore input status and close HDU regardless of input status value ibuff=bufnum(iunit) C check that unit number is valid (that file is actually opened) if (ibuff .eq. 0)then if (status .le. 0)status=101 return end if C see if we have write access to this file if (wrmode(ibuff))then C if data has been written to heap, update the PCOUNT keyword if (heapsz(ibuff) .gt. 0)then call ftgkyj(iunit,'PCOUNT',pcount,comm,status) if (heapsz(ibuff) .gt. pcount)then call ftmkyj(iunit,'PCOUNT',heapsz(ibuff),'&',status) end if C update the variable length TFORM values if necessary call ftuptf(iunit, status) end if C rewrite the header END card and the following blank fill, and C insure that the internal data structure matches the keywords call ftrdef(iunit,status) C write the correct data fill values, if they are not already correct call ftpdfl(iunit,status) end if C set current column name buffer as undefined call ftrsnm C flush the buffers holding data for this HDU call ftflsh(ibuff,status) C recover common block space containing column descriptors for this HDU call ftfrcl(iunit,status) if (status .gt. 0)then call ftpmsg('Error while closing current HDU (FTCHDU).') end if end