-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatm_land_ice_flux_exchange.F90
3855 lines (3417 loc) · 179 KB
/
atm_land_ice_flux_exchange.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
!***********************************************************************
!* GNU Lesser General Public License
!*
!* This file is part of the GFDL Flexible Modeling System (FMS) Coupler.
!*
!* FMS Coupler is free software: you can redistribute it and/or modify
!* it under the terms of the GNU Lesser General Public License as
!* published by the Free Software Foundation, either version 3 of the
!* License, or (at your option) any later version.
!*
!* FMS Coupler is distributed in the hope that it will be useful, but
!* WITHOUT ANY WARRANTY; without even the implied warranty of
!* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
!* General Public License for more details.
!*
!* You should have received a copy of the GNU Lesser General Public
!* License along with FMS Coupler.
!* If not, see <http://www.gnu.org/licenses/>.
!***********************************************************************
module atm_land_ice_flux_exchange_mod
use mpp_mod, only: mpp_npes, mpp_pe, mpp_root_pe, mpp_error, stderr, &
stdout, stdlog, FATAL, WARNING, NOTE, mpp_set_current_pelist, &
mpp_clock_id, mpp_clock_begin, mpp_clock_end, mpp_sum, mpp_max, &
CLOCK_COMPONENT, CLOCK_SUBCOMPONENT, CLOCK_ROUTINE, lowercase, &
input_nml_file
use mpp_domains_mod, only: mpp_get_compute_domain, mpp_get_compute_domains, &
mpp_global_sum, mpp_redistribute, operator(.EQ.)
use mpp_domains_mod, only: mpp_get_global_domain, mpp_get_data_domain
use mpp_domains_mod, only: mpp_set_global_domain, mpp_set_data_domain, mpp_set_compute_domain
use mpp_domains_mod, only: mpp_deallocate_domain, mpp_copy_domain, domain2d, mpp_compute_extent
use mpp_io_mod, only: mpp_close, mpp_open, MPP_MULTI, MPP_SINGLE, MPP_OVERWR
use atmos_model_mod, only: atmos_data_type, land_ice_atmos_boundary_type
use ocean_model_mod, only: ocean_public_type, ice_ocean_boundary_type
use ocean_model_mod, only: ocean_state_type
use ice_model_mod, only: ice_data_type, land_ice_boundary_type, ocean_ice_boundary_type
use ice_model_mod, only: atmos_ice_boundary_type, Ice_stock_pe
use ice_model_mod, only: update_ice_atm_deposition_flux
use land_model_mod, only: land_data_type, atmos_land_boundary_type
#ifndef _USE_LEGACY_LAND_
use land_model_mod, only: set_default_diag_filter, register_tiled_diag_field
use land_model_mod, only: send_tile_data, dump_tile_diag_fields
#else
use diag_manager_mod, only: register_tiled_diag_field=>register_diag_field
#endif
use surface_flux_mod, only: surface_flux, surface_flux_init
use monin_obukhov_mod, only: mo_profile
use xgrid_mod, only: xmap_type, setup_xmap, set_frac_area, put_to_xgrid, &
get_from_xgrid, xgrid_count, some, conservation_check, xgrid_init, &
stock_integrate_2d, stock_move, stock_print
#ifndef _USE_LEGACY_LAND_
use xgrid_mod, only: get_from_xgrid_land => get_from_xgrid_ug
use xgrid_mod, only: put_to_xgrid_land => put_to_xgrid_ug
use xgrid_mod, only: set_frac_area_land => set_frac_area_ug
use xgrid_mod, only: stock_move_land => stock_move_ug
use data_override_mod, only: data_override_land => data_override_ug
#else
use xgrid_mod, only: get_from_xgrid_land => get_from_xgrid
use xgrid_mod, only: put_to_xgrid_land => put_to_xgrid
use xgrid_mod, only: set_frac_area_land => set_frac_area
use xgrid_mod, only: stock_move_land => stock_move
use data_override_mod, only: data_override_land => data_override
#endif
use diag_integral_mod, only: diag_integral_field_init, sum_diag_integral_field
use diag_manager_mod, only: register_diag_field, register_static_field, send_data, &
send_tile_averaged_data, diag_field_add_attribute, &
get_diag_field_id, DIAG_FIELD_NOT_FOUND
use diag_data_mod, only: CMOR_MISSING_VALUE, null_axis_id
use time_manager_mod, only: time_type
use sat_vapor_pres_mod, only: compute_qs, sat_vapor_pres_init
use constants_mod, only: rdgas, rvgas, cp_air, stefan, WTMAIR, HLV, HLF, Radius, &
PI, CP_OCEAN, WTMCO2, WTMC, EPSLN, GRAV
use fms_mod, only: clock_flag_default, check_nml_error, error_mesg
use fms_mod, only: open_namelist_file, write_version_number
use data_override_mod, only: data_override
use coupler_types_mod, only: coupler_1d_bc_type, coupler_type_copy, ind_psurf, ind_u10, ind_flux, ind_flux0, ind_out1, ind_out2, ind_ustar, ind_hs !liao ! bgr_prustogi
use coupler_types_mod, only: coupler_type_initialized, coupler_type_spawn
use coupler_types_mod, only: coupler_type_send_data, coupler_type_set_diags
use coupler_types_mod, only: coupler_type_data_override
use ocean_model_mod, only: ocean_model_init_sfc, ocean_model_flux_init, ocean_model_data_get
#ifdef use_AM3_physics
use atmos_tracer_driver_mod, only: atmos_tracer_flux_init
#else
use atmos_tracer_driver_mod, only: atmos_tracer_flux_init, &
atmos_tracer_has_surf_setl_flux, get_atmos_tracer_surf_setl_flux
use atmos_tracer_driver_mod, only: atmos_tracer_driver_gather_data_down
use atmos_cmip_diag_mod, only: register_cmip_diag_field_2d
use atmos_global_diag_mod, only: register_global_diag_field, &
get_global_diag_field_id, &
send_global_diag
#ifndef _USE_LEGACY_LAND_
use land_model_mod, only: send_global_land_diag
#endif
#endif
use field_manager_mod, only: MODEL_ATMOS, MODEL_LAND, MODEL_ICE, parse
use tracer_manager_mod, only: get_tracer_index, query_method
use tracer_manager_mod, only: get_tracer_names, get_number_tracers, NO_TRACER
use stock_constants_mod, only: NELEMS, ISTOCK_WATER, ISTOCK_HEAT, ISTOCK_SALT
use stock_constants_mod, only: ISTOCK_SIDE, ISTOCK_TOP, ISTOCK_BOTTOM , STOCK_UNITS, STOCK_NAMES
use stock_constants_mod, only: stocks_file, stocks_report, stocks_report_init
use stock_constants_mod, only: Atm_stock, Ocn_stock, Lnd_stock, Ice_stock
use land_model_mod, only: Lnd_stock_pe
use ocean_model_mod, only: Ocean_stock_pe
use atmos_model_mod, only: Atm_stock_pe
use atmos_ocean_fluxes_mod, only: atmos_ocean_fluxes_init
use atmos_ocean_fluxes_calc_mod, only: atmos_ocean_fluxes_calc
use atmos_ocean_dep_fluxes_calc_mod, only: atmos_ocean_dep_fluxes_calc
#ifdef SCM
! option to override various surface boundary conditions for SCM
use scm_forc_mod, only: do_specified_flux, scm_surface_flux, &
do_specified_tskin, TSKIN, &
do_specified_albedo, ALBEDO_OBS, &
do_specified_rough_leng, ROUGH_MOM, ROUGH_HEAT, &
do_specified_land
#endif
implicit none
include 'netcdf.inc'
private
public :: atm_land_ice_flux_exchange_init, &
sfc_boundary_layer, &
generate_sfc_xgrid, &
flux_down_from_atmos, &
flux_up_to_atmos, &
flux_atmos_to_ocean, &
flux_ex_arrays_dealloc,&
atm_stock_integrate, &
send_ice_mask_sic
!-----------------------------------------------------------------------
character(len=128) :: version = '$Id$'
character(len=128) :: tag = '$Name$'
!-----------------------------------------------------------------------
!---- exchange grid maps -----
type(xmap_type), save :: xmap_sfc
integer :: n_xgrid_sfc=0
!-----------------------------------------------------------------------
!-------- namelist (for diagnostics) ------
character(len=4), parameter :: mod_name = 'flux'
integer :: id_drag_moist, id_drag_heat, id_drag_mom, &
id_rough_moist, id_rough_heat, id_rough_mom, &
id_land_mask, id_ice_mask, &
id_u_star, id_b_star, id_q_star, id_u_flux, id_v_flux, &
id_t_surf, id_t_flux, id_r_flux, id_q_flux, id_slp, &
id_t_atm, id_u_atm, id_v_atm, id_wind, &
id_t_ref, id_rh_ref, id_u_ref, id_v_ref, id_wind_ref, &
id_del_h, id_del_m, id_del_q, id_rough_scale, &
id_t_ca, id_q_surf, id_q_atm, id_z_atm, id_p_atm, id_gust, &
id_t_ref_land, id_rh_ref_land, id_u_ref_land, id_v_ref_land, &
id_q_ref, id_q_ref_land, id_q_flux_land, id_rh_ref_cmip, &
id_hussLut_land, id_tasLut_land, id_t_flux_land
integer :: id_co2_atm_dvmr, id_co2_surf_dvmr
! 2017/08/15 jgj added
integer :: id_co2_bot, id_co2_flux_pcair_atm, id_o2_flux_pcair_atm
integer, allocatable :: id_tr_atm(:), id_tr_surf(:), id_tr_flux(:), id_tr_mol_flux(:)
integer, allocatable :: id_tr_mol_flux0(:), id_tr_out1(:), id_tr_out2(:) !f1p !bgr_prustogi
integer, allocatable :: id_tr_flux_land(:), id_tr_mol_flux_land(:)
! id's for cmip specific fields
integer :: id_tas, id_uas, id_vas, id_ts, id_psl, &
id_sfcWind, id_tauu, id_tauv, &
id_hurs, id_huss, id_evspsbl, id_hfls, id_hfss, &
id_rhs, id_sftlf, id_tos, id_sic, id_tslsi, &
id_height2m, id_height10m
! globally averaged diagnostics
integer :: id_evspsbl_g, id_ts_g, id_tas_g, id_tasl_g, id_hfss_g, id_hfls_g, id_rls_g
logical :: first_static = .true.
logical :: do_init = .true.
integer :: remap_method = 1
real, parameter :: bound_tol = 1e-7
real, parameter :: d622 = rdgas/rvgas
real, parameter :: d378 = 1.0-d622
real, parameter :: tfreeze = 273.15
real, allocatable, dimension(:,:) :: frac_precip
!--- the following is from flux_exchange_nml
real :: z_ref_heat = 2. !< Reference height (meters) for temperature and relative humidity diagnostics (t_ref, rh_ref, del_h, del_q)
real :: z_ref_mom = 10. !< Reference height (meters) for mementum diagnostics (u_ref, v_ref, del_m)
logical :: ex_u_star_smooth_bug = .false. !< By default, the global exchange grid \c u_star will not be interpolated
!! from atmospheric grid, this is different from Jakarta behavior and will
!! change answers. So to preserve Jakarta behavior and reproduce answers
!! explicitly set this namelist variable to .true. in input.nml.
logical :: sw1way_bug = .false.
logical :: do_area_weighted_flux = .FALSE.
logical :: do_forecast = .false.
integer :: nblocks = 1
logical :: partition_fprec_from_lprec = .FALSE. !< option for ATM override experiments where liquid+frozen precip are combined
!! This option will convert liquid precip to snow when t_ref is less than
!! tfreeze parameter
logical :: scale_precip_2d = .false.
integer :: my_nblocks = 1
integer, allocatable :: block_start(:), block_end(:)
! ---- allocatable module storage --------------------------------------------
real, allocatable, dimension(:) :: &
! NOTE: T canopy is only differet from t_surf over vegetated land
ex_t_surf, & !< surface temperature for radiation calc, degK
ex_t_surf_miz,& !< miz
ex_t_ca, & !< near-surface (canopy) air temperature, degK
ex_p_surf, & !< surface pressure
ex_slp, & !< surface pressure
ex_flux_t, & !< sens heat flux
ex_flux_lw, & !< longwave radiation flux
ex_dhdt_surf, & !< d(sens.heat.flux)/d(T canopy)
ex_dedt_surf, & !< d(water.vap.flux)/d(T canopy)
ex_dqsatdt_surf, & !< d(water.vap.flux)/d(q canopy)
ex_e_q_n, &
ex_drdt_surf, & !< d(LW flux)/d(T surf)
ex_dhdt_atm, & !< d(sens.heat.flux)/d(T atm)
ex_flux_u, & !< u stress on atmosphere
ex_flux_v, & !< v stress on atmosphere
ex_dtaudu_atm,& !< d(stress)/d(u)
ex_dtaudv_atm,& !< d(stress)/d(v)
ex_seawater, &
ex_albedo_fix,&
ex_albedo_vis_dir_fix,&
ex_albedo_nir_dir_fix,&
ex_albedo_vis_dif_fix,&
ex_albedo_nir_dif_fix,&
ex_old_albedo,& !< old value of albedo for downward flux calculations
ex_drag_q, & !< q drag.coeff.
ex_cd_t, &
ex_cd_m, &
ex_b_star, &
ex_u_star, &
ex_wind, &
ex_z_atm
#ifdef SCM
real, allocatable, dimension(:) :: &
ex_dhdt_surf_forland, &
ex_dedt_surf_forland, &
ex_dedq_surf_forland
#endif
real, allocatable, dimension(:,:) :: &
ex_tr_surf, & !< near-surface tracer fields
ex_flux_tr, & !< tracer fluxes
ex_dfdtr_surf, & !< d(tracer flux)/d(surf tracer)
ex_dfdtr_atm, & !< d(tracer flux)/d(atm tracer)
ex_e_tr_n, & !< coefficient in implicit scheme
ex_f_tr_delt_n !< coefficient in implicit scheme
logical, allocatable, dimension(:) :: &
ex_avail, & !< true where data on exchange grid are available
ex_land !< true if exchange grid cell is over land
real, allocatable, dimension(:) :: &
ex_e_t_n, &
ex_f_t_delt_n
integer :: n_atm_tr !< number of prognostic tracers in the atmos model
integer :: n_atm_tr_tot !< number of prognostic tracers in the atmos model
integer :: n_lnd_tr !< number of prognostic tracers in the land model
integer :: n_lnd_tr_tot !< number of prognostic tracers in the land model
integer :: n_exch_tr !< number of tracers exchanged between models
type :: tracer_ind_type
integer :: atm, ice, lnd !< indices of the tracer in the respective models
end type tracer_ind_type
type(tracer_ind_type), allocatable :: tr_table(:) !< table of tracer indices
type :: tracer_exch_ind_type
integer :: exch = 0 !< exchange grid index
integer :: ice = 0 !< ice model index
integer :: lnd = 0 !< land model index
end type tracer_exch_ind_type
type(tracer_exch_ind_type), allocatable :: tr_table_map(:) !< map atm tracers to exchange, ice and land variables
integer :: isphum = NO_TRACER !< index of specific humidity tracer in tracer table
integer :: ico2 = NO_TRACER !< index of co2 tracer in tracer table
integer :: inh3 = NO_TRACER !< index of nh3 tracer in tracer table
type(coupler_1d_bc_type), pointer :: ex_gas_fields_atm=>NULL() !< gas fields in atm
!< Place holder for various atmospheric fields.
type(coupler_1d_bc_type), pointer :: ex_gas_fields_ice=>NULL() ! gas fields on ice
type(coupler_1d_bc_type), pointer :: ex_gas_fluxes=>NULL() ! gas flux
!< Place holder of intermediate calculations, such as
!< piston velocities etc.
interface put_logical_to_real
module procedure put_logical_to_real_sg
module procedure put_logical_to_real_ug
end interface
integer :: ni_atm, nj_atm !< to do atmos diagnostic from flux_ocean_to_ice
real, dimension(3) :: ccc !< for conservation checks
!Balaji, sets boundary_type%xtype
! REGRID: grids are physically different, pass via exchange grid
! REDIST: same physical grid, different decomposition, must move data around
! DIRECT: same physical grid, same domain decomposition, can directly copy data
integer, parameter :: REGRID=1, REDIST=2, DIRECT=3
integer :: cplClock, sfcClock, fluxAtmDnClock, regenClock, fluxAtmUpClock
! Exchange grid indices
integer :: X1_GRID_ATM, X1_GRID_ICE, X1_GRID_LND
real :: Dt_atm, Dt_cpl
integer :: nxc_ice=0, nyc_ice=0, nk_ice=0
integer :: nxc_lnd=0, nyc_lnd=0
contains
!#######################################################################
!> \brief Initialization routine.
!!
!! Initializes the interpolation routines,diagnostics and boundary data
!!
!! \throw FATAL, "grid_spec.nc incompatible with atmosphere resolution"
!! The atmosphere grid size from file grid_spec.nc is not compatible with the atmosphere
!! resolution from atmosphere model.
!! \throw FATAL, "grid_spec.nc incompatible with atmosphere longitudes (see xba.dat and yba.dat)"
!! The longitude from file grid_spec.nc ( from field yba ) is different from the longitude from atmosphere model.
!! \throw FATAL, "grid_spec.nc incompatible with atmosphere longitudes (see xba.dat and yba.dat)"
!! The longitude from file grid_spec.nc ( from field xba ) is different from the longitude from atmosphere model.
!! \throw FATAL, "grid_spec.nc incompatible with atmosphere latitudes (see grid_spec.nc)"
!! The latitude from file grid_spec.nc is different from the latitude from atmosphere model.
subroutine atm_land_ice_flux_exchange_init(Time, Atm, Land, Ice, atmos_ice_boundary, land_ice_atmos_boundary, &
Dt_atm_in, Dt_cpl_in, z_ref_heat_in, z_ref_mom_in, &
ex_u_star_smooth_bug_in, sw1way_bug_in, do_area_weighted_flux_in, &
do_forecast_in, partition_fprec_from_lprec_in, scale_precip_2d_in, &
nblocks_in, cplClock_in, ex_gas_fields_atm_in, &
ex_gas_fields_ice_in, ex_gas_fluxes_in)
type(time_type), intent(in) :: Time !< The model's current time
type(atmos_data_type), intent(inout) :: Atm !< A derived data type to specify atmosphere boundary data
type(land_data_type), intent(in) :: Land !< A derived data type to specify land boundary data
type(ice_data_type), intent(inout) :: Ice !< A derived data type to specify ice boundary data
type(atmos_ice_boundary_type), intent(inout) :: atmos_ice_boundary !< A derived data type to specify properties and fluxes passed from atmosphere to ice
type(land_ice_atmos_boundary_type),intent(inout) :: land_ice_atmos_boundary !< A derived data type to specify properties and fluxes passed from exchange grid to
!! the atmosphere, land and ice
real, intent(in) :: Dt_atm_in !< Atmosphere time step in seconds
real, intent(in) :: Dt_cpl_in !< Coupled time step in seconds
real, intent(in) :: z_ref_heat_in, z_ref_mom_in
logical, intent(in) :: ex_u_star_smooth_bug_in, scale_precip_2d_in
logical, intent(in) :: sw1way_bug_in, do_area_weighted_flux_in
logical, intent(in) :: do_forecast_in, partition_fprec_from_lprec_in
integer, intent(in) :: nblocks_in
integer, intent(in) :: cplClock_in
type(coupler_1d_bc_type), intent(in), target :: ex_gas_fields_atm_in, ex_gas_fields_ice_in, ex_gas_fluxes_in
character(len=48), parameter :: module_name = 'flux_exchange_mod'
character(len=64), parameter :: sub_name = 'flux_exchange_init'
character(len=256), parameter :: note_header = '==>Note from ' // trim(module_name) // &
'(' // trim(sub_name) // '):'
integer :: i, n
integer :: outunit, logunit
integer :: is, ie, js, je, kd
character(32) :: tr_name
logical :: found
character(32) :: method
character(512) :: parameters
real :: value
Dt_atm = Dt_atm_in
Dt_cpl = Dt_cpl_in
z_ref_heat = z_ref_heat_in
z_ref_mom = z_ref_mom_in
ex_u_star_smooth_bug = ex_u_star_smooth_bug_in
sw1way_bug = sw1way_bug_in
do_area_weighted_flux = do_area_weighted_flux_in
do_forecast = do_forecast_in
partition_fprec_from_lprec = partition_fprec_from_lprec_in
scale_precip_2d = scale_precip_2d_in
nblocks = nblocks_in
cplClock = cplClock_in
ex_gas_fields_atm => ex_gas_fields_atm_in
ex_gas_fields_ice => ex_gas_fields_ice_in
ex_gas_fluxes => ex_gas_fluxes_in
outunit = stdout(); logunit = stdlog()
allocate(block_start(nblocks), block_end(nblocks))
!----- find out number of atmospheric prognostic tracers and index of specific
! humidity in the tracer table
call get_number_tracers (MODEL_ATMOS, num_tracers=n_atm_tr_tot, &
num_prog=n_atm_tr)
call get_number_tracers (MODEL_LAND, num_tracers=n_lnd_tr_tot, &
num_prog=n_lnd_tr)
! assemble the table of tracer number translation by matching names of
! prognostic tracers in the atmosphere and surface models; skip all atmos.
! tracers that have no corresponding surface tracers.
allocate(tr_table(n_atm_tr))
allocate(tr_table_map(n_atm_tr))
n = 1
do i = 1,n_atm_tr
call get_tracer_names( MODEL_ATMOS, i, tr_name )
tr_table(n)%atm = i
tr_table(n)%ice = get_tracer_index ( MODEL_ICE, tr_name )
tr_table_map(i)%ice = tr_table(n)%ice
tr_table(n)%lnd = get_tracer_index ( MODEL_LAND, tr_name )
tr_table_map(i)%lnd = tr_table(n)%lnd
if(tr_table(n)%ice/=NO_TRACER.or.tr_table(n)%lnd/=NO_TRACER) then
tr_table_map(i)%exch = n
n = n + 1
endif
enddo
n_exch_tr = n - 1
!
! Set up tracer table entries for ocean-atm gas fluxes where the names of tracers in the
! atmosphere and ocean may not be equal
!
do n = 1, ex_gas_fluxes%num_bcs !{
if (ex_gas_fluxes%bc(n)%atm_tr_index .gt. 0) then !{
found = .false.
do i = 1, n_exch_tr !{
if (ex_gas_fluxes%bc(n)%atm_tr_index .eq. tr_table(i)%atm) then
found = .true.
exit
endif
enddo !} i
if (.not. found) then
n_exch_tr = n_exch_tr + 1
tr_table(n_exch_tr)%atm = ex_gas_fluxes%bc(n)%atm_tr_index
tr_table(n_exch_tr)%ice = NO_TRACER ! because ocean-atm gas fluxes are not held in the ice model as tracers
tr_table(n_exch_tr)%lnd = NO_TRACER ! because this would have been found above
tr_table_map(n_exch_tr)%exch = n_exch_tr
tr_table_map(n_exch_tr)%ice = tr_table(n_exch_tr)%ice
tr_table_map(n_exch_tr)%lnd = tr_table(n_exch_tr)%lnd
endif
endif !}
enddo !} n
write(outunit,*) trim(note_header), ' Number of exchanged tracers = ', n_exch_tr
write(logunit,*) trim(note_header), ' Number of exchanged tracers = ', n_exch_tr
do i = 1,n_exch_tr
call get_tracer_names( MODEL_ATMOS, tr_table(i)%atm, tr_name )
write(outunit,*)'Tracer field name :'//trim(tr_name)
write(logunit,*)'Tracer field name :'//trim(tr_name)
enddo
! find out which tracer is specific humidity
! +fix-me-slm+ specific humidity may not be present if we are running with
! dry atmosphere. Besides, model may use mixing ratio ('mix_rat') (?). However,
! some atmos code also assumes 'sphum' is present, so for now the following
! code may be good enough.
do i = 1,n_exch_tr
call get_tracer_names( MODEL_ATMOS, tr_table(i)%atm, tr_name )
if(lowercase(tr_name)=='sphum') then
isphum = i
endif
! jgj: find out which exchange tracer is co2
if(lowercase(tr_name)=='co2') then
ico2 = i
write(outunit,*)'Exchange tracer index for '//trim(tr_name),' : ',ico2
endif
if(lowercase(tr_name)=='nh3') then
inh3 = i
write(outunit,*)'Exchange tracer index for '//trim(tr_name),' : ',inh3
endif
enddo
if (isphum==NO_TRACER) then
call error_mesg('atm_land_ice_flux_exchange_mod',&
'tracer "sphum" must be present in the atmosphere', FATAL )
endif
if (ico2==NO_TRACER) then
call error_mesg('atm_land_ice_flux_exchange_mod',&
'tracer "co2" not present in the atmosphere', NOTE )
endif
!--------- read gridspec file ------------------
!only atmos pelists needs to do it here, ocean model will do it elsewhere
!
! check atmosphere and grid_spec.nc have same atmosphere lat/lon boundaries
!
call mpp_get_compute_domain(Atm%domain, is, ie, js, je)
if (scale_precip_2d) then
allocate(frac_precip(is:ie,js:je))
frac_precip=0.0
endif
call xgrid_init(remap_method)
#ifndef _USE_LEGACY_LAND_
call setup_xmap(xmap_sfc, (/ 'ATM', 'OCN', 'LND' /), &
(/ Atm%Domain, Ice%Domain, Land%Domain /), &
"INPUT/grid_spec.nc", Atm%grid, lnd_ug_domain=Land%ug_domain)
#else
call setup_xmap(xmap_sfc, (/ 'ATM', 'OCN', 'LND' /), &
(/ Atm%Domain, Ice%Domain, Land%Domain /), &
"INPUT/grid_spec.nc", Atm%grid)
#endif
! exchange grid indices
X1_GRID_ATM = 1; X1_GRID_ICE = 2; X1_GRID_LND = 3;
call generate_sfc_xgrid( Land, Ice )
if (n_xgrid_sfc.eq.1) write (*,'(a,i6,6x,a)') 'PE = ', mpp_pe(), 'Surface exchange size equals one.'
call surface_flux_init()
!-----------------------------------------------------------------------
!-----------------------------------------------------------------------
!----- initialize quantities for global integral package -----
!! call diag_integral_field_init ('prec', 'f6.3')
call diag_integral_field_init ('evap', 'f6.3')
#ifndef use_AM3_physics
call diag_integral_field_init ('t_surf', 'f10.3') !miz
call diag_integral_field_init ('t_ref', 'f10.3') !miz
#endif
!-----------------------------------------------------------------------
!----- initialize diagnostic fields -----
!----- all fields will be output on the atmospheric grid -----
call diag_field_init ( Time, Atm%axes(1:2), Land%axes, Land%pe )
ni_atm = size(Atm%lon_bnd,1)-1 ! to dimension "diag_atm"
nj_atm = size(Atm%lon_bnd,2)-1 ! in flux_ocean_to_ice
!Balaji
!allocate atmos_ice_boundary
call mpp_get_compute_domain( Ice%domain, is, ie, js, je )
kd = size(Ice%part_size,3)
allocate( atmos_ice_boundary%u_flux(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%v_flux(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%u_star(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%t_flux(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%q_flux(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%lw_flux(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%sw_flux_vis_dir(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%sw_flux_vis_dif(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%sw_flux_nir_dir(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%sw_flux_nir_dif(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%sw_down_vis_dir(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%sw_down_vis_dif(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%sw_down_nir_dir(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%sw_down_nir_dif(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%lprec(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%fprec(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%dhdt(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%dedt(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%drdt(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%coszen(is:ie,js:je,kd) )
allocate( atmos_ice_boundary%p(is:ie,js:je,kd) )
! initialize boundary values for override experiments (mjh)
atmos_ice_boundary%u_flux=0.0
atmos_ice_boundary%v_flux=0.0
atmos_ice_boundary%u_star=0.0
atmos_ice_boundary%t_flux=0.0
atmos_ice_boundary%q_flux=0.0
atmos_ice_boundary%lw_flux=0.0
atmos_ice_boundary%sw_flux_vis_dir=0.0
atmos_ice_boundary%sw_flux_vis_dif=0.0
atmos_ice_boundary%sw_flux_nir_dir=0.0
atmos_ice_boundary%sw_flux_nir_dif=0.0
atmos_ice_boundary%sw_down_vis_dir=0.0
atmos_ice_boundary%sw_down_vis_dif=0.0
atmos_ice_boundary%sw_down_nir_dir=0.0
atmos_ice_boundary%sw_down_nir_dif=0.0
atmos_ice_boundary%lprec=0.0
atmos_ice_boundary%fprec=0.0
atmos_ice_boundary%dhdt=0.0
atmos_ice_boundary%dedt=0.0
atmos_ice_boundary%drdt=0.0
atmos_ice_boundary%coszen=0.0
atmos_ice_boundary%p=0.0
! allocate fields for extra fluxes
! Copying initialized gas fluxes from exchange grid to atmosphere_ice boundary
call coupler_type_copy(ex_gas_fluxes, atmos_ice_boundary%fluxes, is, ie, js, je, kd, &
mod_name, Ice%axes, Time, suffix = '_atm_ice')
!--- Ice%ocean_fields and Ice%ocean_fluxes_top will not be passed to ocean, so these two
!--- coupler_type_copy calls are moved from ice_ocean_flux_init to here.
if (.not.coupler_type_initialized(Ice%ocean_fields)) &
call coupler_type_spawn(ex_gas_fields_ice, Ice%ocean_fields, (/is,is,ie,ie/), &
(/js,js,je,je/), (/1, kd/), suffix = '_ice')
call coupler_type_set_diags(Ice%ocean_fields, 'ice_flux', Ice%axes, Time)
! This call sets up a structure that is private to the ice model, and it
! does not belong here. This line should be eliminated once an update
! to the FMS coupler_types code is made available that overloads the
! subroutine coupler_type_copy to use 2d and 3d coupler type sources. -RWH
if (.not.coupler_type_initialized(Ice%ocean_fluxes_top)) &
call coupler_type_spawn(ex_gas_fields_ice, Ice%ocean_fluxes_top, (/is,is,ie,ie/), &
(/js,js,je,je/), (/1, kd/), suffix = '_ice_top')
call coupler_type_set_diags(Ice%ocean_fluxes_top, 'ice_flux', Ice%axes, Time)
!allocate land_ice_atmos_boundary
call mpp_get_compute_domain( Atm%domain, is, ie, js, je )
allocate( land_ice_atmos_boundary%t(is:ie,js:je) )
allocate( land_ice_atmos_boundary%u_ref(is:ie,js:je) ) ! bqx
allocate( land_ice_atmos_boundary%v_ref(is:ie,js:je) ) ! bqx
allocate( land_ice_atmos_boundary%t_ref(is:ie,js:je) ) ! cjg: PBL depth mods
allocate( land_ice_atmos_boundary%q_ref(is:ie,js:je) ) ! cjg: PBL depth mods
allocate( land_ice_atmos_boundary%albedo(is:ie,js:je) )
allocate( land_ice_atmos_boundary%albedo_vis_dir(is:ie,js:je) )
allocate( land_ice_atmos_boundary%albedo_nir_dir(is:ie,js:je) )
allocate( land_ice_atmos_boundary%albedo_vis_dif(is:ie,js:je) )
allocate( land_ice_atmos_boundary%albedo_nir_dif(is:ie,js:je) )
allocate( land_ice_atmos_boundary%land_frac(is:ie,js:je) )
allocate( land_ice_atmos_boundary%dt_t(is:ie,js:je) )
allocate( land_ice_atmos_boundary%dt_tr(is:ie,js:je,n_atm_tr) )
allocate( land_ice_atmos_boundary%u_flux(is:ie,js:je) )
allocate( land_ice_atmos_boundary%v_flux(is:ie,js:je) )
allocate( land_ice_atmos_boundary%dtaudu(is:ie,js:je) )
allocate( land_ice_atmos_boundary%dtaudv(is:ie,js:je) )
allocate( land_ice_atmos_boundary%u_star(is:ie,js:je) )
allocate( land_ice_atmos_boundary%b_star(is:ie,js:je) )
allocate( land_ice_atmos_boundary%q_star(is:ie,js:je) )
#ifndef use_AM3_physics
allocate( land_ice_atmos_boundary%shflx(is:ie,js:je) )!miz
allocate( land_ice_atmos_boundary%lhflx(is:ie,js:je) )!miz
#endif
allocate( land_ice_atmos_boundary%rough_mom(is:ie,js:je) )
allocate( land_ice_atmos_boundary%frac_open_sea(is:ie,js:je) )
! initialize boundary values for override experiments (mjh)
land_ice_atmos_boundary%t=273.0
land_ice_atmos_boundary%u_ref=0.0 ! bqx
land_ice_atmos_boundary%v_ref=0.0 ! bqx
land_ice_atmos_boundary%t_ref=273.0 ! cjg: PBL depth mods
land_ice_atmos_boundary%q_ref=0.0 ! cjg: PBL depth mods
land_ice_atmos_boundary%albedo=0.0
land_ice_atmos_boundary%albedo_vis_dir=0.0
land_ice_atmos_boundary%albedo_nir_dir=0.0
land_ice_atmos_boundary%albedo_vis_dif=0.0
land_ice_atmos_boundary%albedo_nir_dif=0.0
land_ice_atmos_boundary%land_frac=0.0
land_ice_atmos_boundary%dt_t=0.0
land_ice_atmos_boundary%dt_tr=0.0
land_ice_atmos_boundary%u_flux=0.0
land_ice_atmos_boundary%v_flux=0.0
land_ice_atmos_boundary%dtaudu=0.0
land_ice_atmos_boundary%dtaudv=0.0
land_ice_atmos_boundary%u_star=0.0
land_ice_atmos_boundary%b_star=0.0
land_ice_atmos_boundary%q_star=0.0
#ifndef use_AM3_physics
land_ice_atmos_boundary%shflx=0.0
land_ice_atmos_boundary%lhflx=0.0
#endif
land_ice_atmos_boundary%rough_mom=0.01
land_ice_atmos_boundary%frac_open_sea=0.0
! allocate fields for extra tracers
! The first call is no longer necessary, the fluxes will be passed by the land module
! The 2nd call is useful in the case of a ocean model only simulation
!
call coupler_type_copy(ex_gas_fields_atm, Atm%fields, is, ie, js, je, &
mod_name, Atm%axes(1:2), Time, suffix = '_atm')
if( Ice%pe) then
call mpp_get_compute_domain(Ice%domain, xsize=nxc_ice, ysize=nyc_ice)
nk_ice = size(Ice%part_size,3)
endif
if( Land%pe) then
call mpp_get_compute_domain(Land%domain, xsize=nxc_lnd, ysize=nyc_lnd)
endif
!Balaji: clocks on atm%pe only
sfcClock = mpp_clock_id( 'SFC boundary layer', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
fluxAtmDnClock = mpp_clock_id( 'Flux DN from atm', flags=clock_flag_default, grain=CLOCK_ROUTINE )
regenClock = mpp_clock_id( 'XGrid generation', flags=clock_flag_default, grain=CLOCK_ROUTINE )
fluxAtmUpClock = mpp_clock_id( 'Flux UP to atm', flags=clock_flag_default, grain=CLOCK_ROUTINE )
do_init = .false.
end subroutine atm_land_ice_flux_exchange_init
!#######################################################################
!> \brief Computes explicit fluxes as well as derivatives that will be used to compute an implicit flux correction.
!!
!!
!! The following quantities in the land_ice_atmos_boundary_type are computed:
!!
!! <pre>
!! t_surf_atm = surface temperature (used for radiation) (K)
!! albedo_atm = surface albedo (used for radiation) (nondimensional)
!! rough_mom_atm = surface roughness for momentum (m)
!! land_frac_atm = fractional area of land beneath an atmospheric
!! grid box
!! dtaudu_atm, dtaudv_atm = derivatives of wind stress w.r.t. the
!! lowest level wind speed (Pa/(m/s))
!! flux_u_atm = zonal wind stress (Pa)
!! flux_v_atm = meridional wind stress (Pa)
!! u_star_atm = friction velocity (m/s)
!! b_star_atm = buoyancy scale (m2/s)
!! </pre>
!! \note `u_star` and `b_star` are defined so that `u_star**2` is the magnitude
!! of surface stress divided by density of air at the surface,
!! and `u_star*b_star` is the buoyancy flux at the surface.
!!
!! \throw FATAL, "must call atm_land_ice_flux_exchange_init first"
!! atm_land_ice_flux_exchange_init has not been called before calling sfc_boundary_layer.
subroutine sfc_boundary_layer ( dt, Time, Atm, Land, Ice, Land_Ice_Atmos_Boundary )
real, intent(in) :: dt !< Time step
type(time_type), intent(in) :: Time !< Current time
type(atmos_data_type), intent(inout) :: Atm !< A derived data type to specify atmosphere boundary data
type(land_data_type), intent(inout) :: Land !< A derived data type to specify land boundary data
type(ice_data_type), intent(inout) :: Ice !< A derived data type to specify ice boundary data
type(land_ice_atmos_boundary_type), intent(inout) :: Land_Ice_Atmos_Boundary !< A derived data type to specify properties and
!! fluxes passed from exchange grid to the atmosphere,
!! land and ice
! ---- local vars ----------------------------------------------------------
real, dimension(n_xgrid_sfc) :: &
ex_albedo, &
ex_albedo_vis_dir, &
ex_albedo_nir_dir, &
ex_albedo_vis_dif, &
ex_albedo_nir_dif, &
ex_land_frac, &
ex_t_atm, &
ex_p_atm, &
ex_u_atm, ex_v_atm, &
ex_hs, &
ex_gust, &
ex_t_surf4, &
ex_u_surf, ex_v_surf, &
ex_rough_mom, ex_rough_heat, ex_rough_moist, &
ex_rough_scale,&
ex_q_star, &
ex_cd_q, &
ex_ref, ex_ref_u, ex_ref_v, ex_u10, ex_u10N, & ! bgr_prustogi
ex_ref2, &
ex_t_ref, &
ex_qs_ref, &
ex_qs_ref_cmip, &
ex_del_m, &
ex_del_h, &
ex_del_q, &
ex_frac_open_sea
real, dimension(n_xgrid_sfc,n_exch_tr) :: ex_tr_atm
! jgj: added for co2_atm diagnostic
real, dimension(n_xgrid_sfc) :: ex_co2_atm_dvmr
real, dimension(size(Land_Ice_Atmos_Boundary%t,1),size(Land_Ice_Atmos_Boundary%t,2)) :: diag_atm
#ifndef _USE_LEGACY_LAND_
real, dimension(size(Land%t_ca, 1),size(Land%t_ca,2)) :: diag_land
real, dimension(size(Land%t_ca, 1)) :: diag_land_ug, tile_size_ug
real, dimension(nxc_lnd,nyc_lnd) :: diag_land_sg, tile_size_sg
logical, dimension(size(Land%t_ca, 1)) :: mask_ug
logical, dimension(nxc_lnd,nyc_lnd) :: mask_sg
integer :: k
#else
real, dimension(size(Land%t_ca, 1),size(Land%t_ca,2), size(Land%t_ca,3)) :: diag_land
#endif
real, dimension(size(Ice%t_surf,1),size(Ice%t_surf,2),size(Ice%t_surf,3)) :: sea
real, dimension(size(Ice%albedo,1),size(Ice%albedo,2),size(Ice%albedo,3)) :: tmp_open_sea
real :: zrefm, zrefh
logical :: used
character(32) :: tr_name, tr_units ! tracer name
integer :: tr, n, m ! tracer indices
integer :: i
integer :: is,ie,l,j
integer :: isc,iec,jsc,jec
! [1] check that the module was initialized
if (do_init) call error_mesg ('atm_land_ice_flux_exchange_mod', &
'must call atm_land_ice_flux_exchange_init first', FATAL)
!Balaji
call mpp_clock_begin(cplClock)
call mpp_clock_begin(sfcClock)
! [2] allocate storage for variables that are also used in flux_up_to_atmos
allocate ( &
ex_t_surf (n_xgrid_sfc), &
ex_t_surf_miz(n_xgrid_sfc), &
ex_p_surf (n_xgrid_sfc), &
ex_slp (n_xgrid_sfc), &
ex_t_ca (n_xgrid_sfc), &
ex_dhdt_surf(n_xgrid_sfc), &
ex_dedt_surf(n_xgrid_sfc), &
ex_dqsatdt_surf(n_xgrid_sfc), &
ex_drdt_surf(n_xgrid_sfc), &
ex_dhdt_atm (n_xgrid_sfc), &
ex_flux_t (n_xgrid_sfc), &
ex_flux_lw (n_xgrid_sfc), &
ex_drag_q (n_xgrid_sfc), &
ex_avail (n_xgrid_sfc), &
ex_f_t_delt_n(n_xgrid_sfc), &
ex_tr_surf (n_xgrid_sfc, n_exch_tr), &
ex_dfdtr_surf (n_xgrid_sfc, n_exch_tr), &
ex_dfdtr_atm (n_xgrid_sfc, n_exch_tr), &
ex_flux_tr (n_xgrid_sfc, n_exch_tr), &
ex_f_tr_delt_n (n_xgrid_sfc, n_exch_tr), &
ex_e_tr_n (n_xgrid_sfc, n_exch_tr), &
! MOD these were moved from local ! so they can be passed to flux down
ex_flux_u(n_xgrid_sfc), &
ex_flux_v(n_xgrid_sfc), &
ex_dtaudu_atm(n_xgrid_sfc),&
ex_dtaudv_atm(n_xgrid_sfc),&
ex_seawater(n_xgrid_sfc), &
! values added for LM3
ex_cd_t (n_xgrid_sfc), &
ex_cd_m (n_xgrid_sfc), &
ex_b_star (n_xgrid_sfc), &
ex_u_star (n_xgrid_sfc), &
ex_wind (n_xgrid_sfc), &
ex_z_atm (n_xgrid_sfc), &
ex_e_t_n (n_xgrid_sfc), &
ex_e_q_n (n_xgrid_sfc), &
ex_land (n_xgrid_sfc) )
#ifdef SCM
allocate ( &
ex_dhdt_surf_forland(n_xgrid_sfc), &
ex_dedt_surf_forland(n_xgrid_sfc), &
ex_dedq_surf_forland(n_xgrid_sfc) )
#endif
ex_p_surf = 1.0
! Actual allocation of exchange fields for ocean_ice boundary
do n = 1, ex_gas_fields_ice%num_bcs !{
do m = 1, ex_gas_fields_ice%bc(n)%num_fields !{
if (associated(ex_gas_fields_ice%bc(n)%field(m)%values)) then !{
call mpp_error( FATAL, 'sfc_boundary_layer: ex_gas_fields_ice already allocated.' )
endif !}
allocate ( ex_gas_fields_ice%bc(n)%field(m)%values(n_xgrid_sfc) )
ex_gas_fields_ice%bc(n)%field(m)%values = 0.0
enddo !} m
enddo !} n
do n = 1, ex_gas_fields_atm%num_bcs !{
do m = 1, ex_gas_fields_atm%bc(n)%num_fields !{
if (associated(ex_gas_fields_atm%bc(n)%field(m)%values)) then !{
call mpp_error( FATAL, 'sfc_boundary_layer: ex_gas_fields_atm already allocated.' )
endif !}
allocate ( ex_gas_fields_atm%bc(n)%field(m)%values(n_xgrid_sfc) )
ex_gas_fields_atm%bc(n)%field(m)%values = 0.0
enddo !} m
enddo !} n
do n = 1, ex_gas_fluxes%num_bcs !{
do m = 1, ex_gas_fluxes%bc(n)%num_fields !{
if (associated(ex_gas_fluxes%bc(n)%field(m)%values)) then !{
call mpp_error( FATAL, 'sfc_boundary_layer: ex_gas_fluxes already allocated.' )
endif !}
allocate ( ex_gas_fluxes%bc(n)%field(m)%values(n_xgrid_sfc) )
ex_gas_fluxes%bc(n)%field(m)%values = 0.0
enddo !} m
enddo !} n
!
! Call the atmosphere tracer driver to gather the data needed for extra gas tracers
! For ocean only model
! call atmos_get_fields_for_flux(Atm)
! [3] initialize some values on exchange grid: this is actually a safeguard
! against using undefined values
!$OMP parallel do default(none) shared(my_nblocks,block_start,block_end,ex_t_surf,ex_u_surf, &
!$OMP ex_v_surf,ex_albedo,ex_albedo_vis_dir,ex_albedo_nir_dir, &
!$OMP ex_albedo_vis_dif,ex_albedo_nir_dif,ex_cd_t,ex_cd_m, &
!$OMP ex_cd_q,ex_frac_open_sea) &
!$OMP private(is,ie)
do l = 1, my_nblocks
is=block_start(l)
ie=block_end(l)
do i = is,ie
ex_t_surf(i) = 200.
ex_u_surf(i) = 0.
ex_v_surf(i) = 0.
ex_albedo(i) = 0. ! bw
ex_albedo_vis_dir(i) = 0.
ex_albedo_nir_dir(i) = 0.
ex_albedo_vis_dif(i) = 0.
ex_albedo_nir_dif(i) = 0.
!---- do not use if relax time /= 0 ----
ex_cd_t(i) = 0.0
ex_cd_m(i) = 0.0
ex_cd_q(i) = 0.0
ex_frac_open_sea(i) =0.
enddo
enddo
!-----------------------------------------------------------------------
!Balaji: data_override stuff moved from coupler_main
call data_override ('ATM', 't_bot', Atm%t_bot , Time)
call data_override ('ATM', 'z_bot', Atm%z_bot , Time)
call data_override ('ATM', 'p_bot', Atm%p_bot , Time)
call data_override ('ATM', 'u_bot', Atm%u_bot , Time)
call data_override ('ATM', 'v_bot', Atm%v_bot , Time)
call data_override ('ATM', 'hs', Atm%hs, Time) !brandon & liao
call data_override ('ATM', 'p_surf', Atm%p_surf, Time)
call data_override ('ATM', 'slp', Atm%slp, Time)
call data_override ('ATM', 'gust', Atm%gust, Time)
!
! jgj: 2008/07/18
! FV atm advects tracers in moist mass mixing ratio: kg co2 /(kg air + kg water)
! cubed sphere advects moist mass mixing ratio also (per SJ)
! data table co2 overrides for ocean (co2_flux_pcair_atm)
! and land (co2_bot) should be in dry vmr (mol/mol) units.
! ATM: co2_flux_pcair_atm : to override atm_btm layer to send to ocean
! ATM: co2_bot : to override atm_btm layer to send to land
! data override for co2 to be passed to land/photosynthesis (co2_bot)
! land co2 data override is in dry_vmr units, so convert to wet_mmr for land model.
! co2mmr = (wco2/wair) * co2vmr; wet_mmr = dry_mmr * (1-Q)
!
do tr = 1,n_atm_tr
call get_tracer_names( MODEL_ATMOS, tr, tr_name )
call data_override('ATM', trim(tr_name)//'_bot', Atm%tr_bot(:,:,tr), Time, override=used)
! conversion for land co2 data override from dry vmr to moist mmr
if (used .and. lowercase(trim(tr_name)).eq.'co2') then
! 2017/08/08 jgj add co2_bot diagnostic in dry_vmr units
if ( id_co2_bot > 0 ) used = send_data ( id_co2_bot, Atm%tr_bot(:,:,tr), Time )
isc = lbound(Atm%tr_bot,1); iec = ubound(Atm%tr_bot,1)
jsc = lbound(Atm%tr_bot,2); jec = ubound(Atm%tr_bot,2)
!$OMP parallel do default(none) shared(isc,iec,jsc,jec,Atm,tr,isphum)
do j = jsc, jec
do i = isc, iec
Atm%tr_bot(i,j,tr) = Atm%tr_bot(i,j,tr) * (WTMCO2/WTMAIR) * &
(1.0 - Atm%tr_bot(i,j,isphum))
enddo
enddo
end if
enddo
! data override for co2 to be passed to ocean (co2_flux_pcair_atm)
! atmos_co2.F90 already called: converts tr_bot passed to ocean via gas_flux
! from moist mmr to dry vmr.
do n = 1, atm%fields%num_bcs !{
do m = 1, atm%fields%bc(n)%num_fields !{
call data_override('ATM', atm%fields%bc(n)%field(m)%name, &
atm%fields%bc(n)%field(m)%values, Time, override = atm%fields%bc(n)%field(m)%override)
ex_gas_fields_atm%bc(n)%field(m)%override = atm%fields%bc(n)%field(m)%override
! 2017/08/08 jgj add co2_flux_pcair_atm diagnostic
if ( atm%fields%bc(n)%field(m)%override .and. lowercase(trim(atm%fields%bc(n)%field(m)%name)) .eq. 'co2_flux_pcair_atm') then
if( id_co2_flux_pcair_atm > 0 ) used = send_data ( id_co2_flux_pcair_atm, atm%fields%bc(n)%field(m)%values, Time )
endif
! 2017/08/15 jgj add o2_flux_pcair_atm diagnostic
if ( atm%fields%bc(n)%field(m)%override .and. lowercase(trim(atm%fields%bc(n)%field(m)%name)) .eq. 'o2_flux_pcair_atm') then
if( id_o2_flux_pcair_atm > 0 ) used = send_data ( id_o2_flux_pcair_atm, atm%fields%bc(n)%field(m)%values, Time )
endif
enddo !} m
enddo !} n
do n = 1, atm%fields%num_bcs !{
if (atm%fields%bc(n)%use_atm_pressure) then !{
if (.not. atm%fields%bc(n)%field(ind_psurf)%override) then !{
atm%fields%bc(n)%field(ind_psurf)%values = Atm%p_surf
endif !}
endif !}
enddo !} n
call data_override ('ICE', 't_surf', Ice%t_surf, Time)
call data_override ('ICE', 'rough_mom', Ice%rough_mom, Time)
call data_override ('ICE', 'rough_heat', Ice%rough_heat, Time)
call data_override ('ICE', 'rough_moist',Ice%rough_moist, Time)
call data_override ('ICE', 'albedo', Ice%albedo, Time)
call data_override ('ICE', 'albedo_vis_dir', Ice%albedo_vis_dir, Time)
call data_override ('ICE', 'albedo_nir_dir', Ice%albedo_nir_dir, Time)
call data_override ('ICE', 'albedo_vis_dif', Ice%albedo_vis_dif, Time)
call data_override ('ICE', 'albedo_nir_dif', Ice%albedo_nir_dif, Time)
call data_override ('ICE', 'u_surf', Ice%u_surf, Time)
call data_override ('ICE', 'v_surf', Ice%v_surf, Time)
call coupler_type_data_override('ICE', Ice%ocean_fields, Time)
call coupler_type_send_data(Ice%ocean_fields, Time)
call data_override_land ('LND', 't_surf', Land%t_surf, Time)
call data_override_land ('LND', 't_ca', Land%t_ca, Time)
call data_override_land ('LND', 'rough_mom', Land%rough_mom, Time)
call data_override_land ('LND', 'rough_heat', Land%rough_heat, Time)
call data_override_land ('LND', 'albedo', Land%albedo, Time)
! tracer data override
do tr = 1, n_lnd_tr
call get_tracer_names( MODEL_LAND, tr, tr_name )
#ifndef _USE_LEGACY_LAND_
call data_override_land('LND', trim(tr_name)//'_surf', Land%tr(:,:,tr), Time)
#else
call data_override_land('LND', trim(tr_name)//'_surf', Land%tr(:,:,:,tr), Time)
#endif
enddo
call data_override_land ('LND', 'albedo_vis_dir', Land%albedo_vis_dir,Time)
call data_override_land ('LND', 'albedo_nir_dir', Land%albedo_nir_dir,Time)
call data_override_land ('LND', 'albedo_vis_dif', Land%albedo_vis_dif,Time)
call data_override_land ('LND', 'albedo_nir_dif', Land%albedo_nir_dif,Time)
!---- put atmosphere quantities onto exchange grid ----
! [4] put all the qantities we need onto exchange grid
! [4.1] put atmosphere quantities onto exchange grid
#ifdef use_AM3_physics
if (do_forecast) then
call put_to_xgrid (Atm%Surf_diff%sst_miz , 'ATM', ex_t_surf_miz, xmap_sfc, remap_method=remap_method, complete=.false.)