
program CERF
!=========================== DOCUMENTATION ============================= 
!DOCDEBh*    NUM/CERF  *
!
!    NOM
! CERF
!    DESCRIPTION  
!*
! CERF: Computation, ERosion and Flow
! Parallel Finite volume code using adaptive mesh refinement technique
! IMATH from university of Toulon
! INSTITUT DE MATHEMATIQUE DE TOULON
!*
!>    AUTEUR 
!> Frederic GOLAY
!  
!    SOURCE
! Ce logiciel est regi par la licence [CeCILL-B]
! This software is governed by the [CeCILL-B] license
!=========================== DEBUT DES DECLARATIONS ==================== 
!.1-----  Implicit, Use
   use num
#ifdef _MPI
  use ptim
#endif  
  
implicit none

#ifdef _MPI
    include 'mpif.h'
#endif

!.2-----  Declaration
  type(calcul) :: calc !! Objet calcul 
  integer ierr,id,iu

!=========================== DEBUT DU CODE EXECUTABLE ==================





! Initialisation 
!------------------------------------------------------
  call print_info('CERF', ' Initialisation')
  call init_calc(calc)
# ifdef _MPI
  CALL PTIM_start(LABEL="Parallel work")  
# endif
IF(calc%msh%numdom.eq.1)then
    write(*,*)achar(27)//'[34m**********************************************************'
    write(*,*) fdate()
    write(*,*)'CERF : Computation, ERosion and Flow '
    write(*,*)'**********************************************************' //achar(27)//'[0m'
endif

! Calcul
!------------------------------------------------------
  
  call print_info('CERF', ' Calcul')
  
   select case (calc%imeth_int_temps) 
   case(1) ! rk2
      IF(calc%msh%numdom.eq.1)call print_info('CERF','Integration temporelle: RUNGE-KUTTA')
     call rk2(calc)
     
     case default
       call print_err('CERF',' Time integration not defined')
    !~else if (calc%imeth_int_temps.eq.2) then
    !~   write(*,*), 'Integration temporelle: ADAMS BASHFORT '
    !~   call adams(calc)  
    !~else if (calc%imeth_int_temps.eq.3) then
    !~   write(*,*), 'Integration temporelle: ADAMS BASHFORT pas de temps local'
    !~   call adams(calc)  
    end select


#ifdef _MPI
  CALL PTIM_stop(LABEL="Parallel work")  
# endif

! Sauvegardes
!------------------------------------------------------

  id=idint(calc%isauv/10.d0)
  iu=idint(calc%isauv-id*10.d0)
  
  if(id.ne.0)call save_1D(calc)  
  if(iu.ne.0)call save_calc(calc)
  
! Fin
!------------------------------------------------------

IF(calc%msh%numdom.eq.1)then
    write(*,*)achar(27)//'[34m**********************************************************'
    write(*,*) fdate()
    write(*,*)'CERF End of computation '
    write(*,*)'**********************************************************' //achar(27)//'[0m'
endif


  call empty_mesh(calc%msh,0,0)  ! liberation de la mémoire
# ifdef _MPI
  call MPI_FINALIZE(ierr)
# endif
!===========================   FIN DU PROGRAMME    ====================
end program CERF
!DOCFIN
