MAPL_demo_fargparse.F90 Source File


This file depends on

sourcefile~~mapl_demo_fargparse.f90~~EfferentGraph sourcefile~mapl_demo_fargparse.f90 MAPL_demo_fargparse.F90 sourcefile~mapl.f90 MAPL.F90 sourcefile~mapl_demo_fargparse.f90->sourcefile~mapl.f90 sourcefile~base.f90 Base.F90 sourcefile~mapl.f90->sourcefile~base.f90 sourcefile~esmf_cfiomod.f90 ESMF_CFIOMod.F90 sourcefile~mapl.f90->sourcefile~esmf_cfiomod.f90 sourcefile~fieldbundleread.f90 FieldBundleRead.F90 sourcefile~mapl.f90->sourcefile~fieldbundleread.f90 sourcefile~fieldbundlewrite.f90 FieldBundleWrite.F90 sourcefile~mapl.f90->sourcefile~fieldbundlewrite.f90 sourcefile~fieldutils.f90 FieldUtils.F90 sourcefile~mapl.f90->sourcefile~fieldutils.f90 sourcefile~mapl_generic.f90 MAPL_Generic.F90 sourcefile~mapl.f90->sourcefile~mapl_generic.f90 sourcefile~mapl_gridcomps.f90 MAPL_GridComps.F90 sourcefile~mapl.f90->sourcefile~mapl_gridcomps.f90 sourcefile~mapl_profiler.f90~2 MAPL_Profiler.F90 sourcefile~mapl.f90->sourcefile~mapl_profiler.f90~2 sourcefile~openmp_support.f90 OpenMP_Support.F90 sourcefile~mapl.f90->sourcefile~openmp_support.f90 sourcefile~pfio.f90 pFIO.F90 sourcefile~mapl.f90->sourcefile~pfio.f90 sourcefile~stubcomponent.f90 StubComponent.F90 sourcefile~mapl.f90->sourcefile~stubcomponent.f90 sourcefile~varspecmiscmod.f90 VarSpecMiscMod.F90 sourcefile~mapl.f90->sourcefile~varspecmiscmod.f90

Source Code

!------------------------------------------------------------------------------
!># Standalone Program for Testing fargparse
!
!------------------------------------------------------------------------------
#define I_AM_MAIN
#include "MAPL_ErrLog.h"
#include "unused_dummy.H"

program main
      use MAPL
      use mpi
      use fargparse

      implicit none

      type(MAPL_FargparseCLI) :: cli
      type(MAPL_CapOptions)   :: cap_options
      integer :: status

!------------------------------------------------------------------------------

      call run(_RC)

   contains

#undef I_AM_MAIN
#include "MAPL_ErrLog.h"
      subroutine run(rc)

         integer, intent(out), optional :: rc

         integer :: status
         character(len=:), allocatable :: input_file

         call MPI_Init(status)
         _VERIFY(status)

         ! Read and parse the command line, and set parameters
         ! If you have extra options you make a procedure as seen below and add arguments
         ! there and pass in here
         cli = MAPL_FargparseCLI(extra=extra_options)

         ! This does the casting of arguments into cap_options for CAP
         cap_options = MAPL_CapOptions(cli, _RC)

         write(*,*) "done with MAPL_FargparseCLI"
         write(*,*) "  cap_options%with_esmf_moab = ", cap_options%with_esmf_moab
         write(*,*) "  cap_options%npes_input_server = ", cap_options%npes_input_server
         write(*,*) "  cap_options%nodes_input_server = ", cap_options%nodes_input_server
         write(*,*) "  cap_options%npes_output_server = ", cap_options%npes_output_server
         write(*,*) "  cap_options%nodes_output_server = ", cap_options%nodes_output_server
         write(*,*) "  cap_options%egress_file = ", cap_options%egress_file

         ! For our extra options we have to explicitly cast them
         call cast(cli%options%at('file'), input_file, _RC)

         write(*,*) ""
         write(*,*) "Extra arguments"
         write(*,*) "  input file = ", input_file

         _RETURN(_SUCCESS)

      end subroutine run

      subroutine extra_options(parser, rc)
         type (ArgParser), intent(inout) :: parser
         integer, intent(out), optional :: rc

         call parser%add_argument('-f', '--file', &
              help='A file to read', &
              type='string', &
              default='default.config', &
              action='store')

         !_RETURN(_SUCCESS)
         if (present(rc)) rc = 0

      end subroutine extra_options

end program main