SCALE-RM
scale_random.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
14  !-----------------------------------------------------------------------------
15  !
16  !++ used modules
17  !
18  use scale_precision
19  use scale_stdio
20  !-----------------------------------------------------------------------------
21  implicit none
22  private
23  !-----------------------------------------------------------------------------
24  !
25  !++ Public procedure
26  !
27  public :: random_setup
28  public :: random_get
29 
30  !-----------------------------------------------------------------------------
31  !
32  !++ Public parameters & variables
33  !
34  !-----------------------------------------------------------------------------
35  !
36  !++ Private procedure
37  !
38  private :: random_reset
39 
40  !-----------------------------------------------------------------------------
41  !
42  !++ Private parameters & variables
43  !
44  logical, private :: random_fix = .false.
45 
46  integer, private, allocatable :: random_seedvar(:)
47 
48  !-----------------------------------------------------------------------------
49 contains
50  !-----------------------------------------------------------------------------
52  subroutine random_setup
53  use scale_process, only: &
55  implicit none
56 
57  namelist / param_random / &
58  random_fix
59 
60  integer :: nseeds, ierr
61  !---------------------------------------------------------------------------
62 
63  if( io_l ) write(io_fid_log,*)
64  if( io_l ) write(io_fid_log,*) '++++++ Module[RANDOM] / Categ[COMMON] / Origin[SCALElib]'
65 
66  !--- read namelist
67  rewind(io_fid_conf)
68  read(io_fid_conf,nml=param_random,iostat=ierr)
69  if( ierr < 0 ) then !--- missing
70  if( io_l ) write(io_fid_log,*) '*** Not found namelist. Default used.'
71  elseif( ierr > 0 ) then !--- fatal error
72  write(*,*) 'xxx Not appropriate names in namelist PARAM_RANDOM. Check!'
73  call prc_mpistop
74  endif
75  if( io_lnml ) write(io_fid_log,nml=param_random)
76 
77  call random_seed
78  call random_seed(size=nseeds)
79 
80  allocate( random_seedvar(nseeds))
81 
82  if( io_l ) write(io_fid_log,*)
83  if( io_l ) write(io_fid_log,*) '*** Array size for random seed:', nseeds
84  if ( random_fix ) then
85  if( io_l ) write(io_fid_log,*) '*** random seed is fixed.'
86  endif
87 
88  return
89  end subroutine random_setup
90 
91  !-----------------------------------------------------------------------------
93  subroutine random_reset
94  use scale_process, only: &
96  implicit none
97 
98  integer :: time1(8)
99  real(RP) :: time2
100  !---------------------------------------------------------------------------
101 
102  if ( random_fix ) then
103  time1(1) = 2011
104  time1(2) = 12
105  time1(3) = 5
106  time1(4) = 10
107  time1(5) = 20
108  time1(6) = 41 ! birthday of SCALE
109  time2 = 0.0_rp
110  else
111  call date_and_time(values=time1)
112  call cpu_time(time2)
113  endif
114 
115  random_seedvar(:) = &
116  + ( time1(1) - 1970 ) * 32140800 &
117  + time1(2) * 2678400 &
118  + time1(3) * 86400 &
119  + time1(4) * 60 &
120  + time1(5) * 3600 &
121  + time1(6) * 60 &
122  + time1(7) &
123  + int(time2*1.e6_rp) + prc_myrank
124 
125  call random_seed(put=random_seedvar)
126 
127  return
128  end subroutine random_reset
129 
130  !-----------------------------------------------------------------------------
132  subroutine random_get( var )
133  implicit none
134 
135  real(RP), intent(out) :: var(:,:,:)
136  !---------------------------------------------------------------------------
137 
138  call random_reset
139  call random_number(var)
140 
141  return
142  end subroutine random_get
143 
144 end module scale_random
subroutine, public prc_mpistop
Abort MPI.
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:59
subroutine, public random_setup
Setup.
module STDIO
Definition: scale_stdio.F90:12
module PROCESS
integer, public prc_myrank
process num in local communicator
subroutine, public random_get(var)
Get random number.
logical, public io_lnml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:60
module PRECISION
integer, public io_fid_conf
Config file ID.
Definition: scale_stdio.F90:55
module RANDOM
integer, public io_fid_log
Log file ID.
Definition: scale_stdio.F90:56