read_arguments Subroutine

public subroutine read_arguments()

Uses

  • proc~~read_arguments~~UsesGraph proc~read_arguments read_arguments module~mod_global_parameters mod_global_parameters proc~read_arguments->module~mod_global_parameters module~mod_basic_types mod_basic_types module~mod_global_parameters->module~mod_basic_types module~mod_connectivity mod_connectivity module~mod_global_parameters->module~mod_connectivity module~mod_constants mod_constants module~mod_global_parameters->module~mod_constants module~mod_physicaldata mod_physicaldata module~mod_global_parameters->module~mod_physicaldata module~mod_variables mod_variables module~mod_global_parameters->module~mod_variables mpi mpi module~mod_global_parameters->mpi module~mod_variables->module~mod_basic_types

Read the command line arguments passed to agile

Arguments

None

Calls

proc~~read_arguments~~CallsGraph proc~read_arguments read_arguments mpi_finalize mpi_finalize proc~read_arguments->mpi_finalize proc~get_fields_string get_fields_string proc~read_arguments->proc~get_fields_string

Called by

proc~~read_arguments~~CalledByGraph proc~read_arguments read_arguments proc~main main proc~main->proc~read_arguments program~agile agile program~agile->proc~main

Source Code

  subroutine read_arguments()
    use mod_global_parameters

    integer                          :: len, stat, n, i, ipars
    integer, parameter               :: max_files = 20 !Maximum number of par files
    integer                          :: n_par_files
    character(len=max_files*std_len) :: all_par_files
    character(len=std_len)           :: tmp_files(max_files), arg
    logical                          :: unknown_arg, help, morepars

    if (mype == 0) then
       print *, "-----------------------------------------------------------------------------"
       print *, "-----------------------------------------------------------------------------"
       print *, "|                                                                           |"
       print *, "|                                                                           |"
       print *, "|                                        d8, d8b                            |"
       print *, "|                                       `8P  88P                            |"
       print *, "|                                           d88                             |"
       print *, "|                   d888b8b   d888b8b    88b888   d8888b                    |"
       print *, "|                  d8P' ?88  d8P' ?88    88P?88  d8b_,dP                    |"
       print *, "|                  88b  ,88b 88b  ,88b  d88  88b 88b                        |"
       print *, "|                  `?88P'`88b`?88P'`88bd88'   88b`?888P'                    |"
       print *, "|                                   )88                                     |"
       print *, "|                                  ,88P                                     |"
       print *, "|                              `?8888P                                      |"
       print *, "|                                                                           |"
       print *, "-----------------------------------------------------------------------------"
       print *, "-----------------------------------------------------------------------------"
    end if

    ! =============== Fortran 2003 command line reading ================

    ! Default command line arguments
    all_par_files="agile.par"
    restart_from_file=undefined
    snapshotnext=-1
    slicenext=-1
    collapsenext=-1
    help=.false.
    convert=.false.
    resume_previous_run=.false.

    ! Argument 0 is program name, so we start from one
    i = 1
    unknown_arg=.false.
    DO
       CALL get_command_argument(i, arg)
       IF (LEN_TRIM(arg) == 0) EXIT
       select case(arg)
         case("-i")
           i = i+1
           CALL get_command_argument(i, arg)
           !if(mype==0)print *,'found argument=',arg
           all_par_files=TRIM(arg)
           morepars=.true.
           ipars=1
           do while (ipars<max_files.and.morepars)
              CALL get_command_argument(i+ipars,arg)
              !if(mype==0)print *,'found argument=',arg
              if (index(TRIM(arg),"-")==1.or.LEN_TRIM(arg)==0) then
                 morepars=.false.
              else
                 ipars=ipars+1
                 all_par_files=TRIM(all_par_files)//" "//TRIM(arg)
                 !if(mype==0)print *,'now all_par_files=',TRIM(all_par_files)
              endif
           end do
           !if(mype==0)print *,'-i identified ',ipars, ' par-file arguments'
           i=i+ipars-1
           !if(mype==0)print *,'-i arguments passed to all_par_files=',TRIM(all_par_files)
         case("-if")
           i = i+1
           CALL get_command_argument(i, arg)
           restart_from_file=TRIM(arg)
           !if(mype==0)print *,'-if has argument=',TRIM(arg),' passed to restart_from_file=',TRIM(restart_from_file)
         case("-slicenext")
           i = i+1
           CALL get_command_argument(i, arg)
           read(arg,*,iostat=stat) slicenext
           !if(mype==0)print *,'-slicenext has argument=',arg,' passed to slicenext=',slicenext
         case("-collapsenext")
           i = i+1
           CALL get_command_argument(i, arg)
           read(arg,*,iostat=stat) collapsenext
           !if(mype==0)print *,'-collapsenext has argument=',arg,' passed to collapsenext=',collapsenext
         case("-snapshotnext")
           i = i+1
           CALL get_command_argument(i, arg)
           read(arg,*,iostat=stat) snapshotnext
           !if(mype==0)print *,'-snapshotnext has argument=',arg,' passed to snapshotnext=',snapshotnext
         case("-resume")
           resume_previous_run=.true.
           !if(mype==0)print *,'resume specified: resume_previous_run=T'
         case("-convert")
           convert=.true.
           if(mype==0)print *,'convert specified: convert=T'
         case("--help","-help")
           help=.true.
           EXIT
         case default
           unknown_arg=.true.
           help=.true.
           EXIT
       end select
       i = i+1
    END DO

    if (unknown_arg) then
       print*,"======================================="
       print*,"Error: Command line argument ' ",TRIM(arg)," ' not recognized"
       print*,"======================================="
       help=.true.
    end if

    ! Show the usage if the help flag was given, or no par file was specified
    if (help) then
       if (mype == 0) then
          print *, 'Usage example:'
          print *, 'mpirun -np 4 ./agile -i file.par [file2.par ...]'
          print *, '         (later .par files override earlier ones)'
          print *, ''
          print *, 'Optional arguments:'
          print *, '-convert             Convert snapshot files'
          print *, '-if file0001.dat     Use this snapshot to restart from'
          print *, '                     (you can modify e.g. output names)'
          print *, '-resume              Automatically resume previous run'
          print *, '                     (useful for long runs on HPC systems)'
          print *, '-snapshotnext N      Manual index for next snapshot'
          print *, '-slicenext N         Manual index for next slice output'
          print *, '-collapsenext N      Manual index for next collapsed output'
          print *, ''
       end if
       call MPI_FINALIZE(ierrmpi)
       stop
    end if

    ! Split the input files, in case multiple were given
    call get_fields_string(all_par_files, " ,'"""//char(9), max_files,&
        tmp_files, n_par_files)

    allocate(par_files(n_par_files))
    par_files = tmp_files(1:n_par_files)

  end subroutine read_arguments