Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added random number seeds as optional input to parameter file
  • Loading branch information
daminton committed May 25, 2021
1 parent 661c6c6 commit 72d758d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/user/user_read_param_in.f90
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module subroutine user_read_param_in(param,inparfile)
write(*,*) "EXTRA_FORCE = ",param%lextra_force
write(*,*) "BIG_DISCARD = ",param%lbig_discard
write(*,*) "RHILL_PRESENT = ",param%lrhill_present
write(*,*) "SEED = ",size(param%seed), param%seed(:)
ierr = 0

! Added by D. Minton
Expand Down
31 changes: 26 additions & 5 deletions src/user/user_udio_reader.f90
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ module subroutine user_udio_reader(param, unit, iotype, v_list, iostat, iomsg)
logical :: t0_set = .false. !! Is the initial time set in the input file?
logical :: tstop_set = .false. !! Is the final time set in the input file?
logical :: dt_set = .false. !! Is the step size set in the input file?
logical :: seed_set = .false. !! Is the random seed set in the input file?
integer(I4B) :: ilength, ifirst, ilast !! Variables used to parse input file
character(STRMAX) :: line !! Line of the input file
character (len=:), allocatable :: line_trim,param_name, param_value
character(*),parameter :: linefmt = '(A)'
integer(I4B) :: nseeds
integer(I4B) :: nseeds, nseeds_from_file, i

call random_seed(size = nseeds)
if (allocated(param%seed)) deallocate(param%seed)
allocate(param%seed(nseeds))
!seed(:) = [(i * 1, i = 1, nseeds)]
!call random_seed(put = seed)

! Parse the file line by line, extracting tokens then matching them up with known parameters if possible
do
Expand Down Expand Up @@ -145,7 +144,6 @@ module subroutine user_udio_reader(param, unit, iotype, v_list, iostat, iomsg)
if (param_value == "YES" .or. param_value == 'T') param%lringmoons = .true.
case ("RING_OUTFILE")
param%ring_outfile = param_value

case ("TIDES")
call util_toupper(param_value)
if (param_value == "YES" .or. param_value == 'T') param%ltides = .true.
Expand All @@ -159,7 +157,24 @@ module subroutine user_udio_reader(param, unit, iotype, v_list, iostat, iomsg)
call util_toupper(param_value)
if (param_value == "YES" .or. param_value == 'T') param%lyorp = .true.
case("SEED")
read(param_value, *) param%qmin
read(param_value, *) nseeds_from_file
! Because the number of seeds can vary between compilers/systems, we need to make sure we can handle cases in which the input file has a different
! number of seeds than the current system. If the number of seeds in the file is smaller than required, we will use them as a source to fill in the missing elements.
! If the number of seeds in the file is larger than required, we will truncate the seed array.
if (nseeds_from_file >= nseeds) then
do i = 1, nseeds
ifirst = ilast + 1
param_value = user_get_token(line, ifirst, ilast, iostat)
read(param_value, *) param%seed(i)
end do
else if (nseeds_from_file < nseeds) then ! Seed array in file is too small
do i = 1, nseeds_from_file
ifirst = ilast + 1
param_value = user_get_token(line, ifirst, ilast, iostat)
read(param_value, *) param%seed(i)
end do
end if
seed_set = .true.
case default
write(iomsg,*) "Unknown parameter -> ",param_name
iostat = -1
Expand Down Expand Up @@ -240,6 +255,12 @@ module subroutine user_udio_reader(param, unit, iotype, v_list, iostat, iomsg)
end if
end if

if (seed_set) then
call random_seed(put = param%seed)
else
call random_seed(get = param%seed)
end if

return

end subroutine user_udio_reader
Expand Down
1 change: 1 addition & 0 deletions src/user/user_udio_writer.f90
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module subroutine user_udio_writer(param, unit, iotype, v_list, iostat, iomsg)
write(unit, Rfmt) "MU2KG",MU2KG
write(unit, Rfmt) "TU2S",TU2S
write(unit, Rfmt) "DU2M",DU2M
write(unit,*) "SEED",size(param%seed),param%seed(:)

write(unit, Lfmt) "EXTRA_FORCE",param%lextra_force
write(unit, Lfmt) "BIG_DISCARD",param%lbig_discard
Expand Down

0 comments on commit 72d758d

Please sign in to comment.