forked from altMITgcm/MITgcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rbcs_fields_load.F
287 lines (264 loc) · 10.3 KB
/
rbcs_fields_load.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
C $Header: /u/gcmpack/MITgcm/pkg/rbcs/rbcs_fields_load.F,v 1.15 2011/06/07 22:25:10 jmc Exp $
C $Name: $
#include "RBCS_OPTIONS.h"
C !ROUTINE: RBCS_FIELDS_LOAD
C !INTERFACE:
SUBROUTINE RBCS_FIELDS_LOAD( myTime, myIter, myThid )
C !DESCRIPTION: \bv
C *==========================================================*
C | SUBROUTINE RBCS_FIELDS_LOAD
C | o Control reading of fields from external source.
C *==========================================================*
C | RBCS External source field loading routine.
C | This routine is called every time we want to
C | load a a set of external fields. The routine decides
C | which fields to load and then reads them in.
C *==========================================================*
C \ev
C !USES:
IMPLICIT NONE
C === Global variables ===
#include "SIZE.h"
#include "EEPARAMS.h"
#include "PARAMS.h"
#ifdef ALLOW_PTRACERS
#include "PTRACERS_SIZE.h"
#include "PTRACERS_PARAMS.h"
#endif
#include "RBCS_SIZE.h"
#include "RBCS_PARAMS.h"
#include "RBCS_FIELDS.h"
C !INPUT/OUTPUT PARAMETERS:
C === Routine arguments ===
C myTime :: Simulation time
C myIter :: Simulation timestep number
C myThid :: Thread no. that called this routine.
_RL myTime
INTEGER myIter
INTEGER myThid
C !FUNCTIONS:
INTEGER IFNBLNK, ILNBLNK
EXTERNAL IFNBLNK, ILNBLNK
C !LOCAL VARIABLES:
C === Local arrays ===
C [01] :: End points for interpolation
C Above use static heap storage to allow exchange.
C aWght, bWght :: Interpolation weights
INTEGER bi, bj, i, j, k
INTEGER intimeP, intime0, intime1
_RL aWght, bWght, locTime
INTEGER Ifprd
#ifdef ALLOW_PTRACERS
INTEGER iTracer
#endif
INTEGER IL, initer0, initer1
CHARACTER*(MAX_LEN_FNAM) fullName
CEOP
#ifdef ALLOW_RBCS
CALL TIMER_START('RBCS_FIELDS_LOAD [I/O]', myThid)
C-- First call requires that we initialize everything to zero for safety
C <= already done in RBCS_INIT_VARIA
C-- Now calculate whether it is time to update the forcing arrays
bi = myBxLo(myThid)
bj = myByLo(myThid)
IF (rbcsForcingPeriod.GT.0. _d 0) THEN
locTime = myTime - rbcsForcingOffset
CALL GET_PERIODIC_INTERVAL(
O intimeP, intime0, intime1, bWght, aWght,
I rbcsForcingCycle, rbcsForcingPeriod,
I deltaTclock, locTime, myThid )
#ifdef ALLOW_DEBUG
IF ( debugLevel.GE.debLevB ) THEN
_BEGIN_MASTER(myThid)
WRITE(standardMessageUnit,'(A,I10,A,4I5,A,2F14.10)')
& ' RBCS_FIELDS_LOAD,', myIter,
& ' : iP,iLd,i0,i1=', intimeP,rbcsLdRec(bi,bj), intime0,intime1,
& ' ; Wght=', bWght, aWght
_END_MASTER(myThid)
ENDIF
#endif /* ALLOW_DEBUG */
ELSE
intimeP = 1
intime1 = 1
intime0 = 1
aWght = .5 _d 0
bWght = .5 _d 0
ENDIF
#ifdef ALLOW_AUTODIFF_TAMC
C- assuming that we call S/R RBCS_FIELDS_LOAD at each time-step and
C with increasing time, this will catch when we need to load new records;
C But with Adjoint run, this is not always the case => might end-up using
C the wrong time-records
IF ( intime0.NE.intimeP .OR. myIter.EQ.nIter0 ) THEN
#else /* ALLOW_AUTODIFF_TAMC */
C- Make no assumption on sequence of calls to RBCS_FIELDS_LOAD ;
C This is the correct formulation (works in Adjoint run).
C Unfortunatly, produces many recomputations <== not used until it is fixed
IF ( intime1.NE.rbcsLdRec(bi,bj) ) THEN
#endif /* ALLOW_AUTODIFF_TAMC */
C-- If the above condition is met then we need to read in
C data for the period ahead and the period behind myTime.
IF ( debugLevel.GE.debLevZero ) THEN
_BEGIN_MASTER(myThid)
WRITE(standardMessageUnit,'(A,I10,A,2(2I5,A))')
& ' RBCS_FIELDS_LOAD, it=', myIter,
& ' : Reading new data, i0,i1=', intime0, intime1,
& ' (prev=', intimeP, rbcsLdRec(bi,bj), ' )'
_END_MASTER(myThid)
ENDIF
C for rbcsSingleTimeFiles=.TRUE.
Ifprd = NINT(rbcsForcingPeriod/deltaTrbcs)
initer0 = rbcsIter0 + intime0*Ifprd
initer1 = rbcsIter0 + intime1*Ifprd
#ifndef DISABLE_RBCS_MOM
IF ( useRBCuVel .AND. relaxUFile.NE.' ' ) THEN
IF ( rbcsSingleTimeFiles ) THEN
IL=ILNBLNK( relaxUFile )
WRITE(fullName,'(2A,I10.10)') relaxUFile(1:IL),'.',initer0
CALL READ_REC_XYZ_RS(fullName, rbcu0, 1, myIter, myThid)
WRITE(fullName,'(2A,I10.10)') relaxUFile(1:IL),'.',initer1
CALL READ_REC_XYZ_RS(fullName, rbcu1, 1, myIter, myThid)
ELSE
CALL READ_REC_XYZ_RS(relaxUFile,rbcu0,intime0,myIter,myThid)
CALL READ_REC_XYZ_RS(relaxUFile,rbcu1,intime1,myIter,myThid)
ENDIF
ENDIF
IF ( useRBCvVel .AND. relaxVFile.NE.' ' ) THEN
IF ( rbcsSingleTimeFiles ) THEN
IL=ILNBLNK( relaxVFile )
WRITE(fullName,'(2A,I10.10)') relaxVFile(1:IL),'.',initer0
CALL READ_REC_XYZ_RS(fullName, rbcv0, 1, myIter, myThid)
WRITE(fullName,'(2A,I10.10)') relaxVFile(1:IL),'.',initer1
CALL READ_REC_XYZ_RS(fullName, rbcv1, 1, myIter, myThid)
ELSE
CALL READ_REC_XYZ_RS(relaxVFile,rbcv0,intime0,myIter,myThid)
CALL READ_REC_XYZ_RS(relaxVFile,rbcv1,intime1,myIter,myThid)
ENDIF
ENDIF
IF ( (useRBCuVel .AND. relaxUFile.NE.' ') .OR.
& (useRBCvVel .AND. relaxVFile.NE.' ') ) THEN
CALL EXCH_UV_XYZ_RS( rbcu0, rbcv0, .TRUE., myThid )
CALL EXCH_UV_XYZ_RS( rbcu1, rbcv1, .TRUE., myThid )
ENDIF
#endif /* DISABLE_RBCS_MOM */
IF ( useRBCtemp .AND. relaxTFile .NE. ' ' ) THEN
IF ( rbcsSingleTimeFiles ) THEN
IL=ILNBLNK( relaxTFile )
WRITE(fullName,'(2a,i10.10)') relaxTFile(1:IL),'.',initer0
CALL READ_REC_XYZ_RS(fullName, rbct0, 1, myIter, myThid)
WRITE(fullName,'(2a,i10.10)') relaxTFile(1:IL),'.',initer1
CALL READ_REC_XYZ_RS(fullName, rbct1, 1, myIter, myThid)
ELSE
CALL READ_REC_XYZ_RS(relaxTFile,rbct0,intime0,myIter,myThid)
CALL READ_REC_XYZ_RS(relaxTFile,rbct1,intime1,myIter,myThid)
ENDIF
CALL EXCH_XYZ_RS( rbct0 , myThid )
CALL EXCH_XYZ_RS( rbct1 , myThid )
ENDIF
IF ( useRBCsalt .AND. relaxSFile .NE. ' ' ) THEN
IF ( rbcsSingleTimeFiles ) THEN
IL=ILNBLNK( relaxSFile )
WRITE(fullName,'(2a,i10.10)') relaxSFile(1:IL),'.',initer0
CALL READ_REC_XYZ_RS(fullName, rbcs0, 1, myIter, myThid)
WRITE(fullName,'(2a,i10.10)') relaxSFile(1:IL),'.',initer1
CALL READ_REC_XYZ_RS(fullName, rbcs1, 1, myIter, myThid)
ELSE
CALL READ_REC_XYZ_RS(relaxSFile,rbcs0,intime0,myIter,myThid)
CALL READ_REC_XYZ_RS(relaxSFile,rbcs1,intime1,myIter,myThid)
ENDIF
CALL EXCH_XYZ_RS( rbcs0 , myThid )
CALL EXCH_XYZ_RS( rbcs1 , myThid )
ENDIF
#ifdef ALLOW_PTRACERS
IF ( usePTRACERS ) THEN
DO iTracer = 1, PTRACERS_numInUse
IF ( useRBCptrnum(iTracer) .AND.
& relaxPtracerFile(iTracer).NE. ' ' ) THEN
IF ( rbcsSingleTimeFiles ) THEN
IL=ILNBLNK( relaxPtracerFile(iTracer) )
WRITE(fullName,'(2a,i10.10)') relaxPtracerFile(iTracer)(1:IL)
& ,'.',initer0
CALL READ_REC_XYZ_RS( fullName,
& rbcptr0(1-Olx,1-Oly,1,1,1,iTracer),
& 1, myIter, myThid )
WRITE(fullName,'(2a,i10.10)') relaxPtracerFile(iTracer)(1:IL)
& ,'.',initer1
CALL READ_REC_XYZ_RS( fullName,
& rbcptr1(1-Olx,1-Oly,1,1,1,iTracer),
& 1, myIter, myThid )
ELSE
CALL READ_REC_XYZ_RS( relaxPtracerFile(iTracer),
& rbcptr0(1-Olx,1-Oly,1,1,1,iTracer),
& intime0, myIter, myThid )
CALL READ_REC_XYZ_RS( relaxPtracerFile(iTracer),
& rbcptr1(1-Olx,1-Oly,1,1,1,iTracer),
& intime1, myIter, myThid )
ENDIF
CALL EXCH_XYZ_RS( rbcptr0(1-Olx,1-Oly,1,1,1,iTracer),myThid )
CALL EXCH_XYZ_RS( rbcptr1(1-Olx,1-Oly,1,1,1,iTracer),myThid )
ENDIF
ENDDO
ENDIF
#endif /* ALLOW_PTRACERS */
C- save newly loaded time-record
DO bj = myByLo(myThid), myByHi(myThid)
DO bi = myBxLo(myThid), myBxHi(myThid)
rbcsLdRec(bi,bj) = intime1
ENDDO
ENDDO
C-- end if-block for loading new time-records
ENDIF
C-- Interpolate
DO bj = myByLo(myThid), myByHi(myThid)
DO bi = myBxLo(myThid), myBxHi(myThid)
#ifndef DISABLE_RBCS_MOM
IF ( useRBCuVel .OR. useRBCvVel ) THEN
DO k=1,Nr
DO j=1-Oly,sNy+Oly
DO i=1-Olx,sNx+Olx
RBCuVel(i,j,k,bi,bj) = bWght*rbcu0(i,j,k,bi,bj)
& +aWght*rbcu1(i,j,k,bi,bj)
RBCvVel(i,j,k,bi,bj) = bWght*rbcv0(i,j,k,bi,bj)
& +aWght*rbcv1(i,j,k,bi,bj)
ENDDO
ENDDO
ENDDO
ENDIF
#endif /* DISABLE_RBCS_MOM */
DO k=1,Nr
DO j=1-Oly,sNy+Oly
DO i=1-Olx,sNx+Olx
RBCtemp(i,j,k,bi,bj) = bWght*rbct0(i,j,k,bi,bj)
& +aWght*rbct1(i,j,k,bi,bj)
RBCsalt(i,j,k,bi,bj) = bWght*rbcs0(i,j,k,bi,bj)
& +aWght*rbcs1(i,j,k,bi,bj)
ENDDO
ENDDO
ENDDO
ENDDO
ENDDO
#ifdef ALLOW_PTRACERS
IF ( usePTRACERS ) THEN
DO iTracer = 1, PTRACERS_numInUse
IF (useRBCptrnum(iTracer)) THEN
DO bj = myByLo(myThid), myByHi(myThid)
DO bi = myBxLo(myThid), myBxHi(myThid)
DO k=1,Nr
DO j=1-Oly,sNy+Oly
DO i=1-Olx,sNx+Olx
RBC_ptracers(i,j,k,bi,bj,iTracer) =
& bWght*rbcptr0(i,j,k,bi,bj,iTracer)
& +aWght*rbcptr1(i,j,k,bi,bj,iTracer)
ENDDO
ENDDO
ENDDO
ENDDO
ENDDO
ENDIF
ENDDO
ENDIF
#endif /* ALLOW_PTRACERS */
CALL TIMER_STOP ('RBCS_FIELDS_LOAD [I/O]', myThid)
#endif /* ALLOW_RBCS */
RETURN
END