forked from NOAA-PSL/stochastic_physics
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setlats_a_stochy.f
196 lines (181 loc) · 5.9 KB
/
setlats_a_stochy.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
!>@brief The module 'setlats_a_stochy_mod' contains the subroutine setlats_a_stochy
module setlats_a_stochy_mod
implicit none
contains
!>@brief The subroutine 'setlats_a_stochy' selects the latitude points on this task
!>@details This code is taken from the legacy spectral GFS
subroutine setlats_a_stochy(lats_nodes_a,global_lats_a,
& iprint,lonsperlat)
!
use spectral_layout_mod , only : nodes,me,latg,lonf
!
implicit none
!
integer, dimension(latg) :: global_lats_a, lonsperlat
integer lats_nodes_a(nodes)
integer iprint,opt,ifin,nodesio
&, jcount,jpt,lat,lats_sum,node,i,ii
&, ngrptg,ngrptl,ipe,irest,idp
&, ngrptgh,nodesioh
! &, ilatpe,ngrptg,ngrptl,ipe,irest,idp
!
integer,allocatable :: lats_hold(:,:)
!
allocate ( lats_hold(latg,nodes) )
!
! iprint = 1
iprint = 0
opt = 1 ! reduced grid
if (opt == 2) lonsperlat = lonf ! full grid
lats_nodes_a = 0
! if (liope .and. icolor == 2) then
! nodesio = 1
! else
nodesio = nodes
! endif
!
ngrptg = 0
do lat=1,latg
do i=1,lonsperlat(lat)
ngrptg = ngrptg + 1
enddo
enddo
!
! ngrptg contains total number of grid points.
!
! distribution of the grid
nodesioh = nodesio / 2
if (nodesioh*2 /= nodesio) then
! ilatpe = ngrptg / nodesio
ngrptl = 0
ipe = 0
irest = 0
idp = 1
do lat=1,latg
ifin = lonsperlat(lat)
ngrptl = ngrptl + ifin
! if (me == 0)
! &write(2000+me,*)'in setlats lat=',lat,' latg=',latg,' ifin=',ifin
! &,' ngrptl=',ngrptl,' nodesio=',nodesio,' ngrptg=',ngrptg
! &,' irest=',irest
if (ngrptl*nodesio <= ngrptg+irest) then
lats_nodes_a(ipe+1) = lats_nodes_a(ipe+1) + 1
lats_hold(idp,ipe+1) = lat
idp = idp + 1
! if (me == 0)
! & write(2000+me,*)' nodesio1=',nodesio,' idp=',idp,' ipe=',ipe
else
ipe = ipe + 1
if (ipe <= nodesio) lats_hold(1,ipe+1) = lat
idp = 2
irest = irest + ngrptg - (ngrptl-ifin)*nodesio
ngrptl = ifin
lats_nodes_a(ipe+1) = lats_nodes_a(ipe+1) + 1
! if (me == 0)
! & write(2000+me,*)' nodesio1=',nodesio,' idp=',idp,' ipe=',ipe
endif
! if (me == 0)
! & write(2000+me,*)' lat=',lat,' lats_nodes_a=',lats_nodes_a(ipe+1)
! &,' ipe+1=',ipe+1
enddo
else
nodesioh = nodesio/2
ngrptgh = ngrptg/2
ngrptl = 0
ipe = 0
irest = 0
idp = 1
do lat=1,latg/2
ifin = lonsperlat(lat)
ngrptl = ngrptl + ifin
! if (me == 0)
! &write(0,*)'in setlats lat=',lat,' latg=',latg,' ifin=',ifin
! &,' ngrptl=',ngrptl,' nodesio=',nodesio,' ngrptg=',ngrptg
! &,' irest=',irest,' ngrptgh=',ngrptgh,' nodesioh=',nodesioh
if (ngrptl*nodesioh <= ngrptgh+irest .or. lat == latg/2) then
lats_nodes_a(ipe+1) = lats_nodes_a(ipe+1) + 1
lats_hold(idp,ipe+1) = lat
! lats_nodes_a(nodesio-ipe) = lats_nodes_a(nodesio-ipe) + 1
! lats_hold(idp,nodesio-ipe) = latg+1-lat
idp = idp + 1
! if (me == 0)
! & write(0,*)' nodesio1=',nodesioh,' idp=',idp,' ipe=',ipe
else
ipe = ipe + 1
if (ipe <= nodesioh) then
lats_hold(1,ipe+1) = lat
! lats_hold(1,nodesio-ipe) = latg+1-lat
endif
idp = 2
irest = irest + ngrptgh - (ngrptl-ifin)*nodesioh
ngrptl = ifin
lats_nodes_a(ipe+1) = lats_nodes_a(ipe+1) + 1
! lats_nodes_a(nodesio-ipe) = lats_nodes_a(nodesio-ipe) + 1
! if (me == 0)
! & write(0,*)' nodesio1h=',nodesioh,'idp=',idp,' ipe=',ipe
endif
! if (me == 0)
! & write(0,*)' lat=',lat,' lats_nodes_a=',lats_nodes_a(ipe+1)
! &,' ipe+1=',ipe+1
enddo
do node=1, nodesioh
ii = nodesio-node+1
jpt = lats_nodes_a(node)
lats_nodes_a(ii) = jpt
do i=1,jpt
lats_hold(jpt+1-i,ii) = latg+1-lats_hold(i,node)
enddo
enddo
endif
!!
!!........................................................
!!
jpt = 0
do node=1,nodesio
! write(2000+me,*)'node=',node,' lats_nodes_a=',lats_nodes_a(node)
! &, ' jpt=',jpt,' nodesio=',nodesio
if ( lats_nodes_a(node) > 0 ) then
do jcount=1,lats_nodes_a(node)
global_lats_a(jpt+jcount) = lats_hold(jcount,node)
! write(2000+me,*)' jpt+jcount=',jpt+jcount
! &, 'global_lats_a=',global_lats_a(jpt+jcount)
enddo
endif
jpt = jpt + lats_nodes_a(node)
enddo
!!
deallocate (lats_hold)
if ( iprint /= 1 ) return
!!
if (me == 0) then
jpt=0
do node=1,nodesio
if ( lats_nodes_a(node) > 0 ) then
print 600
lats_sum=0
do jcount=1,lats_nodes_a(node)
lats_sum=lats_sum + lonsperlat(global_lats_a(jpt+jcount))
print 700, node-1,
x node, lats_nodes_a(node),
x jpt+jcount, global_lats_a(jpt+jcount),
x lonsperlat(global_lats_a(jpt+jcount)),
x lats_sum
enddo
endif
jpt=jpt+lats_nodes_a(node)
enddo
!
print 600
!
600 format ( ' ' )
!
700 format ( 'setlats me=', i4,
x ' lats_nodes_a(', i4, ' )=', i4,
x ' global_lats_a(', i4, ' )=', i4,
x ' lonsperlat=', i5,
x ' lats_sum=', i6 )
!
endif
return
end
end module setlats_a_stochy_mod