Changeset 4592 for palm/trunk/SOURCE/random_function_mod.f90
- Timestamp:
- Jul 8, 2020 9:56:29 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SOURCE/random_function_mod.f90
r4360 r4592 1 1 !> @file random_function_mod.f90 2 !------------------------------------------------------------------------------ !2 !--------------------------------------------------------------------------------------------------! 3 3 ! This file is part of the PALM model system. 4 4 ! 5 ! PALM is free software: you can redistribute it and/or modify it under the 6 ! terms of the GNU General Public License as published by the Free Software 7 ! Foundation, either version 3 of the License, or (at your option) any later 8 ! version. 5 ! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 ! Public License as published by the Free Software Foundation, either version 3 of the License, or 7 ! (at your option) any later version. 9 8 ! 10 ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY 11 ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR12 ! A PARTICULAR PURPOSE. See the GNU GeneralPublic License for more details.9 ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 ! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 11 ! Public License for more details. 13 12 ! 14 ! You should have received a copy of the GNU General Public License along with 15 ! PALM. If not, see<http://www.gnu.org/licenses/>.13 ! You should have received a copy of the GNU General Public License along with PALM. If not, see 14 ! <http://www.gnu.org/licenses/>. 16 15 ! 17 16 ! Copyright 1997-2020 Leibniz Universitaet Hannover 18 !------------------------------------------------------------------------------! 17 !--------------------------------------------------------------------------------------------------! 18 ! 19 19 ! 20 20 ! Current revisions: 21 21 ! ----------------- 22 ! 23 ! 22 ! 23 ! 24 24 ! Former revisions: 25 25 ! ----------------- 26 26 ! $Id$ 27 ! File re-formatted to follow the PALM coding standard 28 ! 29 ! 4360 2020-01-07 11:25:50Z suehring 27 30 ! Corrected "Former revisions" section 28 ! 31 ! 29 32 ! 4144 2019-08-06 09:11:47Z raasch 30 ! relational operators .EQ., .NE., etc. replaced by ==, /=, etc.31 ! 33 ! Relational operators .EQ., .NE., etc. replaced by ==, /=, etc. 34 ! 32 35 ! 3802 2019-03-17 13:33:42Z raasch 33 ! type conversion added to avoid compiler warning about constant integer 34 ! division truncation 35 ! 36 ! Type conversion added to avoid compiler warning about constant integer division truncation 37 ! 36 38 ! 3655 2019-01-07 16:51:22Z knoop 37 39 ! Corrected "Former revisions" section … … 41 43 ! 42 44 ! 45 !--------------------------------------------------------------------------------------------------! 43 46 ! Description: 44 47 ! ------------ 45 !> Random number generator, produces numbers equally distributed in interval [0,1] 46 !> This routine is taken from the "numerical recipes" 47 !------------------------------------------------------------------------------ !48 !> Random number generator, produces numbers equally distributed in interval [0,1]. 49 !> This routine is taken from the "numerical recipes". 50 !--------------------------------------------------------------------------------------------------! 48 51 MODULE random_function_mod 49 52 50 53 51 54 USE kinds … … 70 73 CONTAINS 71 74 72 !------------------------------------------------------------------------------ !75 !--------------------------------------------------------------------------------------------------! 73 76 ! Description: 74 77 ! ------------ 75 78 !> @todo Missing subroutine description. 76 !------------------------------------------------------------------------------ !77 79 !--------------------------------------------------------------------------------------------------! 80 SUBROUTINE random_function_ini 78 81 79 82 IMPLICIT NONE 80 83 81 82 84 random_iv = 0 85 random_iy = 0 83 86 84 87 END SUBROUTINE random_function_ini 85 88 86 FUNCTION random_function( idum ) 89 !--------------------------------------------------------------------------------------------------! 90 ! Description: 91 ! ------------ 92 !> @todo Missing function description. 93 !--------------------------------------------------------------------------------------------------! 94 FUNCTION random_function( idum ) 87 95 88 96 89 97 IMPLICIT NONE 90 98 91 92 93 94 95 96 97 99 INTEGER(iwp) :: ia !< 100 INTEGER(iwp) :: idum !< 101 INTEGER(iwp) :: im !< 102 INTEGER(iwp) :: iq !< 103 INTEGER(iwp) :: ir !< 104 INTEGER(iwp) :: ndiv !< 105 INTEGER(iwp) :: ntab !< 98 106 99 100 107 INTEGER(iwp) :: j !< 108 INTEGER(iwp) :: k !< 101 109 102 103 104 105 110 REAL(wp) :: am !< 111 REAL(wp) :: eps !< 112 REAL(wp) :: random_function !< 113 REAL(wp) :: rnmx !< 106 114 107 PARAMETER ( ia=16807, im=2147483647, am=1.0_wp/im, iq=127773, ir=2836,&108 ntab=32, ndiv=1+INT(REAL(im-1)/ntab), eps=1.2e-7_wp, rnmx=1.0_wp-eps )115 PARAMETER ( ia = 16807, im = 2147483647, am = 1.0_wp / im, iq = 127773, ir = 2836, ntab = 32, & 116 ndiv = 1 + INT( REAL( im - 1 ) / ntab ), eps = 1.2e-7_wp, rnmx = 1.0_wp - eps ) 109 117 110 111 idum = max (-idum,1)112 DO j = ntab+8,1,-1113 114 115 116 117 118 119 118 IF ( idum <= 0 .OR. random_iy == 0 ) THEN 119 idum = MAX( -idum, 1 ) 120 DO j = ntab + 8, 1, -1 121 k = idum / iq 122 idum = ia * ( idum - k * iq ) - ir * k 123 IF ( idum < 0 ) idum = idum + im 124 IF ( j <= ntab ) random_iv(j) = idum 125 ENDDO 126 random_iy = random_iv(1) 127 ENDIF 120 128 121 122 123 124 125 126 127 129 k = idum / iq 130 idum = ia * ( idum - k * iq ) - ir * k 131 IF ( idum < 0 ) idum = idum + im 132 j = 1 + random_iy / ndiv 133 random_iy = random_iv(j) 134 random_iv(j) = idum 135 random_function = MIN( am * random_iy , rnmx ) 128 136 129 137 END FUNCTION random_function 130 138 131 139 END MODULE random_function_mod
Note: See TracChangeset
for help on using the changeset viewer.