Added possibility to select random number within range

master
Alex Selimov 5 years ago
parent a677e0026e
commit 3aed6966da

@ -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[val1:val2]` - returns a random position that lies within the range

@ -172,20 +172,33 @@ module subroutines
return
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
integer, intent(in) :: i !The dimension of the position
character(len=100), intent(in) :: pos_string !The position string
real(kind=dp), intent(out) :: pos !The output parsed position value
integer :: iospara
real(kind=dp) :: rand
real(kind=dp) :: rand, rone, rtwo
character(len=100) :: cone, ctwo
iospara = 0
if(trim(adjustl(pos_string)) == 'inf') then
pos=box_bd(2*i)
else if(trim(adjustl(pos_string)) == '-inf') then
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
!Now extract the number we are reducing from infinity
if(index(pos_string,'inf') < index(pos_string,'-')) then
@ -211,9 +224,6 @@ module subroutines
end if
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
read(pos_string, *, iostat=iospara) pos
end if

Loading…
Cancel
Save