[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 | ! ----------------- |
---|
| 22 | ! |
---|
| 23 | ! |
---|
| 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
[3] | 26 | ! $Id: random_function.f90 1037 2012-10-22 14:10:22Z maronga $ |
---|
[1037] | 27 | ! |
---|
| 28 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 29 | ! code put under GPL (PALM 3.9) |
---|
| 30 | ! |
---|
[3] | 31 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 32 | ! |
---|
[1] | 33 | ! Revision 1.3 2003/10/29 09:06:57 raasch |
---|
| 34 | ! Former function changed to a module. |
---|
| 35 | ! |
---|
| 36 | ! Revision 1.1 1998/02/04 16:09:45 raasch |
---|
| 37 | ! Initial revision |
---|
| 38 | ! |
---|
| 39 | ! |
---|
| 40 | ! Description: |
---|
| 41 | ! ------------ |
---|
| 42 | ! Random number generator, produces numbers equally distributed in interval [0,1] |
---|
| 43 | ! This routine is taken from the "numerical recipies" |
---|
[3] | 44 | !------------------------------------------------------------------------------! |
---|
[1] | 45 | |
---|
| 46 | IMPLICIT NONE |
---|
| 47 | |
---|
| 48 | PRIVATE |
---|
| 49 | |
---|
| 50 | PUBLIC random_function, random_function_ini |
---|
| 51 | |
---|
| 52 | INTEGER, PUBLIC, SAVE :: random_iv(32), random_iy |
---|
| 53 | |
---|
| 54 | INTERFACE random_function_ini |
---|
| 55 | MODULE PROCEDURE random_function_ini |
---|
| 56 | END INTERFACE random_function_ini |
---|
| 57 | |
---|
| 58 | INTERFACE random_function |
---|
| 59 | MODULE PROCEDURE random_function |
---|
| 60 | END INTERFACE random_function |
---|
| 61 | |
---|
| 62 | CONTAINS |
---|
| 63 | |
---|
| 64 | SUBROUTINE random_function_ini |
---|
| 65 | |
---|
| 66 | IMPLICIT NONE |
---|
| 67 | |
---|
| 68 | random_iv = 0 |
---|
| 69 | random_iy = 0 |
---|
| 70 | |
---|
| 71 | END SUBROUTINE random_function_ini |
---|
| 72 | |
---|
| 73 | FUNCTION random_function( idum ) |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | IMPLICIT NONE |
---|
| 77 | |
---|
| 78 | INTEGER :: ia, idum, im, iq, ir, ndiv, ntab |
---|
| 79 | REAL :: am, eps, random_function, ranf, rnmx |
---|
| 80 | |
---|
| 81 | PARAMETER ( ia=16807, im=2147483647, am=1.0/im, iq=127773, ir=2836, & |
---|
| 82 | ntab=32, ndiv=1+(im-1)/ntab, eps=1.2e-7, rnmx=1.0-eps ) |
---|
| 83 | |
---|
| 84 | INTEGER :: j, k |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | IF ( idum .le. 0 .or. random_iy .eq. 0 ) THEN |
---|
| 88 | idum = max (-idum,1) |
---|
| 89 | DO j = ntab+8,1,-1 |
---|
| 90 | k = idum / iq |
---|
| 91 | idum = ia * ( idum - k * iq ) - ir * k |
---|
| 92 | IF ( idum .lt. 0 ) idum = idum + im |
---|
| 93 | IF ( j .le. ntab ) random_iv(j) = idum |
---|
| 94 | ENDDO |
---|
| 95 | random_iy = random_iv(1) |
---|
| 96 | ENDIF |
---|
| 97 | |
---|
| 98 | k = idum / iq |
---|
| 99 | idum = ia * ( idum - k * iq ) - ir * k |
---|
| 100 | IF ( idum .lt. 0 ) idum = idum + im |
---|
| 101 | j = 1 + random_iy / ndiv |
---|
| 102 | random_iy = random_iv(j) |
---|
| 103 | random_iv(j) = idum |
---|
| 104 | random_function = min ( am * random_iy , rnmx ) |
---|
| 105 | |
---|
| 106 | END FUNCTION random_function |
---|
| 107 | |
---|
| 108 | END MODULE random_function_mod |
---|