Skip to content

Commit

Permalink
Merge pull request #561 from NCAR/random-test-no-loop
Browse files Browse the repository at this point in the history
remove loop from Mersenne twister test
  • Loading branch information
hkershaw-brown authored Nov 7, 2023
2 parents b324e02 + 960eed1 commit 45013ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 41 deletions.
2 changes: 1 addition & 1 deletion assimilation_code/modules/utilities/random_seq_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module random_seq_mod

! the following routines were transcribed from C to F90, originally
! from the GNU scientific library: init_ran, ran_unif, ran_gauss,
! ran_gamma
! ran_gamma, ran_twist

integer, parameter :: N = 624 ! period parameters
integer, parameter :: M = 397
Expand Down
48 changes: 8 additions & 40 deletions developer_tests/random_seq/test_ran_unif.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,19 @@ program test_ran_unif


type (random_seq_type) :: r
integer :: j, i, n, f, seq
logical :: write_this_one
character(len=50) :: formf = '(I12,4(F16.5))'
character(len=256) :: fname, temp

logical :: write_me = .true. ! if true, write each distribution into a file for later diagnostics
integer :: write_limit = 1000000 ! but only if rep count is not greater than this limit

! to add more tests or change the parameters, specify a test count
! and update the sets of inputs here:

integer, parameter :: ntests = 1
integer :: seq

call initialize_utilities('test_ran_unif')

write(*, *) ''

do j=1, ntests

call init_random_seq(r, 5)
call init_random_seq(r, 5)

n = j

! save all values in a file for post-plotting?
write_this_one = (write_me .and. n <= write_limit)

if (write_this_one) then
write(temp, "(A,I10)") "ran_unif_", n
call squeeze_out_blanks(temp, fname)
f = open_file(fname)
endif

seq = ran_twist(r)
seq = ran_twist(r)

if (seq == 953453411) then
write(*,*) 'ran_unif test: PASS'
if (write_this_one) write(f,*) 'PASS'
else
write(*,*) 'ran_unif test: FAIL'
if (write_this_one) write(f,*) 'FAIL'
endif

if (write_this_one) call close_file(f)

enddo
if (seq == 953453411) then
write(*,*) 'ran_unif test: PASS'
else
write(*,*) 'ran_unif test: FAIL'
endif

call finalize_utilities()

Expand Down

0 comments on commit 45013ee

Please sign in to comment.