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_nml ) write(io_fid_nml,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) ! date and time information
99  real(RP) :: time2 ! CPU time
100  !---------------------------------------------------------------------------
101 
102  if ( random_fix ) then
103  ! birthday of SCALE
104  time1(1) = 2011 ! The year
105  time1(2) = 12 ! The month
106  time1(3) = 5 ! The day of the month
107  time1(4) = 9 ! Time difference with UTC in minutes
108  time1(5) = 10 ! The hour of the day
109  time1(6) = 20 ! The minutes of the hour
110  time1(7) = 41 ! The seconds of the minute
111  time1(8) = 0 ! The milliseconds of the second
112  time2 = 0.0_rp
113  else
114  call date_and_time(values=time1)
115  call cpu_time(time2)
116  endif
117 
118  random_seedvar(:) = prc_myrank &
119  + ( time1(1) - 1970 ) * 32140800 &
120  + time1(2) * 2678400 &
121  + time1(3) * 86400 &
122  + time1(5) * 60 &
123  + time1(6) * 3600 &
124  + time1(7) * 60 &
125  + time1(8) &
126  + int(time2*1.e6_rp)
127 
128  call random_seed(put=random_seedvar)
129 
130  return
131  end subroutine random_reset
132 
133  !-----------------------------------------------------------------------------
135  subroutine random_get( var )
136  implicit none
137 
138  real(RP), intent(out) :: var(:,:,:)
139  !---------------------------------------------------------------------------
140 
141  call random_reset
142  call random_number(var)
143 
144  return
145  end subroutine random_get
146 
147 end module scale_random
subroutine, public prc_mpistop
Abort MPI.
logical, public io_l
output log or not? (this process)
Definition: scale_stdio.F90:61
subroutine, public random_setup
Setup.
module STDIO
Definition: scale_stdio.F90:12
logical, public io_nml
output log or not? (for namelist, this process)
Definition: scale_stdio.F90:62
module PROCESS
integer, public prc_myrank
process num in local communicator
subroutine, public random_get(var)
Get random number.
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
integer, public io_fid_nml
Log file ID (only for output namelist)
Definition: scale_stdio.F90:57