      subroutine printerror(status)

!      Print out the FITSIO error messages to the user

      integer status
      character errtext*30,errmessage*80

!     check if status is OK (no error); if so, simply return
      if (status .le. 0)return

!     get the text string which describes the error
 1    call ftgerr(status,errtext)
      print *,'FITSIO Error Status =',status,': ',errtext

!     read and print out all the error messages on the FITSIO stack
 2    call ftgmsg(errmessage)
      do while (errmessage .ne. ' ')
          print *,errmessage
          call ftgmsg(errmessage)
      end do
      end
