C-------------------------------------------------------------------------- subroutine ftgcrd(iunit,keynam,card,status) C Read the 80 character card image of a specified header keyword record C If the input name contains wild cards ('?' matches any single char C and '*' matches any sequence of chars, # matches any string of decimal C digits) then the search ends once the end of header is reached and does C not automatically resume from the top of the header. C iunit i Fortran I/O unit number C keynam c name of keyword to be read C OUTPUT PARAMETERS: C card c 80 character card image that was read C status i returned error status (0=ok) C C written by Wm Pence, HEASARC/GSFC, June, 1991 C modified January 1997 to support wildcards integer iunit,status character*(*) keynam,card C COMMON BLOCK DEFINITIONS:-------------------------------------------- integer nb,ne parameter (nb = 20) parameter (ne = 512) 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 C END OF COMMON BLOCK DEFINITIONS----------------------------------- integer i,j,ibuff,maxkey,start character kname*9 character*80 keybuf logical wild,casesn,match,exact card=' ' if (status .gt. 0)go to 100 casesn=.true. C get the number of the data buffer used for this unit ibuff=bufnum(iunit) C make sure keyword name is in uppercase kname=keynam call ftupch(kname) C test if input name contains wild card characters wild=.false. do 5 i=1,9 if (kname(i:i) .eq. '?' .or. kname(i:i) .eq. '*' & .or. kname(i:i) .eq. '#')wild=.true. 5 continue C Start by searching for keyword from current pointer position to the end. C Calculate the maximum number of keywords to be searched: start=nxthdr(ibuff) maxkey=(hdend(ibuff)-start)/80 do 20 j=1,2 C position I/O pointer to the next header keyword if (maxkey .gt. 0)then call ftmbyt(iunit,start,.false.,status) end if do 10 i=1,maxkey call ftgcbf(iunit,80,keybuf,status) if (status .gt. 0)go to 100 if (wild)then call ftcmps(kname(1:8),keybuf(1:8),casesn,match,exact) if (match)then C setheader pointer to the following keyword nxthdr(ibuff)=start+i*80 card=keybuf return end if else if (keybuf(1:8) .eq. kname(1:8))then C setheader pointer to the following keyword nxthdr(ibuff)=start+i*80 card=keybuf return end if 10 continue C end search at end of header if input name contains wildcards if (wild .or. (j .eq. 2))go to 30 C didn't find keyword yet, so now search from top down to starting pt. C calculate max number of keywords to be searched and reset nxthdr maxkey=(start-hdstrt(ibuff,chdu(ibuff)))/80 start=hdstrt(ibuff,chdu(ibuff)) 20 continue C keyword was not found 30 status=202 C don't write to error stack because this innoculous error happens a lot C call ftpmsg('Could not find the '//kname//' keyword to read.') 100 continue end