C---------------------------------------------------------------------- subroutine ftopnx(funit,fname,oldnew,rwmode,block,status) C low-level, machine-dependent routine to create or open a new file C C funit i Fortran I/O unit number C fname c name of file to be opened C oldnew i file status: 0 = open old/existing file; else open new file C rwmode i file access mode: 0 = readonly; else = read/write C block i FITS record blocking factor C status i returned error status (0=ok) C C written by Wm Pence, HEASARC/GSFC, June 1991 C modified Feb 1995 integer funit,oldnew,rwmode,block,status,i,ibuff,inital,size character*(*) fname logical igneof,found 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) integer buflun,currnt,reclen,bytnum,maxrec common/ftlbuf/buflun(nb),currnt(nb),reclen(nb), & bytnum(nb),maxrec(nb) integer pb parameter (pb = 20) integer maxbuf,logbuf,recnum,pindex logical modify common/ftpbuf/maxbuf,logbuf(pb),recnum(pb),modify(pb), & pindex(pb) integer compid common/ftcpid/compid C END OF COMMON BLOCK DEFINITIONS----------------------------------- real rword double precision dword save inital data inital/0/ if (status .gt. 0)return if (inital .eq. 0)then C first time through need to initialize pointers nxtfld=0 maxbuf=pb do 2 i=1,nb buflun(i)=0 2 continue do 4 i=1,pb logbuf(i)=0 recnum(i)=0 modify(i)=.false. pindex(i)=i 4 continue inital=1 C Determine at run time what type of machine we are running on. C Initialize a real and double value to arbitrary values. rword=1.1111111111 dword=1.1111111111D+00 C ftarch looks at the equivalent integer value call ftarch(rword,dword,compid) end if C check for valid unit number if (funit .lt. 1 .or. funit .gt. 199)then status=101 return end if C find available logical buffer slot for this file do 10 i=1,nb if (buflun(i) .eq. 0)then ibuff=i go to 20 end if 10 continue C error: no vacant logical buffer slots left status=102 return 20 continue if (oldnew .eq. 0)then igneof = .false. C test if file exists inquire(file=fname,exist=found) if (.not. found)then C error: file doesn't exist?? status=103 return end if else igneof = .true. end if call ftopnf(funit,fname,oldnew,rwmode,block,size,status) C initialize the HDU parameters maxrec(ibuff)=size if (oldnew .eq. 1 .or. block .le. 1)then C new files always have a record length of 2880 bytes reclen(ibuff)=2880 else reclen(ibuff)=block end if bufnum(funit)=ibuff chdu(ibuff)=1 hdutyp(ibuff)=0 maxhdu(ibuff)=1 hdstrt(ibuff,1)=0 hdend(ibuff)=0 nxthdr(ibuff)=0 C data start location is undefined dtstrt(ibuff)=-1000000000 heapsz(ibuff)=0 theap(ibuff)=0 tfield(ibuff)=0 rowlen(ibuff)=0 C initialize the logical buffer parameters buflun(ibuff)=funit currnt(ibuff)=0 if (rwmode .eq. 0)then wrmode(ibuff)=.false. else wrmode(ibuff)=.true. end if C load the first record of the file call ftldrc(funit,1,igneof,status) end