Restructure the command parsing loops so the mode commands only parse the mode options
This commit is contained in:
parent
c291ec65b4
commit
0dff3b2ca9
@ -1,4 +1,4 @@
|
|||||||
subroutine call_mode(arg_num,mode)
|
subroutine call_mode(arg_pos,mode)
|
||||||
!This code is used to parse the command line argument for the mode information and calls the required
|
!This code is used to parse the command line argument for the mode information and calls the required
|
||||||
!mode module.
|
!mode module.
|
||||||
|
|
||||||
@ -9,16 +9,16 @@ subroutine call_mode(arg_num,mode)
|
|||||||
|
|
||||||
implicit none
|
implicit none
|
||||||
|
|
||||||
integer, intent(in) :: arg_num
|
integer, intent(out) :: arg_pos
|
||||||
character(len=100), intent(in) :: mode
|
character(len=100), intent(in) :: mode
|
||||||
|
|
||||||
select case(mode)
|
select case(mode)
|
||||||
case('--create')
|
case('--create')
|
||||||
call create
|
call create(arg_pos)
|
||||||
case('--convert')
|
case('--convert')
|
||||||
call convert
|
call convert(arg_pos)
|
||||||
case('--merge')
|
case('--merge')
|
||||||
call merge
|
call merge(arg_pos)
|
||||||
case default
|
case default
|
||||||
print *, "Mode ", trim(adjustl(mode)), " currently not accepted. Please check documentation for ", &
|
print *, "Mode ", trim(adjustl(mode)), " currently not accepted. Please check documentation for ", &
|
||||||
"accepted modes and rerun."
|
"accepted modes and rerun."
|
||||||
|
30
src/main.f90
30
src/main.f90
@ -17,8 +17,8 @@ program main
|
|||||||
use io
|
use io
|
||||||
|
|
||||||
|
|
||||||
integer :: arg_num
|
integer :: i, end_mode_arg, arg_num
|
||||||
character(len=100) :: mode
|
character(len=100) :: argument
|
||||||
|
|
||||||
!Call initialization functions
|
!Call initialization functions
|
||||||
call lattice_init
|
call lattice_init
|
||||||
@ -29,13 +29,29 @@ program main
|
|||||||
|
|
||||||
!Determine if a mode is being used and what it is. The first argument has to be the mode
|
!Determine if a mode is being used and what it is. The first argument has to be the mode
|
||||||
!if a mode is being used
|
!if a mode is being used
|
||||||
call get_command_argument(1, mode)
|
call get_command_argument(1, argument)
|
||||||
|
|
||||||
mode = trim(adjustl(mode))
|
argument = trim(adjustl(argument))
|
||||||
if (mode(1:2) == '--') then
|
if (argument(1:2) == '--') then
|
||||||
call call_mode(arg_num, mode)
|
call call_mode(end_mode_arg, argument)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
!Finish by writing the files
|
!Now we loop through all of the arguments and check for passed options or for a filename to be written out
|
||||||
|
do i = end_mode_arg-1, arg_num
|
||||||
|
call get_command_argument(i, argument)
|
||||||
|
|
||||||
|
!Check to see if a filename was passed
|
||||||
|
if(scan(argument,'.',.true.) > 0) then
|
||||||
|
call get_out_file(argument)
|
||||||
|
end if
|
||||||
|
end do
|
||||||
|
|
||||||
|
!Check to make sure a file was passed to be written out and then write out
|
||||||
|
! Before building do a check on the file
|
||||||
|
if (outfilenum == 0) then
|
||||||
|
argument = 'none'
|
||||||
|
call get_out_file(argument)
|
||||||
|
end if
|
||||||
call write_out
|
call write_out
|
||||||
|
|
||||||
end program main
|
end program main
|
@ -8,8 +8,9 @@ module mode_convert
|
|||||||
public
|
public
|
||||||
contains
|
contains
|
||||||
|
|
||||||
subroutine convert
|
subroutine convert(arg_pos)
|
||||||
!This subroutine converts a single input file from one format to another
|
!This subroutine converts a single input file from one format to another
|
||||||
|
integer, intent(out) :: arg_pos
|
||||||
character(len=100) :: infile, outfile
|
character(len=100) :: infile, outfile
|
||||||
real(kind = dp) :: temp_box_bd(6)
|
real(kind = dp) :: temp_box_bd(6)
|
||||||
!We have to allocate the element and atom arrays with a size of 1 for the read in code to work
|
!We have to allocate the element and atom arrays with a size of 1 for the read in code to work
|
||||||
@ -19,10 +20,7 @@ module mode_convert
|
|||||||
call get_in_file(infile)
|
call get_in_file(infile)
|
||||||
call read_in(1, (/0.0_dp,0.0_dp,0.0_dp/), temp_box_bd)
|
call read_in(1, (/0.0_dp,0.0_dp,0.0_dp/), temp_box_bd)
|
||||||
call grow_box(temp_box_bd)
|
call grow_box(temp_box_bd)
|
||||||
|
arg_pos = 3
|
||||||
!Now get the outfile, writing is done after all the codes complete
|
|
||||||
call get_command_argument(3, outfile)
|
|
||||||
call get_out_file(outfile)
|
|
||||||
|
|
||||||
end subroutine convert
|
end subroutine convert
|
||||||
end module mode_convert
|
end module mode_convert
|
@ -21,11 +21,12 @@ module mode_create
|
|||||||
public
|
public
|
||||||
contains
|
contains
|
||||||
|
|
||||||
subroutine create()
|
subroutine create(arg_pos)
|
||||||
! Main subroutine which controls execution
|
! Main subroutine which controls execution
|
||||||
|
|
||||||
character(len=100) :: textholder
|
character(len=100) :: textholder
|
||||||
|
integer, intent(out) :: arg_pos
|
||||||
|
|
||||||
integer :: i, ibasis, inod
|
integer :: i, ibasis, inod
|
||||||
real(kind=dp), allocatable :: r_node_temp(:,:,:)
|
real(kind=dp), allocatable :: r_node_temp(:,:,:)
|
||||||
|
|
||||||
@ -45,14 +46,8 @@ module mode_create
|
|||||||
lat_atom_num = 0
|
lat_atom_num = 0
|
||||||
|
|
||||||
!First we parse the command
|
!First we parse the command
|
||||||
call parse_command()
|
call parse_command(arg_pos)
|
||||||
|
|
||||||
! Before building do a check on the file
|
|
||||||
if (outfilenum == 0) then
|
|
||||||
textholder = 'none'
|
|
||||||
call get_out_file(textholder)
|
|
||||||
end if
|
|
||||||
|
|
||||||
!Now we setup the unit element and call other init subroutines
|
!Now we setup the unit element and call other init subroutines
|
||||||
call def_ng_node(1, element_type)
|
call def_ng_node(1, element_type)
|
||||||
|
|
||||||
@ -161,10 +156,10 @@ module mode_create
|
|||||||
sub_box_array_bd(2,2,1) = ele_num
|
sub_box_array_bd(2,2,1) = ele_num
|
||||||
end subroutine create
|
end subroutine create
|
||||||
!This subroutine parses the command and pulls out information needed for mode_create
|
!This subroutine parses the command and pulls out information needed for mode_create
|
||||||
subroutine parse_command()
|
subroutine parse_command(arg_pos)
|
||||||
|
|
||||||
|
integer, intent(out) :: arg_pos
|
||||||
integer :: arg_pos, ori_pos, i, j, arglen, stat
|
integer :: ori_pos, i, j, arglen, stat
|
||||||
character(len=100) :: textholder
|
character(len=100) :: textholder
|
||||||
character(len=8) :: orient_string
|
character(len=8) :: orient_string
|
||||||
|
|
||||||
@ -245,20 +240,10 @@ module mode_create
|
|||||||
read(textholder, *) origin(i)
|
read(textholder, *) origin(i)
|
||||||
arg_pos = arg_pos + 1
|
arg_pos = arg_pos + 1
|
||||||
end do
|
end do
|
||||||
!If a filetype is passed then we add name.ext to the outfiles list
|
|
||||||
case('xyz')
|
|
||||||
textholder = trim(adjustl(name)) //'.xyz'
|
|
||||||
call get_out_file(textholder)
|
|
||||||
|
|
||||||
case default
|
case default
|
||||||
!Check to see if it is an option command, if so then mode_create must be finished
|
!If it isn't an option then you have to exit
|
||||||
if(textholder(1:1) == '-') then
|
exit
|
||||||
exit
|
|
||||||
|
|
||||||
!Check to see if a filename was passed
|
|
||||||
elseif(scan(textholder,'.',.true.) > 0) then
|
|
||||||
call get_out_file(textholder)
|
|
||||||
end if
|
|
||||||
end select
|
end select
|
||||||
end do
|
end do
|
||||||
|
|
||||||
|
@ -12,13 +12,14 @@ module mode_merge
|
|||||||
|
|
||||||
public
|
public
|
||||||
contains
|
contains
|
||||||
subroutine merge
|
subroutine merge(arg_pos)
|
||||||
|
|
||||||
|
integer, intent(out) :: arg_pos
|
||||||
integer :: i
|
integer :: i
|
||||||
real(kind=dp) :: displace(3), temp_box_bd(6)
|
real(kind=dp) :: displace(3), temp_box_bd(6)
|
||||||
|
|
||||||
!First we parse the merge command
|
!First we parse the merge command
|
||||||
call parse_command
|
call parse_command(arg_pos)
|
||||||
|
|
||||||
!Now loop over all files and stack them
|
!Now loop over all files and stack them
|
||||||
do i = 1, in_num
|
do i = 1, in_num
|
||||||
@ -44,10 +45,12 @@ module mode_merge
|
|||||||
return
|
return
|
||||||
end subroutine merge
|
end subroutine merge
|
||||||
|
|
||||||
subroutine parse_command
|
subroutine parse_command(arg_pos)
|
||||||
|
|
||||||
|
integer, intent(out) :: arg_pos
|
||||||
|
|
||||||
character(len=100) :: textholder
|
character(len=100) :: textholder
|
||||||
integer :: i, stat, arglen, arg_pos
|
integer :: i, stat, arglen
|
||||||
|
|
||||||
!Get dimension to concatenate along
|
!Get dimension to concatenate along
|
||||||
call get_command_argument(2, dim, arglen)
|
call get_command_argument(2, dim, arglen)
|
||||||
@ -88,13 +91,8 @@ module mode_merge
|
|||||||
select case(trim(textholder))
|
select case(trim(textholder))
|
||||||
|
|
||||||
case default
|
case default
|
||||||
!Check to see if it is an option command, if so then mode_create must be finished
|
!If it isn't an available option to mode merge then we just exit
|
||||||
if(textholder(1:1) == '-') then
|
exit
|
||||||
exit
|
|
||||||
!Check to see if a filename was passed
|
|
||||||
elseif(scan(textholder,'.',.true.) > 0) then
|
|
||||||
call get_out_file(textholder)
|
|
||||||
end if
|
|
||||||
end select
|
end select
|
||||||
end do
|
end do
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user