!
!  main.f90
!
! Problem that can be solved on CPU/GPU's
!
      program problem
!
! Input files (configuration file format - directory tree):  
!
      use main_memory
      implicit none
      real, allocatable :: rzp(:),rz(:)
      integer, allocatable :: izp(:),iz(:)
      character (len=30), allocatable :: czp(:),cz(:)
      real (selected_int_kind (5)), allocatable :: dz(:)  
!
      integer :: ierr
!
! Allocate physics space
! Allocate rest of memory

      allocate(rzp(1:irzp))
      allocate(izp(1:iizp))
      allocate(czp(1:iczp))
!      
! Read physics configuration file into memory
! - also query task and cell configuration files             
      call physics_input(rzp,izp,czp,ierr)  
!      if ( ierr>0 ) call error_stop('physics',ierr)
!
      call get_int_value('physics','/rz_size',irz,izp,ierr) 
!      if ( ierr > 0 ) call error_stop('physics',ierr) 
!
      call get_int_value('physics','/iz_size',iiz,izp,ierr) 
!      if ( ierr > 0 ) call error_stop('physics',ierr)
!      
      call get_int_value('physics','/dz_size',idz,izp,ierr) 
!      if ( ierr > 0 ) call error_stop('physics',ierr)
!
      call get_int_value('physics','/cz_size',icz,izp,ierr) 
!      if ( ierr > 0 ) call error_stop('physics',ierr)
!
      allocate(rz(1:irz))
      allocate(iz(1:iiz))     
      allocate(cz(1:icz))
      allocate(dz(1:idz)) 
!
! Read in task configuration file in full 
!      call task_input(rz,iz,dz,cz,rzp,izp,czp,ierr)
!      if ( ierr>0 ) call error_stop('main',ierr)
!
! Read in cell configuration file in full
      call cell_input(rz,iz,dz,cz,rzp,izp,czp,ierr)
!      if ( ierr>0 ) call error_stop('main',ierr)
!
! Now initialize space for coefficients 
      call coefficients_init(rz,iz,dz,cz,rzp,izp,czp,ierr)
!      if ( ierr>0 ) call error_stop('main',ierr)
!
! Read in interface configuration file in full
      call interface_input(rz,iz,dz,cz,rzp,izp,czp,ierr)
!      if ( ierr>0 ) call error_stop('main',ierr)
!
! Call solver (OpenMP/MPI and GPU allocation)
      call problem_solve(rz,iz,dz,cz,rzp,izp,czp,ierr)
!      if ( ierr>0 ) call error_stop('main',ierr)
!
! Final statistics
      end program problem
