-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver.F
563 lines (558 loc) · 18 KB
/
driver.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
program driver
c
c=======================================================================
c
c This is the main driver for the Modular Ocean Model (MOM). The
c structure allows for surface boundary conditions (SBC) to
c come from a dataset or an atmospheric model. Integration time
c is divided into a number of equal time segments and SBC are held
c fixed for each time segment. When coupling to an atmospheric
c model, SBC are supplied each time segment (the coupling period)
c and held fixed for that period. When supplying SBC to MOM from a
c dataset, the length of each time segment is one ocean time step.
c
c author: r. c. pacanowski e-mail=> rcp@gfdl.gov
c a. rosati e-mail=> ar@gfdl.gov
c=======================================================================
c
#include "param.h"
#include "coord.h"
#include "csbc.h"
#include "iounit.h"
#include "levind.h"
#include "mw.h"
#include "scalar.h"
#include "switch.h"
#include "tmngr.h"
c
write (stdout,'(/,48x,a,//)') '==== Driving MOM 2 ===='
c
c-----------------------------------------------------------------------
c initialize i/o units for MOM
c-----------------------------------------------------------------------
c
call ioinit
c
c-----------------------------------------------------------------------
c initialize timing analysis for various parts of MOM
c-----------------------------------------------------------------------
c
call inittimers
c
c-----------------------------------------------------------------------
c Initialize S.B.C. names and related items.
c
c Dimensional units for the S.B.C. are for the model where they
c will be used. eg: Heat flux will be used as a S.B.C. for the
c ocean in cal/cm**2/sec.
#ifdef coupled
c If the atmosphere calculates heat flux in watts/m**2 then the
c conversion factor is 0.2389e-4 to go from watts/m**2 to
c cal/cm**2/sec.
c Note: the conversion factors are multiplicative except for
c SST where the conversion factor is added.
c
c default convergence criteria are for extrapolating S.B.C. into
c land on the model grid where they were constructed. units are for
c the model grid where the S.B.C. was constructed.
c as a guide, the
c criteria should only be chosen large enough to give reasonable
c values near the coastlines. whether the field is extrapolated
c well into the interior of continents is presumed unimportant.
#endif
c-----------------------------------------------------------------------
c
do n=1,maxsbc
mapsbc(n) = 0
coabc(n) = c0
crits(n) = c0
sbcname(n) = 'unknown'
dunits(n) = 'unknown'
enddo
c
write (stdout,*) ' '
write (stdout,*)
& ' Surface Boundary Conditions are defined as follows:'
write (stdout,*) ' '
write (stdout,*) ' for the ocean (applied to MOM):'
c
do n=1,numsbc
c
c order S.B.C.'s such that S.B.C. "n" has index "m"=mapsbc(n)
c within arrays "sbcocn" and "sbcatm"
c
mapsbc(n) = n
m = mapsbc(n)
if (m .eq. 1) then
sbcname(m) = ' taux '
dunits(m) = ' dynes/cm**2 '
coabc(m) = 1.0
crits(m) = 1.e-3
else if (m .eq. 2) then
sbcname(m) = ' tauy '
dunits(m) = ' dynes/cm**2 '
coabc(m) = 1.0
crits(m) = 1.e-3
else if (m .eq. 3) then
sbcname(m) = ' heat flux'
dunits(m) = ' cal/cm**2/sec '
coabc(m) = 1.0
crits(m) = 1.e-5
else if (m .eq. 4) then
sbcname(m) = ' salt flux'
dunits(m) = ' gm/cm**2/sec '
coabc(m) = 1.0
crits(m) = 1.e-6
else if (m .eq. 5) then
sbcname(m) = 'short wave'
dunits(m) = ' cal/cm**2/sec '
coabc(m) = 1.0
crits(m) = 1.e-5
else if (m .eq. 6) then
sbcname(m) = ' SST '
dunits(m) = ' deg C '
coabc(m) = 0.0
crits(m) = 0.05
else if (m .eq. 7) then
sbcname(m) = ' SSS '
dunits(m) = ' (S-35.0)/1000 '
coabc(m) = 1.0
crits(m) = 1.e-5
else if (m .eq. 8) then
sbcname(m) = ' surface u'
dunits(m) = ' cm/sec '
coabc(m) = 1.0
crits(m) = 0.1
else if (m .eq. 9) then
sbcname(m) = ' surface v'
dunits(m) = ' cm/sec '
coabc(m) = 1.0
crits(m) = 0.1
endif
if (n .eq. numosbc+1) then
write (stdout,*) ' '
write (stdout,*) ' for the atmosphere (from MOM):'
endif
if (n .le. numosbc) then
write (stdout,*) ' S.B.C. # ',m,' is ',sbcname(m)
&,', atmos native units are ', dunits(m)
#ifdef coupled
&,', conversion factor to MOM is ',coabc(m)
&,', extrap crit =',crits(m)
#endif
else
write (stdout,*) ' S.B.C. # ',m,' is ',sbcname(m)
&,', MOM native units are ', dunits(m)
#ifdef coupled
&,', conversion factor to atmos is ',coabc(m)
&,', extrap crit =',crits(m)
#endif
endif
enddo
c
c-----------------------------------------------------------------------
c do the introductory ocean setup once per run
c-----------------------------------------------------------------------
c
call setocn
c
c-----------------------------------------------------------------------
c do the introductory atmosphere setup once per run
c-----------------------------------------------------------------------
c
write (stdout,'(/a36/)') ' ==> Note: the atmos setup follows:'
c
#ifdef timing
call tic ('driver', 'setatm')
#endif
#ifdef simple_sbc
write (stdout,'(/,a,/)')
&'==> Note: Simple S.B.C. are implemented in setvbc.F'
dtatm = 0.0
#else
c
c "setatm" must do the following:
c 1) set up the atmospheric S.B.C. grid definition
c 2) define the atmosphere land/sea mask
c 3) set the atmosphere time step "dtatm" {seconds}
c
call setatm (dtatm)
#endif
#ifdef timing
call toc ('driver', 'setatm')
#endif
c
#if !defined coupled
c
c when the MOM S.B.C. come from a dataset, force the segment time
c and atmospheric time step to one MOM time step. This will force
c the number of segments to one and the number of time steps per
c segment to represent the length of the run in days.
c
dtatm = dtts
segtim = dtts*secday
#endif
c
c-----------------------------------------------------------------------
c compute the number of ocean time steps "numots" for this run and
c the number of ocean time steps per ocean segment "ntspos".
c compute the number of atmos time steps "numats" for this run and
c the number of atmos time steps per atmos segment "ntspas".
c divide the integration time "days" into "numseg" segments.
c each will be length "segtim" days. Surface boundary conditions
c are supplied every "segtim" days.
c-----------------------------------------------------------------------
c
numots = nint(rundays/(dtts*secday))
ntspos = nint(segtim/(dtts*secday))
numats = nint(rundays/(dtatm*secday))
ntspas = nint(segtim/(dtatm*secday))
numseg = numots/ntspos
c
#ifdef coupled
write (stdout,8800) rundays, numseg, segtim, ntspos, ntspas, dtts
&, dtatm
#else
write (stdout,8800) rundays, numseg, segtim, ntspos, dtts
#endif
c
c-----------------------------------------------------------------------
c prepare initial condition S.B.C. for the models
c-----------------------------------------------------------------------
c
#if !defined simple_sbc
write (stdout,'(/,1x,a)')
& '==> Initializing all S.B.C. for MOM now.'
c
c initialize S.B.C. for the atmosphere (on the ocean S.B.C. grid)
c
do n=1,numsbc
m = mapsbc(n)
do jrow=1,jmt
do i=1,imt
sbcocn(i,jrow,m) = c0
enddo
enddo
enddo
c
c load the tracers (SST & SSS) for each row "j". (zero on land)
c load from the MW if fully opened otherwise load from disk
c
isst = mapsbc(6)
isss = mapsbc(7)
if (wide_open_mw) then
do jrow=1,jmt
do i=1,imt
if (isst .ne. 0) sbcocn(i,jrow,isst) = t(i,1,jrow,1,taup1)
if (isss .ne. 0) sbcocn(i,jrow,isss) = t(i,1,jrow,2,taup1)
enddo
enddo
else
do jrow=1,jmt
if (isst .ne. 0) call getst (jrow, sbcocn(1,1,isst), 1)
if (isss .ne. 0) call getst (jrow, sbcocn(1,1,isss), 2)
enddo
endif
#endif
c
#ifdef coupled
if (init .and. numasbc .gt. 0) then
c
c initialize S.B.C. for the ocean (on the atmos S.B.C. grid)
c
do n=1,numsbc
m = mapsbc(n)
do jrow=1,jma
do i=1,imap2
sbcatm(i,jrow,m) = c0
enddo
enddo
enddo
c
else
c
c when restarting ... read in the necessary S.B.C. data
c to preserve values in land for extrapolations.
c
call getunit (iosbc, 'restrt_sbc.dta', 'u s r')
read (iosbc) stamp, iotext
read (iosbc) iimt, ijmt, iima, ijma, inbc
read (iosbc) stamp, iotext
read (iosbc) sbcatm
read (iosbc) stamp, iotext
read (iosbc) sbcocn
write (stdout,9100) stamp
call relunit (iosbc)
endif
#endif
c
c-----------------------------------------------------------------------
c check for consistancy in the S.B.C. setup
c-----------------------------------------------------------------------
c
call chkcpl (dtatm, dtts)
c
c
c
c
c-----------------------------------------------------------------------
c S T A R T S E G M E N T L O O P
c-----------------------------------------------------------------------
c
do n=1,numseg
#ifdef coupled
write (stdout,9000) 'A T M O S', n, stamp
c
c-----------------------------------------------------------------------
c get the atmospheric S.B.C. from MOM
c-----------------------------------------------------------------------
c
call gasbc (n)
#endif
c
#if !defined simple_sbc && !defined minimize_sbc_memory
c
c-----------------------------------------------------------------------
c call the atmospheric model once for each time step until one
c segment of "segtim" days is complete. hold atmos S.B.C. fixed
c during each segment and predict average S.B.C. for MOM
c-----------------------------------------------------------------------
c
do loop=1,ntspas
# ifdef timing
call tic ('driver', 'atmos model')
# endif
asegs = (loop .eq. 1)
asege = (loop .eq. ntspas)
afirst = (loop*n .eq. 1)
alast = (loop*n .eq. numats)
c
call release_all
call atmos
call iomngr_resume
c
# ifdef timing
call toc ('driver', 'atmos model')
# endif
enddo
#endif
c
#ifdef coupled
write (stdout,9000) 'O C E A N', n, stamp
c
c-----------------------------------------------------------------------
c get MOM S.B.C.s from the atmosphere
c-----------------------------------------------------------------------
c
call gosbc (n)
#endif
c
c-----------------------------------------------------------------------
c call the ocean model once for each time step until one
c segment of "segtim" days is complete. hold MOM S.B.C. fixed
c during each segment and predict average S.B.C. for atmos
c-----------------------------------------------------------------------
c
do loop=1,ntspos
call mom
enddo
enddo
c
c-----------------------------------------------------------------------
c E N D S E G M E N T L O O P
c-----------------------------------------------------------------------
c
c
c
c
#ifdef coupled
c
c-----------------------------------------------------------------------
c save all S.B.C. for restarting coupled models
c-----------------------------------------------------------------------
c
call getunit (iosbc, 'restrt_sbc.dta', 'u s r')
c
iotext = ' read (iosbc) imt, jmt, ima, jma, numsbc'
write (iosbc) stamp, iotext
write (iosbc) imt, jmt, ima, jma, numsbc
c
iotext =
& ' read (iosbc) (((sbcatm(i,j,n),i=1,imap2),j=1,jma),n=1,numsbc)'
write (iosbc) stamp, iotext
write (iosbc) sbcatm
c
iotext =
& ' read (iosbc) (((sbcocn(i,j,n),i=1,imt),j=1,jmt),n=1,numsbc)'
write (iosbc) stamp, iotext
write (iosbc) sbcocn
write (stdout,9200) stamp
c
call relunit (iosbc)
#endif
c
write (stdout,9300)
c
c show files and close all units
c
call showfiles
call release_all
c
c show timing analysis
c
#ifdef timing
print '(////a/a//)'
&,' WARNING: timing analysis significantly increases cpu time'
&,' so turn it off when making long integrations'
call showtimers
#endif
c
#ifdef coupled
8800 format (//,1x,'The model has been configured to run for'
&,g14.7,' days in ',i4,' segments of ',g14.7,' days each.'
&,/1x,'There will be ',i6,' ocean time steps per segment'
&,' and ',i6,' atmosphere time steps per segment.'/
&,/1x,' The ocean "dtts" =', g14.7, ' seconds'
&,', and the atmosphere "dtatm" =', g14.7,' seconds'
&,//)
9000 format (//,1x,'==== E N T E R I N G ',a9,' S E G M E N T #'
&, i4, ', time = ',a32,' ===='//)
9100 format (10x,'==> Finished reading MOM S.B.C. data from file'
&, ' restrt_sbc.dta at time = ',a32)
9200 format (10x,'==> Finished writing MOM S.B.C. data to file '
&, 'restrt_sbc.dta at time = ',a32)
#else
8800 format (//,1x,'The model has been configured to run for'
&,g14.7,' days in ',i4,' segments of ',g14.7,' days each.'
&,/1x,'There will be ',i6,' ocean time steps per segment.'
&,/1x,' The ocean "dtts" =', g14.7, ' seconds'
&,//)
#endif
9300 format (/,10x,' ==> M.O.M. integration is complete.')
stop
end
subroutine chkcpl (dtatm, dtts)
logical errorc
#include "param.h"
#include "csbc.h"
#include "switch.h"
c
c-----------------------------------------------------------------------
c do consistency checks before allowing model to continue
c-----------------------------------------------------------------------
c
errorc = .false.
write (stdout,*) ' '
write (stdout,*) ' (checking MOM S.B.C. setup)'
c
#ifdef coupled
if (jma .gt. jmt) then
write (stdout,9000)
& '==> Warning: the atmospheric "jma" is greater than "jmt". '
&,' Verify that the atmosphere resoultion is less than the '
&,' ocean resoultion. '
endif
if (imap2 .gt. imt) then
write (stdout,9000)
& '==> Warning: the atmospheric "imap2" is greater than "imt". '
&,' Verify that the atmosphere resoultion is less than the '
&,' ocean resoultion. '
endif
if (bwidth .eq. c0) then
write (stdout,9000)
& '==> Note: no blending region was set. Verify that the ocean '
&,' domain is global. '
else
write (stdout,9000)
& '==> Warning: blending region for SST set. verify the blending '
&,' zone is correctly set by inspecting the "bzone" printout '
&,' this assumes a limited domain ocean and global atmosphere '
write (stdout,'(1x,a27,g10.3,a8)') ' Note: "bwidth" is set to '
&, bwidth, ' degrees'
endif
#endif
if (dtatm .eq. c0) then
write (stdout,9000)
& '==> Error: the atmospheric time step must be set in "setatm" '
errorc = .true.
dtatm = 1.e-6
endif
critv = 1.e-6
if (segtim .ne. c0) then
r1 = rundays/segtim
else
r1 = 0.5
endif
r2 = segtim/(dtts*secday)
r3 = segtim/(dtatm*secday)
if (segtim .eq. c0) then
write (stdout,9000)
& '==> Error: coupling period "segtim" must be specified when '
&,' the "coupled" option is enabled '
errorc = .true.
elseif (abs(r1-nint(r1)) .gt. critv) then
write (stdout,9000)
& '==> Error: there must be an integral number of segments '
&,' "segtim" within "rundays" (the length of the run) '
errorc = .true.
elseif (abs(r2-nint(r2)) .gt. critv) then
write (stdout,9000)
& '==> Error: there must be an integral number of density time '
&,' steps "dtts" within "segtim" (the segment time) '
errorc = .true.
elseif (abs(r3-nint(r3)) .gt. critv) then
write (stdout,9000)
& '==> Error: there must be an integral number of atmos time '
&,' steps "dtatm" within "segtim" (the segment time) '
errorc = .true.
endif
#if defined coupled && defined restorst
write (stdout,9000)
& '==> Warning: restoring to surface tracers ("restorst" enabled)'
&, ' when "coupled" is also enabled '
#endif
#if defined coupled && defined simple_sbc
write (stdout,9000)
& '==> Error: ifdef "simple_sbc" is not compatible '
&, ' with "coupled" '
errorc = .true.
#endif
#ifdef coupled
if (numasbc .eq. 0) then
write (stdout,9000)
& '==> Warning: "coupled" enabled but number of atmosphere '
&,' boundary conditions "numasbc" is zero! '
endif
#endif
if (numsbc .gt. maxsbc) then
write (stdout,9000)
& '==> Error: "numsbc" is greater than "maxsbc" in "csbc.h" '
errorc = .true.
endif
write (stdout,*) ' (End of MOM S.B.C. checks) '
write (stdout,*) ' '
if (errorc) stop '=>chkcpl'
c
9000 format (/,(1x,a80))
return
end
subroutine getst (jrow, ocnout, ntabc)
c
c-----------------------------------------------------------------------
c read surface tracers from disk row "jrow"
c-----------------------------------------------------------------------
c
#include "param.h"
#include "iounit.h"
#include "mw.h"
#include "tmngr.h"
c
dimension ocnout(imt,jmt)
c
call getrow (latdisk(taup1disk), nslab, jrow
&, u(1,1,jmw,1,taup1), t(1,1,jmw,1,taup1))
do i=1,imt
ocnout(i,jrow) = t(i,1,jmw,ntabc,taup1)
enddo
return
end