-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflt_global_tile_mean.F
142 lines (115 loc) · 4.12 KB
/
flt_global_tile_mean.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
C $Header: net 6/5/17
C $Name: compute_global_mean
#include "CPP_OPTIONS.h"
CBOP 0
C !ROUTINE: FLT_LAVD
C !INTERFACE:
SUBROUTINE GLOBAL_TILE_MEAN_RL (
I myNr, arr, arrMask, arrArea,
I myTime, myThid,
O meanOut)
C !DESCRIPTION: \bv
C /==========================================================\
C | SUBROUTINE COMPUTE_GLOBAL_MEAN_RL |
C | o Calculate the area wieghted global mean of array |
C | "_RL arr" |
C | |
C | o based on the code in remove_mean.F and mon_vort3.F |
C \==========================================================/
C \ev
IMPLICIT NONE
C === Global data ===
#include "SIZE.h"
#include "EEPARAMS.h"
#include "PARAMS.h"
C === Functions ====
LOGICAL DIFFERENT_MULTIPLE
EXTERNAL DIFFERENT_MULTIPLE
C === Routine arguments ===
INTEGER myNr
_RL arr(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
_RS arrMask(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
_RS arrArea(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
_RL myTime
_RL meanOut
INTEGER myThid
C#ifdef ALLOW_BALANCE_FLUXES
C === Local variables ====
INTEGER I,J,K,bi,bj
_RL tileMean(nSx,nSy)
_RL tileArea(nSx,nSy)
_RL tmpArea
_RL tmpVal
_RL globalMean
_RL globalArea
CHARACTER*(MAX_LEN_MBUF) msgBuf
K = myNr
C tileMean is named following convention which is
C a bit confusing. It is not the mean, but the
C the numerator of the mean = sum dArea * value
C loop over all the tile subgrids and construct tileArea
C and tileMean
DO bj=myByLo(myThid),myByHi(myThid)
DO bi=myBxLo(myThid),myBxHi(myThid)
tileMean(bi,bj) = 0
tileArea(bi,bj) = 0
tmpVal = 0
tmpArea = 0
DO J=1,sNy
DO I=1,sNx
IF (arrMask(I,J,K,bi,bj).NE.0.) THEN
tmpVal=arr(I,J,K,bi,bj)
tmpArea = arrArea(I,J,bi,bj)
tileArea(bi,bj) = tileArea(bi,bj) + tmpArea
tileMean(bi,bj) = tileMean(bi,bj) + tmpArea*tmpVal
ENDIF
ENDDO
ENDDO
ENDDO
ENDDO
C sum results over all the tiles and processes
C we have to pass the full tile array
C this is why we call it after/ outside subgrid loop
CALL GLOBAL_SUM_TILE_RL( tileMean, globalMean, myThid)
CALL GLOBAL_SUM_TILE_RL( tileArea, globalArea, myThid)
C output to help in debugging
C DO bj=myByLo(myThid),myByHi(myThid)
C DO bi=myBxLo(myThid),myBxHi(myThid)
C WRITE(msgBuf,'(A)')
C & '----- DEBUG COMPUTE_GLOBAL_MEAN_RL -------- '
C CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
C & SQUEEZE_RIGHT, myThid )
C
C WRITE(msgBuf,'(A,I,A,E)')
C & 'myThid= ', myThid, ' last temp area =', tmpArea
C CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
C & SQUEEZE_RIGHT, myThid )
C
C WRITE(msgBuf,'(A,I,A,E)')
C & 'myThid= ', myThid, ' last temp vorticity =', tmpVal
C CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
C & SQUEEZE_RIGHT, myThid )
C
C WRITE(msgBuf,'(A,I,A,E)')
C & 'myThid= ', myThid, ' subgrid vort*area =', tileMean(bi,bj)
C CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
C & SQUEEZE_RIGHT, myThid )
C
C WRITE(msgBuf,'(A,I,A,E)')
C & 'myThid= ', myThid, 'subgrid total area =', tileArea(bi,bj)
C CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
C & SQUEEZE_RIGHT, myThid )
C
C WRITE(msgBuf,'(A)')
C & '------ END DEBUG COMPUTE_GLOBAL_MEAN_RL -------- '
C CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
C & SQUEEZE_RIGHT, myThid )
C ENDDO
C ENDDO
C now compute the actual global mean
IF (globalArea.GT.0.) THEN
globalMean=globalMean/globalArea
ENDIF
meanOut = globalMean
RETURN
END