-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcice_cap.F90
1801 lines (1564 loc) · 91.8 KB
/
cice_cap.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
!--------------- LANL CICE NUOPC CAP -----------------
! This is the LANL CICE model cap component that's NUOPC compiant.
!
! Author: [email protected]
!
! 5/10/13
! This is now acting as a cap/connector between NUOPC driver and LANL CICE code.
!
module cice_cap_mod
use ice_blocks, only: nx_block, ny_block, nblocks_tot, block, get_block, &
get_block_parameter
use ice_domain_size, only: max_blocks, nx_global, ny_global
use ice_domain, only: nblocks, blocks_ice, distrb_info
use ice_distribution, only: ice_distributiongetblockloc
use ice_constants, only: Tffresh, rad_to_deg
use ice_calendar, only: dt
use ice_flux
use ice_grid, only: TLAT, TLON, ULAT, ULON, hm, tarea, ANGLET, ANGLE, &
dxt, dyt, t2ugrid_vector
use ice_state
use CICE_RunMod
use CICE_InitMod
use CICE_FinalMod
use ESMF
use NUOPC
use NUOPC_Model, &
model_routine_SS => SetServices, &
model_label_SetClock => label_SetClock, &
model_label_Advance => label_Advance, &
model_label_Finalize => label_Finalize
implicit none
private
public SetServices
type cice_internalstate_type
end type
type cice_internalstate_wrapper
type(cice_internalstate_type), pointer :: ptr
end type
integer :: import_slice = 0
integer :: export_slice = 0
type fld_list_type
character(len=64) :: stdname
character(len=64) :: shortname
character(len=64) :: transferOffer
logical :: assoc ! is the farrayPtr associated with internal data
real(ESMF_KIND_R8), dimension(:,:,:), pointer :: farrayPtr
end type fld_list_type
integer,parameter :: fldsMax = 100
integer :: fldsToIce_num = 0
type (fld_list_type) :: fldsToIce(fldsMax)
integer :: fldsFrIce_num = 0
type (fld_list_type) :: fldsFrIce(fldsMax)
integer :: lsize ! local number of gridcells for coupling
character(len=256) :: tmpstr
character(len=2048):: info
logical :: isPresent
integer :: dbrc ! temporary debug rc value
type(ESMF_Grid), save :: ice_grid_i
logical :: write_diagnostics = .true.
logical :: profile_memory = .true.
contains
!-----------------------------------------------------------------------
!------------------- CICE code starts here -----------------------
!-----------------------------------------------------------------------
subroutine SetServices(gcomp, rc)
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
character(len=*),parameter :: subname='(cice_cap:SetServices)'
rc = ESMF_SUCCESS
! the NUOPC model component will register the generic methods
call NUOPC_CompDerive(gcomp, model_routine_SS, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! switching to IPD versions
call ESMF_GridCompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
userRoutine=InitializeP0, phase=0, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! set entry point for methods that require specific implementation
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv01p1"/), userRoutine=InitializeAdvertise, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_INITIALIZE, &
phaseLabelList=(/"IPDv01p3"/), userRoutine=InitializeRealize, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! attach specializing method(s)
! No need to change clock settings
call ESMF_MethodAdd(gcomp, label=model_label_SetClock, &
userRoutine=SetClock, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_MethodAdd(gcomp, label=model_label_Advance, &
userRoutine=ModelAdvance_slow, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompSpecialize(gcomp, specLabel=model_label_Finalize, &
specRoutine=cice_model_finalize, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call CICE_FieldsSetup()
end subroutine
!-----------------------------------------------------------------------------
subroutine InitializeP0(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
character(len=10) :: value
type(ESMF_VM) :: vm
integer :: lpet
rc = ESMF_SUCCESS
! Switch to IPDv01 by filtering all other phaseMap entries
call NUOPC_CompFilterPhaseMap(gcomp, ESMF_METHOD_INITIALIZE, &
acceptStringList=(/"IPDv01p"/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_GridCompGet(gcomp, vm=vm, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_VMGet(vm, localPet=lpet, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_AttributeGet(gcomp, name="DumpFields", value=value, defaultValue="true", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
write_diagnostics=(trim(value)=="true")
call ESMF_AttributeGet(gcomp, name="ProfileMemory", value=value, defaultValue="true", &
convention="NUOPC", purpose="Instance", rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
profile_memory=(trim(value)/="false")
if(lpet == 0) &
print *, 'CICE DumpFields = ', write_diagnostics, 'ProfileMemory = ', profile_memory
end subroutine
!-----------------------------------------------------------------------------
subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! Local Variables
type(ESMF_VM) :: vm
integer :: mpi_comm
character(len=*),parameter :: subname='(cice_cap:InitializeAdvertise)'
rc = ESMF_SUCCESS
call ESMF_VMGetCurrent(vm, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_VMGet(vm, mpiCommunicator=mpi_comm, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call CICE_Initialize(mpi_comm)
call CICE_AdvertiseFields(importState, fldsToIce_num, fldsToIce, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call CICE_AdvertiseFields(exportState, fldsFrIce_num, fldsFrIce, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
write(info,*) subname,' --- initialization phase 1 completed --- '
call ESMF_LogWrite(info, ESMF_LOGMSG_INFO, rc=dbrc)
end subroutine
!-----------------------------------------------------------------------------
subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: gcomp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! Local Variables
type(ESMF_VM) :: vm
type(ESMF_Grid) :: gridIn
type(ESMF_Grid) :: gridOut
type(ESMF_DistGrid) :: distgrid
type(ESMF_DistGridConnection), allocatable :: connectionList(:)
integer :: npet
integer :: i,j,iblk, n, i1,j1, DE
integer :: ilo,ihi,jlo,jhi
integer :: ig,jg,cnt
integer :: peID,locID
integer, pointer :: indexList(:)
integer, pointer :: deLabelList(:)
integer, pointer :: deBlockList(:,:,:)
integer, pointer :: petMap(:)
integer, pointer :: i_glob(:),j_glob(:)
integer :: lbnd(2),ubnd(2)
type(block) :: this_block
type(ESMF_DELayout) :: delayout
real(ESMF_KIND_R8), pointer :: tarray(:,:)
real(ESMF_KIND_R8), pointer :: coordXcenter(:,:)
real(ESMF_KIND_R8), pointer :: coordYcenter(:,:)
real(ESMF_KIND_R8), pointer :: coordXcorner(:,:)
real(ESMF_KIND_R8), pointer :: coordYcorner(:,:)
integer(ESMF_KIND_I4), pointer :: gridmask(:,:)
real(ESMF_KIND_R8), pointer :: gridarea(:,:)
character(len=*),parameter :: subname='(cice_cap:InitializeRealize)'
rc = ESMF_SUCCESS
! We can check if npet is 4 or some other value to make sure
! CICE is configured to run on the correct number of processors.
! create a Grid object for Fields
! we are going to create a single tile displaced pole grid from a gridspec
! file. We also use the exact decomposition in CICE so that the Fields
! created can wrap on the data pointers in internal part of CICE
write(tmpstr,'(a,2i8)') subname//' ice nx,ny = ',nx_global,ny_global
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
! distgrid = ESMF_DistGridCreate(minIndex=(/1,1/), maxIndex=(/nx_global,ny_global/), &
! regDecomp=(/2,2/), rc=rc)
allocate(deBlockList(2,2,nblocks_tot))
allocate(petMap(nblocks_tot))
allocate(deLabelList(nblocks_tot))
write(tmpstr,'(a,1i8)') subname//' nblocks = ',nblocks_tot
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
do n = 1, nblocks_tot
deLabelList(n) = n
call get_block_parameter(n,ilo=ilo,ihi=ihi,jlo=jlo,jhi=jhi, &
i_glob=i_glob,j_glob=j_glob)
deBlockList(1,1,n) = i_glob(ilo)
deBlockList(1,2,n) = i_glob(ihi)
deBlockList(2,1,n) = j_glob(jlo)
deBlockList(2,2,n) = j_glob(jhi)
call ice_distributionGetBlockLoc(distrb_info,n,peID,locID)
petMap(n) = peID - 1
write(tmpstr,'(a,2i8)') subname//' IDs = ',n,peID
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
write(tmpstr,'(a,3i8)') subname//' iglo = ',n,deBlockList(1,1,n),deBlockList(1,2,n)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
write(tmpstr,'(a,3i8)') subname//' jglo = ',n,deBlockList(2,1,n),deBlockList(2,2,n)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
enddo
delayout = ESMF_DELayoutCreate(petMap, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
allocate(connectionList(2))
! bipolar boundary condition at top row: nyg
call ESMF_DistGridConnectionSet(connectionList(1), tileIndexA=1, &
tileIndexB=1, positionVector=(/nx_global+1, 2*ny_global+1/), &
orientationVector=(/-1, -2/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! periodic boundary condition along first dimension
call ESMF_DistGridConnectionSet(connectionList(2), tileIndexA=1, &
tileIndexB=1, positionVector=(/nx_global, 0/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
distgrid = ESMF_DistGridCreate(minIndex=(/1,1/), maxIndex=(/nx_global,ny_global/), &
! indexflag = ESMF_INDEX_DELOCAL, &
deBlockList=deBlockList, &
! deLabelList=deLabelList, &
delayout=delayout, &
connectionList=connectionList, &
rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
deallocate(deLabelList)
deallocate(deBlockList)
deallocate(petMap)
deallocate(connectionList)
! call ESMF_DistGridPrint(distgrid=distgrid, rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
! line=__LINE__, &
! file=__FILE__)) &
! return ! bail out
call ESMF_DistGridGet(distgrid=distgrid, localDE=0, elementCount=cnt, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
allocate(indexList(cnt))
write(tmpstr,'(a,i8)') subname//' distgrid cnt= ',cnt
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
call ESMF_DistGridGet(distgrid=distgrid, localDE=0, seqIndexList=indexList, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
write(tmpstr,'(a,4i8)') subname//' distgrid list= ',indexList(1),indexList(cnt),minval(indexList), maxval(indexList)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
deallocate(IndexList)
! gridIn = ESMF_GridCreate('global_gx3_gridspec.nc', ESMF_FILEFORMAT_GRIDSPEC, &
!! (/2,2/), isSphere=.true., coordNames=(/'ulon', 'ulat'/), &
! distgrid=distgrid, isSphere=.true., coordNames=(/'ulon', 'ulat'/), &
! indexflag=ESMF_INDEX_DELOCAL, addCornerStagger=.true., rc=rc)
!! indexflag=ESMF_INDEX_GLOBAL, addCornerStagger=.true., rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
! line=__LINE__, &
! file=__FILE__)) &
! return ! bail out
gridIn = ESMF_GridCreate(distgrid=distgrid, &
coordSys = ESMF_COORDSYS_SPH_DEG, &
gridEdgeLWidth=(/0,0/), gridEdgeUWidth=(/0,1/), &
rc = rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridAddCoord(gridIn, staggerLoc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridAddCoord(gridIn, staggerLoc=ESMF_STAGGERLOC_CORNER, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridAddItem(gridIn, itemFlag=ESMF_GRIDITEM_MASK, itemTypeKind=ESMF_TYPEKIND_I4, &
staggerLoc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridAddItem(gridIn, itemFlag=ESMF_GRIDITEM_AREA, itemTypeKind=ESMF_TYPEKIND_R8, &
staggerLoc=ESMF_STAGGERLOC_CENTER, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
do iblk = 1,nblocks
DE = iblk-1
this_block = get_block(blocks_ice(iblk),iblk)
ilo = this_block%ilo
ihi = this_block%ihi
jlo = this_block%jlo
jhi = this_block%jhi
call ESMF_GridGetCoord(gridIn, coordDim=1, localDE=DE, &
staggerloc=ESMF_STAGGERLOC_CENTER, &
computationalLBound=lbnd, computationalUBound=ubnd, &
farrayPtr=coordXcenter, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridGetCoord(gridIn, coordDim=2, localDE=DE, &
staggerloc=ESMF_STAGGERLOC_CENTER, &
farrayPtr=coordYcenter, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
write(tmpstr,'(a,5i8)') subname//' iblk center bnds ',iblk,lbnd,ubnd
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
if (lbnd(1) /= 1 .or. lbnd(2) /= 1 .or. ubnd(1) /= ihi-ilo+1 .or. ubnd(2) /= jhi-jlo+1) then
write(tmpstr,'(a,5i8)') subname//' iblk bnds ERROR '
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, line=__LINE__, file=__FILE__, rc=dbrc)
rc = ESMF_FAILURE
return
endif
call ESMF_GridGetItem(gridIn, itemflag=ESMF_GRIDITEM_MASK, localDE=DE, &
staggerloc=ESMF_STAGGERLOC_CENTER, &
farrayPtr=gridmask, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridGetItem(gridIn, itemflag=ESMF_GRIDITEM_AREA, localDE=DE, &
staggerloc=ESMF_STAGGERLOC_CENTER, &
farrayPtr=gridarea, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
do j1 = lbnd(2),ubnd(2)
do i1 = lbnd(1),ubnd(1)
i = i1 + ilo - lbnd(1)
j = j1 + jlo - lbnd(2)
coordXcenter(i1,j1) = TLON(i,j,iblk) * rad_to_deg
coordYcenter(i1,j1) = TLAT(i,j,iblk) * rad_to_deg
gridmask(i1,j1) = nint(hm(i,j,iblk))
gridarea(i1,j1) = tarea(i,j,iblk)
enddo
enddo
call ESMF_GridGetCoord(gridIn, coordDim=1, localDE=DE, &
staggerloc=ESMF_STAGGERLOC_CORNER, &
computationalLBound=lbnd, computationalUBound=ubnd, &
farrayPtr=coordXcorner, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_GridGetCoord(gridIn, coordDim=2, localDE=DE, &
staggerloc=ESMF_STAGGERLOC_CORNER, &
farrayPtr=coordYcorner, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
write(tmpstr,'(a,5i8)') subname//' iblk corner bnds ',iblk,lbnd,ubnd
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
! ULON and ULAT are upper right hand corner from TLON and TLAT
! corners in ESMF need to be defined lon lower left corner from center
! ULON and ULAT have ghost cells, leverage that to fill corner arrays
do j1 = lbnd(2),ubnd(2)
do i1 = lbnd(1),ubnd(1)
i = i1 + ilo - lbnd(1)
j = j1 + jlo - lbnd(2)
coordXcorner(i1,j1) = ULON(i-1,j-1,iblk) * rad_to_deg
coordYcorner(i1,j1) = ULAT(i-1,j-1,iblk) * rad_to_deg
enddo
enddo
enddo
call ESMF_GridGetCoord(gridIn, coordDim=1, localDE=0, &
staggerLoc=ESMF_STAGGERLOC_CENTER, farrayPtr=tarray, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
write(tmpstr,'(a,2g15.7)') subname//' gridIn center1 = ',minval(tarray),maxval(tarray)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
call ESMF_GridGetCoord(gridIn, coordDim=2, localDE=0, &
staggerLoc=ESMF_STAGGERLOC_CENTER, farrayPtr=tarray, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
write(tmpstr,'(a,2g15.7)') subname//' gridIn center2 = ',minval(tarray),maxval(tarray)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
call ESMF_GridGetCoord(gridIn, coordDim=1, localDE=0, &
staggerLoc=ESMF_STAGGERLOC_CORNER, farrayPtr=tarray, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
write(tmpstr,'(a,2g15.7)') subname//' gridIn corner1 = ',minval(tarray),maxval(tarray)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
call ESMF_GridGetCoord(gridIn, coordDim=2, localDE=0, &
staggerLoc=ESMF_STAGGERLOC_CORNER, farrayPtr=tarray, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
write(tmpstr,'(a,2g15.7)') subname//' gridIn corner2 = ',minval(tarray),maxval(tarray)
call ESMF_LogWrite(trim(tmpstr), ESMF_LOGMSG_INFO, rc=dbrc)
gridOut = gridIn ! for now out same as in
ice_grid_i = gridIn
call CICE_RealizeFields(importState, gridIn , fldsToIce_num, fldsToIce, "Ice import", rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call CICE_RealizeFields(exportState, gridOut, fldsFrIce_num, fldsFrIce, "Ice export", rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! Have to be careful with reset since states are pointing directly into cice arrays
! call state_reset(ImportState, value=-99._ESMF_KIND_R8, rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
! line=__LINE__, &
! file=__FILE__)) &
! return ! bail out
call state_reset(ExportState, value=-99._ESMF_KIND_R8, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! call State_getFldPtr(exportState,'ifrac' ,dataPtr_ifrac,rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
! call State_getFldPtr(exportState,'sit' ,dataPtr_itemp,rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
! dataPtr_ifrac = -99._ESMF_KIND_R8
! dataPtr_itemp = -99._ESMF_KIND_R8
write(info,*) subname,' --- initialization phase 2 completed --- '
call ESMF_LogWrite(info, ESMF_LOGMSG_INFO, line=__LINE__, file=__FILE__, rc=dbrc)
end subroutine
!-----------------------------------------------------------------------------
! CICE model uses same clock as parent gridComp
subroutine SetClock(gcomp, rc)
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
! local variables
type(ESMF_Clock) :: clock
type(ESMF_TimeInterval) :: stabilityTimeStep, timestep
character(len=*),parameter :: subname='(cice_cap:SetClock)'
rc = ESMF_SUCCESS
! query the Component for its clock, importState and exportState
call ESMF_GridCompGet(gcomp, clock=clock, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! tcraig: dt is the cice thermodynamic timestep in seconds
call ESMF_TimeIntervalSet(timestep, s=nint(dt), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_ClockSet(clock, timestep=timestep, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! initialize internal clock
! here: parent Clock and stability timeStep determine actual model timeStep
call ESMF_TimeIntervalSet(stabilityTimeStep, s=nint(dt), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call NUOPC_CompSetClock(gcomp, clock, stabilityTimeStep, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
end subroutine
!-----------------------------------------------------------------------------
subroutine ModelAdvance_slow(gcomp, rc)
type(ESMF_GridComp) :: gcomp
integer, intent(out) :: rc
! local variables
type(ESMF_Clock) :: clock
type(ESMF_State) :: importState, exportState
type(ESMF_Time) :: currTime
type(ESMF_TimeInterval) :: timeStep
type(ESMF_Field) :: lfield,lfield2d
type(ESMF_Grid) :: grid
real(ESMF_KIND_R8), pointer :: fldptr(:,:,:)
real(ESMF_KIND_R8), pointer :: fldptr2d(:,:)
type(block) :: this_block
character(len=64) :: fldname
integer :: i,j,iblk,n,i1,i2,j1,j2
integer :: ilo,ihi,jlo,jhi
real(ESMF_KIND_R8) :: ue, vn, ui, vj
real(ESMF_KIND_R8) :: sigma_r, sigma_l, sigma_c
type(ESMF_StateItem_Flag) :: itemType
! imports
real(ESMF_KIND_R8), pointer :: dataPtr_mdlwfx(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_swvr(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_swvf(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_swir(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_swif(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_lprec(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fprec(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_sst(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_sss(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_sl(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_sssz(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_sssm(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_ocncz(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_ocncm(:,:,:)
! real(ESMF_KIND_R8), pointer :: dataPtr_ocnci(:,:,:)
! real(ESMF_KIND_R8), pointer :: dataPtr_ocncj(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fmpot(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_mld(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_mzmf(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_mmmf(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_rhoabot(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_Tbot(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_pbot(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_qbot(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_zlvl(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_ubot(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_vbot(:,:,:)
! exports
real(ESMF_KIND_R8), pointer :: dataPtr_mask(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_ifrac(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_itemp(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_alvdr(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_alidr(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_alvdf(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_alidf(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_strairxT(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_strairyT(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_strocnxT(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_strocnyT(:,:,:)
! real(ESMF_KIND_R8), pointer :: dataPtr_strocni(:,:,:)
! real(ESMF_KIND_R8), pointer :: dataPtr_strocnj(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fswthru(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fswthruvdr(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fswthruvdf(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fswthruidr(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fswthruidf(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_flwout(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fsens(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_flat(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_evap(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fhocn(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fresh(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_fsalt(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_vice(:,:,:)
real(ESMF_KIND_R8), pointer :: dataPtr_vsno(:,:,:)
character(240) :: msgString
character(len=*),parameter :: subname='(cice_cap:ModelAdvance_slow)'
rc = ESMF_SUCCESS
if(profile_memory) call ESMF_VMLogMemInfo("Entering CICE Model_ADVANCE: ")
write(info,*) subname,' --- run phase 1 called --- '
call ESMF_LogWrite(info, ESMF_LOGMSG_INFO, rc=dbrc)
! query the Component for its clock, importState and exportState
call ESMF_GridCompGet(gcomp, clock=clock, importState=importState, &
exportState=exportState, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
! HERE THE MODEL ADVANCES: currTime -> currTime + timeStep
! Because of the way that the internal Clock was set in SetClock(),
! its timeStep is likely smaller than the parent timeStep. As a consequence
! the time interval covered by a single parent timeStep will result in
! multiple calls to the ModelAdvance() routine. Every time the currTime
! will come in by one internal timeStep advanced. This goes until the
! stopTime of the internal Clock has been reached.
call ESMF_ClockPrint(clock, options="currTime", &
preString="------>Advancing CICE from: ", unit=msgString, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_LogWrite(msgString, ESMF_LOGMSG_INFO, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_ClockGet(clock, currTime=currTime, timeStep=timeStep, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_TimePrint(currTime + timeStep, &
preString="--------------------------------> to: ", &
unit=msgString, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_LogWrite(msgString, ESMF_LOGMSG_INFO, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
if(write_diagnostics) then
import_slice = import_slice + 1
#if (1 == 0)
!tcx causes core dumps and garbage
call NUOPC_StateWrite(importState, filePrefix='field_ice_import_', &
timeslice=import_slice, relaxedFlag=.true., rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
#else
do i = 1,fldsToice_num
fldname = fldsToice(i)%shortname
call ESMF_StateGet(importState, itemName=trim(fldname), itemType=itemType, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
if (itemType /= ESMF_STATEITEM_NOTFOUND) then
call ESMF_StateGet(importState, itemName=trim(fldname), field=lfield, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_FieldGet(lfield,grid=grid,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
! create a copy of the 3d data in lfield but in a 2d array, lfield2d
lfield2d = ESMF_FieldCreate(grid, ESMF_TYPEKIND_R8, indexflag=ESMF_INDEX_DELOCAL, &
name=trim(fldname), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_FieldGet(lfield , farrayPtr=fldptr , rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
call ESMF_FieldGet(lfield2d, farrayPtr=fldptr2d, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
fldptr2d(:,:) = fldptr(:,:,1)
! causes core dumps and garbage
! call NUOPC_Write(lfield, fileName='fieldN3d_ice_import_'//trim(fldname)//'.nc', &
! timeslice=import_slice, relaxedFlag=.true., rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
! line=__LINE__, &
! file=__FILE__)) &
! return ! bail out
! causes run time error in usage
! call NUOPC_Write(lfield2d, fileName='fieldN_ice_import_'//trim(fldname)//'.nc', &
! timeslice=import_slice, relaxedFlag=.true., rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
! line=__LINE__, &
! file=__FILE__)) &
! return ! bail out
! causes core dumps and garbage
! call ESMF_FieldPrint(lfield,rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
! line=__LINE__, &
! file=__FILE__)) &
! return ! bail out
! call ESMF_FieldWrite(lfield, fileName='field3d_ice_import_'//trim(fldname)//'.nc', &
! timeslice=import_slice, rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
! line=__LINE__, &
! file=__FILE__)) &
! return ! bail out
call ESMF_FieldWrite(lfield2d, fileName='field_ice_import_'//trim(fldname)//'.nc', &
timeslice=import_slice, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
call ESMF_FieldDestroy(lfield2d, noGarbage=.true., rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, &
line=__LINE__, &
file=__FILE__)) &
return ! bail out
endif
enddo
#endif
endif ! write_diagnostics
call State_getFldPtr(importState,'inst_temp_height_lowest',dataPtr_Tbot,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'inst_spec_humid_height_lowest',dataPtr_qbot,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'inst_zonal_wind_height_lowest',dataPtr_ubot,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'inst_merid_wind_height_lowest',dataPtr_vbot,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'inst_pres_height_lowest',dataPtr_pbot,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_down_lw_flx',dataPtr_mdlwfx,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_down_sw_vis_dir_flx',dataPtr_swvr,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_down_sw_vis_dif_flx',dataPtr_swvf,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_down_sw_ir_dir_flx',dataPtr_swir,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_down_sw_ir_dif_flx',dataPtr_swif,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_prec_rate',dataPtr_lprec,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_fprec_rate',dataPtr_fprec,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'sea_surface_temperature',dataPtr_sst,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'s_surf',dataPtr_sss,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'sea_lev',dataPtr_sl,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'sea_surface_slope_zonal',dataPtr_sssz,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'sea_surface_slope_merid',dataPtr_sssm,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'ocn_current_zonal',dataPtr_ocncz,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'ocn_current_merid',dataPtr_ocncm,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
! call State_getFldPtr(importState,'ocn_current_idir',dataPtr_ocnci,rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
! call State_getFldPtr(importState,'ocn_current_jdir',dataPtr_ocncj,rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'freezing_melting_potential',dataPtr_fmpot,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mixed_layer_depth',dataPtr_mld,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_zonal_moment_flx',dataPtr_mzmf,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'mean_merid_moment_flx',dataPtr_mmmf,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'inst_height_lowest',dataPtr_zlvl,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(importState,'air_density_height_lowest',dataPtr_rhoabot,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
do iblk = 1,nblocks
this_block = get_block(blocks_ice(iblk),iblk)
ilo = this_block%ilo
ihi = this_block%ihi
jlo = this_block%jlo
jhi = this_block%jhi
do j = jlo,jhi
do i = ilo,ihi
i1 = i - ilo + 1
j1 = j - jlo + 1
!rhoa (i,j,iblk) = dataPtr_ips(i1,j1,iblk)/(287.058*(1+0.608*dataPtr_ishh2m (i1,j1,iblk))*dataPtr_ith2m (i1,j1,iblk))
rhoa (i,j,iblk) = dataPtr_rhoabot(i1,j1,iblk) ! import directly from mediator
potT (i,j,iblk) = dataPtr_Tbot (i1,j1,iblk) * (100000./dataPtr_pbot(i1,j1,iblk))**0.286 ! Potential temperature (K)
Tair (i,j,iblk) = dataPtr_Tbot (i1,j1,iblk) ! near surface temp, maybe lowest level (K)
Qa (i,j,iblk) = dataPtr_qbot (i1,j1,iblk) ! near surface humidity, maybe lowest level (kg/kg)
zlvl (i,j,iblk) = dataPtr_zlvl (i1,j1,iblk) ! height of the lowest level (m)
flw (i,j,iblk) = dataPtr_mdlwfx (i1,j1,iblk) ! downwelling longwave flux
swvdr (i,j,iblk) = dataPtr_swvr (i1,j1,iblk) ! downwelling shortwave flux, vis dir
swvdf (i,j,iblk) = dataPtr_swvf (i1,j1,iblk) ! downwelling shortwave flux, vis dif
swidr (i,j,iblk) = dataPtr_swir (i1,j1,iblk) ! downwelling shortwave flux, nir dir
swidf (i,j,iblk) = dataPtr_swif (i1,j1,iblk) ! downwelling shortwave flux, nir dif
fsw(i,j,iblk) = swvdr(i,j,iblk)+swvdf(i,j,iblk)+swidr(i,j,iblk)+swidf(i,j,iblk)
frain (i,j,iblk) = dataPtr_lprec (i1,j1,iblk) ! flux of rain (liquid only)
fsnow (i,j,iblk) = dataPtr_fprec (i1,j1,iblk) ! flux of frozen precip ! fprec is all junk values from med, no src
sss (i,j,iblk) = dataPtr_sss (i1,j1,iblk) ! sea surface salinity (maybe for mushy layer)
! availability of ocean heat content (or freezing potential, use all if freezing) ! can potentially connect but contains junk from med, no src
sst (i,j,iblk) = dataPtr_sst (i1,j1,iblk) - 273.15 ! sea surface temp (may not be needed?)
!! Ice%bheat : bottom heat conducted up from ocean due to temperaure difference between sst and melting ice
!! real :: kmelt = 6e-5*4e6 ! ocean/ice heat flux constant
!! real, public, parameter :: TFREEZE = 273.16
!! real, parameter :: MU_TS = 0.054 ! relates freezing temp. to salinity
! frzmlt (i,j,iblk) = -6e-5*4e6*(sst (i,j,iblk) + 0.054*dataPtr_sss(i1,j1,iblk))
! if(dataPtr_fmpot (i1,j1,iblk) .gt. 0) frzmlt (i,j,iblk) = dataPtr_fmpot (i1,j1,iblk)/dt
! Fei, Let MOM5 take care of frazil calculation 10/5/15 (import dataPtr_fmpot in W/m^2)
frzmlt (i,j,iblk) = dataPtr_fmpot (i1,j1,iblk)
! hmix (i,j,iblk) = dataPtr_mld (i1,j1,iblk) ! ocean mixed layer depth (may not be needed?)
! ! --- rotate these vectors from east/north to i/j ---
!ue = dataPtr_mzmf(i1,j1,iblk)
!vn = dataPtr_mmmf(i1,j1,iblk)
!strax (i,j,iblk) = -(ue*cos(ANGLET(i,j,iblk)) + vn*sin(ANGLET(i,j,iblk))) ! lowest level wind stress or momentum flux (Pa)
!stray (i,j,iblk) = -(ue*cos(ANGLET(i,j,iblk)) - vn*sin(ANGLET(i,j,iblk))) ! lowest level wind stress or momentum flux (Pa)
ue = dataPtr_ocncz (i1,j1,iblk)
vn = dataPtr_ocncm (i1,j1,iblk)
uocn (i,j,iblk) = ue*cos(ANGLET(i,j,iblk)) + vn*sin(ANGLET(i,j,iblk)) ! ocean current
vocn (i,j,iblk) = -ue*sin(ANGLET(i,j,iblk)) + vn*cos(ANGLET(i,j,iblk)) ! ocean current
! uocn (i,j,iblk) = dataPtr_ocnci (i1,j1,iblk)
! vocn (i,j,iblk) = dataPtr_ocncj (i1,j1,iblk)
ue = dataPtr_ubot (i1,j1,iblk)
vn = dataPtr_vbot (i1,j1,iblk)
uatm (i,j,iblk) = ue*cos(ANGLET(i,j,iblk)) + vn*sin(ANGLET(i,j,iblk)) ! wind u component
vatm (i,j,iblk) = -ue*sin(ANGLET(i,j,iblk)) + vn*cos(ANGLET(i,j,iblk)) ! wind v component
wind (i,j,iblk) = sqrt(dataPtr_ubot (i1,j1,iblk)**2 + dataPtr_vbot (i1,j1,iblk)**2) ! wind speed
! zonal sea surface slope
sigma_r = 0.5*(dataPtr_sl(i1+1,j1+1,iblk)-dataPtr_sl(i1,j1+1,iblk)+ dataPtr_sl(i1+1,j1,iblk)-dataPtr_sl(i1,j1,iblk))/dxt(i,j,iblk)
sigma_l = 0.5*(dataPtr_sl(i1,j1+1,iblk)-dataPtr_sl(i1-1,j1+1,iblk)+ dataPtr_sl(i1,j1,iblk)-dataPtr_sl(i1-1,j1,iblk))/dxt(i,j,iblk)
sigma_c = 0.5*(sigma_r+sigma_l)
if ( (sigma_r * sigma_l) .GT. 0.0 ) then
ss_tltx(i,j,iblk) = sign ( min( 2.*min(abs(sigma_l),abs(sigma_r)), abs(sigma_c) ), sigma_c )
else
ss_tltx(i,j,iblk) = 0.0
endif
! meridional sea surface slope
sigma_r = 0.5*(dataPtr_sl(i1+1,j1+1,iblk)-dataPtr_sl(i1+1,j1,iblk)+ dataPtr_sl(i1,j1+1,iblk)-dataPtr_sl(i1,j1,iblk))/dyt(i,j,iblk)
sigma_l = 0.5*(dataPtr_sl(i1+1,j1,iblk)-dataPtr_sl(i1+1,j1-1,iblk)+ dataPtr_sl(i1,j1,iblk)-dataPtr_sl(i1,j1-1,iblk))/dyt(i,j,iblk)
sigma_c = 0.5*(sigma_r+sigma_l)
if ( (sigma_r * sigma_l) .GT. 0.0 ) then
ss_tlty(i,j,iblk) = sign ( min( 2.*min(abs(sigma_l),abs(sigma_r)), abs(sigma_c) ), sigma_c )
else
ss_tlty(i,j,iblk) = 0.0
endif
! rotate onto local basis vectors
ue = ss_tltx (i,j,iblk)
vn = ss_tlty (i,j,iblk)
ss_tltx(i,j,iblk) = ue*cos(ANGLET(i,j,iblk)) + vn*sin(ANGLET(i,j,iblk))
ss_tlty(i,j,iblk) = -ue*sin(ANGLET(i,j,iblk)) + vn*cos(ANGLET(i,j,iblk))
enddo
enddo
call t2ugrid_vector(ss_tltx)
call t2ugrid_vector(ss_tlty)
enddo
write(info,*) subname,' --- run phase 2 called --- '
call ESMF_LogWrite(info, ESMF_LOGMSG_INFO, rc=dbrc)
if(profile_memory) call ESMF_VMLogMemInfo("Before CICE_Run")
call CICE_Run
if(profile_memory) call ESMF_VMLogMemInfo("Afterr CICE_Run")
write(info,*) subname,' --- run phase 3 called --- '
call ESMF_LogWrite(info, ESMF_LOGMSG_INFO, rc=dbrc)
!---- local modifications to coupling fields -----
call State_getFldPtr(exportState,'ice_mask',dataPtr_mask,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'ice_fraction',dataPtr_ifrac,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'sea_ice_temperature',dataPtr_itemp,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'inst_ice_vis_dir_albedo',dataPtr_alvdr,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'inst_ice_vis_dif_albedo',dataPtr_alvdf,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'inst_ice_ir_dir_albedo',dataPtr_alidr,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'inst_ice_ir_dif_albedo',dataPtr_alidf,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'stress_on_air_ice_zonal',dataPtr_strairxT,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'stress_on_air_ice_merid',dataPtr_strairyT,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'stress_on_ocn_ice_zonal',dataPtr_strocnxT,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'stress_on_ocn_ice_merid',dataPtr_strocnyT,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
! call State_getFldPtr(exportState,'stress_on_ocn_ice_idir',dataPtr_strocni,rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
! call State_getFldPtr(exportState,'stress_on_ocn_ice_jdir',dataPtr_strocnj,rc=rc)
! if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'net_heat_flx_to_ocn',dataPtr_fhocn,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'mean_fresh_water_to_ocean_rate',dataPtr_fresh,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'mean_salt_rate',dataPtr_fsalt,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'mean_ice_volume',dataPtr_vice,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return
call State_getFldPtr(exportState,'mean_snow_volume',dataPtr_vsno,rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU,line=__LINE__,file=__FILE__)) return