subroutine wtebd3(ounit, chatter, 
     &		nk_hist, hist, 
     & 		nk_comm, comment,rmfversn,
     &		telescop, instrume, detnam, filter, areascal, 
     &		chantype, fchan, iebound, e_min, e_max, ierr) 

	integer chatter, ierr
	integer ounit, nk_hist, nk_comm
	integer iebound, fchan
	real areascal
	real e_min(*), e_max(*)
	character*(*) rmfversn, chantype
	character*(*) telescop, instrume, detnam, filter
	character*(*) hist(*), comment(*)
c Description:
c  Creates and Writes the EBOUNDS extension for an RMF file one of the formats
c  conforming to the HDUVERS2='1.*.*' family.
c Currently the following formats are supported (see OGIP/92-002a)
c   HDUVERS2 = '1.0.0'
c   HDUVERS2 = '1.1.0'
c   HDUVERS2 = '1.2.0'
c but HDUVERS2 = '1.0.0' & '1.1.0' will be overridden such that '1.2.0' is
c written.
c  Assumes the FITS is open and has had the Primary Header written
c  !!! Note !!!! File is left open at the end  
c      and  MUST BE CLOSED               by FTCLOS 
c  in order to (automatically) write the mandatory END header keyword.
c This routine differs from wtebd1.f only in so far that the FCHAN parameter
c  is passed which specifies the channel number of the first PHA channel
c  The value of this parameter therefore is usually either 0 or 1
c Passed parameters
c  OUNIT         i   : FORTRAN unit number of open RMF file
c  CHATTER       i   : chattiness flag for o/p (5 quite,10 normal,>20 silly)
c  NK_HIST       i   : No. records to be written as HISTORY records
c  HIST          i   : Array of history strings to be written
c  NK_COMM       i   : No. records to be written as COMMENT records
c  COMMENT       i   : Array of comment strings to be written
c  RMFVERSN      i   : String denoting OGIP HDUVERS2 family  
c  TELESCOP      i   : String listing telescope/mission
c  INSTRUME      i   : String listing instrument/detector
c  DETNAM        i   : String listing specific detector name
c  FILTER        i   : String listing instrument filter in use
c  AREA          i   : Area scaling factor
c  FCHAN         i   : No. ("name") of first channel (usually 0 or 1)
c  CHANTYPE      i   : Type of detector channels in use (PHA, PI)
c  IEBOUND       i   : No. channels in the full array
c  E_MIN         i   : Array containing min nominal energy bound to each chan
c  E_MAX         i   : Array containing max nominal energy bound to each chan
c  IERR            o : Error Flag (0=OK)
c User i/ps required (prompted for):
c  None
c Include files
c  None
c Called Routines:
c  subroutine FCECHO     : (FTOOLS) writes to standard o/p unit
c  subroutine FTBDEF     : (FITSIO) Defines the BINTABLE data structure
c  subroutine FTCRHD     : (FITSIO) Creates a new FITS extension file
c  subroutine FTPHBN     : (FITSIO) Writes the required header keywords
c  subroutine FTPCOM     : (FITSIO) Writes a FITS comment keyword
c  subroutine FTPCLx     : (FITSIO) Writes the data 
c  subroutine FTPHIS     : (FITSIO) Writes a FITS history keyword
c  subroutine FTPKYS     : (FITSIO) Writes a keyword
c  subroutine WT_FERRMSG : (CALLIB) Dumps FITSIO Error message etc
c Compilation & Linking
c  link with FITSIO & CALLIB & FTOOLS
c Origin:
c  Code mostly hacked from wtebd1.f, which itself was hacked from 
c  within Alan Smale's BBRSP program
c Authors/Modification History:
c  Ian M George     (1.0.0; 95 Jun 21), copied from wtebd2.f 
	character*7 version
	parameter (version = '1.0.0')