      program co_sunset 
!                                                                       
!     ***************************************************************0**
! *   Compute_Sunset: computation of sunrise and sunset time            
!     P. Robert, Dec 2011                                               
!     ***************************************************************0**
!                                                                       
      character*32 lieu 
      character*8  tmer,tris,tset,durd 
      character*80 ligne 
!                                                                       
      print 200 
      print 200, '****************************************************' 
      print 200 
      print 200, 'sunset: computation of sunrise and sunset time' 
      print 200, '        assuming spherical Earth' 
      print 200 
!                                                                       
   10 continue 
      print 200, '-----------------------------------------------------' 
!                                                                       
      call r_date(iyear,imon,iday) 
!                                                                       
      print 200, 'lat et long en degre, et lieu ? (blank separator,'//  &
     &        ' 0 or q to quit)'                                        
!                                                                       
      read(*,200,end=20) ligne 
      if(ligne(1:1).eq.'0' .or. ligne(1:1).eq.'q') go to 20 
      read(ligne,*) rlat, rlon 
!                                                                       
      call cchapos_(ligne,' ',-1,npos) 
      lieu=ligne(npos+1:32) 
!                                                                       
      print 300, rlat, rlon,'   ',lieu 
      print 200 
!                                                                       
!                                                                       
      rlat=rlat*3.1415927/180. 
      rlon=rlon*3.1415927/180. 
!                                                                       
      icor=3 
!                                                                       
      call cp_sunrise_sunset(iyear,imon,iday,rlat,rlon,tmer,tris,tset,  &
     &             durd,elemer,azimer,eleris,aziris,eleset,aziset,icor) 
                                                                        
!                                                                       
      print 100, tmer,tris,tset,durd 
      go to 10 
   20 continue 
!                                                                       
  100 format(' merid. time (UT)= ',a8,' sunrise= ',a8,                  &
     &                     ' sunset= ',a8,' durd= ',a8)                 
  200 format(4a) 
  300 format(2f10.3,2a) 
!                                                                       
      print 200 
      print 200, '****************************************************' 
      print 200 
                                                                        
      stop 'co_sunset: normal termination' 
      END                                           
!                                                                       
!     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX
!                                                                       
      subroutine cchapos_(chast,cha,isens,npos) 
!                                                                       
!     ---------------------------------------------------------------+--
! *   Object : compute_character_position without end blanks            
! *   Class  : compute modules of Rogralib Software                     
! *   Author : P. Robert, PatCie, 1992                                  
!     ---------------------------------------------------------------+--
!                                                                       
      character*(*) chast, cha 
                                                                        
!                                                                       
      nbc=len(cha) 
      if(nbc.ne.1) then 
                   print*, '***cha=',cha(1:nbc), ' must be 1 character' 
                   print*, '   program aborted' 
                   stop '*** program aborted' 
                   endif 
!                                                                       
!                                                                       
      nbc=len(chast) 
      if(nbc.gt.255) then 
                     print*, '***nbc=',nbc, ' > 255' 
                     print*, '   program aborted' 
                     stop '*** program aborted' 
                     endif 
!                                                                       
! *** dernier caractere non blanc                                       
!                                                                       
      do 10 i=1,nbc 
      ii=nbc-i+1 
      if(chast(ii:ii).ne.' ') go to 12 
   10 continue 
      ii=0 
   12 continue 
!                                                                       
      nbcha=ii 
!                                                                       
! *** recherche du caratere cha                                         
!                                                                       
      do 20 i=1,nbcha 
      if (isens.lt.0) then 
                      ii=nbcha-i+1 
                      else 
                      ii=1 
      endif 
!                                                                       
      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 
!                                                                       
      return 
      END                                           
