      program co_sunset
c
c     ***************************************************************0**
c *   Compute_Sunset: computation of sunrise and sunset time
c     P. Robert, Dec 2011                                  
c     ***************************************************************0**
c
      character*32 lieu
      character*8  tmer,tris,tset,durd
      character*80 ligne
c
      print 200
      print 200, '****************************************************'
      print 200
      print 200, 'sunset: computation of sunrise and sunset time'
      print 200, '        assuming spherical Earth'
      print 200
c
   10 continue
      print 200, '-----------------------------------------------------'
c 
      call r_date(iyear,imon,iday)
c
      print 200, 'lat et long en degre, et lieu ? (blank separator,'//
     &        ' 0 or q to quit)'
c
      read(*,200,end=20) ligne
      if(ligne(1:1).eq.'0' .or. ligne(1:1).eq.'q') go to 20
      read(ligne,*) rlat, rlon
c
      call cchapos_(ligne,' ',-1,npos)
      lieu=ligne(npos+1:32)
c
      print 300, rlat, rlon,'   ',lieu
      print 200
c
c
      rlat=rlat*3.1415927/180.
      rlon=rlon*3.1415927/180.
c
      icor=3
c
      call cp_sunrise_sunset(iyear,imon,iday,rlat,rlon,tmer,tris,tset,
     &             durd,elemer,azimer,eleris,aziris,eleset,aziset,icor)

c
      print 100, tmer,tris,tset,durd
      go to 10
   20 continue
c
  100 format(' merid. time (UT)= ',a8,' sunrise= ',a8,
     &                     ' sunset= ',a8,' durd= ',a8)
  200 format(4a)
  300 format(2f10.3,2a)
c
      print 200
      print 200, '****************************************************'
      print 200
       
      stop 'co_sunset: normal termination'
      end
c
c     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX
c
      subroutine cchapos_(chast,cha,isens,npos)
c
c     ---------------------------------------------------------------+--
c *   Object : compute_character_position without end blanks
c *   Class  : compute modules of Rogralib Software
c *   Author : P. Robert, PatCie, 1992
c     ---------------------------------------------------------------+--
c
      character*(*) chast, cha
      
c
      nbc=len(cha)
      if(nbc.ne.1) then
                   print*, '***cha=',cha(1:nbc), ' must be 1 character'
                   print*, '   program aborted'
                   stop '*** program aborted'
                   endif
c
c
      nbc=len(chast)
      if(nbc.gt.255) then
                     print*, '***nbc=',nbc, ' > 255'
                     print*, '   program aborted'
                     stop '*** program aborted'
                     endif
c
c *** dernier caractere non blanc
c
      do 10 i=1,nbc
      ii=nbc-i+1
      if(chast(ii:ii).ne.' ') go to 12
   10 continue
      ii=0
   12 continue
c
      nbcha=ii
c
c *** recherche du caratere cha
c
      do 20 i=1,nbcha
      if (isens.lt.0) then
                      ii=nbcha-i+1
                      else
                      ii=1
      endif
c
      if(chast(ii:ii).eq.cha) go to 22
   20 continue
      print*, '* cchapos: char. ',cha,' not found in ',chast(1:nbcha)
      print*, '           npos set to zero'
      npos=0
   22 continue
      npos=ii
c
      return
      end
c
c     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX
c
