File: demo_get_args.f90

package info (click to toggle)
fortran-cli2 3.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,856 kB
  • sloc: f90: 6,172; javascript: 3,423; makefile: 189; sh: 25
file content (36 lines) | stat: -rwxr-xr-x 1,273 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
      program demo_get_args
      use M_CLI2,  only : filenames=>unnamed, set_args, get_args
      implicit none
      integer                      :: i
       ! Define ARGS
      real                         :: x, y, z
      real,allocatable             :: p(:)
      character(len=:),allocatable :: title
      logical                      :: l, lbig
       ! Define and parse (to set initial values) command line
       !   o only quote strings and use double-quotes
       !   o set all logical values to F or T.
      call set_args('         &
         & -x 1 -y 2 -z 3     &
         & -p -1,-2,-3        &
         & --title "my title" &
         & -l F -L F          &
         & --label " "        &
         & ')
       ! Assign values to elements
       ! Scalars
      call get_args('x',x,'y',y,'z',z,'l',l,'L',lbig)
       ! Allocatable string
      call get_args('title',title)
       ! Allocatable arrays
      call get_args('p',p)
       ! Use values
      write(*,'(1x,g0,"=",g0)')'x',x, 'y',y, 'z',z
      write(*,*)'p=',p
      write(*,*)'title=',title
      write(*,*)'l=',l
      write(*,*)'L=',lbig
      if(size(filenames) > 0)then
         write(*,'(i6.6,3a)')(i,'[',filenames(i),']',i=1,size(filenames))
      endif
      end program demo_get_args