-
Notifications
You must be signed in to change notification settings - Fork 137
/
atmos_ocean_fluxes.F90
1440 lines (1267 loc) · 74.8 KB
/
atmos_ocean_fluxes.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).
!*
!* FMS 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 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. If not, see <http://www.gnu.org/licenses/>.
!***********************************************************************
!> @defgroup atmos_ocean_fluxes_mod atmos_ocean_fluxes_mod
!> @ingroup coupler
!> @brief Implementation of routines to solve the gas fluxes at the
!! ocean surface for a coupled model as outlined in the Biotic-HOWTO
!! documentation below, revision 1.7, 1999/10/05.
!!
!> @author Richard Slater, John Dunne
!!
!! Ocean Carbon Model Intercomparison Study II: Gas exchange coupler.
!!
!! This module will take fields from an atmospheric and an
!! oceanic model and calculate ocean surface fluxes for
!! CO2, O2, CFC-11 or CFC-12 as outlined in the various
!! HOWTO documents at the OCMIP2 website. Multiple instances
!! of a given tracer may be given, resulting in multiple
!! surface fluxes. Additionally, data may be overridden at
!! the individual fields, or fluxes. This could be used in
!! the absence of an atmospheric or oceanic model.
!> @addtogroup atmos_ocean_fluxes_mod
!> @{
module atmos_ocean_fluxes_mod
use mpp_mod, only: stdout, mpp_error, FATAL, mpp_sum, mpp_npes
use fms_mod, only: write_version_number
use coupler_types_mod, only: coupler_1d_bc_type
use coupler_types_mod, only: ind_alpha, ind_csurf, ind_sc_no
use coupler_types_mod, only: ind_pcair, ind_u10, ind_psurf
use coupler_types_mod, only: ind_deposition
use coupler_types_mod, only: ind_runoff
use coupler_types_mod, only: ind_flux, ind_deltap, ind_kw, ind_flux0
use field_manager_mod, only: fm_path_name_len, fm_string_len, fm_exists, fm_get_index
use field_manager_mod, only: fm_new_list, fm_get_current_list, fm_change_list
use field_manager_mod, only: fm_field_name_len, fm_type_name_len, fm_dump_list
use field_manager_mod, only: fm_loop_over_list
use fm_util_mod, only: fm_util_default_caller
use fm_util_mod, only: fm_util_get_length
use fm_util_mod, only: fm_util_set_value, fm_util_set_good_name_list
use fm_util_mod, only: fm_util_set_no_overwrite, fm_util_set_caller
use fm_util_mod, only: fm_util_reset_good_name_list, fm_util_reset_no_overwrite
use fm_util_mod, only: fm_util_reset_caller, fm_util_get_string_array
use fm_util_mod, only: fm_util_check_for_bad_fields, fm_util_get_string
use fm_util_mod, only: fm_util_get_real_array, fm_util_get_real, fm_util_get_integer
use fm_util_mod, only: fm_util_get_logical, fm_util_get_logical_array
use fms_io_utils_mod, only: get_data_type_string
use platform_mod, only: r4_kind, r8_kind
implicit none
private
public :: atmos_ocean_fluxes_init
public :: atmos_ocean_type_fluxes_init
public :: aof_set_coupler_flux
character(len=*), parameter :: mod_name = 'atmos_ocean_fluxes_mod'
real(r8_kind), parameter :: epsln=1.0e-30_r8_kind
! Include variable "version" to be written to log file.
#include<file_version.h>
contains
!> @brief Set the values for a coupler flux
!! @return its index (0 on error)
!! @throw FATAL, "Empty name given"
!! Name is empty
!! @throw FATAL, "Could not get coupler flux"
!! coupler_index is less than 1
!! @throw FATAL, "Could not set coupler flux"
!! coupler_index is less than 1
!! @throw FATAL, "Could not get the current list"
!! Current list is empty
!! @throw FATAL, "Could not change to the new list"
!! fm_change_list(coupler_list) returns false
!! @throw FATAL, "Blank flux_type given"
!! flux_type or implementation is empty
!! @throw FATAL, "Undefined flux_type given from field_table"
!! flux_type does not equal flux_type_test
!! @throw FATAL, "Undefined flux_type given as argument to the subroutine"
!! flux_type does not equal flux_type_test
!! @throw FATAL, "Undefined flux_type/implementation (implementation given from field_table)"
!! flux_type does not equal flux_type_test
!! @throw FATAL, "Undefined flux_type/implementation (flux_type given from field_table)"
!! flux_type does not equal flux_type_test
!! @throw FATAL, "Undefined flux_type/implementation (both given from field_table)"
!! flux_type does not equal flux_type_test
!! @throw FATAL, "Undefined flux_type/implementation given as argument to the subroutine"
!! flux_type does not equal flux_type_test
!! @throw NOTE, "Number of parameters provided for [variable] does not match the number of parameters required"
!! Mismatch between parameter input and the parameters being replaced
!! @throw FATAL, "Could not change back to [current_list]"
!! @throw FATAL, "Empty [name] list"
function aof_set_coupler_flux(name, flux_type, implementation, atm_tr_index, param, flag,&
& mol_wt, ice_restart_file, ocean_restart_file, units, caller, verbosity) &
& result (coupler_index)
character(len=*), intent(in) :: name !< name
character(len=*), intent(in) :: flux_type !< flux_type
character(len=*), intent(in) :: implementation !< implementation
integer, intent(in), optional :: atm_tr_index !< atm_tr_index
class(*), intent(in), dimension(:), optional :: param !< param
logical, intent(in), dimension(:), optional :: flag !< flag
class(*), intent(in), optional :: mol_wt !< mol_wt
character(len=*), intent(in), optional :: ice_restart_file !< ice_restart_file
character(len=*), intent(in), optional :: ocean_restart_file !< ocean_restart_file
character(len=*), intent(in), optional :: units !< units
character(len=*), intent(in), optional :: caller !< caller
integer, intent(in), optional :: verbosity !< A 0-9 integer indicating a level of verbosity.
integer :: coupler_index
character(len=*), parameter :: sub_name = 'aof_set_coupler_flux'
integer :: n
integer :: length
integer :: num_parameters
integer :: outunit
character(len=fm_path_name_len) :: coupler_list
character(len=fm_path_name_len) :: current_list
character(len=fm_string_len) :: flux_type_test
character(len=fm_string_len) :: implementation_test
character(len=256) :: error_header
character(len=256) :: warn_header
character(len=256) :: note_header
character(len=128) :: flux_list
character(len=128) :: caller_str
character(len=fm_string_len), pointer, dimension(:) :: good_list => NULL()
character(len=256) :: long_err_msg
integer :: verbose !< An integer indicating the level of verbosity.
character(len=17) :: err_str
verbose = 5 ! Default verbosity level
if (present(verbosity)) verbose = verbosity
! Set the caller string and headers.
if (present(caller)) then
caller_str = '[' // trim(caller) // ']'
else
caller_str = fm_util_default_caller
endif
error_header = '==>Error from ' // trim(mod_name) //&
& '(' // trim(sub_name) // ')' // trim(caller_str) // ':'
warn_header = '==>Warning from ' // trim(mod_name) //&
& '(' // trim(sub_name) // ')' // trim(caller_str) // ':'
note_header = '==>Note from ' // trim(mod_name) //&
& '(' // trim(sub_name) // ')' // trim(caller_str) // ':'
! Check that a name is given (fatal if not).
if (name .eq. ' ') then
call mpp_error(FATAL, trim(error_header) // ' Empty name given')
endif
outunit = stdout()
if (verbose >= 5) then
write (outunit,*)
write (outunit,*) trim(note_header), ' Processing coupler fluxes ', trim(name)
endif
! Define the coupler list name.
coupler_list = '/coupler_mod/fluxes/' // trim(name)
! Check whether a flux has already been set for this name, and if so, return the index for it
! (this is because the fluxes may be defined in both the atmosphere and ocean models) (check
! whether the good_list list exists, since this will indicate that this routine has already been
! called, and not just that the field table input has this list defined)
if (fm_exists('/coupler_mod/GOOD/fluxes/' // trim(name) // '/good_list')) then
if (verbose >= 5) then
write (outunit,*)
write (outunit,*) trim(note_header), ' Using previously defined coupler flux'
endif
coupler_index = fm_get_index(coupler_list)
if (coupler_index .le. 0) then
call mpp_error(FATAL, trim(error_header) // ' Could not get coupler flux ')
endif
! Allow atm_tr_index to be set here, since it will only be set from atmospheric
! PEs, and the atmospheric routines call this routine last, thus overwriting the
! current value is safe (furthermore, this is not a value which could have any meaningful
! value set from the run script.
if (present(atm_tr_index)) then
if (verbose >= 5) &
write (outunit,*) trim(note_header), ' Redefining atm_tr_index to ', atm_tr_index
call fm_util_set_value(trim(coupler_list) // '/atm_tr_index', atm_tr_index,&
& no_create = .true., no_overwrite = .false., caller = caller_str)
endif
return
endif
! Set a new coupler flux and get its index.
coupler_index = fm_new_list(coupler_list)
if (coupler_index .le. 0) then
call mpp_error(FATAL, trim(error_header) // ' Could not set coupler flux ')
endif
! Change to the new list, first saving the current list.
current_list = fm_get_current_list()
if (current_list .eq. ' ') then
call mpp_error(FATAL, trim(error_header) // ' Could not get the current list')
endif
if (.not. fm_change_list(coupler_list)) then
call mpp_error(FATAL, trim(error_header) // ' Could not change to the new list')
endif
! Set the array in which to save the valid names for this list,
! used later for a consistency check. This is used in the fm_util_set_value
! routines to make the list of valid values.
call fm_util_set_good_name_list('/coupler_mod/GOOD/fluxes/' // trim(name) // '/good_list')
! Set other defaults for the fm_util_set_value routines.
call fm_util_set_no_overwrite(.true.)
call fm_util_set_caller(caller_str)
! Set various values to given values, or to defaults if not given.
if (flux_type .eq. ' ') then
call mpp_error(FATAL, trim(error_header) // ' Blank flux_type given')
else
if (fm_exists('/coupler_mod/types/' // trim(flux_type))) then
call fm_util_set_value('flux_type', flux_type)
! Check that the flux_type that we will use (possibly given from the field_table)
! is defined.
flux_type_test = fm_util_get_string('flux_type', scalar = .true.)
if (.not. fm_exists('/coupler_mod/types/' // trim(flux_type_test))) then
call mpp_error(FATAL, trim(error_header) //&
& ' Undefined flux_type given from field_table: ' // trim(flux_type_test))
endif
else
call mpp_error(FATAL, trim(error_header) //&
& ' Undefined flux_type given as argument to the subroutine: ' // trim(flux_type))
endif
endif
if (implementation .eq. ' ') then
call mpp_error(FATAL, trim(error_header) // ' Blank flux_type given')
else
if (fm_exists('/coupler_mod/types/' // trim(flux_type) // '/implementation/' // trim(implementation))) then
call fm_util_set_value('implementation', implementation)
! Check that the flux_type/implementation that we will use
! (both possibly given from the field_table) is defined
implementation_test = fm_util_get_string('implementation', scalar = .true.)
if (.not. fm_exists('/coupler_mod/types/' // trim(flux_type_test) // '/implementation/' // &
& trim(implementation_test))) then
if (flux_type .eq. flux_type_test) then
if (implementation .eq. implementation_test) then
call mpp_error(FATAL, trim(error_header) // ' Should not get here, as it is tested for above')
else
call mpp_error(FATAL, trim(error_header) //&
& ' Undefined flux_type/implementation (implementation given from field_table): ' //&
& trim(flux_type_test) // '/implementation/' // trim(implementation_test))
endif
else
if (implementation .eq. implementation_test) then
long_err_msg = 'Undefined flux_type/implementation (flux_type given from field_table): '
long_err_msg = long_err_msg // trim(flux_type_test) // '/implementation/'&
& // trim(implementation_test)
call mpp_error(FATAL, trim(error_header) // long_err_msg)
else
long_err_msg = ' Undefined flux_type/implementation (both given from field_table): '
long_err_msg = long_err_msg // trim(flux_type_test) // '/implementation/'&
& // trim(implementation_test)
call mpp_error(FATAL, trim(error_header) // long_err_msg)
endif
endif
endif
else
call mpp_error(FATAL, trim(error_header) //&
& ' Undefined flux_type/implementation given as argument to the subroutine: ' //&
& trim(flux_type) // '/implementation/' // trim(implementation))
endif
endif
if (present(atm_tr_index)) then
call fm_util_set_value('atm_tr_index', atm_tr_index)
else
call fm_util_set_value('atm_tr_index', 0)
endif
if (present(mol_wt)) then
select type(mol_wt)
type is (real(r8_kind))
call fm_util_set_value('mol_wt', mol_wt)
type is (real(r4_kind))
call fm_util_set_value('mol_wt', mol_wt)
class default
call get_data_type_string(mol_wt, err_str)
call mpp_error(FATAL, "aof_set_coupler_flux: invalid type for passed in mol_wt, type should be" // &
"real(r4_kind) or real(r8_kind). Passed in type:"//err_str)
end select
else
call fm_util_set_value('mol_wt', 0.0_r8_kind)
endif
if (present(ice_restart_file)) then
call fm_util_set_value('ice_restart_file', ice_restart_file)
else
call fm_util_set_value('ice_restart_file', 'ice_coupler_fluxes.res.nc')
endif
if (present(ocean_restart_file)) then
call fm_util_set_value('ocean_restart_file', ocean_restart_file)
else
call fm_util_set_value('ocean_restart_file', 'ocean_coupler_fluxes.res.nc')
endif
if (present(param)) then
num_parameters = fm_util_get_integer('/coupler_mod/types/' //&
& trim(fm_util_get_string('flux_type', scalar = .true.)) // '/implementation/' //&
& trim(fm_util_get_string('implementation', scalar = .true.)) // '/num_parameters',&
& scalar = .true.)
length = min(size(param(:)),num_parameters)
if ((length .ne. num_parameters) .and. (verbose >= 5)) then
write (outunit,*) trim(note_header), ' Number of parameters provided for ', trim(name), ' does not match the'
write (outunit,*) 'number of parameters required (', size(param(:)), ' != ', num_parameters, ').'
write (outunit,*) 'This could be an error, or more likely is just a result of the implementation being'
write (outunit,*) 'overridden by the field table input'
endif
if (length .gt. 0) then
select type (param)
type is (real(r4_kind))
call fm_util_set_value('param', param(1:length), length)
type is (real(r8_kind))
call fm_util_set_value('param', param(1:length), length)
class default
call get_data_type_string(param, err_str)
call mpp_error(FATAL, "aof_set_coupler_flux: invalid type for passed in param, type should be" // &
"real(r4_kind) or real(r8_kind). Passed in type:"//err_str)
end select
else
call fm_util_set_value('param', 'null', index = 0)
endif
else
call fm_util_set_value('param', 'null', index = 0)
endif
if (present(flag)) then
call fm_util_set_value('flag', flag, size(flag(:)))
else
call fm_util_set_value('flag', .false., index = 0)
endif
flux_list = '/coupler_mod/types/' // trim(flux_type) // '/'
if (present(units)) then
call fm_util_set_value(trim(fm_util_get_string(trim(flux_list) // 'flux/name', index = ind_flux)) // '-units',&
& units)
else
call fm_util_set_value(trim(fm_util_get_string(trim(flux_list) // 'flux/name', index = ind_flux)) // '-units',&
& fm_util_get_string(trim(flux_list) // 'flux/units', index = ind_flux))
endif
do n = 1, fm_util_get_length(trim(flux_list) // 'flux/name')
if (n .ne. ind_flux) then
call fm_util_set_value(trim(fm_util_get_string(trim(flux_list) // 'flux/name', index = n)) // '-units',&
& fm_util_get_string(trim(flux_list) // 'flux/units', index = n))
endif
call fm_util_set_value(trim(fm_util_get_string(trim(flux_list) // 'flux/name', index = n)) // '-long_name',&
& fm_util_get_string(trim(flux_list) // 'flux/long_name', index = n))
enddo ! n
do n = 1, fm_util_get_length(trim(flux_list) // 'atm/name')
call fm_util_set_value(trim(fm_util_get_string(trim(flux_list) // 'atm/name', index = n)) //&
& '-units', fm_util_get_string(trim(flux_list) // 'atm/units', index = n))
call fm_util_set_value(trim(fm_util_get_string(trim(flux_list) // 'atm/name', index = n)) // '-long_name',&
& fm_util_get_string(trim(flux_list) // 'atm/long_name', index = n))
enddo ! n
do n = 1, fm_util_get_length(trim(flux_list) // 'ice/name')
call fm_util_set_value(trim(fm_util_get_string(trim(flux_list) // 'ice/name', index = n)) // '-units',&
& fm_util_get_string(trim(flux_list) // 'ice/units', index = n))
call fm_util_set_value(trim(fm_util_get_string(trim(flux_list) // 'ice/name', index = n)) // '-long_name',&
& fm_util_get_string(trim(flux_list) // 'ice/long_name', index = n))
enddo ! n
! Reset the defaults for the fm_util_set_value calls.
call fm_util_reset_good_name_list
call fm_util_reset_no_overwrite
call fm_util_reset_caller
! Change back to the saved current list.
if (.not. fm_change_list(current_list)) then
call mpp_error(FATAL, trim(error_header) // ' Could not change back to ' // trim(current_list))
endif
! Check for any errors in the number of fields in this list.
if (caller_str .eq. ' ') then
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')'
endif
good_list => fm_util_get_string_array('/coupler_mod/GOOD/fluxes/' // trim(name) // '/good_list',&
& caller = caller_str)
if (associated(good_list)) then
call fm_util_check_for_bad_fields(trim(coupler_list), good_list, caller = caller_str)
deallocate(good_list)
else
call mpp_error(FATAL, trim(error_header) // ' Empty "' // trim(name) // '" list')
endif
return
end function aof_set_coupler_flux
!> @brief Initialize gas flux structures.
!!Will allocate to r8_kind unless use_r4_kind is present and true.
!! @throw FATAL, "Could not get number of fluxes"
!! Number of gas fluxes is not a valid number
!! @throw NOTE, "No gas fluxes"
!! No gas fluxes were found
!! @throw NOTE, "Processing [gas_fluxes%num_bcs] gas fluxes"
!! Gas fluxes were found
!! @throw FATAL, "[name] is not a list"
!! name needs to be a list, or typ is incorrectly defined
!! @throw FATAL, "Flux index, [ind] does not match array index, [n] for [name]"
!! @throw FATAL, "Problem changing to [name]"
!! @throw FATAL, "Undefined flux_type given for [name]: [gas_fluxes%bc(n)%flux_type]"
!! @throw FATAL, "Undefined implementation given for [name]:
!! [gas_fluxes%bc(n)%flux_type]/implementation/[gas_fluxes%bc(n)%implementation]"
!! @throw FATAL, "No param for [name]: need [num_parameters]"
!! @throw FATAL, "Wrong number of param for [name]: [size(gas_fluxes%bc(n)%param(:))] given, need [num_parameters]"
!! @throw FATAL, "No params needed for [name] but has size of [size(gas_fluxes%bc(n)%param(:))]"
!! @throw FATAL, "Num_parameters is negative for [name]: [num_parameters]"
!! @throw FATAL, "No flag for [name]: need [num_flags]"
!! @throw FATAL, "Wrong number of flag for [name]: [size(gas_fluxes%bc(n)%flag(:))] given, need [num_flags]"
!! @throw FATAL, "No flags needed for [name] but has size of [size(gas_fluxes%bc(n)%flag(:))]"
!! @throw FATAL, "Num_flags is negative for [name]: [num_flags]"
!! @throw FATAL, "Problem dumping fluxes tracer tree"
!! @throw FATAL, "Number of fluxes does not match across the processors: [gas_fluxes%num_bcs] fluxes"
subroutine atmos_ocean_fluxes_init(gas_fluxes, gas_fields_atm, gas_fields_ice, verbosity, use_r4_kind)
type(coupler_1d_bc_type), intent(inout) :: gas_fluxes !< Structure containing the gas fluxes between
!! the atmosphere and the ocean and parameters
!! related to the calculation of these fluxes.
!! The properties stored in this type are set
!! here, but the actual value arrays are set later.
type(coupler_1d_bc_type), intent(inout) :: gas_fields_atm !< Structure containing atmospheric surface
!! variables that are used in the calculation
!! of the atmosphere-ocean gas fluxes.
!! The properties stored in this type are set
!! here, but the actual value arrays are set later.
type(coupler_1d_bc_type), intent(inout) :: gas_fields_ice !< Structure containing ice-top and ocean
!! surface variables that are used in the
!! calculation of the atmosphere-ocean gas fluxes.
!! The properties stored in this type are set
!! here, but the actual value arrays are set later.
integer, optional, intent(in) :: verbosity !< A 0-9 integer indicating a level of verbosity.
logical, optional, intent(in) :: use_r4_kind!< Allocate field data to r4 kind instead of r8 kind.
!! Defaults to r8_kind if not present.
logical :: use_r4_kind_loc = .false.
character(len=*), parameter :: sub_name = 'atmos_ocean_fluxes_init'
character(len=*), parameter :: error_header =&
& '==>Error from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
character(len=*), parameter :: warn_header =&
& '==>Warning from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
character(len=*), parameter :: note_header =&
& '==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
integer :: num_parameters
integer :: num_flags
integer :: n
integer :: m
character(len=128) :: caller_str
character(len=fm_type_name_len) :: typ
character(len=fm_field_name_len) :: name
integer :: ind
integer :: outunit
integer :: total_fluxes
character(len=8) :: string
character(len=128) :: error_string
character(len=128) :: flux_list
logical, save :: initialized = .false.
integer :: verbose !< An integer indicating the level of verbosity.
if (initialized) return
verbose = 5 ! Default verbosity level
if (present(verbosity)) verbose = verbosity
! Write out the version of the file to the log file.
call write_version_number(trim(mod_name), version)
initialized = .true.
outunit = stdout()
! initialize the coupler type flux tracers
call atmos_ocean_type_fluxes_init(verbose)
if (verbose >= 9) then
write (outunit,*)
write (outunit,*) 'Dumping field manager tree'
if (.not. fm_dump_list('/', recursive = .true.)) &
call mpp_error(FATAL, trim(error_header) // ' Problem dumping field manager tree')
endif
caller_str = trim(mod_name) // '(' // trim(sub_name) // ')'
! Set other defaults for the fm_util_set_value routines.
call fm_util_set_no_overwrite(.true.)
call fm_util_set_caller(caller_str)
! Determine the number of flux fields.
gas_fluxes%num_bcs = fm_util_get_length('/coupler_mod/fluxes/')
gas_fluxes%set = .true.
gas_fields_atm%num_bcs = gas_fluxes%num_bcs ; gas_fields_atm%set = .true.
gas_fields_ice%num_bcs = gas_fluxes%num_bcs ; gas_fields_ice%set = .true.
if (gas_fluxes%num_bcs .lt. 0) then
call mpp_error(FATAL, trim(error_header) // ' Could not get number of fluxes')
elseif (gas_fluxes%num_bcs .eq. 0) then
if (verbose >= 5) &
write (outunit,*) trim(note_header), ' No gas fluxes'
return
else
if (verbose >= 5) &
write (outunit,*) trim(note_header), ' Processing ', gas_fluxes%num_bcs, ' gas fluxes'
endif
if(present(use_r4_kind)) use_r4_kind_loc = use_r4_kind
! allocate the arrays for selected kind (default r8)
if( .not. use_r4_kind_loc) then
allocate (gas_fluxes%bc(gas_fluxes%num_bcs))
allocate (gas_fields_atm%bc(gas_fields_atm%num_bcs))
allocate (gas_fields_ice%bc(gas_fields_ice%num_bcs))
else
allocate (gas_fluxes%bc_r4(gas_fluxes%num_bcs))
allocate (gas_fields_atm%bc_r4(gas_fields_atm%num_bcs))
allocate (gas_fields_ice%bc_r4(gas_fields_ice%num_bcs))
endif
! Loop over the input fields, setting the values in the flux_type.
n = 0
do while (fm_loop_over_list('/coupler_mod/fluxes', name, typ, ind))
if (typ .ne. 'list') then
call mpp_error(FATAL, trim(error_header) // ' ' // trim(name) // ' is not a list')
endif
n = n + 1 ! increment the array index
if (n .ne. ind) then
if (verbose >= 3) &
write (outunit,*) trim(warn_header), ' Flux index, ', ind,&
& ' does not match array index, ', n, ' for ', trim(name)
endif
! Change list to the new flux.
if (.not. fm_change_list('/coupler_mod/fluxes/' // trim(name))) then
call mpp_error(FATAL, trim(error_header) // ' Problem changing to ' // trim(name))
endif
!! mixed precision support
!! if use_r4_kind is false or not present will allocate to r8_kind
if (.not.use_r4_kind_loc) then
! Save and check the flux_type.
gas_fluxes%bc(n)%flux_type = fm_util_get_string('flux_type', scalar = .true.)
if (.not. fm_exists('/coupler_mod/types/' // trim(gas_fluxes%bc(n)%flux_type))) then
call mpp_error(FATAL, trim(error_header) // ' Undefined flux_type given for ' //&
& trim(name) // ': ' // trim(gas_fluxes%bc(n)%flux_type))
endif
gas_fields_atm%bc(n)%flux_type = gas_fluxes%bc(n)%flux_type
gas_fields_ice%bc(n)%flux_type = gas_fluxes%bc(n)%flux_type
! Save and check the implementation.
gas_fluxes%bc(n)%implementation = fm_util_get_string('implementation', scalar = .true.)
if (.not. fm_exists('/coupler_mod/types/' // trim(gas_fluxes%bc(n)%flux_type) //&
& '/implementation/' // trim(gas_fluxes%bc(n)%implementation))) then
call mpp_error(FATAL, trim(error_header) // ' Undefined implementation given for ' //&
& trim(name) // ': ' // trim(gas_fluxes%bc(n)%flux_type) // '/implementation/' //&
& trim(gas_fluxes%bc(n)%implementation))
endif
gas_fields_atm%bc(n)%implementation = gas_fluxes%bc(n)%implementation
gas_fields_ice%bc(n)%implementation = gas_fluxes%bc(n)%implementation
! Set the flux list name.
flux_list = '/coupler_mod/types/' // trim(gas_fluxes%bc(n)%flux_type) // '/'
! allocate the arrays
gas_fluxes%bc(n)%num_fields = fm_util_get_length(trim(flux_list) // 'flux/name')
allocate (gas_fluxes%bc(n)%field(gas_fluxes%bc(n)%num_fields))
gas_fields_atm%bc(n)%num_fields = fm_util_get_length(trim(flux_list) // 'atm/name')
allocate (gas_fields_atm%bc(n)%field(gas_fields_atm%bc(n)%num_fields))
gas_fields_ice%bc(n)%num_fields = fm_util_get_length(trim(flux_list) // 'ice/name')
allocate (gas_fields_ice%bc(n)%field(gas_fields_ice%bc(n)%num_fields))
! Save the name and generate unique field names for Flux, Ice and Atm.
gas_fluxes%bc(n)%name = name
do m = 1, fm_util_get_length(trim(flux_list) // 'flux/name')
gas_fluxes%bc(n)%field(m)%name = trim(name) // "_" // fm_util_get_string(trim(flux_list) //&
& 'flux/name', index = m)
gas_fluxes%bc(n)%field(m)%override = .false.
gas_fluxes%bc(n)%field(m)%mean = .false.
enddo
gas_fields_atm%bc(n)%name = name
do m = 1, fm_util_get_length(trim(flux_list) // 'atm/name')
gas_fields_atm%bc(n)%field(m)%name = trim(name) // "_" // fm_util_get_string(trim(flux_list) //&
& 'atm/name', index = m)
gas_fields_atm%bc(n)%field(m)%override = .false.
gas_fields_atm%bc(n)%field(m)%mean = .false.
enddo
gas_fields_ice%bc(n)%name = name
do m = 1, fm_util_get_length(trim(flux_list) // 'ice/name')
gas_fields_ice%bc(n)%field(m)%name = trim(name) // "_" // fm_util_get_string(trim(flux_list) // &
& 'ice/name', index = m)
gas_fields_ice%bc(n)%field(m)%override = .false.
gas_fields_ice%bc(n)%field(m)%mean = .false.
enddo
! Save the units.
do m = 1, fm_util_get_length(trim(flux_list) // 'flux/name')
gas_fluxes%bc(n)%field(m)%units =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'flux/name', index = m)) // &
& '-units', scalar = .true.)
enddo
do m = 1, fm_util_get_length(trim(flux_list) // 'atm/name')
gas_fields_atm%bc(n)%field(m)%units =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'atm/name', index = m)) // '-units')
enddo
do m = 1, fm_util_get_length(trim(flux_list) // 'ice/name')
gas_fields_ice%bc(n)%field(m)%units =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'ice/name', index = m)) // '-units')
enddo
! Save the long names.
do m = 1, fm_util_get_length(trim(flux_list) // 'flux/name')
gas_fluxes%bc(n)%field(m)%long_name =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'flux/name', index = m)) // &
& '-long_name', scalar = .true.)
gas_fluxes%bc(n)%field(m)%long_name = trim(gas_fluxes%bc(n)%field(m)%long_name) // ' for ' // name
enddo
do m = 1, fm_util_get_length(trim(flux_list) // 'atm/name')
gas_fields_atm%bc(n)%field(m)%long_name =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'atm/name', index = m)) // '-long_name')
gas_fields_atm%bc(n)%field(m)%long_name = trim(gas_fields_atm%bc(n)%field(m)%long_name) // ' for ' // name
enddo
do m = 1, fm_util_get_length(trim(flux_list) // 'ice/name')
gas_fields_ice%bc(n)%field(m)%long_name =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'ice/name', index = m)) // '-long_name')
gas_fields_ice%bc(n)%field(m)%long_name = trim(gas_fields_ice%bc(n)%field(m)%long_name) // ' for ' // name
enddo
! Save the atm_tr_index.
gas_fluxes%bc(n)%atm_tr_index = fm_util_get_integer('atm_tr_index', scalar = .true.)
! Save the molecular weight.
gas_fluxes%bc(n)%mol_wt = fm_util_get_real('mol_wt', scalar = .true.)
gas_fields_atm%bc(n)%mol_wt = gas_fluxes%bc(n)%mol_wt
gas_fields_ice%bc(n)%mol_wt = gas_fluxes%bc(n)%mol_wt
! Save the ice_restart_file.
gas_fluxes%bc(n)%ice_restart_file = fm_util_get_string('ice_restart_file', scalar = .true.)
gas_fields_atm%bc(n)%ice_restart_file = gas_fluxes%bc(n)%ice_restart_file
gas_fields_ice%bc(n)%ice_restart_file = gas_fluxes%bc(n)%ice_restart_file
! Save the ocean_restart_file.
gas_fluxes%bc(n)%ocean_restart_file = fm_util_get_string('ocean_restart_file', scalar = .true.)
gas_fields_atm%bc(n)%ocean_restart_file = gas_fluxes%bc(n)%ocean_restart_file
gas_fields_ice%bc(n)%ocean_restart_file = gas_fluxes%bc(n)%ocean_restart_file
! Save the params.
gas_fluxes%bc(n)%param => fm_util_get_real_array('param')
! Save the flags.
gas_fluxes%bc(n)%flag => fm_util_get_logical_array('flag')
! Perform some integrity checks.
num_parameters = fm_util_get_integer(trim(flux_list) // 'implementation/' //&
& trim(gas_fluxes%bc(n)%implementation) // '/num_parameters', scalar = .true.)
if (num_parameters .gt. 0) then
if (.not. associated(gas_fluxes%bc(n)%param)) then
write (error_string,'(a,i2)') ': need ', num_parameters
call mpp_error(FATAL, trim(error_header) // ' No param for ' // trim(name) // trim(error_string))
elseif (size(gas_fluxes%bc(n)%param(:)) .ne. num_parameters) then
write (error_string,'(a,i2,a,i2)') ': ', size(gas_fluxes%bc(n)%param(:)), ' given, need ', num_parameters
call mpp_error(FATAL, trim(error_header) // &
& ' Wrong number of param for ' // trim(name) // trim(error_string))
endif
elseif (num_parameters .eq. 0) then
if (associated(gas_fluxes%bc(n)%param)) then
write (error_string,'(a,i3)') ' but has size of ', size(gas_fluxes%bc(n)%param(:))
call mpp_error(FATAL, trim(error_header) // ' No params needed for ' // trim(name) // trim(error_string))
endif
else
write (error_string,'(a,i2)') ': ', num_parameters
call mpp_error(FATAL, trim(error_header) // &
& 'Num_parameters is negative for ' // trim(name) // trim(error_string))
endif
num_flags = fm_util_get_integer(trim(flux_list) // '/num_flags', scalar = .true.)
if (num_flags .gt. 0) then
if (.not. associated(gas_fluxes%bc(n)%flag)) then
write (error_string,'(a,i2)') ': need ', num_flags
call mpp_error(FATAL, trim(error_header) // ' No flag for ' // trim(name) // trim(error_string))
elseif (size(gas_fluxes%bc(n)%flag(:)) .ne. num_flags) then
write (error_string,'(a,i2,a,i2)') ': ', size(gas_fluxes%bc(n)%flag(:)), ' given, need ', num_flags
call mpp_error(FATAL, trim(error_header) // ' Wrong number of flag for ' // trim(name)//trim(error_string))
endif
elseif (num_flags .eq. 0) then
if (associated(gas_fluxes%bc(n)%flag)) then
write (error_string,'(a,i3)') ' but has size of ', size(gas_fluxes%bc(n)%flag(:))
call mpp_error(FATAL, trim(error_header) // ' No flags needed for ' // trim(name) // trim(error_string))
endif
else
write (error_string,'(a,i2)') ': ', num_flags
call mpp_error(FATAL, trim(error_header) // 'Num_flags is negative for ' // trim(name) // trim(error_string))
endif
! Set some flags for this flux_type.
gas_fluxes%bc(n)%use_atm_pressure = fm_util_get_logical(trim(flux_list) // '/use_atm_pressure')
gas_fields_atm%bc(n)%use_atm_pressure = gas_fluxes%bc(n)%use_atm_pressure
gas_fields_ice%bc(n)%use_atm_pressure = gas_fluxes%bc(n)%use_atm_pressure
gas_fluxes%bc(n)%use_10m_wind_speed = fm_util_get_logical(trim(flux_list) // '/use_10m_wind_speed')
gas_fields_atm%bc(n)%use_10m_wind_speed = gas_fluxes%bc(n)%use_10m_wind_speed
gas_fields_ice%bc(n)%use_10m_wind_speed = gas_fluxes%bc(n)%use_10m_wind_speed
gas_fluxes%bc(n)%pass_through_ice = fm_util_get_logical(trim(flux_list) // '/pass_through_ice')
gas_fields_atm%bc(n)%pass_through_ice = gas_fluxes%bc(n)%pass_through_ice
gas_fields_ice%bc(n)%pass_through_ice = gas_fluxes%bc(n)%pass_through_ice
!! mixed precision support
!! if use_r4_kind is present and true will intialize to the r4_kind type
else
! Save and check the flux_type.
gas_fluxes%bc_r4(n)%flux_type = fm_util_get_string('flux_type', scalar = .true.)
if (.not. fm_exists('/coupler_mod/types/' // trim(gas_fluxes%bc_r4(n)%flux_type))) then
call mpp_error(FATAL, trim(error_header) // ' Undefined flux_type given for ' //&
& trim(name) // ': ' // trim(gas_fluxes%bc_r4(n)%flux_type))
endif
gas_fields_atm%bc_r4(n)%flux_type = gas_fluxes%bc_r4(n)%flux_type
gas_fields_ice%bc_r4(n)%flux_type = gas_fluxes%bc_r4(n)%flux_type
! Save and check the implementation.
gas_fluxes%bc_r4(n)%implementation = fm_util_get_string('implementation', scalar = .true.)
if (.not. fm_exists('/coupler_mod/types/' // trim(gas_fluxes%bc_r4(n)%flux_type) //&
& '/implementation/' // trim(gas_fluxes%bc_r4(n)%implementation))) then
call mpp_error(FATAL, trim(error_header) // ' Undefined implementation given for ' //&
& trim(name) // ': ' // trim(gas_fluxes%bc_r4(n)%flux_type) // '/implementation/' //&
& trim(gas_fluxes%bc_r4(n)%implementation))
endif
gas_fields_atm%bc_r4(n)%implementation = gas_fluxes%bc_r4(n)%implementation
gas_fields_ice%bc_r4(n)%implementation = gas_fluxes%bc_r4(n)%implementation
! Set the flux list name.
flux_list = '/coupler_mod/types/' // trim(gas_fluxes%bc_r4(n)%flux_type) // '/'
! allocate the arrays
gas_fluxes%bc_r4(n)%num_fields = fm_util_get_length(trim(flux_list) // 'flux/name')
allocate (gas_fluxes%bc_r4(n)%field(gas_fluxes%bc_r4(n)%num_fields))
gas_fields_atm%bc_r4(n)%num_fields = fm_util_get_length(trim(flux_list) // 'atm/name')
allocate (gas_fields_atm%bc_r4(n)%field(gas_fields_atm%bc_r4(n)%num_fields))
gas_fields_ice%bc_r4(n)%num_fields = fm_util_get_length(trim(flux_list) // 'ice/name')
allocate (gas_fields_ice%bc_r4(n)%field(gas_fields_ice%bc_r4(n)%num_fields))
! Save the name and generate unique field names for Flux, Ice and Atm.
gas_fluxes%bc_r4(n)%name = name
do m = 1, fm_util_get_length(trim(flux_list) // 'flux/name')
gas_fluxes%bc_r4(n)%field(m)%name = trim(name) // "_" // fm_util_get_string(trim(flux_list) //&
& 'flux/name', index = m)
gas_fluxes%bc_r4(n)%field(m)%override = .false.
gas_fluxes%bc_r4(n)%field(m)%mean = .false.
enddo
gas_fields_atm%bc_r4(n)%name = name
do m = 1, fm_util_get_length(trim(flux_list) // 'atm/name')
gas_fields_atm%bc_r4(n)%field(m)%name = trim(name) // "_" // fm_util_get_string(trim(flux_list) //&
& 'atm/name', index = m)
gas_fields_atm%bc_r4(n)%field(m)%override = .false.
gas_fields_atm%bc_r4(n)%field(m)%mean = .false.
enddo
gas_fields_ice%bc_r4(n)%name = name
do m = 1, fm_util_get_length(trim(flux_list) // 'ice/name')
gas_fields_ice%bc_r4(n)%field(m)%name = trim(name) // "_" // fm_util_get_string(trim(flux_list) // &
& 'ice/name', index = m)
gas_fields_ice%bc_r4(n)%field(m)%override = .false.
gas_fields_ice%bc_r4(n)%field(m)%mean = .false.
enddo
! Save the units.
do m = 1, fm_util_get_length(trim(flux_list) // 'flux/name')
gas_fluxes%bc_r4(n)%field(m)%units =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'flux/name', index = m)) // &
& '-units', scalar = .true.)
enddo
do m = 1, fm_util_get_length(trim(flux_list) // 'atm/name')
gas_fields_atm%bc_r4(n)%field(m)%units =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'atm/name', index = m)) // '-units')
enddo
do m = 1, fm_util_get_length(trim(flux_list) // 'ice/name')
gas_fields_ice%bc_r4(n)%field(m)%units =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'ice/name', index = m)) // '-units')
enddo
! Save the long names.
do m = 1, fm_util_get_length(trim(flux_list) // 'flux/name')
gas_fluxes%bc_r4(n)%field(m)%long_name =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'flux/name', index = m)) // &
& '-long_name', scalar = .true.)
gas_fluxes%bc_r4(n)%field(m)%long_name = trim(gas_fluxes%bc_r4(n)%field(m)%long_name) // ' for ' // name
enddo
do m = 1, fm_util_get_length(trim(flux_list) // 'atm/name')
gas_fields_atm%bc_r4(n)%field(m)%long_name =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'atm/name', index = m)) // '-long_name')
gas_fields_atm%bc_r4(n)%field(m)%long_name = trim(gas_fields_atm%bc_r4(n)%field(m)%long_name)// &
' for '// name
enddo
do m = 1, fm_util_get_length(trim(flux_list) // 'ice/name')
gas_fields_ice%bc_r4(n)%field(m)%long_name =&
& fm_util_get_string(trim(fm_util_get_string(trim(flux_list) // 'ice/name', index = m)) // '-long_name')
gas_fields_ice%bc_r4(n)%field(m)%long_name = trim(gas_fields_ice%bc_r4(n)%field(m)%long_name) // &
' for ' // name
enddo
! Save the atm_tr_index.
gas_fluxes%bc_r4(n)%atm_tr_index = fm_util_get_integer('atm_tr_index', scalar = .true.)
! Save the molecular weight.
gas_fluxes%bc_r4(n)%mol_wt = fm_util_get_real('mol_wt', scalar = .true.)
gas_fields_atm%bc_r4(n)%mol_wt = gas_fluxes%bc_r4(n)%mol_wt
gas_fields_ice%bc_r4(n)%mol_wt = gas_fluxes%bc_r4(n)%mol_wt
! Save the ice_restart_file.
gas_fluxes%bc_r4(n)%ice_restart_file = fm_util_get_string('ice_restart_file', scalar = .true.)
gas_fields_atm%bc_r4(n)%ice_restart_file = gas_fluxes%bc_r4(n)%ice_restart_file
gas_fields_ice%bc_r4(n)%ice_restart_file = gas_fluxes%bc_r4(n)%ice_restart_file
! Save the ocean_restart_file.
gas_fluxes%bc_r4(n)%ocean_restart_file = fm_util_get_string('ocean_restart_file', scalar = .true.)
gas_fields_atm%bc_r4(n)%ocean_restart_file = gas_fluxes%bc_r4(n)%ocean_restart_file
gas_fields_ice%bc_r4(n)%ocean_restart_file = gas_fluxes%bc_r4(n)%ocean_restart_file
! Save the params.
gas_fluxes%bc_r4(n)%param => fm_util_get_real_array('param')
! Save the flags.
gas_fluxes%bc_r4(n)%flag => fm_util_get_logical_array('flag')
! Perform some integrity checks.
num_parameters = fm_util_get_integer(trim(flux_list) // 'implementation/' //&
& trim(gas_fluxes%bc_r4(n)%implementation) // '/num_parameters', scalar = .true.)
if (num_parameters .gt. 0) then
if (.not. associated(gas_fluxes%bc_r4(n)%param)) then
write (error_string,'(a,i2)') ': need ', num_parameters
call mpp_error(FATAL, trim(error_header) // ' No param for ' // trim(name) // trim(error_string))
elseif (size(gas_fluxes%bc_r4(n)%param(:)) .ne. num_parameters) then
write (error_string,'(a,i2,a,i2)') ': ', size(gas_fluxes%bc_r4(n)%param(:)), ' given, need ', num_parameters
call mpp_error(FATAL, trim(error_header) // &
& ' Wrong number of param for ' // trim(name) // trim(error_string))
endif
elseif (num_parameters .eq. 0) then
if (associated(gas_fluxes%bc_r4(n)%param)) then
write (error_string,'(a,i3)') ' but has size of ', size(gas_fluxes%bc_r4(n)%param(:))
call mpp_error(FATAL, trim(error_header) // ' No params needed for ' // trim(name) // trim(error_string))
endif
else
write (error_string,'(a,i2)') ': ', num_parameters
call mpp_error(FATAL, trim(error_header) // &
& 'Num_parameters is negative for ' // trim(name) // trim(error_string))
endif
num_flags = fm_util_get_integer(trim(flux_list) // '/num_flags', scalar = .true.)
if (num_flags .gt. 0) then
if (.not. associated(gas_fluxes%bc_r4(n)%flag)) then
write (error_string,'(a,i2)') ': need ', num_flags
call mpp_error(FATAL, trim(error_header) // ' No flag for ' // trim(name) // trim(error_string))
elseif (size(gas_fluxes%bc_r4(n)%flag(:)) .ne. num_flags) then
write (error_string,'(a,i2,a,i2)') ': ', size(gas_fluxes%bc_r4(n)%flag(:)), ' given, need ', num_flags
call mpp_error(FATAL, trim(error_header) // ' Wrong number of flag for '//trim(name)//trim(error_string))
endif
elseif (num_flags .eq. 0) then
if (associated(gas_fluxes%bc_r4(n)%flag)) then
write (error_string,'(a,i3)') ' but has size of ', size(gas_fluxes%bc_r4(n)%flag(:))
call mpp_error(FATAL, trim(error_header) // ' No flags needed for ' // trim(name) // trim(error_string))
endif
else
write (error_string,'(a,i2)') ': ', num_flags
call mpp_error(FATAL, trim(error_header) // 'Num_flags is negative for ' // trim(name) // trim(error_string))
endif
! Set some flags for this flux_type.
gas_fluxes%bc_r4(n)%use_atm_pressure = fm_util_get_logical(trim(flux_list) // '/use_atm_pressure')
gas_fields_atm%bc_r4(n)%use_atm_pressure = gas_fluxes%bc_r4(n)%use_atm_pressure
gas_fields_ice%bc_r4(n)%use_atm_pressure = gas_fluxes%bc_r4(n)%use_atm_pressure
gas_fluxes%bc_r4(n)%use_10m_wind_speed = fm_util_get_logical(trim(flux_list) // '/use_10m_wind_speed')
gas_fields_atm%bc_r4(n)%use_10m_wind_speed = gas_fluxes%bc_r4(n)%use_10m_wind_speed
gas_fields_ice%bc_r4(n)%use_10m_wind_speed = gas_fluxes%bc_r4(n)%use_10m_wind_speed
gas_fluxes%bc_r4(n)%pass_through_ice = fm_util_get_logical(trim(flux_list) // '/pass_through_ice')
gas_fields_atm%bc_r4(n)%pass_through_ice = gas_fluxes%bc_r4(n)%pass_through_ice
gas_fields_ice%bc_r4(n)%pass_through_ice = gas_fluxes%bc_r4(n)%pass_through_ice
endif ! r8/r4kind if
enddo ! while loop
if (verbose >= 5) then
write (outunit,*)
write (outunit,*) 'Dumping fluxes tracer tree'
if (.not. fm_dump_list('/coupler_mod/fluxes', recursive = .true.)) then
call mpp_error(FATAL, trim(error_header) // ' Problem dumping fluxes tracer tree')
endif
endif
! Check that the number of fluxes is the same on all processors
! If they are, then the sum of the number of fluxes across all processors
! should equal to the number of fluxes on each processor times the number of processors
total_fluxes = gas_fluxes%num_bcs
call mpp_sum(total_fluxes)
if (total_fluxes .ne. mpp_npes() * gas_fluxes%num_bcs) then
write (string, '(i4)') gas_fluxes%num_bcs
call mpp_error(FATAL, trim(error_header) //&
& ' Number of fluxes does not match across the processors: ' // trim(string) // ' fluxes')
endif
! Reset the defaults for the fm_util_set_value calls.
call fm_util_reset_no_overwrite
call fm_util_reset_caller
end subroutine atmos_ocean_fluxes_init
!> @brief Initialize the coupler type flux tracers
!> Initialize the /coupler_mod/types/ fields in the field manager. These fields
!! include:
!! @verbatim
!! air_sea_gas_flux_generic/
!! implementation/
!! ocmip2/
!! num_parameters = 2
!! num_flags = 0
!! use_atm_pressure = t
!! use_10m_wind_speed = t
!! pass_through_ice = f
!! atm/
!! name/
!! pcair, u10, psurf
!! long_name/
!! 'Atmospheric concentration'
!! 'Wind speed at 10 m'
!! 'Surface atmospheric pressure'
!! units/
!! 'mol/mol', 'm/s', 'Pa'
!! ice/
!! name/
!! alpha, csurf, sc_no
!! long_name/
!! 'Solubility from atmosphere'
!! 'Surface concentration from ocean'
!! 'Schmidt number'
!! units/
!! 'mol/m^3/atm', 'mol/m^3', 'dimensionless'
!! flux/
!! name/
!! flux, deltap, kw
!! long_name/
!! 'Surface gas flux'
!! 'ocean-air delta pressure'
!! 'piston velocity'
!! units/
!! 'mol/m^2/s', 'uatm', 'm/s'
!! air_sea_gas_flux/
!! implementation/
!! ocmip2/
!! num_parameters = 2
!! ocmip2_data/
!! num_parameters = 2
!! linear/
!! num_parameters = 3
!! num_flags = 0
!! use_atm_pressure = t
!! use_10m_wind_speed = t
!! pass_through_ice = f
!! atm/
!! name/
!! pcair, u10, psurf
!! long_name/
!! 'Atmospheric concentration'
!! 'Wind speed at 10 m'
!! 'Surface atmospheric pressure'
!! units/
!! 'mol/mol', 'm/s', 'Pa'
!! ice/
!! name/
!! alpha, csurf
!! long_name/