-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_line_argument_module.f90
executable file
·54 lines (47 loc) · 1.16 KB
/
command_line_argument_module.f90
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module cmd_line
implicit none
integer,parameter :: rk=selected_real_kind(15,307)
integer,parameter :: MAXBUF=200
character(len=MAXBUF),private :: argu
contains
!
! Define here functions
!
! cmd2real(i)
! of type real(rk) that reads the ith command line
! argument, converts it to real(rk) and returns this value
!
! cmd2int(i)
! of type integer that reads the ith command line
! argument, converts it to integer and returns this value
!
! Note that constant 'rk' and variable 'argu' can be used here. Use
! 'internal io' to do the conversion.
!
real(kind=rk) function cmd2real(i)
implicit none
integer,intent(in) :: i
integer :: ios
call get_command_argument(i,argu)
read(argu,*,iostat=ios),cmd2real
if (ios/=0) then
cmd2real=-1
return
else
return
end if
end function cmd2real
integer function cmd2int(i)
implicit none
integer,intent(in) :: i
integer :: ios
call get_command_argument(i,argu)
read(argu,*,iostat=ios),cmd2int
if (ios/=0) then
cmd2int=-1
return
else
return
end if
end function cmd2int
end module cmd_line