Merge pull request #24 from aselimov/ft--rand-ranges
Added possibility to select random number within range
This commit is contained in:
commit
170e8b76fd
@ -281,3 +281,5 @@ Specifying positions in cacmb can be done through a variety of ways. Examples of
|
|||||||
|
|
||||||
`rand` - Returns a random position that lies within the simulation cell.
|
`rand` - Returns a random position that lies within the simulation cell.
|
||||||
|
|
||||||
|
`rand[val1:val2]` - returns a random position that lies within the range
|
||||||
|
|
||||||
|
@ -172,20 +172,33 @@ module subroutines
|
|||||||
return
|
return
|
||||||
end subroutine parse_ori_vec
|
end subroutine parse_ori_vec
|
||||||
|
|
||||||
subroutine parse_pos(i, pos_string, pos)
|
recursive subroutine parse_pos(i, pos_string, pos)
|
||||||
!This subroutine parses the pos command allowing for command which include inf
|
!This subroutine parses the pos command allowing for command which include inf
|
||||||
integer, intent(in) :: i !The dimension of the position
|
integer, intent(in) :: i !The dimension of the position
|
||||||
character(len=100), intent(in) :: pos_string !The position string
|
character(len=100), intent(in) :: pos_string !The position string
|
||||||
real(kind=dp), intent(out) :: pos !The output parsed position value
|
real(kind=dp), intent(out) :: pos !The output parsed position value
|
||||||
|
|
||||||
integer :: iospara
|
integer :: iospara
|
||||||
real(kind=dp) :: rand
|
real(kind=dp) :: rand, rone, rtwo
|
||||||
|
character(len=100) :: cone, ctwo
|
||||||
|
|
||||||
iospara = 0
|
iospara = 0
|
||||||
if(trim(adjustl(pos_string)) == 'inf') then
|
if(trim(adjustl(pos_string)) == 'inf') then
|
||||||
pos=box_bd(2*i)
|
pos=box_bd(2*i)
|
||||||
else if(trim(adjustl(pos_string)) == '-inf') then
|
else if(trim(adjustl(pos_string)) == '-inf') then
|
||||||
pos=box_bd(2*i-1)
|
pos=box_bd(2*i-1)
|
||||||
|
|
||||||
|
else if (trim(adjustl(pos_string)) == 'rand') then
|
||||||
|
call random_number(rand)
|
||||||
|
pos = (box_bd(2*i)-box_bd(2*i-1))*rand + box_bd(2*i-1)
|
||||||
|
|
||||||
|
else if (index(pos_string,'rand')>0) then
|
||||||
|
call random_number(rand)
|
||||||
|
cone = pos_string(index(pos_string, '[')+1:index(pos_string,':')-1)
|
||||||
|
call parse_pos(i, cone, rone)
|
||||||
|
ctwo = pos_string(index(pos_string, ':')+1:index(pos_string,']')-1)
|
||||||
|
call parse_pos(i, ctwo, rtwo)
|
||||||
|
pos = (rtwo - rone)*rand + rone
|
||||||
else if ((index(pos_string,'-') > 0).and.(index(pos_string,'inf')>0)) then
|
else if ((index(pos_string,'-') > 0).and.(index(pos_string,'inf')>0)) then
|
||||||
!Now extract the number we are reducing from infinity
|
!Now extract the number we are reducing from infinity
|
||||||
if(index(pos_string,'inf') < index(pos_string,'-')) then
|
if(index(pos_string,'inf') < index(pos_string,'-')) then
|
||||||
@ -211,9 +224,6 @@ module subroutines
|
|||||||
end if
|
end if
|
||||||
pos = (box_bd(2*i)-box_bd(2*i-1))*pos + box_bd(2*i-1)
|
pos = (box_bd(2*i)-box_bd(2*i-1))*pos + box_bd(2*i-1)
|
||||||
|
|
||||||
else if (trim(adjustl(pos_string)) == 'rand') then
|
|
||||||
call random_number(rand)
|
|
||||||
pos = (box_bd(2*i)-box_bd(2*i-1))*rand + box_bd(2*i-1)
|
|
||||||
else
|
else
|
||||||
read(pos_string, *, iostat=iospara) pos
|
read(pos_string, *, iostat=iospara) pos
|
||||||
end if
|
end if
|
||||||
|
Loading…
x
Reference in New Issue
Block a user