From 41024b96743df63463630027198d4846054b21c1 Mon Sep 17 00:00:00 2001 From: Alex Selimov Date: Sun, 15 Dec 2019 18:59:21 -0500 Subject: [PATCH] Added new parse ori_vec subroutine to parse orientation vectors --- src/mode_create.f90 | 15 +-------------- src/subroutines.f90 | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/mode_create.f90 b/src/mode_create.f90 index 23b9100..bac9b12 100644 --- a/src/mode_create.f90 +++ b/src/mode_create.f90 @@ -199,20 +199,7 @@ module mode_create call get_command_argument(arg_pos, orient_string, arglen) if (arglen==0) STOP "Missing orientation in orient command of mode create" arg_pos = arg_pos+1 - ori_pos=2 - do j = 1,3 - if (orient_string(ori_pos:ori_pos) == '-') then - ori_pos = ori_pos + 1 - read(orient_string(ori_pos:ori_pos), *, iostat=stat) orient(i,j) - if (stat>0) STOP "Error reading orient value" - orient(i,j) = -orient(i,j) - ori_pos = ori_pos + 1 - else - read(orient_string(ori_pos:ori_pos), *, iostat=stat) orient(i,j) - if(stat>0) STOP "Error reading orient value" - ori_pos=ori_pos + 1 - end if - end do + call parse_ori_vec(orient_string, orient(i,:)) end do diff --git a/src/subroutines.f90 b/src/subroutines.f90 index 0682037..f4447d7 100644 --- a/src/subroutines.f90 +++ b/src/subroutines.f90 @@ -145,4 +145,29 @@ module subroutines return end subroutine matrix_inverse + subroutine parse_ori_vec(ori_string, ori_vec) + !This subroutine parses a string to vector in the format [ijk] + character(len=8), intent(in) :: ori_string + real(kind=dp), dimension(3), intent(out) :: ori_vec + + integer :: i, ori_pos, stat + + ori_pos=2 + do i = 1,3 + if (ori_string(ori_pos:ori_pos) == '-') then + ori_pos = ori_pos + 1 + read(ori_string(ori_pos:ori_pos), *, iostat=stat) ori_vec(i) + if (stat>0) STOP "Error reading orientation value" + ori_vec(i) = -ori_vec(i) + ori_pos = ori_pos + 1 + else + read(ori_string(ori_pos:ori_pos), *, iostat=stat) ori_vec(i) + if(stat>0) STOP "Error reading orientation value" + ori_pos=ori_pos + 1 + end if + end do + + return + end subroutine parse_ori_vec + end module subroutines \ No newline at end of file