c ***************************************** 
      subroutine xsisnhei(ear,ne,param,Ifl,photar)
c *****************************************
c *****************************************
c     number of model parameters: 14 
c   1: Te, electron temperature in keV
c        if Te > 0 exact redistribution function (RF),
c        if Te < 0 isotropic approximation for RF
c   2: p,      power-law index 
c   3: gmin,  Lorentz factor of the break 
c   4: gmax,  maximum Lorentz factor 
c   5: Tbb, blackbody temperature at the inner edge in keV  
c   6: tau, vertical optical depth of the corona 
c        if tau > 0 isotropic source function (SF) starting
c                   from the 3rd scattering
c        if tau < 0 isotropic SF starting from the 1st scattering
c   7: cosIncl, cosine of inclination angle 
c   8: Rin, inner radius of the disk 
c   9, R, amount of reflection 
c      (if R < 0 then only reflection component) 
c   10: FeAb, iron abundance in units of solar 
c   11: MeAb, abundance of heavy elements in units of solar
c   12: xi, disk ionization parameter L/(nR^2)
c   13: temp, disk temperature for reflection in K
c   14: redshift 
c
c *****************************************
c     algorithm:
c       exact solution of the radiative transfer equation
c       in HEMISPHERE geometry, 
c       neglecting the energy balance 
c electrons: Maxwellian + power-law tail 
c       includes: Comptonization of the BB radiation from the 
c       disk, and reflection
c  cold disk with the hole in the center 
c 
c *****************************************
      implicit none
      integer np,i,nem
      PARAMETER(nem=5000) 
      PARAMETER(np=20)
      integer ne,ne1,iigeom,iidistf,iion,Ifl 
      real*4  param(*),ear(0:ne),photar(ne)
      real*4  pa0(np)
      real*8  pac(np)    
      real*8  phcon(nem),phref(nem),phblb(nem),obj(nem)  
      real*4  phtot(nem)
      logical firstcall
      save firstcall
      data firstcall/.true./
c      logical fl0
      data    pa0/np*9999./

      if (firstcall) then
        call xwrite('ISM Version 2.3',5) 
        call xwrite('Comptonization in hemisphere-corona',5)
        call xwrite('sombrero model & ionized reflector',5)
        call xwrite('Maxwellian + power-law tail electrons',5)
        call xwrite('Questions: Juri Poutanen',5)
        call xwrite('juri@astro.su.se',5)
        call xwrite('Attention ! This code is under development',5)
        call xwrite('and is NOT sufficiently tested yet.',5)
        call xwrite('Before publishing any results ask the author',5)
        call xwrite('for the latest version of the code.',5)
        call xwrite('Your comments are welcome.',5)
        firstcall = .false.
      end if

      ne1=ne+1 
c check if the parameters were changed  
c      do n=1,np
c         if(param(n).ne.pa0(n)) fl0=.true.
c      enddo
       do i=1,np
       pac(i)=0d0
       enddo
c electron temperature
         pac(1)=dble(param(1))
c power-law index
         pac(2)=dble(param(2))
c gamma_min
         pac(3)=dble(param(3))
c gamma_max
         pac(4)=dble(param(4))
c disc temperature (keV)
         pac(5)=dble(param(5))
c Thomson optical depth
         pac(6)=dble(param(6))
c cosine of inclination angle
         pac(7)=dble(param(7))
c g, or Rin (inner radius of the disc)
         pac(8)=dble(param(8))
c normalization of reflection
         pac(9)=dabs(dble(param(9)))
c iron abundance
         pac(10)=dble(param(10))
c "metal" abundances
         pac(11)=dble(param(11)) 
c xi (ionization parameter)
         pac(12)=dble(param(12))
c disc temp (for ionization)
         pac(13)=dble(param(13)) 
c redshift
         pac(14)=dble(param(14))
         pac(15)=0d0
         pac(16)=0d0
         pac(17)=0d0
         pac(18)=0d0
         pac(19)=0d0
         pac(20)=0d0

C IGEOM=0, 3 SLAB geometry
C IGEOM=1, 4 CYLINDER geometry (with T0TAUG=H/R)
C IGEOM=2, 5 HEMISPHERE geometry  (TOTAUG=1, H=R)
c for IIGEOM.gt.2 -- holly disk 
c HEMISPHERE 
      IIGEOM=5
C IDISTF=0 Maxwellian electron distribution 
C IDISTF=1 monoenergetic electron distribution 
C IDISTF=2 power-law  electron distribution 
C IDISTF=4 Maxwellian + power-law tail
      IIDISTF=4
c IION=0 neutral reflector (H and He are always ionized)
c IION=1 ionized reflector
      IION=1
 

c object's frame energies (in mc2) 
         do i=0,ne
            obj(i+1)=dble((1.+param(14))*ear(i)/511.) 
         enddo 
c ---- 
        call ismco(pac,obj,phcon,phref,phblb,ne1,iigeom,iidistf,iion) 
c ----
c keep the new parameters  
c         do n=1,np
c            pa0(n)=param(n)
c         enddo
c         fl0=.false.
      do i=1,ne1
      if(param(9).ge.0.) then 
      phtot(i)=sngl(phcon(i)+phref(i)+phblb(i)) 
c       phtot(i)=sngl(phcon(i)+phref(i)) 
      else 
       phtot(i)=sngl(phref(i)+phblb(i)) 
c       phtot(i)=sngl(phref(i)) 
      endif 
      enddo 
c integrate over the bin size 
      do i=1,ne
        photar(i)=(phtot(i+1)+phtot(i))*(ear(i)-ear(i-1))/2. 
      enddo
      return
      end
c ------------------------------------------------------------------- c
