main.f90 2.82 KB
!--------------------------------------------------------------------
!DESCRIPTION: This is the main program of WIM. This routine merely
!             calls other subroutines and do the main time loop.
!             It also contains the subroutine progress which display
!             a progress bar in the terminal while the model is
!             running.
!--------------------------------------------------------------------

!INTERFACE:
program wim2

!MODULE USES:
use parameters
        
call message(1)

! read parameters from namelists
call message(2)
call read_namelist
call message(7)

! allocate memory for arrays
call message(3)
call array_allocation
call message(7)

! initialize the model
call message(4)
call initialization
call message(7)

dirout=trim(root)//trim(name_sim)
open(25,file='src/tmp.txt')
write(25,*)trim(dirout)
close(25)
call system('src/OUT_DIR.sh')

!TIME LOOP
call message(5)

do n=2,nt

   ! display progress bar
   !call progress(n,nt)

   ! do advection for each frequency band
   do ii=1,nf
      call advection
   end do

   ! spatial calculations
   do i=1,nx

      ! compute spectrum attenuation
      call attenuation

      ! compute floe breaking
      call ice_fracture
      call statistics
   end do

end do

!OUTPUT

! write outputs in NETCDF
namefile=trim(root)//trim(name_sim)//'/'//trim(name_sim)//'.nc'
call message(6)
call write_output
call message(7)
write(*,*)'     -------------------------------------------'

contains


subroutine progress(j,jmax)

   implicit none
   integer           :: j,k,jmax
   character(len=20) :: bar='     processing ???%'
   
   write(unit=bar(17:19),fmt="(i3)")ceiling((real(j)/real(jmax))*100)
   write(unit=6,fmt="(a1,a22)",advance="no") char(13), bar

   if (real(j)/real(jmax).eq.1) then
      write(unit=6,fmt=*)
      write(*,*)'     Simulation completed !'
      write(*,*)'     -------------------------------------------'
      write(*,*)''
   endif

end subroutine progress


subroutine message(info)

   implicit none
   integer,intent(in)::info


   if ( info.eq.1 ) then
      write(*,*)'     -------------------------------------------'
      write(*,*)'                  Welcome in WIM'
      write(*,*)'     -------------------------------------------'
      write(*,*)''
   endif


   if ( info.eq.2 ) then
      write(*,*)'     Read parameters from namelists ... '
   endif

   if ( info.eq.3 ) then
      write(*,*)'     Allocate memory ...                '
   endif

   if ( info.eq.4 ) then
      write(*,*)'     Initialize arrays and variables ...'
   endif

   if ( info.eq.5 ) then
      write(*,*)'     Time loop starting...'
   endif

   if ( info.eq.6 ) then
      write(*,*)'     Writing NETCDF output file...'
   endif

   if ( info.eq.7 ) then
      write(*,*)'                                           done!'
   endif
        
end subroutine message

end program wim2