forked from HYCOM/HYCOM-src
-
Notifications
You must be signed in to change notification settings - Fork 3
/
mod_restart.F90
1175 lines (1151 loc) · 37.7 KB
/
mod_restart.F90
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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module mod_restart
use mod_xc ! HYCOM communication interface
use mod_za ! HYCOM I/O interface
implicit none
!
! --- module for restart and related routines
!
private !! default is private
public :: restart_in, restart_out, restart_zero
interface restart_in
module procedure restart_in_standalone
module procedure restart_in_coupled
end interface restart_in
interface restart_out
module procedure restart_out_standalone
module procedure restart_out_coupled
end interface restart_out
contains
subroutine restart_in_standalone(nstep0, dtime0, flnmra,flnmrb)
implicit none
integer nstep0
real*8 dtime0
character*(*) flnmra,flnmrb
!
call restart_in_coupled(nstep0, dtime0, flnmra,flnmrb,.false.)
end subroutine restart_in_standalone
subroutine restart_out_standalone(nstepx, dtimex, flnmra,flnmrb, last)
implicit none
!
logical last
integer nstepx
real*8 dtimex
character*(*) flnmra,flnmrb
!
call restart_out_coupled(nstepx, dtimex, flnmra,flnmrb, last, .false.)
end subroutine restart_out_standalone
subroutine restart_in_coupled(nstep0, dtime0, flnmra,flnmrb, restart_cpl)
use mod_cb_arrays ! HYCOM saved arrays
use mod_tides ! HYCOM tides
implicit none
!
integer nstep0
real*8 dtime0
character*(*) flnmra,flnmrb
logical, intent(in) :: restart_cpl ! coupled case
!
! read in a restart file.
! flnmra is the ".a" file, and flnmrb is the ".b" file.
!
logical lmyin,ltidin,lold
integer i,ios,j,k,kskip,ktr
character cline*80
!
# include "stmt_fns.h"
!
call zaiopf(flnmra,'old', 11)
if (mnproc.eq.1) then ! .b file from 1st tile only
open (unit=uoff+11,file=flnmrb, &
status='old',action='read',form='formatted')
endif
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
if (mnproc.eq.1) then
write(lp,'(a)') trim(cline)
endif !1st tile
if (cline(1:9).eq.'RESTART: ') then
lold = .true. !original, larger, restart file
elseif (cline(1:9).eq.'RESTART2:') then
lold = .false.
else
if (mnproc.eq.1) then
write(lp,'(/ a /)') 'error in hycom - unknown restart type'
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
if (mnproc.eq.1) then
write(lp,'(a)') trim(cline)
call flush(lp)
endif !1st tile
i = index(cline,'=')
read(cline(i+1:),*) nstep0,dtime0
!
call restart_in3d(u, 2*kdm, iu, 'u ')
call restart_in3d(v, 2*kdm, iv, 'v ')
call restart_in3d(dp, 2*kdm, ip, 'dp ')
call restart_in3d(temp, 2*kdm, ip, 'temp ')
call restart_in3d(saln, 2*kdm, ip, 'saln ')
if (lold) then
call restart_in3d(th3d, 2*kdm, ip, 'th3d ')
else
do k= 1,kdm
do j= 1,jj
do i= 1,ii
if (ip(i,j).eq.1) then
th3d(i,j,k,1)=sig(temp(i,j,k,1),saln(i,j,k,1))-thbase
th3d(i,j,k,2)=sig(temp(i,j,k,2),saln(i,j,k,2))-thbase
else
th3d(i,j,k,1) = 0.0
th3d(i,j,k,2) = 0.0
endif
enddo !i
enddo !j
enddo !k
endif
!
! do we have MY2.5 arrays in the restart file?
!
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
if (lold) then
kskip = 12*kdm + 2
else
kskip = 10*kdm + 2
endif
call restart_inrw(kskip)
!
lmyin = cline(1:8).eq.'q2 '
!
if (lmyin) then
!
! MY2.5 in restart file.
!
if (mxlmy) then
call restart_in3d(q2 ,2*kdm+4, ip, 'q2 ')
call restart_in3d(q2l ,2*kdm+4, ip, 'q2l ')
call restart_in3d(vctymy, kdm+2, ip, 'vctymy ')
call restart_in3d(difqmy, kdm+2, ip, 'difqmy ')
call restart_in3d(diftmy, kdm+2, ip, 'diftmy ')
else
if (mnproc.eq.1) then
write(lp,'(a)') 'RESTART: skipping MY2.5 input fields'
call flush(lp)
endif !1st tile
kskip = 7*kdm+14
do k= 1,kskip
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
! if (mnproc.eq.1) then
! write(lp,'(a)') cline
! endif !1st tile
call zaiosk(11)
enddo !k
endif !mxlmy:else
!
! do we have DETIDE arrays in the restart file?
!
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
if (lold) then
kskip = 12*kdm + 2 + 7*kdm+14
else
kskip = 10*kdm + 2 + 7*kdm+14
endif
call restart_inrw(kskip)
elseif (mxlmy) then
if (mnproc.eq.1) then
write(lp,'(a)') 'RESTART: no MY2.5 fields input'
call flush(lp)
endif !1st tile
endif !lmyin:mxlmy
!
! do we have DETIDE arrays in the restart file?
!
ltidin = cline(1:8).eq.'uhrly '
!
if (ltidin) then
!
! DETIDE in restart file.
! 25 or 49 hrs present?
!
call restart_inrw(kskip+25)
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
if (cline(1:8).eq.'uhrly ') then !49 hrs
nhrly = 49 ![uv]ntide will be initialised in tides_set (tides_detide)
else
nhrly = 25 ![uv]ntide will be initialised in tides_set (tides_detide)
endif
call restart_inrw(kskip)
!
if (tidflg.gt.0) then
if (.not.allocated(uhrly)) then
allocate( uhrly(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy,49), &
vhrly(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy,49), &
untide(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy), &
vntide(1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy) )
call mem_stat_add( 2*(idm+2*nbdy)*(jdm+2*nbdy)*50 )
else
if (mnproc.eq.1) then
write(lp,'(/ a /)') &
'error - uhrly already allocated'
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif !allocated:else
call restart_in3d(uhrly ,nhrly, iu, 'uhrly ')
call restart_in3d(vhrly ,nhrly, iv, 'vhrly ')
else
if (mnproc.eq.1) then
write(lp,'(a)') 'RESTART: skipping DETIDE input fields'
call flush(lp)
endif !1st tile
do k= 1,2*nhrly
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
! if (mnproc.eq.1) then
! write(lp,'(a)') cline
! endif !1st tile
call zaiosk(11)
enddo !k
endif !tidflg:else
elseif (tidflg.gt.0) then
! --- [uv]hrly & [uv]ntide will be allocated/initialized in tides_set
if (mnproc.eq.1) then
write(lp,'(a)') 'RESTART: no DETIDE fields input'
call flush(lp)
endif !1st tile
endif !ltidin:tidflg
!
call restart_in3d(ubavg, 3, iu, 'ubavg ')
call restart_in3d(vbavg, 3, iv, 'vbavg ')
call restart_in3d(pbavg, 3, ip, 'pbavg ')
call restart_in3d(pbot, 1, ip, 'pbot ')
call restart_in3d(psikk,kapnum, ip, 'psikk ') !kapnum 1 or 2
call restart_in3d(thkk, kapnum, ip, 'thkk ') !kapnum 1 or 2
call restart_in3d(dpmixl, 2, ip, 'dpmixl ')
!
if (sshflg.eq.2) then
! --- montg_c makes montg1 steric SSH, assumes long term mean SSH is all steric
do j= 1,jj
do i= 1,ii
if (ip(i,j).eq.1) then
pbavg(i,j,1) = pbavg(i,j,1) - montg_c(i,j)*rhoref
pbavg(i,j,2) = pbavg(i,j,2) - montg_c(i,j)*rhoref
pbavg(i,j,3) = pbavg(i,j,3) - montg_c(i,j)*rhoref
endif ! ip
enddo !i
enddo !j
endif ! sshflg==2
!
do j= 1,jj
do i= 1,ii
if (ip(i,j).eq.1) then
oneta(i,j,1) = max( oneta0, 1.0 + pbavg(i,j,1)/pbot(i,j) )
oneta(i,j,2) = max( oneta0, 1.0 + pbavg(i,j,2)/pbot(i,j) )
else
oneta(i,j,1) = 1.0
oneta(i,j,2) = 1.0
endif !ip
enddo !i
enddo !j
vland = 1.0
call xctilr(oneta,1,2, nbdy,nbdy, halo_ps)
vland = 0.0
!
if (icegln) then
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in)')
stop '(restart_in)'
endif
if (ios.ne.0 .or. cline(1:8).ne.'temice ') then
!
! --- assume this is an addition of ice to the simulation.
!
if (mnproc.eq.1) then
write(lp,'(/ a /)') 'adding ice to the simulation.'
call flush(lp)
endif !1st tile
!
do j= 1,jj
do i= 1,ii
temice(i,j) = temp(i,j,1,1)
covice(i,j) = 0.0
thkice(i,j) = 0.0
enddo
enddo
if (trcrin .and. cline(1:8).eq.'tracer ') then
! --- reposition file for tracer input
if (lold) then
kskip = 12*kdm+14+2*kapnum
else
kskip = 10*kdm+14+2*kapnum
endif
if (lmyin) then
kskip = kskip + 7*kdm+14
endif
if (ltidin) then
kskip = kskip + 2*nhrly
endif
call restart_inrw(kskip)
endif
else
!
! --- reposition file for ice input
!
if (lold) then
kskip = 12*kdm+14+2*kapnum
else
kskip = 10*kdm+14+2*kapnum
endif
if (lmyin) then
kskip = kskip + 7*kdm+14
endif
if (ltidin) then
kskip = kskip + 2*nhrly
endif
call restart_inrw(kskip)
!
call restart_in3d(temice, 1, ip, 'temice ')
call restart_in3d(covice, 1, ip, 'covice ')
call restart_in3d(thkice, 1, ip, 'thkice ')
endif !new ice:read ice
else
! --- no sea ice, but still need covice
do j= 1,jj
do i= 1,ii
covice(i,j) = 0.0
enddo
enddo
endif !icegln:else
if (trcrin) then
do ktr= 1,ntracr
call restart_in3d(tracer(1-nbdy,1-nbdy,1,1,ktr), &
2*kdm, ip, 'tracer ')
enddo
endif
#if defined (USE_NUOPC_CESMBETA)
if (restart_cpl) then
call zagetc(cline,ios, uoff+11)
if (cline(1:8).eq. 'tml ') then
!!Alex average export fields
! --- reposition file for coupled input
!
if (lold) then
kskip = 12*kdm+14+2*kapnum
else
kskip = 10*kdm+14+2*kapnum
endif
if (lmyin) then
kskip = kskip + 7*kdm+14
endif
if (ltidin) then
kskip = kskip + 2*nhrly
endif
call restart_inrw(kskip)
call restart_in3d(tml , 1, ip, 'tml ')
call restart_in3d(sml , 1, ip, 'sml ')
call restart_in3d(umxl, 1, ip, 'umxl ')
call restart_in3d(vmxl, 1, ip, 'vmxl ')
else
! --- reposition file for coupled input
!
if (lold) then
kskip = 12*kdm+14+2*kapnum
else
kskip = 10*kdm+14+2*kapnum
endif
if (lmyin) then
kskip = kskip + 7*kdm+14
endif
if (ltidin) then
kskip = kskip + 2*nhrly
endif
call restart_inrw(kskip)
endif !cline
endif ! restart_cpl = .true.
#endif /* USE_NUOPC_CESMBETA */
if (mnproc.eq.1) then ! .b file from 1st tile only
close (unit=uoff+11)
endif
call zaiocl(11)
!
do j=1-nbdy,jj+nbdy
do i=1-nbdy,ii+nbdy
srfhgt(i,j) = 0.0 !for pipe_compareall
montg1(i,j) = 0.0 !for pipe_compareall
dpbl(i,j) = 0.0 !for pipe_compareall
klist(i,j) = kk !for MY2.5 mixed layer
enddo
enddo
return
end subroutine restart_in_coupled
subroutine restart_in3d(field,l, mask, cfield)
!
integer l
real, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy,l) :: &
field
integer, dimension (1-nbdy:idm+nbdy,1-nbdy:jdm+nbdy) :: &
mask
character cfield*8
!
! --- read a single restart 3-d array field.
!
integer i,ios,layer,level,k
real hmina(2*kdm+49),hminb,hmaxa(2*kdm+49),hmaxb !+49 for [uv]hrly
character cline*80
!
if (mnproc.eq.1) then
write(lp,'(a,i3,2x,a)') 'restart_in3d - l,cfield = ',l,cfield
call flush(lp)
endif !1st tile
call zaiord3(field,l, mask,.false., hmina,hmaxa, 11)
!
do k= 1,l
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_in3d)')
stop '(restart_in3d)'
endif
if (mnproc.eq.1) then
write (lp,'(a)') trim(cline)
endif !1st tile
if (cline(1:8).ne.cfield) then
if (mnproc.eq.1) then
write(lp,'(/ a / a,a /)') trim(cline), &
'error in restart_in3d - expected ',cfield
endif !1st tile
call xcstop('(restart_in3d)')
stop '(restart_in3d)'
endif
i = index(cline,'=')
read (cline(i+1:),*) layer,level,hminb,hmaxb
if (abs(hmina(k)-hminb).gt.abs(hminb)*1.e-4 .or. &
abs(hmaxa(k)-hmaxb).gt.abs(hmaxb)*1.e-4 ) then
if (mnproc.eq.1) then
write(lp,'(/ a / a,3i3 / a / a,1p3e14.6 / a,1p3e14.6 /)') &
'error - .a and .b files not consistent:', &
'iunit,k,l = ',11,k,l, &
cline, &
'.a,.b min = ',hmina(k),hminb,hmina(k)-hminb, &
'.a,.b max = ',hmaxa(k),hmaxb,hmaxa(k)-hmaxb
endif !1st tile
call xcstop('(restart_in3d)')
stop '(restart_in3d)'
endif
enddo
!
return
end subroutine restart_in3d
subroutine restart_inrw(kline)
!
integer kline
!
! reposition the input restart .b file at line kline.
!
integer ios,k
character cline*80
!
if (mnproc.eq.1) then ! .b file from 1st tile only
rewind(uoff+11)
endif
do k= 1,kline
call zagetc(cline,ios, uoff+11)
if (ios.ne.0) then
if (mnproc.eq.1) then
write(lp,'(/ a,i4,i9 /)') &
'I/O error from zagetc, iunit,ios = ',uoff+11,ios
endif !1st tile
call xcstop('(restart_inrw)')
stop '(restart_inrw)'
endif
enddo !k
if (mnproc.eq.1) then
write(lp,'(a,i5)') 'restart_inrw, kline =',kline
write(lp,'(a)') trim(cline)
call flush(lp)
endif !1st tile
return
end subroutine restart_inrw
subroutine restart_out_coupled(nstepx, dtimex, flnmra,flnmrb, last, restart_cpl)
use mod_cb_arrays ! HYCOM saved arrays
use mod_tides ! HYCOM tides
implicit none
logical last
integer nstepx
real*8 dtimex
character*(*) flnmra,flnmrb
logical, intent(in) :: restart_cpl ! coupled
!
! write out in a restart file on unit 12 or 22 (and a flux file on 25).
!
! flnmra is the ".a" file (usually without the .a, and
! flnmrb is the ".b" file (usually without the .b).
! Usually flnmra == flnmrb, and there are standard and backup restarts;
! otherwise the restart is unique and flnmra and flnmrb are the complete
! filenames (including any .a and .b).
!
logical lopen
integer i,iunit,iunta,j,k,ktr,l
real xmin(2*kdm+49),xmax(2*kdm+49) !+49 for [uv]hrly
character cline*80
!
integer, save :: icount = 0
!
# include "stmt_fns.h"
!
icount = icount + 1
!
if (flnmra.ne.flnmrb .or. last .or. mod(icount,2).eq.0) then
iunta = 12 ! standard restart file
else
iunta = 22 ! backup restart file
endif
iunit = uoff+iunta
!!Alex add unit for CESM restart
if (restart_cpl) iunta = 15
!
call zaiopi(lopen, iunta)
if (.not.lopen) then
if (flnmra.ne.flnmrb) then
call zaiopf(trim(flnmra), 'new', iunta) !unique
elseif (iunta.eq.12) then
call zaiopf(trim(flnmra)//'.a', 'new', iunta) !standard
elseif (iunta.eq.15) then
call zaiopf(trim(flnmra)//'.a', 'new', iunta) !standard coupled !!Alex
else
call zaiopf(trim(flnmra)//'1.a','new', iunta) !backup
endif
if (mnproc.eq.1) then
if (flnmra.ne.flnmrb) then
open (unit=iunit,file=trim(flnmrb), & !12
status='new',action='write',form='formatted')
write(lp,'(a)') ' creating a new unique restart file'
elseif (iunta.eq.12) then
open (unit=iunit,file=trim(flnmra)//'.b', & !12
status='new',action='write',form='formatted')
write(lp,'(a)') ' creating a new standard restart file'
elseif (iunta.eq.15) then
open (unit=iunit,file=trim(flnmra)//'.b', &!15 !!Alex
status='new',action='write',form='formatted')
write(lp,'(a)') ' creating a new standard restart file'
else
open (unit=iunit,file=trim(flnmra)//'1.b', & !22
status='new',action='write',form='formatted')
write(lp,'(a)') ' creating a new backup restart file'
endif
call flush(lp)
endif !1st tile
elseif (flnmra.ne.flnmrb) then
if (mnproc.eq.1) then
write(lp,'(a)') &
' error - (unique) restart file already exists.'
write(lp,'(a,a)') &
' flnmra = ',trim(flnmra)
write(lp,'(a,a)') &
' flnmrb = ',trim(flnmrb)
endif !1st tile
call xcstop('(restart_out)')
stop '(restart_out)'
else
call zaiorw(iunta)
if (mnproc.eq.1) then
rewind(unit=iunit)
if (iunta.eq.12) then
write(lp,'(a)') &
' over-writing any previous standard restart'
else
write(lp,'(a)') &
' over-writing any previous backup restart'
endif
call flush(lp)
endif !1st tile
endif
!
if (mnproc.eq.1) then
write(iunit,'(a,4i6)') 'RESTART2: iexpt,iversn,yrflag,sigver = ', &
iexpt,iversn,yrflag,sigver
write(cline,*) nstepx,dtimex,thbase
write(iunit,'(a,a)') 'RESTART2: nstep,dtime,thbase = ', &
trim(cline)
call flush(iunit)
endif !1st tile
!
call zaiowr3(u, 2*kdm, iu,.false., xmin,xmax, iunta,.true.)
call xctilr( u, 1,2*kdm, nbdy,nbdy, halo_uv)
if (mnproc.eq.1) then
do l= 0,1
do k= 1,kdm
write(iunit,4100) 'u ',k,l+1,xmin(k+l*kdm),xmax(k+l*kdm)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(v, 2*kdm, iv,.false., xmin,xmax, iunta,.true.)
call xctilr( v, 1,2*kdm, nbdy,nbdy, halo_vv)
if (mnproc.eq.1) then
do l= 0,1
do k= 1,kdm
write(iunit,4100) 'v ',k,l+1,xmin(k+l*kdm),xmax(k+l*kdm)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(dp, 2*kdm, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( dp, 1,2*kdm, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 0,1
do k= 1,kdm
write(iunit,4100) 'dp ',k,l+1,xmin(k+l*kdm),xmax(k+l*kdm)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(temp, 2*kdm, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( temp, 1,2*kdm, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 0,1
do k= 1,kdm
write(iunit,4100) 'temp ',k,l+1,xmin(k+l*kdm),xmax(k+l*kdm)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(saln, 2*kdm, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( saln, 1,2*kdm, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 0,1
do k= 1,kdm
write(iunit,4100) 'saln ',k,l+1,xmin(k+l*kdm),xmax(k+l*kdm)
enddo
enddo
call flush(iunit)
endif !1st tile
!
! --- temp and saln may have been changed, so update th3d
do k= 1,kdm
do j= 1-nbdy,jj+nbdy
do i= 1-nbdy,ii+nbdy
if (ip(i,j).eq.1) then
th3d(i,j,k,1)=sig(temp(i,j,k,1),saln(i,j,k,1))-thbase
th3d(i,j,k,2)=sig(temp(i,j,k,2),saln(i,j,k,2))-thbase
else
th3d(i,j,k,1) = 0.0
th3d(i,j,k,2) = 0.0
endif
enddo !i
enddo !j
enddo !k
!
if (mxlmy) then
call zaiowr3(q2, 2*kdm+4, ip,.false., xmin,xmax, iunta,.true.)
if (mnproc.eq.1) then
do l= 0,1
do k= 1,kdm+2
write(iunit,4100) 'q2 ' &
,k,l+1,xmin(k+l*(kdm+2)),xmax(k+l*(kdm+2))
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(q2l, 2*kdm+4, ip,.false., xmin,xmax, iunta,.true.)
if (mnproc.eq.1) then
do l= 0,1
do k= 1,kdm+2
write(iunit,4100) 'q2l ' &
,k,l+1,xmin(k+l*(kdm+2)),xmax(k+l*(kdm+2))
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(vctymy, kdm+2, ip,.false., xmin,xmax, iunta,.true.)
if (mnproc.eq.1) then
do l= 1,1
do k= 1,kdm+2
write(iunit,4100) 'vctymy ',k,l,xmin(k),xmax(k)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(difqmy, kdm+2, ip,.false., xmin,xmax, iunta,.true.)
if (mnproc.eq.1) then
do l= 1,1
do k= 1,kdm+2
write(iunit,4100) 'difqmy ',k,l,xmin(k),xmax(k)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(diftmy, kdm+2, ip,.false., xmin,xmax, iunta,.true.)
if (mnproc.eq.1) then
do l= 1,1
do k= 1,kdm+2
write(iunit,4100) 'diftmy ',k,l,xmin(k),xmax(k)
enddo
enddo
call flush(iunit)
endif !1st tile
endif !mxlmy
!
if (tidflg.gt.0) then
call zaiowr3(uhrly, 49, iu,.false., xmin,xmax, iunta,.true.)
call xctilr( uhrly, 1,49, nbdy,nbdy, halo_uv)
if (mnproc.eq.1) then
do l= 1,49
do k= 0,0
write(iunit,4100) 'uhrly ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(vhrly, 49, iv,.false., xmin,xmax, iunta,.true.)
call xctilr( vhrly, 1,49, nbdy,nbdy, halo_vv)
if (mnproc.eq.1) then
do l= 1,49
do k= 0,0
write(iunit,4100) 'vhrly ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
endif !tidflg
!
call zaiowr3(ubavg, 3, iu,.false., xmin,xmax, iunta,.true.)
call xctilr( ubavg, 1,3, nbdy,nbdy, halo_uv)
if (mnproc.eq.1) then
do l= 1,3
do k= 0,0
write(iunit,4100) 'ubavg ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(vbavg, 3, iv,.false., xmin,xmax, iunta,.true.)
call xctilr( vbavg, 1,3, nbdy,nbdy, halo_vv)
if (mnproc.eq.1) then
do l= 1,3
do k= 0,0
write(iunit,4100) 'vbavg ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
if (sshflg.eq.2) then
! --- unwind the pbavg correction for compatibility with psikk
do j= 1,jj
do i= 1,ii
if (ip(i,j).eq.1) then
pbavg(i,j,1) = pbavg(i,j,1) + montg_c(i,j)*rhoref
pbavg(i,j,2) = pbavg(i,j,2) + montg_c(i,j)*rhoref
pbavg(i,j,3) = pbavg(i,j,3) + montg_c(i,j)*rhoref
endif ! ip
enddo !i
enddo !j
endif ! sshflg==2
call zaiowr3(pbavg, 3, ip,.false., xmin,xmax, iunta,.true.)
if (sshflg.eq.2) then
! --- re-apply the pbavg correction
do j= 1,jj
do i= 1,ii
if (ip(i,j).eq.1) then
pbavg(i,j,1) = pbavg(i,j,1) - montg_c(i,j)*rhoref
pbavg(i,j,2) = pbavg(i,j,2) - montg_c(i,j)*rhoref
pbavg(i,j,3) = pbavg(i,j,3) - montg_c(i,j)*rhoref
endif ! ip
enddo !i
enddo !j
endif ! sshflg==2
call xctilr( pbavg, 1,3, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,3
do k= 0,0
write(iunit,4100) 'pbavg ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(pbot, 1, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( pbot, 1,1, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,1
do k= 0,0
write(iunit,4100) 'pbot ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(psikk, kapnum,ip,.false., xmin,xmax, iunta,.true.)
call xctilr( psikk,1,kapnum,nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,kapnum !kapnum 1 or 2
do k= 0,0
write(iunit,4100) 'psikk ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(thkk, kapnum, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( thkk,1,kapnum, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,kapnum !kapnum 1 or 2
do k= 0,0
write(iunit,4100) 'thkk ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(dpmixl, 2, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( dpmixl, 1,2, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,2
do k= 0,0
write(iunit,4100) 'dpmixl ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
!
! --- needed because zaiowr fields have been cast to REAL*4
!
do j= 1,jj
do i= 1,ii
if (ip(i,j).eq.1) then
oneta(i,j,1) = max( oneta0, 1.0 + pbavg(i,j,1)/pbot(i,j) )
oneta(i,j,2) = max( oneta0, 1.0 + pbavg(i,j,2)/pbot(i,j) )
else
oneta(i,j,1) = 1.0
oneta(i,j,2) = 1.0
endif !ip
enddo !i
enddo !j
vland = 1.0
call xctilr(oneta,1,2, nbdy,nbdy, halo_ps)
vland = 0.0
if (icegln) then
call zaiowr3(temice, 1, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( temice, 1,1, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,1
do k= 0,0
write(iunit,4100) 'temice ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(covice, 1, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( covice, 1,1, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,1
do k= 0,0
write(iunit,4100) 'covice ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(thkice, 1, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( thkice, 1,1, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,1
do k= 0,0
write(iunit,4100) 'thkice ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
endif
if (trcout) then
do ktr= 1,ntracr
call zaiowr3(tracer(1-nbdy,1-nbdy,1,1,ktr), 2*kdm, &
ip,.false., xmin,xmax, iunta,.true.)
call xctilr( tracer(1-nbdy,1-nbdy,1,1,ktr),1,2*kdm, &
nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 0,1
do k= 1,kdm
write(iunit,4100) 'tracer ',k,l+1,xmin(k+l*kdm), &
xmax(k+l*kdm)
enddo
enddo
call flush(iunit)
endif !1st tile
enddo !ktr
endif !trcout
#if defined (USE_NUOPC_CESMBETA)
if (restart_cpl) then
!!Alex averaged export fields
call zaiowr3(tml, 1, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( tml, 1,1, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,1
do k= 0,0
write(iunit,4100) 'tml ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(sml, 1, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( sml, 1,1, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,1
do k= 0,0
write(iunit,4100) 'sml ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(umxl, 1, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( umxl, 1,1, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,1
do k= 0,0
write(iunit,4100) 'umxl ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
call zaiowr3(vmxl, 1, ip,.false., xmin,xmax, iunta,.true.)
call xctilr( vmxl, 1,1, nbdy,nbdy, halo_ps)
if (mnproc.eq.1) then
do l= 1,1
do k= 0,0
write(iunit,4100) 'vmxl ',k,l, xmin(l),xmax(l)
enddo
enddo
call flush(iunit)
endif !1st tile
endif ! restart_cpl = .true.
#endif /* USE_NUOPC_CESMBETA */
if (flnmra.ne.flnmrb) then !unique restart file
call zaiocl(iunta)