[1850] | 1 | !> @file random_function_mod.f90 |
---|
[1036] | 2 | !--------------------------------------------------------------------------------! |
---|
| 3 | ! This file is part of PALM. |
---|
| 4 | ! |
---|
| 5 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 6 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 7 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 8 | ! |
---|
| 9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 10 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 11 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 12 | ! |
---|
| 13 | ! You should have received a copy of the GNU General Public License along with |
---|
| 14 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 15 | ! |
---|
[1818] | 16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
[1036] | 17 | !--------------------------------------------------------------------------------! |
---|
| 18 | ! |
---|
[484] | 19 | ! Current revisions: |
---|
[1] | 20 | ! ----------------- |
---|
[1343] | 21 | ! |
---|
[1683] | 22 | ! |
---|
[1321] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
| 25 | ! $Id: random_function_mod.f90 1851 2016-04-08 13:32:50Z hellstea $ |
---|
| 26 | ! |
---|
[1851] | 27 | ! 1850 2016-04-08 13:29:27Z maronga |
---|
| 28 | ! Module renamed |
---|
| 29 | ! |
---|
| 30 | ! |
---|
[1683] | 31 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 32 | ! Code annotations made doxygen readable |
---|
| 33 | ! |
---|
[1343] | 34 | ! 1342 2014-03-26 17:04:47Z kanani |
---|
| 35 | ! REAL constants defined as wp-kind |
---|
| 36 | ! |
---|
[1321] | 37 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 38 | ! ONLY-attribute added to USE-statements, |
---|
| 39 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 40 | ! kinds are defined in new module kinds, |
---|
| 41 | ! old module precision_kind is removed, |
---|
| 42 | ! revision history before 2012 removed, |
---|
| 43 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 44 | ! all variable declaration statements |
---|
[1] | 45 | ! |
---|
[1093] | 46 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 47 | ! unused variables removed |
---|
| 48 | ! |
---|
[1037] | 49 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 50 | ! code put under GPL (PALM 3.9) |
---|
| 51 | ! |
---|
[3] | 52 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 53 | ! |
---|
[1] | 54 | ! Revision 1.1 1998/02/04 16:09:45 raasch |
---|
| 55 | ! Initial revision |
---|
| 56 | ! |
---|
| 57 | ! |
---|
| 58 | ! Description: |
---|
| 59 | ! ------------ |
---|
[1682] | 60 | !> Random number generator, produces numbers equally distributed in interval [0,1] |
---|
| 61 | !> This routine is taken from the "numerical recipies" |
---|
[3] | 62 | !------------------------------------------------------------------------------! |
---|
[1682] | 63 | MODULE random_function_mod |
---|
| 64 | |
---|
[1] | 65 | |
---|
[1320] | 66 | USE kinds |
---|
| 67 | |
---|
[1] | 68 | IMPLICIT NONE |
---|
| 69 | |
---|
| 70 | PRIVATE |
---|
| 71 | |
---|
| 72 | PUBLIC random_function, random_function_ini |
---|
| 73 | |
---|
[1682] | 74 | INTEGER(iwp), PUBLIC, SAVE :: random_iv(32) !< |
---|
| 75 | INTEGER(iwp), PUBLIC, SAVE :: random_iy !< |
---|
[1] | 76 | |
---|
| 77 | INTERFACE random_function_ini |
---|
| 78 | MODULE PROCEDURE random_function_ini |
---|
| 79 | END INTERFACE random_function_ini |
---|
| 80 | |
---|
| 81 | INTERFACE random_function |
---|
| 82 | MODULE PROCEDURE random_function |
---|
| 83 | END INTERFACE random_function |
---|
| 84 | |
---|
| 85 | CONTAINS |
---|
| 86 | |
---|
[1682] | 87 | !------------------------------------------------------------------------------! |
---|
| 88 | ! Description: |
---|
| 89 | ! ------------ |
---|
| 90 | !> @todo Missing subroutine description. |
---|
| 91 | !------------------------------------------------------------------------------! |
---|
[1] | 92 | SUBROUTINE random_function_ini |
---|
| 93 | |
---|
| 94 | IMPLICIT NONE |
---|
| 95 | |
---|
| 96 | random_iv = 0 |
---|
| 97 | random_iy = 0 |
---|
| 98 | |
---|
| 99 | END SUBROUTINE random_function_ini |
---|
| 100 | |
---|
| 101 | FUNCTION random_function( idum ) |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | IMPLICIT NONE |
---|
| 105 | |
---|
[1682] | 106 | INTEGER(iwp) :: ia !< |
---|
| 107 | INTEGER(iwp) :: idum !< |
---|
| 108 | INTEGER(iwp) :: im !< |
---|
| 109 | INTEGER(iwp) :: iq !< |
---|
| 110 | INTEGER(iwp) :: ir !< |
---|
| 111 | INTEGER(iwp) :: ndiv !< |
---|
| 112 | INTEGER(iwp) :: ntab !< |
---|
[1] | 113 | |
---|
[1682] | 114 | INTEGER(iwp) :: j !< |
---|
| 115 | INTEGER(iwp) :: k !< |
---|
[1320] | 116 | |
---|
[1682] | 117 | REAL(wp) :: am !< |
---|
| 118 | REAL(wp) :: eps !< |
---|
| 119 | REAL(wp) :: random_function !< |
---|
| 120 | REAL(wp) :: rnmx !< |
---|
[1320] | 121 | |
---|
[1342] | 122 | PARAMETER ( ia=16807, im=2147483647, am=1.0_wp/im, iq=127773, ir=2836, & |
---|
| 123 | ntab=32, ndiv=1+(im-1)/ntab, eps=1.2e-7_wp, rnmx=1.0_wp-eps ) |
---|
[1] | 124 | |
---|
| 125 | IF ( idum .le. 0 .or. random_iy .eq. 0 ) THEN |
---|
| 126 | idum = max (-idum,1) |
---|
| 127 | DO j = ntab+8,1,-1 |
---|
| 128 | k = idum / iq |
---|
| 129 | idum = ia * ( idum - k * iq ) - ir * k |
---|
| 130 | IF ( idum .lt. 0 ) idum = idum + im |
---|
| 131 | IF ( j .le. ntab ) random_iv(j) = idum |
---|
| 132 | ENDDO |
---|
| 133 | random_iy = random_iv(1) |
---|
| 134 | ENDIF |
---|
| 135 | |
---|
| 136 | k = idum / iq |
---|
| 137 | idum = ia * ( idum - k * iq ) - ir * k |
---|
| 138 | IF ( idum .lt. 0 ) idum = idum + im |
---|
| 139 | j = 1 + random_iy / ndiv |
---|
| 140 | random_iy = random_iv(j) |
---|
| 141 | random_iv(j) = idum |
---|
| 142 | random_function = min ( am * random_iy , rnmx ) |
---|
| 143 | |
---|
| 144 | END FUNCTION random_function |
---|
| 145 | |
---|
| 146 | END MODULE random_function_mod |
---|