dftd3_main Program

Variables

Type Attributes Name Initial
class(app_config), allocatable :: config
type(error_type), allocatable :: error

Subroutines

subroutine handle_error(error)

Arguments

Type IntentOptional Attributes Name
type(error_type), intent(inout), allocatable :: error

Source Code

program dftd3_main
   use, intrinsic :: iso_fortran_env, only : output_unit, error_unit
   use mctc_env, only : error_type
   use dftd3_app_cli, only : app_config, get_arguments
   use dftd3_app_driver, only : app_driver
   implicit none
   class(app_config), allocatable :: config
   type(error_type), allocatable :: error

   call get_arguments(config, error)
   call handle_error(error)

   call app_driver(config, error)
   call handle_error(error)

contains

subroutine handle_error(error)
   type(error_type), allocatable, intent(inout) :: error

   interface
      subroutine sys_exit(stat) bind(c, name="exit")
         use, intrinsic :: iso_c_binding, only : c_int
         integer(c_int), value :: stat
      end subroutine sys_exit
   end interface

   if (allocated(error)) then
      if (error%stat == 0) then
         write(output_unit, '(a)') error%message
         call sys_exit(0)
      else
         write(error_unit, '("[Error]", 1x, a)') error%message
         call sys_exit(1)
      end if
   end if
end subroutine handle_error

end program dftd3_main