-
Notifications
You must be signed in to change notification settings - Fork 12
/
cpl_forcing_handler.F90
1398 lines (1156 loc) · 52.8 KB
/
cpl_forcing_handler.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 cpl_forcing_handler
!
!==============================================================================
!
use ice_blocks
use ice_forcing
use ice_read_write
use ice_domain_size
use ice_domain, only : distrb_info, nblocks
use ice_flux !forcing data definition (Tair, Qa, uocn, etc.)
use ice_state, only : aice, trcr !ice concentration and tracers
use ice_gather_scatter !gather and scatter routines...
! use ice_constants, only : gravit, Tocnfrz
use ice_constants
use ice_grid, only : tmask
use ice_communicate, only : my_task, master_task
use ice_ocean, only : cprho
!20091118
use ice_shortwave, only : ocn_albedo2D
use ice_exit, only: abort_ice
use cpl_parameters
use cpl_netcdf_setup
use cpl_arrays_setup
use ice_calendar, only: dt
use ice_zbgc_shared, only: ocean_bio, flux_bio, nlt_bgc_N, nlt_bgc_NO, skl_bgc
implicit none
contains
!===============================================================================
subroutine nullify_i2o_fluxes()
iostrsu(:,:,:) = 0.0
iostrsv(:,:,:) = 0.0
iorain(:,:,:) = 0.0
iosnow(:,:,:) = 0.0
iostflx(:,:,:) = 0.0
iohtflx(:,:,:) = 0.0
ioswflx(:,:,:) = 0.0
ioqflux(:,:,:) = 0.0
ioshflx(:,:,:) = 0.0
iolwflx(:,:,:) = 0.0
iopress(:,:,:) = 0.0
iorunof(:,:,:) = 0.0
ioaice(:,:,:) = 0.0
iomelt(:,:,:) = 0.0
ioform(:,:,:) = 0.0
iownd(:,:,:) = 0.0
ionit(:,:,:) = 0.0
ioalg(:,:,:) = 0.0
iolicefw(:,:,:) = 0.0
iolicefh(:,:,:) = 0.0
end subroutine nullify_i2o_fluxes
!===============================================================================
subroutine tavg_i2o_fluxes
iostrsu(:,:,:) = iostrsu(:,:,:) + tiostrsu(:,:,:)*coef_ic
iostrsv(:,:,:) = iostrsv(:,:,:) + tiostrsv(:,:,:)*coef_ic
iorain (:,:,:) = iorain (:,:,:) + tiorain (:,:,:)*coef_ic
iosnow (:,:,:) = iosnow (:,:,:) + tiosnow (:,:,:)*coef_ic
iostflx(:,:,:) = iostflx(:,:,:) + tiostflx(:,:,:)*coef_ic
iohtflx(:,:,:) = iohtflx(:,:,:) + tiohtflx(:,:,:)*coef_ic
ioswflx(:,:,:) = ioswflx(:,:,:) + tioswflx(:,:,:)*coef_ic
ioqflux(:,:,:) = ioqflux(:,:,:) + tioqflux(:,:,:)*coef_ic
ioshflx(:,:,:) = ioshflx(:,:,:) + tioshflx(:,:,:)*coef_ic
iolwflx(:,:,:) = iolwflx(:,:,:) + tiolwflx(:,:,:)*coef_ic
iorunof(:,:,:) = iorunof(:,:,:) + tiorunof(:,:,:)*coef_ic
iopress(:,:,:) = iopress(:,:,:) + tiopress(:,:,:)*coef_ic
ioaice(:,:,:) = ioaice(:,:,:) + tioaice(:,:,:)*coef_ic
!!!
iomelt (:,:,:) = iomelt (:,:,:) + tiomelt (:,:,:)*coef_ic
ioform (:,:,:) = ioform (:,:,:) + tioform (:,:,:)*coef_ic
iownd (:,:,:) = iownd (:,:,:) + tiownd (:,:,:)*coef_ic
ionit (:,:,:) = ionit (:,:,:) + tionit (:,:,:)*coef_ic
ioalg (:,:,:) = ioalg (:,:,:) + tioalg (:,:,:)*coef_ic
iolicefw (:,:,:) = iolicefw (:,:,:) + tiolicefw (:,:,:)*coef_ic
iolicefh (:,:,:) = iolicefh (:,:,:) + tiolicefh (:,:,:)*coef_ic
return
end subroutine tavg_i2o_fluxes
!===============================================================================
subroutine get_core_runoff(fname, vname, nrec)
! read in the remapped core runoff data (S.Marsland) which will be used to replace
! the ncep2 runoff sent from matm via coupler
implicit none
character*(*), intent(in) :: fname, vname
integer(kind=int_kind), intent(in) :: nrec
logical :: dbug
integer(kind=int_kind) :: ncid
dbug = .true.
if ( file_exist(fname) ) then
call ice_open_nc(fname, ncid)
call ice_read_global_nc(ncid, nrec, vname, gwork, dbug)
call scatter_global(core_runoff, gwork, master_task, distrb_info, &
field_loc_center, field_type_scalar)
if (my_task == master_task) call ice_close_nc(ncid)
else
if (my_task == 0) print *, '(get_core_runoff) file doesnt exist: ', fname
stop 'CICE stopped: core runoff (remapped) file not found.'
endif
return
end subroutine get_core_runoff
!===============================================================================
subroutine get_time0_sstsss(fname, nmonth)
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind), intent(in) :: nmonth
logical :: dbug
integer(kind=int_kind) :: ncid
dbug = .true.
if ( file_exist(fname) ) then
call ice_open_nc(fname, ncid)
call ice_read_global_nc(ncid, nmonth, 'TEMP', gwork, dbug)
call scatter_global(sst, gwork, master_task, distrb_info, &
field_loc_center, field_type_scalar)
call ice_read_global_nc(ncid, nmonth, 'SALT', gwork, dbug)
call scatter_global(sss, gwork, master_task, distrb_info, &
field_loc_center, field_type_scalar)
if (my_task == master_task) call ice_close_nc(ncid)
else
if (my_task == 0) print *, '(get_time0_sstsss) file doesnt exist: ', fname
stop 'CICE stopped--initial SST and SSS ncfile not found.'
endif
return
end subroutine get_time0_sstsss
!===============================================================================
subroutine get_time0_sstsss_OLD(fname, nmonth)
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind), intent(in) :: nmonth
logical :: dbug
integer(kind=int_kind) :: ncid
dbug = .true.
!dbug = .false.
if ( file_exist(fname) ) then
call ice_open_nc(fname, ncid)
call ice_read_nc(ncid, nmonth, 'TEMP', sst, dbug)
call gather_global(gwork, sst, master_task, distrb_info)
call ice_read_nc(ncid, nmonth, 'SALT', sss, dbug)
call gather_global(gwork, sss, master_task, distrb_info)
if (my_task == master_task) call ice_close_nc(ncid)
else
if (my_task == 0) print*, '(get_time0_sstsss) file doesnt exist: ', fname
stop 'CICE stopped--initial SST and SSS ncfile not found.'
endif
return
end subroutine get_time0_sstsss_OLD
!===============================================================================
subroutine get_time0_o2i_fields(fname)
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind) :: ncid_o2i
logical :: dbug
dbug = .true.
if ( file_exist(fname) ) then
call ice_open_nc(fname, ncid_o2i)
call ice_read_nc(ncid_o2i, 1, 'sst_i', ssto, dbug, field_loc_center, field_type_scalar)
call ice_read_nc(ncid_o2i, 1, 'sss_i', ssso, dbug)
call ice_read_nc(ncid_o2i, 1, 'ssu_i', ssuo, dbug)
call ice_read_nc(ncid_o2i, 1, 'ssv_i', ssvo, dbug)
call ice_read_nc(ncid_o2i, 1, 'sslx_i', sslx, dbug)
call ice_read_nc(ncid_o2i, 1, 'ssly_i', ssly, dbug)
call ice_read_nc(ncid_o2i, 1, 'pfmice_i', pfmice, dbug)
if ( skl_bgc ) then
call ice_read_nc(ncid_o2i, 1, 'ssn_i', ssn, dbug)
call ice_read_nc(ncid_o2i, 1, 'ssalg_i', ssalg, dbug)
endif
if (my_task == master_task) call ice_close_nc(ncid_o2i)
else
print *, 'CICE: (get_time0_o2i_fields_old) not found file *** ',fname
stop 'CICE stopped -- Need time0 o2i data file.'
endif
return
end subroutine get_time0_o2i_fields
!===============================================================================
subroutine get_time0_i2o_fields(fname)
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind) :: ncid_i2o, i
if ( file_exist(fname) ) then
#if defined(DEBUG)
if (my_task == master_task) write(il_out,*) '(get_time0_i2o_fields) reading in i2o fields......'
#endif
call ice_open_nc(fname, ncid_i2o)
do i=1, num_fields_to_ocn
vwork(:, :, :) = 0.0
call ice_read_nc(ncid_i2o, 1, trim(fields_to_ocn(i)) , vwork, .true.)
if (trim(fields_to_ocn(i)) == 'strsu_io') then
iostrsu = vwork
elseif (trim(fields_to_ocn(i)) == 'strsv_io') then
iostrsv = vwork
elseif (trim(fields_to_ocn(i)) == 'rain_io') then
iorain = vwork
elseif (trim(fields_to_ocn(i)) == 'snow_io') then
iosnow = vwork
elseif (trim(fields_to_ocn(i)) == 'stflx_io') then
iostflx = vwork
elseif (trim(fields_to_ocn(i)) == 'htflx_io') then
iohtflx = vwork
elseif (trim(fields_to_ocn(i)) == 'swflx_io') then
ioswflx = vwork
elseif (trim(fields_to_ocn(i)) == 'qflux_io') then
ioqflux = vwork
elseif (trim(fields_to_ocn(i)) == 'shflx_io') then
ioshflx = vwork
elseif (trim(fields_to_ocn(i)) == 'lwflx_io') then
iolwflx = vwork
elseif (trim(fields_to_ocn(i)) == 'runof_io') then
iorunof = vwork
elseif (trim(fields_to_ocn(i)) == 'press_io') then
iopress = vwork
elseif (trim(fields_to_ocn(i)) == 'aice_io') then
ioaice = vwork
elseif (trim(fields_to_ocn(i)) == 'melt_io') then
iomelt = vwork
elseif (trim(fields_to_ocn(i)) == 'form_io') then
ioform = vwork
elseif (trim(fields_to_ocn(i)) == 'wnd10_io') then
iownd = vwork
elseif (trim(fields_to_ocn(i)) == 'nit_io') then
ionit = vwork
elseif (trim(fields_to_ocn(i)) == 'alg_io') then
ioalg = vwork
elseif (trim(fields_to_ocn(i)) == 'licefw_io') then
iolicefw = vwork
elseif (trim(fields_to_ocn(i)) == 'licefh_io') then
iolicefh = vwork
else
call abort_ice('ice: bad initialization array name '//trim(fields_to_ocn(i)))
endif
enddo
if (my_task == master_task) call ice_close_nc(ncid_i2o)
#if defined(DEBUG)
if (my_task == master_task) write(il_out,*) '(get_time0_i2o_fields) has read in 11 i2o fields.'
#endif
else
print *, 'CICE: (get_time0_i2o_fields_old) not found file *** ',fname
stop 'CICE stopped -- Need time0 i2o data file.'
endif
end subroutine get_time0_i2o_fields
!===============================================================================
subroutine get_u_star(fname)
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind) :: ncid
logical :: dbug
dbug = .true.
if ( file_exist(fname) ) then
#if defined(DEBUG)
if (my_task == master_task) write(il_out,*) '(get_u_star) reading in initial u_star field ......'
#endif
call ice_open_nc(fname, ncid)
call ice_read_nc(ncid, 1, 'u_star', vwork, dbug)
u_star0 = vwork
if (my_task == master_task) call ice_close_nc(ncid)
#if defined(DEBUG)
if (my_task == master_task) write(il_out,*) '(get_u_star) has read in u_star field.'
#endif
else
print *, 'CICE: (get_u_star) not found file *** ',fname
stop 'CICE stopped -- Need u_star restart datafile.'
endif
return
end subroutine get_u_star
!===============================================================================
subroutine get_sicemass(fname)
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind) :: ncid
logical :: dbug
dbug = .true.
if ( file_exist(fname) ) then
call ice_open_nc(fname, ncid)
call ice_read_nc(ncid, 1, 'sicemass', vwork, dbug)
sicemass = vwork
if (my_task == master_task) then
call ice_close_nc(ncid)
#if defined(DEBUG)
write(il_out,*) '(sicemass) reading in initial sicemass field ......'
write(il_out,*) '(get_sicemass) has read in sicemass field.'
#endif
endif
else
if (my_task == master_task) then
#if defined(DEBUG)
write(il_out,*) 'WARNING: (get_sicemass) not found file *** ',fname
write(il_out,*) 'CICE: (get_sicemass) not found file *** ',fname
write(il_out,*) 'CICE: Will estimate sicemass as iopress/(ioaice*gravit) *** '
#endif
endif
! below crashes for some reason when cold start
!where (ioaice>0.0)
! sicemass = iopress/(ioaice*gravit)
!elsewhere
! sicemass = 0.0
!end where
sicemass = 0.0
endif
return
end subroutine get_sicemass
!===============================================================================
subroutine newt_forcing_raw
implicit none
! --- from atm:
tair(:,:,:) = tair0(:,:,:)
fsw(:,:,:) = swflx0(:,:,:)
flw(:,:,:) = lwflx0(:,:,:)
uatm(:,:,:) = uwnd0(:,:,:)
vatm(:,:,:) = vwnd0(:,:,:)
qa(:,:,:) = qair0(:,:,:)
frain(:,:,:) = rain0(:,:,:)
fsnow(:,:,:) = snow0(:,:,:)
press(:,:,:) = press0(:,:,:)
runof(:,:,:) = runof0(:,:,:)
calv(:,:,:) = calv0(:,:,:)
! --- from ocean:
uocn(:,:,:) = ssuo(:,:,:)
vocn(:,:,:) = ssvo(:,:,:)
sst(:,:,:) = ssto(:,:,:)
!make sure SST is 'all right' K==>C
if (maxval(sst).gt.200) then
sst = sst - 273.15
endif
sss(:,:,:) = ssso(:,:,:)
ocean_bio(:,:,nlt_bgc_NO,:) = ssn(:,:,:)
ocean_bio(:,:,nlt_bgc_N,:) = ssalg(:,:,:)
ss_tltx(:,:,:) = sslx(:,:,:)
ss_tlty(:,:,:) = ssly(:,:,:)
!frzmlt(:,:,:) = pfmice(:,:,:) * frazil_factor / dt_cpl_io !W/m^2 as required by cice.
frzmlt(:,:,:) = pfmice(:,:,:)
!frazil_factor and unit conversion done in ocean model (16/07/2008)
!12/03/2008: set max melt htflux allowed from ocn, eg, meltlimit = -200 (W/m^2)
! meltlimit is read in from input_ice.nml
!20090320: set option 'limit_icemelt' in case no limit is needed when cice 'behaves'!
if (limit_icemelt) then
frzmlt(:,:,:) = max(frzmlt(:,:,:), meltlimit)
endif
end subroutine newt_forcing_raw
!===============================================================================
! output the last i2o forcing data, to be read in at the beginning of next run
! by cice and sent to ocn immediately
subroutine save_time0_i2o_fields(fname, nstep)
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind), intent(in) :: nstep
integer(kind=int_kind) :: ncid
integer(kind=int_kind) :: i, ll, ilout
if (my_task == 0) then
call create_ncfile(fname, ncid, nx_global, ny_global, ll=1, ilout=il_out)
call write_nc_1Dtime(real(nstep), 1, 'time', ncid)
do i=1, num_fields_to_ocn
call define_nc2D(ncid, fields_to_ocn(i), 2)
enddo
endif
do i=1, num_fields_to_ocn
if (trim(fields_to_ocn(i)) == 'strsu_io') then
vwork = iostrsu
elseif (trim(fields_to_ocn(i)) == 'strsv_io') then
vwork = iostrsv
elseif (trim(fields_to_ocn(i)) == 'rain_io') then
vwork = iorain
elseif (trim(fields_to_ocn(i)) == 'snow_io') then
vwork = iosnow
elseif (trim(fields_to_ocn(i)) == 'stflx_io') then
vwork = iostflx
elseif (trim(fields_to_ocn(i)) == 'htflx_io') then
vwork = iohtflx
elseif (trim(fields_to_ocn(i)) == 'swflx_io') then
vwork = ioswflx
elseif (trim(fields_to_ocn(i)) == 'qflux_io') then
vwork = ioqflux
elseif (trim(fields_to_ocn(i)) == 'shflx_io') then
vwork = ioshflx
elseif (trim(fields_to_ocn(i)) == 'lwflx_io') then
vwork = iolwflx
elseif (trim(fields_to_ocn(i)) == 'runof_io') then
vwork = iorunof
elseif (trim(fields_to_ocn(i)) == 'press_io') then
vwork = iopress
elseif (trim(fields_to_ocn(i)) == 'aice_io') then
vwork = ioaice
elseif (trim(fields_to_ocn(i)) == 'melt_io') then
vwork = iomelt
elseif (trim(fields_to_ocn(i)) == 'form_io') then
vwork = ioform
elseif (trim(fields_to_ocn(i)) == 'licefw_io') then
vwork = iolicefw
elseif (trim(fields_to_ocn(i)) == 'licefh_io') then
vwork = iolicefh
elseif (trim(fields_to_ocn(i)) == 'wnd10_io') then
vwork = iownd
elseif (trim(fields_to_ocn(i)) == 'nit_io') then
vwork = ionit
elseif (trim(fields_to_ocn(i)) == 'alg_io') then
vwork = ioalg
else
call abort_ice('ice: bad save array name '//trim(fields_to_ocn(i)))
endif
call gather_global(gwork, vwork, master_task, distrb_info)
if (my_task == 0) then
call write_nc2D(ncid, fields_to_ocn(i), gwork, 2, nx_global, ny_global, 1, ilout=il_out)
endif
enddo
if (my_task == 0) then
call ncheck(nf_close(ncid), 'save_time0_i2o_fields: nf_close')
endif
end subroutine save_time0_i2o_fields
!===============================================================================
subroutine save_u_star(fname, nstep)
! --- output the last u_star fields, to be read in at the beginning of next run
! by cice for roughness calculation if the gfdl surface flux scheme is used
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind), intent(in) :: nstep
integer(kind=int_kind) :: ncid
integer(kind=int_kind) :: ll, ilout
if (my_task == 0) then
call create_ncfile(fname, ncid, nx_global, ny_global, ll=1, ilout=il_out)
call write_nc_1Dtime(real(nstep), 1, 'time', ncid)
endif
vwork = u_star0
call gather_global(gwork, vwork, master_task, distrb_info)
if (my_task == 0) then
call write_nc2D(ncid, 'u_star', gwork, 2, nx_global, ny_global, 1, ilout=il_out)
call ncheck(nf_close(ncid), 'save_u_star: nf_close')
endif
return
end subroutine save_u_star
!===============================================================================
subroutine save_sicemass(fname, nstep)
! --- output the last sicemass field, to be read in at the beginning of next run
! by cice for iopress calculation
implicit none
character*(*), intent(in) :: fname
integer(kind=int_kind), intent(in) :: nstep
integer(kind=int_kind) :: ncid
integer(kind=int_kind) :: ll, ilout
if (my_task == 0) then
call create_ncfile(fname, ncid, nx_global, ny_global, ll=1, ilout=il_out)
call write_nc_1Dtime(real(nstep), 1, 'time', ncid)
endif
vwork = sicemass
call gather_global(gwork, vwork, master_task, distrb_info)
if (my_task == 0) then
call write_nc2D(ncid, 'sicemass', gwork, 2, nx_global, ny_global, 1, ilout=il_out)
call ncheck(nf_close(ncid), 'save_sicemass: nf_close')
endif
return
end subroutine save_sicemass
!===============================================================================
subroutine get_i2o_fluxes
use ice_atmo, only : atmo_boundary_layer, atmbndy, atmo_boundary_const
implicit none
real (kind=dbl_kind) :: &
dtice ! time step
integer(kind=int_kind) :: &
i, j , & ! horizontal indices
iblk !, & ! block index
!ilo,ihi,jlo,jhi ! beginning and end of physical domain
!ars599: 26032014 new code add in (CODE:Cdn)
real (kind=dbl_kind), dimension(nx_block,ny_block) :: &
delt ,& ! potential temperature difference (K)
delq ,& ! specific humidity difference (kg/kg)
shcoef ,& ! transfer coefficient for sensible heat
lhcoef ,& ! transfer coefficient for latent heat
Cdn_atm ,& ! neutral drag coefficient
Cdn_atm_ocn_n ! ratio drag coeff / neutral drag coeff
!
real (kind=dbl_kind), dimension(nx_block,ny_block,max_blocks) :: &
sst_B, frzmlt_B
!B: we don't want CICE to update sst and frzmlt, which suppose to be from
! ocn model. *** May need revisit this part... and, rethink how the ocn
! model 'top layer' (with free surface) changes its properties upon
! receiving the i2o forcing... e.g., the Heatfluxes only works on the
! top layer no matter how thin it is? -- it could ca use instaneous
! extreme SST for some points, I assume...... Feb, 2008 ***
real (kind=dbl_kind), dimension(nx_block,ny_block,max_blocks) :: &
swabs_ocn, pice
!
integer(kind=int_kind) :: &
ij ! combined ij index
integer(kind=int_kind), save :: &
icells ! number of ocean cells
integer(kind=int_kind), dimension(nx_block*ny_block), save :: &
indxi, indxj ! compressed indices for ocean cells
!type (block) :: &
! this_block ! block information for current block
!
dtice = dt
swabs_ocn = 0.0
pice = 0.0
!initialization of array is critical -- otherwise it would be assigned HUGE value
!and lead to '* 253 Invalid operation ' (Fatal) error whenever it is involved in
!any operation such as a simple maxval(swabs_ocn), or even var = pice + 0.0 ....!
do iblk = 1, nblocks
!-----------------------------------------------------------------
! Identify ocean cells.
! Set fluxes to zero in land cells.
!-----------------------------------------------------------------
icells = 0
do j = 1, ny_block
do i = 1, nx_block
if (tmask(i,j,iblk)) then
icells = icells + 1
indxi(icells) = i
indxj(icells) = j
else
sst (i,j,iblk) = c0
frzmlt (i,j,iblk) = c0
flwout_ocn(i,j,iblk) = c0
fsens_ocn (i,j,iblk) = c0
flat_ocn (i,j,iblk) = c0
evap_ocn (i,j,iblk) = c0
endif
enddo ! i
enddo ! j
!-----------------------------------------------------------------
! Compute boundary layer quantities
!-----------------------------------------------------------------
if (trim(atmbndy) == 'constant') then
!ars599: 26032014 new code add in (CODE:Cdn)
call atmo_boundary_const (nx_block, ny_block, &
'ice', icells, &
indxi, indxj, &
uatm (:,:,iblk), &
vatm (:,:,iblk), &
wind (:,:,iblk), &
rhoa (:,:,iblk), &
strairx_ocn(:,:,iblk), &
strairy_ocn(:,:,iblk), &
sst (:,:,iblk), &
potT (:,:,iblk), &
Qa (:,:,iblk), &
delt (:,:), &
delq (:,:), &
lhcoef (:,:), &
shcoef (:,:), &
Cdn_atm (:,:))
else ! default
call atmo_boundary_layer (nx_block, ny_block, &
'ocn', icells, &
indxi, indxj, &
sst (:,:,iblk), &
potT (:,:,iblk), &
uatm (:,:,iblk), &
vatm (:,:,iblk), &
wind (:,:,iblk), &
zlvl (:,:,iblk), &
Qa (:,:,iblk), &
rhoa (:,:,iblk), &
strairx_ocn(:,:,iblk), &
strairy_ocn(:,:,iblk), &
Tref_ocn (:,:,iblk), &
Qref_ocn (:,:,iblk), &
delt (:,:), &
delq (:,:), &
lhcoef (:,:), &
shcoef (:,:), &
Cdn_atm (:,:), &
Cdn_atm_ocn_n (:,:))
!ars599: 26032014 new code add in (CODE:Cdn)
endif
!-----------------------------------------------------------------
! Ocean albedo
! For now, assume albedo = albocn in each spectral band.
!-----------------------------------------------------------------
! alvdr_ocn(:,:,iblk) = albocn
! alidr_ocn(:,:,iblk) = albocn
! alvdf_ocn(:,:,iblk) = albocn
! alidf_ocn(:,:,iblk) = albocn
!B: 20091118
alvdr_ocn(:,:,iblk) = ocn_albedo2D(:,:,iblk)
alidr_ocn(:,:,iblk) = ocn_albedo2D(:,:,iblk)
alvdf_ocn(:,:,iblk) = ocn_albedo2D(:,:,iblk)
alidf_ocn(:,:,iblk) = ocn_albedo2D(:,:,iblk)
!-----------------------------------------------------------------
! Compute ocean fluxes *BUT NOT update SST (let ocn model do it!)*
! (see comments above)
!-----------------------------------------------------------------
sst_B (:,:,iblk) = sst (:,:,iblk)
frzmlt_B(:,:,iblk) = frzmlt(:,:,iblk) !actually no need to do so!
call ocean_energy_budget_B (nx_block, ny_block, &
dtice, icells, &
indxi, indxj, &
delt (:,:), &
delq (:,:), &
lhcoef (:,:), &
shcoef (:,:), &
aice (:,:,iblk), &
Tf (:,:,iblk), &
swvdr (:,:,iblk), &
swidr (:,:,iblk), &
swvdf (:,:,iblk), &
swidf (:,:,iblk), &
alvdr_ocn (:,:,iblk), &
alidr_ocn (:,:,iblk), &
alvdf_ocn (:,:,iblk), &
alidf_ocn (:,:,iblk), &
flw (:,:,iblk), &
qdp (:,:,iblk), &
hmix (:,:,iblk), &
flwout_ocn(:,:,iblk), &
fsens_ocn (:,:,iblk), &
flat_ocn (:,:,iblk), &
evap_ocn (:,:,iblk), &
sst_B (:,:,iblk), &
frzmlt_B (:,:,iblk), &
swabs_ocn (:,:,iblk))
enddo ! iblk
!tioqflux = flat_ocn
!tioshflx = fsens_ocn
!tiolwflx = flw + flwout_ocn !net lw flux (down) into ocean
!tioswflx = swabs_ocn
if (gfdl_surface_flux) then
!!call gather_global(gwork, u_star0, master_task, distrb_info)
!!if (my_task == master_task) write(52,'(10e12.4)')gwork
!overwrite the surface fluxes (sh, lh, lw and windstress) with the GFDL calculation
call gfdl_ocean_fluxes ( fsens_ocn, flat_ocn, flwout_ocn, strairx_ocn, strairy_ocn )
endif
tioqflux = flat_ocn
tioshflx = fsens_ocn
tiolwflx = flw + flwout_ocn !net lw flux (down) into ocean
tioswflx = swabs_ocn
! === double checked with Siobhan the following mergeing under sea ice: ===
! Note: for those i2o fluxes which are already weighted with ice catagory
! fractions in routine 'merge_fluxes', they must NOT be weighted here
! AGAIN using the 'total' ice fraction aice! 30/07/07
! (eg, using 'fresh' instead of 'aice * fresh',
! 'fswthru' instead of 'aice * fswthru' and so on.
! However, ice-ocean stresses are different: they are calculated (see
! ice_flux_in.F for details) with no aice(n) weighing. they thus must be
! wighted by " * aice " here before being passed to ocean model. 08/08/07
! -----------------------------------------------------------------------------
! 1) air- or ice-sea interface stress x
! tiostrsu(:,:,:) = strairx_ocn(:,:,:) * (1. - aice(:,:,:)) + strocnxT(:,:,:) * aice(:,:,:)
! 2) air- or ice-sea interface stress y
! tiostrsv(:,:,:) = strairy_ocn(:,:,:) * (1. - aice(:,:,:)) + strocnyT(:,:,:) * aice(:,:,:)
!
!!! *** BUG found here: strocnx/yT MUST change sign to '-'! 11/03/2009 *** !!!
!
tiostrsu(:,:,:) = strairx_ocn(:,:,:) * (1. - aice(:,:,:)) - strocnxT(:,:,:) * aice(:,:,:)
tiostrsv(:,:,:) = strairy_ocn(:,:,:) * (1. - aice(:,:,:)) - strocnyT(:,:,:) * aice(:,:,:)
! 3) rainfall to ocean
tiorain(:,:,:) = frain(:,:,:) * (1. - aice(:,:,:))
!!! if (ice_fwflux) tiorain(:,:,:) = tiorain(:,:,:) + fresh(:,:,:) !!!CH confirmed--ice_fwflux=.t.!!!
!!!
!!! Now ice_fwflux (melt/form) is sent to ocn seperately (see below)
!!!
! 4) snowfall to ocean
tiosnow(:,:,:) = fsnow(:,:,:) * (1. - aice(:,:,:))
! 5) salt flux to ocean
tiostflx(:,:,:) = fsalt(:,:,:)
! 6) ice melting heatflux into ocean (fhnet renamed to fhocn)
tiohtflx(:,:,:) = fhocn(:,:,:)
! 7) short wave radiation into ocean
tioswflx(:,:,:) = tioswflx(:,:,:) * (1. - aice(:,:,:)) + fswthru(:,:,:)
! 8) latent heat flux:
! *** Note sign changed here, to become positive out of ocean as required by mom4!
tioqflux(:,:,:) = - tioqflux(:,:,:) * (1. - aice(:,:,:))
! 9) sensible heat flux:
! *** Note sign changed here, to become positive out of ocean as required by mom4!
tioshflx(:,:,:) = - tioshflx(:,:,:) * (1. - aice(:,:,:))
!109)long wave radiation
tiolwflx(:,:,:) = tiolwflx(:,:,:) * (1. - aice(:,:,:))
!11)runoff: relocated onto coastal grid points (pre-processed by Steve Phipps)
tiorunof(:,:,:) = runof(:,:,:) + calv(:,:,:)
tiolicefw(:,:,:) = 0.0
tiolicefh(:,:,:) = 0.0
!12)pressure
! if (my_task == 0) write(il_out,*)'size of pice, ',&
! size(pice(:,1,1)), size(pice(1,:,1)), size(pice(1,1,:))
! if (my_task == 0) write(il_out,*)'size of sicemass: ',&
! size(sicemass(:,1,1)),size(sicemass(1,:,1)),size(sicemass(1,1,:))
pice(:,:,:) = gravit * sicemass(:,:,:) !sicemass = rho_ice x hi + rho_snow x hs (in m)
!----------------------------------------------------------------------------
! Should we set limit to the ovelying ice pressure as suggested in MOM4 code?
!(see ocean_sbc.F90) if yes, we may use following
!pice(i,j) = min(pice(i,j), gravit*rhow*max_ice_thickness)
! (note rhow = 1026 kg/m^3 here, but mom4 instead uses rho0 = 1035 kg/m^3)
! No, let mom4 handle it (see ocean_sbc.F90)
!----------------------------------------------------------------------------
tiopress = press - 1.0e5 !as GFDL SIS, we use patm anormaly!
if (ice_pressure_on) then
!sjm 20101118
! tiopress(:,:,:) = press(:,:,:) + pice(:,:,:) * aice(:,:,:)
tiopress(:,:,:) = pice(:,:,:) * aice(:,:,:)
endif
!----------------------------------------------------------------------------
!as GFDL SIS, we use patm anormaly and then add in the ice/snow pressure!
!29/11/2007
!----------------------------------------------------------------------------
!13) ice coverage
tioaice(:,:,:) = aice(:,:,:)
!--------------------------
!14) ice melt waterflux:
tiomelt(:,:,:) = max(0.0,fresh(:,:,:))
!15) ice form waterflux:
tioform(:,:,:) = min(0.0,fresh(:,:,:))
!16 10m wind. To mask or not to mask?
tiownd(:,:,:) = sqrt(uatm(:,:,:)**2 + vatm(:,:,:)**2)
!17 ice-water nitrate flux (mmol/m2/s)
tionit(:,:,:) = flux_bio(:,:,nlt_bgc_NO,:)
!18 ice-to-ocean algal flux (mmol/m2/2)
tioalg(:,:,:) = flux_bio(:,:,nlt_bgc_N,:)
return
end subroutine get_i2o_fluxes
!=======================================================================
subroutine ocean_energy_budget_B ( nx_block, ny_block, &
dtice, icells, &
indxi, indxj, &
delt, delq, &
lhcoef, shcoef, &
Baice, Tf, &
swvdr, swidr, &
swvdf, swidf, &
alvdr_ocn, alidr_ocn, &
alvdf_ocn, alidf_ocn, &
Bflw, &
qdp, hmix, &
flwout_ocn, fsens_ocn, &
flat_ocn, evap_ocn, &
sst_B, frzmlt_B, &
swabs_ocn )
! Compute ocean energy budget.
!
! HISTORY: adapted from ocean_energy_budget, Feb 2008 by D. Bi for i2o_fluxes.
!
! !INPUT/OUTPUT PARAMETERS:
!
integer(kind=int_kind), intent(in) :: &
nx_block, ny_block, & ! block dimensions
icells ! number of cells that require atmo fluxes
integer(kind=int_kind), dimension(nx_block*ny_block), &
intent(in) :: &
indxi, indxj ! compressed i and j indices
real (kind=dbl_kind), intent(in) :: &
dtice ! time step
real (kind=dbl_kind), dimension(nx_block,ny_block), &
intent(in) :: &
delt , & ! potential T difference (K)
delq , & ! humidity difference (kg/kg)
shcoef , & ! transfer coefficient for sensible heat
lhcoef , & ! transfer coefficient for latent heat
Baice , & ! fractional ice area
Tf , & ! ocean freezing temperature (C)
swvdr , & ! incoming shortwave, visible direct (W/m^2)
swidr , & ! incoming shortwave, near IR direct (W/m^2)
swvdf , & ! incoming shortwave, visible diff use (W/m^2)
swidf , & ! incoming shortwave, near IR diff use (W/m^2)
alvdr_ocn , & ! visible albedo, direct (fraction)
alidr_ocn , & ! near-ir albedo, direct (fraction)
alvdf_ocn , & ! visible albedo, diff use (fraction)
alidf_ocn , & ! near-ir albedo, diff use (fraction)
Bflw , & ! incoming longwave (W/m^2)
hmix ! ocean mixed layer depth (m)
real (kind=dbl_kind), dimension(nx_block,ny_block), &
intent(inout) :: &
sst_B , & ! sea surface temperature (C)
qdp , & ! deep ocean heat flux (W/m^2)
frzmlt_B , & ! freeze-melt potential (W/m^2)
fsens_ocn , & ! sensible heat flux (W/m^2)
flat_ocn , & ! latent heat flux (W/m^2)
flwout_ocn , & ! outgoing longwave (W/m^2)
evap_ocn ! evaporative vapor flux (kg/m^2/s)
real (kind=dbl_kind), dimension(nx_block,ny_block), intent(out) :: &
swabs_ocn
real (kind=dbl_kind) :: &
TsfK , & ! surface temperature (K)
swabs ! surface absorbed shortwave heat flux (W/m^2)
real (kind=dbl_kind), parameter :: &
frzmlt_max = c1000 ! max magnitude of frzmlt (W/m^2)
integer(kind=int_kind) :: i, j, ij
do ij = 1, icells
i = indxi(ij)
j = indxj(ij)
! shortwave radiative flux
swabs = (c1-alvdr_ocn(i,j)) * swvdr(i,j) &
+ (c1-alidr_ocn(i,j)) * swidr(i,j) &
+ (c1-alvdf_ocn(i,j)) * swvdf(i,j) &
+ (c1-alidf_ocn(i,j)) * swidf(i,j)
swabs_ocn(i,j) = swabs
! ocean surface temperature in Kelvin
TsfK = sst_B(i,j) + Tffresh
! longwave radiative flux
flwout_ocn(i,j) = -stefan_boltzmann * TsfK**4
! downward latent and sensible heat fluxes
fsens_ocn(i,j) = shcoef(i,j) * delt(i,j)
flat_ocn (i,j) = lhcoef(i,j) * delq(i,j)
evap_ocn (i,j) = -flat_ocn(i,j) / Lvap
!B: sst and frzmlt remain unchanged for a coupling period, thus the
! following part is not needed:
if (.false.) then
! Compute sst change due to exchange with atm/ice above
! Note: fhnet, fswthru are added in ice_therm_vertical.F
sst_B(i,j) = sst_B(i,j) + &
(fsens_ocn(i,j) + flat_ocn(i,j) + flwout_ocn(i,j) &
+ Bflw(i,j) + swabs) * (c1-Baice(i,j)) * dtice &
/ (cprho*hmix(i,j))
! adjust qdp if cooling of mixed layer would occur when sst <= Tf
if (sst_B(i,j) <= Tf(i,j) .and. qdp(i,j) > c0) qdp(i,j) = c0
! computed T change due to exchange with deep layers:
sst_B(i,j) = sst_B(i,j) - qdp(i,j)*dtice/(cprho*hmix(i,j))
! compute potential to freeze or melt ice
frzmlt_B(i,j) = (Tf(i,j)-sst_B(i,j))*cprho*hmix(i,j)/dtice
frzmlt_B(i,j) = min(max(frzmlt_B(i,j),-frzmlt_max),frzmlt_max)
! if sst is below freezing, reset sst to Tf
if (sst_B(i,j) <= Tf(i,j)) sst_B(i,j) = Tf(i,j)
endif
enddo ! ij
return
end subroutine ocean_energy_budget_B
!=======================================================================
subroutine gfdl_ocean_fluxes(sh,lh,lwo,taox,taoy)
use ice_fileunits
use ice_exit, only : abort_ice
use ocean_rough_mod
use surface_flux_mod
implicit none
! real (kind=dbl_kind), intent(out), dimension(:,:,:) :: sh,lh,lwo,taox,taoy
real (kind=dbl_kind), intent(out), dimension(nx_block, ny_block, nblocks) :: &
sh,lh,lwo,taox,taoy
!real, dimension(size(sh(:,1,1)),size(sh(1,:,1))) :: &
real, dimension(nx_block, ny_block) :: &
t_atm, q_atm_in, u_atm, v_atm, p_atm, z_atm, &
p_surf, t_surf, t_ca, q_surf, &
u_surf, v_surf, &
rough_mom, rough_heat, rough_moist, rough_scale, gust, &
flux_t, flux_q, flux_r, flux_u, flux_v, &
cd_m, cd_t, cd_q, w_atm, u_star, b_star, q_star, &
dhdt_surf, dedt_surf, dedq_surf, drdt_surf, &
dhdt_atm, dedq_atm, dtaudu_atm, dtaudv_atm
real :: dt_xx = 0.0 !not used!
! logical, dimension(size(sh(:,1,1)),size(sh(1,:,1))) :: land, seawater, avail
logical, dimension(nx_block, ny_block) :: land, seawater, avail
!real, dimension(size(sh(:,1,1)),size(sh(1,:,1))) :: &
real, dimension(nx_block, ny_block) :: tv_atm, d_atm
real :: gust0 = 1.0
integer :: iblk
real, parameter :: d622 = rdgas/rvgas
real, parameter :: d378 = 1.-d622
real :: d608 = d378/d622
z_atm = 10.0 !zlvl
t_ca = 222.222 !not really used (below we set avail = seawater)