startups_m.f90 Source File


Contents

Source Code


Source Code

module startups_m
    !! Some generic routines for startup phase
    use screen_io_m, only : get_stdout
    use technical_constants_m, only : PATHLEN_MAX
    use error_handling_grillix_m, only: handle_error, error_info_t
    use status_codes_grillix_m, only : GRILLIX_ERR_CMD
    implicit none

    public :: grillix_banner
    public :: parse_cmd_filename

contains

    subroutine grillix_banner(is_writer)
        !! Prints banner for grillix code
        logical, intent(in) :: is_writer
        !! If true, banner is printed to stdout

        if (.not. is_writer) return

        write(get_stdout(),'(A)')new_line('a') //  new_line('a') //  new_line('a') 
        write(get_stdout(),'(A)')repeat("-",80)
        write(get_stdout(),'(A)')'WELCOME TO:'

        write(get_stdout(),'(A)') &
        "======================================================", &
        "   GGGGGGGGGGGGG           ll  ll  XXX                ", &
        "   GG                      ll  ll    XXX       XX     ", &
        "   GG                      ll  ll      XXX    XX      ", &
        "   GG                      ll  ll        XXX XX       ", &
        "   GG    GGGGGGG   rrr ii  ll  ll  ii     XXX         ", &
        "   GG         GG  rr   ii  ll  ll  ii   XX  XXX       ", &
        "   GG         GG  rr   ii  ll  ll  ii  XX     XXX     ", &
        "   GGGGGGGGGGGGG  rr   ii  ll  ll  ii XX        XXX   ", &
        "======================================================"
        write(get_stdout(),'(A)')"An awesome plasma fluid turbulence code" // new_line('a') // &
                                 "for the edge and scrape-off layer of tokamaks and stellarators."
        write(get_stdout(),'(A)')"Developed at Max Planck Institute for Plasma Physics, Garching."
        write(get_stdout(),'(A)')"Lead developer: Andreas Stegmeir (Andreas.Stegmeir.at.ipp.mpg.de)."
        write(get_stdout(),'(A)')new_line('a') //  new_line('a') //  new_line('a') 

    end subroutine

    subroutine parse_cmd_filename(fpath, use_default_fpath, fpath_default)
        !! Parses a filepath from command line
        character(len=:), allocatable, intent(out) :: fpath
        !! Filepath parsed from command line
        logical, intent(out), optional :: use_default_fpath
        !! True if no filepath was parsed and default value will be used
        character(len=*), intent(in), optional :: fpath_default
        !! Default filepath, if not provided, fpath will be empty
        integer :: nargs, parser_status
        character(len=PATHLEN_MAX) :: fpath_raw

        nargs = command_argument_count()
        if (nargs == 0) then
            use_default_fpath = .true.
            if (present(fpath_default)) then
                fpath = fpath_default
            endif
        elseif (nargs == 1) then
            use_default_fpath = .false.
            call get_command_argument(1, fpath_raw, status=parser_status)
            if (parser_status /= 0) then
                call handle_error("Parsing from command line failed", &
                                  GRILLIX_ERR_CMD, __LINE__, __FILE__, &
                                  error_info_t('parser_status: ',[parser_status]))
            endif
            fpath = trim(adjustl(fpath_raw))
        else
            call handle_error("Number of parsed arguments from command line not valid", &
                              GRILLIX_ERR_CMD, __LINE__, __FILE__, &
                              error_info_t('nargs: ',[nargs]))
        endif

    end subroutine

end module