[1] | 1 | MODULE random_function_mod |
---|
[1036] | 2 | |
---|
| 3 | !--------------------------------------------------------------------------------! |
---|
| 4 | ! This file is part of PALM. |
---|
| 5 | ! |
---|
| 6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 9 | ! |
---|
| 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 FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 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/>. |
---|
| 16 | ! |
---|
| 17 | ! Copyright 1997-2012 Leibniz University Hannover |
---|
| 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[1093] | 22 | ! |
---|
[1] | 23 | ! |
---|
| 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
[3] | 26 | ! $Id: random_function.f90 1093 2013-02-02 12:58:49Z raasch $ |
---|
[1037] | 27 | ! |
---|
[1093] | 28 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 29 | ! unused variables removed |
---|
| 30 | ! |
---|
[1037] | 31 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 32 | ! code put under GPL (PALM 3.9) |
---|
| 33 | ! |
---|
[3] | 34 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 35 | ! |
---|
[1] | 36 | ! Revision 1.3 2003/10/29 09:06:57 raasch |
---|
| 37 | ! Former function changed to a module. |
---|
| 38 | ! |
---|
| 39 | ! Revision 1.1 1998/02/04 16:09:45 raasch |
---|
| 40 | ! Initial revision |
---|
| 41 | ! |
---|
| 42 | ! |
---|
| 43 | ! Description: |
---|
| 44 | ! ------------ |
---|
| 45 | ! Random number generator, produces numbers equally distributed in interval [0,1] |
---|
| 46 | ! This routine is taken from the "numerical recipies" |
---|
[3] | 47 | !------------------------------------------------------------------------------! |
---|
[1] | 48 | |
---|
| 49 | IMPLICIT NONE |
---|
| 50 | |
---|
| 51 | PRIVATE |
---|
| 52 | |
---|
| 53 | PUBLIC random_function, random_function_ini |
---|
| 54 | |
---|
| 55 | INTEGER, PUBLIC, SAVE :: random_iv(32), random_iy |
---|
| 56 | |
---|
| 57 | INTERFACE random_function_ini |
---|
| 58 | MODULE PROCEDURE random_function_ini |
---|
| 59 | END INTERFACE random_function_ini |
---|
| 60 | |
---|
| 61 | INTERFACE random_function |
---|
| 62 | MODULE PROCEDURE random_function |
---|
| 63 | END INTERFACE random_function |
---|
| 64 | |
---|
| 65 | CONTAINS |
---|
| 66 | |
---|
| 67 | SUBROUTINE random_function_ini |
---|
| 68 | |
---|
| 69 | IMPLICIT NONE |
---|
| 70 | |
---|
| 71 | random_iv = 0 |
---|
| 72 | random_iy = 0 |
---|
| 73 | |
---|
| 74 | END SUBROUTINE random_function_ini |
---|
| 75 | |
---|
| 76 | FUNCTION random_function( idum ) |
---|
| 77 | |
---|
| 78 | |
---|
| 79 | IMPLICIT NONE |
---|
| 80 | |
---|
| 81 | INTEGER :: ia, idum, im, iq, ir, ndiv, ntab |
---|
[1092] | 82 | REAL :: am, eps, random_function, rnmx |
---|
[1] | 83 | |
---|
| 84 | PARAMETER ( ia=16807, im=2147483647, am=1.0/im, iq=127773, ir=2836, & |
---|
| 85 | ntab=32, ndiv=1+(im-1)/ntab, eps=1.2e-7, rnmx=1.0-eps ) |
---|
| 86 | |
---|
| 87 | INTEGER :: j, k |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | IF ( idum .le. 0 .or. random_iy .eq. 0 ) THEN |
---|
| 91 | idum = max (-idum,1) |
---|
| 92 | DO j = ntab+8,1,-1 |
---|
| 93 | k = idum / iq |
---|
| 94 | idum = ia * ( idum - k * iq ) - ir * k |
---|
| 95 | IF ( idum .lt. 0 ) idum = idum + im |
---|
| 96 | IF ( j .le. ntab ) random_iv(j) = idum |
---|
| 97 | ENDDO |
---|
| 98 | random_iy = random_iv(1) |
---|
| 99 | ENDIF |
---|
| 100 | |
---|
| 101 | k = idum / iq |
---|
| 102 | idum = ia * ( idum - k * iq ) - ir * k |
---|
| 103 | IF ( idum .lt. 0 ) idum = idum + im |
---|
| 104 | j = 1 + random_iy / ndiv |
---|
| 105 | random_iy = random_iv(j) |
---|
| 106 | random_iv(j) = idum |
---|
| 107 | random_function = min ( am * random_iy , rnmx ) |
---|
| 108 | |
---|
| 109 | END FUNCTION random_function |
---|
| 110 | |
---|
| 111 | END MODULE random_function_mod |
---|