/[MITgcm]/MITgcm/model/src/port_rand.F
ViewVC logotype

Annotation of /MITgcm/model/src/port_rand.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (hide annotations) (download)
Mon Jul 19 15:13:07 2004 UTC (19 years, 10 months ago) by molod
Branch: MAIN
CVS Tags: checkpoint54d_post, checkpoint54e_post
Changes since 1.3: +12 -8 lines
Change argument list to port_rand - change call sequence everywhere

1 molod 1.4 C $Header: /u/u3/gcmpack/MITgcm/model/src/port_rand.F,v 1.3 2001/09/26 18:09:16 cnh Exp $
2 cnh 1.3 C $Name: $
3 adcroft 1.2
4     C Portable random number generator
5    
6     #undef _USE_INTEGERS
7    
8     ! ==============================================================================
9 cnh 1.3 CBOP
10     C !ROUTINE: port_rand
11     C !INTERFACE:
12 molod 1.4 real*8 function port_rand(seed)
13 cnh 1.3
14     C !DESCRIPTION: \bv
15     C Portable random number generator
16     C \ev
17    
18     C !LOCAL VARIABLES:
19 adcroft 1.2 implicit none
20     integer nff
21     parameter(nff=55)
22     #ifdef _USE_INTEGERS
23 molod 1.4 integer mbig,mseed,mZ,seed
24 adcroft 1.2 #else
25 molod 1.4 real*8 mbig,mseed,mz,seed
26 adcroft 1.2 #endif
27     real*8 fac
28     #ifdef _USE_INTEGERS
29 molod 1.4 parameter (mbig=1000000000,mz=0,fac=1./mbig)
30     data mseed/161803398/
31 adcroft 1.2 #else
32 molod 1.4 parameter (mbig=4000000.,mz=0.,fac=1./mbig)
33     data mseed/1618033./
34 adcroft 1.2 #endif
35     integer i,ii,inext,inextp,k,idum
36     parameter(idum=-2)
37     #ifdef _USE_INTEGERS
38     integer mj,mk,ma(nff)
39     #else
40     real*8 mj,mk,ma(nff)
41     #endif
42     logical firstCall
43     save firstCall,inext,inextp,ma
44     data firstCall /.true./
45 cnh 1.3 CEOP
46 adcroft 1.2 ! ------------------------------------------------------------------------------
47 molod 1.4 mseed = seed
48 adcroft 1.2 if(firstCall)then
49     firstCall=.false.
50     mj=mseed-iabs(idum)
51     mj=mod(mj,mbig)
52     ma(nff)=mj
53     mk=1
54     do i=1,nff-1
55     ii=mod(21*i,nff)
56     ma(ii)=mk
57     mk=mj-mk
58     if(mk.lt.mz)mk=mk+mbig
59     mj=ma(ii)
60     enddo
61     do k=1,4
62     do i=1,nff
63     ma(i)=ma(i)-ma(1+mod(i+30,nff))
64     if(ma(i).lt.MZ)ma(i)=ma(i)+mbig
65     enddo
66     enddo
67     inext=0
68     inextp=31
69     endif
70     inext=mod(inext,nff)+1
71     inextp=mod(inextp,nff)+1
72     mj=ma(inext)-ma(inextp)
73     if(mj.lt.MZ)mj=mj+mbig
74     ma(inext)=mj
75     port_rand=mj*fac
76     return
77     ! ------------------------------------------------------------------------------
78     end
79     ! ==============================================================================
80    
81     ! ==============================================================================
82     subroutine port_ranarr(n,arr)
83     implicit none
84     integer n,i
85     real arr(n)
86 molod 1.4 real*8 port_rand,seed
87     seed=1618033.0d0
88 adcroft 1.2 ! ------------------------------------------------------------------------------
89     do i=1,n
90 molod 1.4 arr(i)=port_rand(seed)
91 adcroft 1.2 enddo
92    
93     return
94     ! ------------------------------------------------------------------------------
95     end
96     ! ==============================================================================

  ViewVC Help
Powered by ViewVC 1.1.22