-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathcoupler_types.F90
4357 lines (3926 loc) · 213 KB
/
coupler_types.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 coupler_types_mod coupler_types_mod
!> @ingroup coupler
!> @brief This module contains type declarations for the coupler.
!> @author Richard Slater, John Dunne
!> @addtogroup coupler_types_mod
!> @{
module coupler_types_mod
use fms_mod, only: write_version_number, lowercase
use fms2_io_mod, only: FmsNetcdfDomainFile_t, open_file, register_restart_field
use fms2_io_mod, only: register_axis, unlimited, variable_exists, check_if_open
use fms2_io_mod, only: register_field, get_num_dimensions, variable_att_exists
use fms2_io_mod, only: get_variable_attribute, get_dimension_size, get_dimension_names
use fms2_io_mod, only: register_variable_attribute, get_variable_dimension_names
use fms2_io_mod, only: get_variable_num_dimensions
#ifdef use_deprecated_io
use fms_io_mod, only: restart_file_type, fms_io_register_restart_field=>register_restart_field
use fms_io_mod, only: query_initialized, restore_state
#endif
use time_manager_mod, only: time_type
use diag_manager_mod, only: register_diag_field, send_data
use data_override_mod, only: data_override
use mpp_domains_mod, only: domain2D, mpp_redistribute
use mpp_mod, only: mpp_error, FATAL, mpp_chksum
use fms_string_utils_mod, only: string
use platform_mod, only: r4_kind, r8_kind, i8_kind
implicit none
private
! Include variable "version" to be written to log file.
#include<file_version.h>
public coupler_types_init
public coupler_type_copy, coupler_type_spawn, coupler_type_set_diags
public coupler_type_write_chksums, coupler_type_send_data, coupler_type_data_override
public coupler_type_register_restarts, coupler_type_restore_state
public coupler_type_increment_data, coupler_type_rescale_data
public coupler_type_copy_data, coupler_type_redistribute_data
public coupler_type_destructor, coupler_type_initialized
public coupler_type_extract_data, coupler_type_set_data
public coupler_type_copy_1d_2d
public coupler_type_copy_1d_3d
character(len=*), parameter :: mod_name = 'coupler_types_mod'
!> @}
!! mixed precision methodology for the encapsulated types:
!!
!! bc(:) (coupler_nd_real8_field) -> field(:) (coupler_nd_real8_values)
!! coupler_nd_bc_type <
!! bc_r4(:) (coupler_nd_real4_field) -> field(:) (coupler_nd_real4_values)
!!
!! Arrays (values + field) are typically directly allocated and then 'spawn' can be used to create a new type
!! from a previously allocated 'template' type
!> Coupler data for 3D values
!> @ingroup coupler_types_mod
type, public :: coupler_3d_real8_values_type
character(len=48) :: name = ' ' !< The diagnostic name for this array
logical :: mean = .true. !< mean
logical :: override = .false. !< override
integer :: id_diag = 0 !< The diagnostic id for this array
character(len=128) :: long_name = ' ' !< The diagnostic long_name for this array
character(len=128) :: units = ' ' !< The units for this array
integer :: id_rest = 0 !< The id of this array in the restart field
logical :: may_init = .true. !< If true, there is an internal method
!! that can be used to initialize this field
!! if it can not be read from a restart file
real(r8_kind), pointer, contiguous, dimension(:,:,:) :: values => NULL() !< The pointer to the
!! array of values for this field; this
!! should be changed to allocatable
end type coupler_3d_real8_values_type
!> Coupler data for 3D fields
!> @ingroup coupler_types_mod
type, public :: coupler_3d_real8_field_type
character(len=48) :: name = ' ' !< name
integer :: num_fields = 0 !< num_fields
type(coupler_3d_real8_values_type), pointer, dimension(:) :: field => NULL() !< field
character(len=128) :: flux_type = ' ' !< flux_type
character(len=128) :: implementation = ' ' !< implementation
logical, pointer, dimension(:) :: flag => NULL() !< flag
integer :: atm_tr_index = 0 !< atm_tr_index
character(len=128) :: ice_restart_file = ' ' !< ice_restart_file
character(len=128) :: ocean_restart_file = ' ' !< ocean_restart_file
#ifdef use_deprecated_io
type(restart_file_type), pointer :: rest_type => NULL() !< A pointer to the restart_file_type
!! that is used for this field.
#endif
type(FmsNetcdfDomainFile_t), pointer :: fms2_io_rest_type => NULL() !< A pointer to the restart_file_type
!! That is used for this field
logical :: use_atm_pressure !< use_atm_pressure
logical :: use_10m_wind_speed !< use_10m_wind_speed
logical :: pass_through_ice !< pass_through_ice
real(r8_kind), pointer, dimension(:) :: param => NULL() !< param
real(r8_kind) :: mol_wt = 0.0_r8_kind !< mol_wt
end type coupler_3d_real8_field_type
!> Coupler data for 3D values
!> @ingroup coupler_types_mod
type, public :: coupler_3d_real4_values_type
character(len=48) :: name = ' ' !< The diagnostic name for this array
logical :: mean = .true. !< mean
logical :: override = .false. !< override
integer :: id_diag = 0 !< The diagnostic id for this array
character(len=128) :: long_name = ' ' !< The diagnostic long_name for this array
character(len=128) :: units = ' ' !< The units for this array
integer :: id_rest = 0 !< The id of this array in the restart field
logical :: may_init = .true. !< If true, there is an internal method
!! that can be used to initialize this field
!! if it can not be read from a restart file
real(r4_kind), pointer, contiguous, dimension(:,:,:) :: values => NULL() !< The pointer to the
!! array of values for this field; this
!! should be changed to allocatable
end type coupler_3d_real4_values_type
!> Coupler data for 3D fields
!> @ingroup coupler_types_mod
type, public :: coupler_3d_real4_field_type
character(len=48) :: name = ' ' !< name
integer :: num_fields = 0 !< num_fields
type(coupler_3d_real4_values_type), pointer, dimension(:) :: field => NULL() !< field
character(len=128) :: flux_type = ' ' !< flux_type
character(len=128) :: implementation = ' ' !< implementation
logical, pointer, dimension(:) :: flag => NULL() !< flag
integer :: atm_tr_index = 0 !< atm_tr_index
character(len=128) :: ice_restart_file = ' ' !< ice_restart_file
character(len=128) :: ocean_restart_file = ' ' !< ocean_restart_file
#ifdef use_deprecated_io
type(restart_file_type), pointer :: rest_type => NULL() !< A pointer to the restart_file_type
!! that is used for this field.
#endif
type(FmsNetcdfDomainFile_t), pointer :: fms2_io_rest_type => NULL() !< A pointer to the restart_file_type
!! That is used for this field
logical :: use_atm_pressure !< use_atm_pressure
logical :: use_10m_wind_speed !< use_10m_wind_speed
logical :: pass_through_ice !< pass_through_ice
!> precision needs to be r8_kind since this array is retrieved from the field_manager routine
!! fm_util_get_real_array which only returns a r8_kind
!! Might be able to change to allocatable(?) to do a conversion
real(r8_kind), pointer, dimension(:) :: param => NULL() !< param
real(r8_kind) :: mol_wt = 0.0_r8_kind !< mol_wt
end type coupler_3d_real4_field_type
!> Coupler data for 3D boundary conditions
!> @ingroup coupler_types_mod
type, public :: coupler_3d_bc_type
integer :: num_bcs = 0 !< The number of boundary condition fields
type(coupler_3d_real8_field_type), dimension(:), pointer :: bc => NULL() !< A pointer to the array of boundary
!! TODO above should be renamed eventually to indicate kind=8
type(coupler_3d_real4_field_type), dimension(:), pointer :: bc_r4 => NULL() !< A pointer to the array of boundary
logical :: set = .false. !< If true, this type has been initialized
integer :: isd, isc, iec, ied !< The i-direction data and computational domain index ranges for this type
integer :: jsd, jsc, jec, jed !< The j-direction data and computational domain index ranges for this type
integer :: ks, ke !< The k-direction index ranges for this type
end type coupler_3d_bc_type
!> Coupler data for 2D values
!> @ingroup coupler_types_mod
type, public :: coupler_2d_real8_values_type
character(len=48) :: name = ' ' !< The diagnostic name for this array
real(r8_kind), pointer, contiguous, dimension(:,:) :: values => NULL() !< The pointer to the
!! array of values for this field; this
!! should be changed to allocatable
logical :: mean = .true. !< mean
logical :: override = .false. !< override
integer :: id_diag = 0 !< The diagnostic id for this array
character(len=128) :: long_name = ' ' !< The diagnostic long_name for this array
character(len=128) :: units = ' ' !< The units for this array
integer :: id_rest = 0 !< The id of this array in the restart field
logical :: may_init = .true. !< If true, there is an internal method
!! that can be used to initialize this field
!! if it can not be read from a restart file
end type coupler_2d_real8_values_type
!> Coupler data for 2D fields
!> @ingroup coupler_types_mod
type, public :: coupler_2d_real8_field_type
character(len=48) :: name = ' ' !< name
integer :: num_fields = 0 !< num_fields
type(coupler_2d_real8_values_type), pointer, dimension(:) :: field => NULL() !< field
character(len=128) :: flux_type = ' ' !< flux_type
character(len=128) :: implementation = ' ' !< implementation
real(r8_kind), pointer, dimension(:) :: param => NULL() !< param
logical, pointer, dimension(:) :: flag => NULL() !< flag
integer :: atm_tr_index = 0 !< atm_tr_index
character(len=128) :: ice_restart_file = ' ' !< ice_restart_file
character(len=128) :: ocean_restart_file = ' ' !< ocean_restart_file
#ifdef use_deprecated_io
type(restart_file_type), pointer :: rest_type => NULL() !< A pointer to the restart_file_type
!! that is used for this field.
#endif
type(FmsNetcdfDomainFile_t), pointer :: fms2_io_rest_type => NULL() !< A pointer to the restart_file_type
!! That is used for this field
logical :: use_atm_pressure !< use_atm_pressure
logical :: use_10m_wind_speed !< use_10m_wind_speed
logical :: pass_through_ice !< pass_through_ice
real(r8_kind) :: mol_wt = 0.0_r8_kind !< mol_wt
end type coupler_2d_real8_field_type
!> Coupler data for 2D values
!> @ingroup coupler_types_mod
type, public :: coupler_2d_real4_values_type
character(len=44) :: name = ' ' !< The diagnostic name for this array
real(r4_kind), pointer, contiguous, dimension(:,:) :: values => NULL() !< The pointer to the
!! array of values for this field; this
!! should be changed to allocatable
logical :: mean = .true. !< mean
logical :: override = .false. !< override
integer :: id_diag = 0 !< The diagnostic id for this array
character(len=124) :: long_name = ' ' !< The diagnostic long_name for this array
character(len=124) :: units = ' ' !< The units for this array
integer :: id_rest = 0 !< The id of this array in the restart field
logical :: may_init = .true. !< If true, there is an internal method
!! that can be used to initialize this field
!! if it can not be read from a restart file
end type coupler_2d_real4_values_type
!> Coupler data for 2D fields
!> @ingroup coupler_types_mod
type, public :: coupler_2d_real4_field_type
character(len=44) :: name = ' ' !< name
integer :: num_fields = 0 !< num_fields
type(coupler_2d_real4_values_type), pointer, dimension(:) :: field => NULL() !< field
character(len=124) :: flux_type = ' ' !< flux_type
character(len=124) :: implementation = ' ' !< implementation
!> precision needs to be r8_kind since this array is retrieved from the field_manager routine
!! fm_util_get_real_array which only returns a r8_kind
!! Might be able to change to allocatable(?) to do a conversion
real(r8_kind), pointer, dimension(:) :: param => NULL() !< param
logical, pointer, dimension(:) :: flag => NULL() !< flag
integer :: atm_tr_index = 0 !< atm_tr_index
character(len=124) :: ice_restart_file = ' ' !< ice_restart_file
character(len=124) :: ocean_restart_file = ' ' !< ocean_restart_file
#ifdef use_deprecated_io
type(restart_file_type), pointer :: rest_type => NULL() !< A pointer to the restart_file_type
!! that is used for this field.
#endif
type(FmsNetcdfDomainFile_t), pointer :: fms2_io_rest_type => NULL() !< A pointer to the restart_file_type
!! That is used for this field
logical :: use_atm_pressure !< use_atm_pressure
logical :: use_10m_wind_speed !< use_10m_wind_speed
logical :: pass_through_ice !< pass_through_ice
real(r8_kind) :: mol_wt = 0.0_r8_kind !< mol_wt
end type coupler_2d_real4_field_type
!> Coupler data for 2D boundary conditions
!> @ingroup coupler_types_mod
type, public :: coupler_2d_bc_type
integer :: num_bcs = 0 !< The number of boundary condition fields
type(coupler_2d_real8_field_type), dimension(:), pointer :: bc => NULL() !< A pointer to the array of boundary
!! condition fields
type(coupler_2d_real4_field_type), dimension(:), pointer :: bc_r4 => NULL() !< A pointer to the array of boundary
!! condition fields
logical :: set = .false. !< If true, this type has been initialized
integer :: isd, isc, iec, ied !< The i-direction data and computational domain index ranges for this type
integer :: jsd, jsc, jec, jed !< The j-direction data and computational domain index ranges for this type
end type coupler_2d_bc_type
!> Coupler data for 1D values
!> @ingroup coupler_types_mod
type, public :: coupler_1d_real8_values_type
character(len=48) :: name = ' ' !< The diagnostic name for this array
real(r8_kind), pointer, dimension(:) :: values => NULL() !< The pointer to the array of values
logical :: mean = .true. !< mean
logical :: override = .false. !< override
integer :: id_diag = 0 !< The diagnostic id for this array
character(len=128) :: long_name = ' ' !< The diagnostic long_name for this array
character(len=128) :: units = ' ' !< The units for this array
logical :: may_init = .true. !< If true, there is an internal method
!! that can be used to initialize this field
!! if it can not be read from a restart file
end type coupler_1d_real8_values_type
!> Coupler data for 1D fields
!> @ingroup coupler_types_mod
type, public :: coupler_1d_real8_field_type
character(len=48) :: name = ' ' !< name
integer :: num_fields = 0 !< num_fields
type(coupler_1d_real8_values_type), pointer, dimension(:) :: field => NULL() !< field
character(len=128) :: flux_type = ' ' !< flux_type
character(len=128) :: implementation = ' ' !< implementation
!> precision has been explicitly defined
!! to be r8_kind during mixedmode update to field_manager
!! this explicit definition can be removed during the coupler update and be made into FMS_CP_KIND_
real(r8_kind), pointer, dimension(:) :: param => NULL() !< param
logical, pointer, dimension(:) :: flag => NULL() !< flag
integer :: atm_tr_index = 0 !< atm_tr_index
character(len=128) :: ice_restart_file = ' ' !< ice_restart_file
character(len=128) :: ocean_restart_file = ' ' !< ocean_restart_file
logical :: use_atm_pressure !< use_atm_pressure
logical :: use_10m_wind_speed !< use_10m_wind_speed
logical :: pass_through_ice !< pass_through_ice
!> precision has been explicitly defined
!! to be r8_kind during mixedmode update to field_manager
!! this explicit definition can be removed during the coupler update and be made into FMS_CP_KIND_
real(r8_kind) :: mol_wt = 0.0_r8_kind !< mol_wt
end type coupler_1d_real8_field_type
!> Coupler data for 1D values
!> @ingroup coupler_types_mod
type, public :: coupler_1d_real4_values_type
character(len=48) :: name = ' ' !< The diagnostic name for this array
real(r4_kind), pointer, dimension(:) :: values => NULL() !< The pointer to the array of values
logical :: mean = .true. !< mean
logical :: override = .false. !< override
integer :: id_diag = 0 !< The diagnostic id for this array
character(len=128) :: long_name = ' ' !< The diagnostic long_name for this array
character(len=128) :: units = ' ' !< The units for this array
logical :: may_init = .true. !< If true, there is an internal method
!! that can be used to initialize this field
!! if it can not be read from a restart file
end type coupler_1d_real4_values_type
!> Coupler data for 1D fields
!> @ingroup coupler_types_mod
type, public :: coupler_1d_real4_field_type
character(len=48) :: name = ' ' !< name
integer :: num_fields = 0 !< num_fields
type(coupler_1d_real4_values_type), pointer, dimension(:) :: field => NULL() !< field
character(len=128) :: flux_type = ' ' !< flux_type
character(len=128) :: implementation = ' ' !< implementation
!> precision needs to be r8_kind since this array is retrieved from the field_manager routine
!! fm_util_get_real_array which only returns a r8_kind
!! Might be able to change to allocatable(?) to do a conversion
real(r8_kind), pointer, dimension(:) :: param => NULL() !< param
logical, pointer, dimension(:) :: flag => NULL() !< flag
integer :: atm_tr_index = 0 !< atm_tr_index
character(len=128) :: ice_restart_file = ' ' !< ice_restart_file
character(len=128) :: ocean_restart_file = ' ' !< ocean_restart_file
logical :: use_atm_pressure !< use_atm_pressure
logical :: use_10m_wind_speed !< use_10m_wind_speed
logical :: pass_through_ice !< pass_through_ice
!> This is also read in r8 from the field manager, but since its not a pointer the conversion is allowed
real(r8_kind) :: mol_wt = 0.0_r8_kind !< mol_wt
end type coupler_1d_real4_field_type
!> Coupler data for 1D boundary conditions
!> @ingroup coupler_types_mod
type, public :: coupler_1d_bc_type
integer :: num_bcs = 0 !< The number of boundary condition fields
type(coupler_1d_real8_field_type), dimension(:), pointer :: bc => NULL() !< A pointer to the array of boundary
!! condition fields
type(coupler_1d_real4_field_type), dimension(:), pointer :: bc_r4 => NULL() !< A pointer to the array of boundary
!! condition fields
logical :: set = .false. !< If true, this type has been initialized
end type coupler_1d_bc_type
!> @addtogroup coupler_types_mod
!> @{
! The following public parameters can help in selecting the sub-elements of a
! coupler type. There are duplicate values because different boundary
! conditions have different sub-elements.
! Note: These should be parameters, but doing so would break openMP directives.
integer, public :: ind_pcair = 1 !< The index of the atmospheric concentration
integer, public :: ind_u10 = 2 !< The index of the 10 m wind speed
integer, public :: ind_psurf = 3 !< The index of the surface atmospheric pressure
integer, public :: ind_alpha = 1 !< The index of the solubility array for a tracer
integer, public :: ind_csurf = 2 !< The index of the ocean surface concentration
integer, public :: ind_sc_no = 3 !< The index for the Schmidt number for a tracer flux
integer, public :: ind_flux = 1 !< The index for the tracer flux
integer, public :: ind_deltap= 2 !< The index for ocean-air gas partial pressure change
integer, public :: ind_kw = 3 !< The index for the piston velocity
integer, public :: ind_flux0 = 4 !< The index for the piston velocity
integer, public :: ind_deposition = 1 !< The index for the atmospheric deposition flux
integer, public :: ind_runoff = 1 !< The index for a runoff flux
!> @}
! Interface definitions for overloaded routines
!> This is the interface to spawn one coupler_bc_type into another and then
!! register diagnostics associated with the new type.
!> @ingroup coupler_types_mod
interface coupler_type_copy
module procedure coupler_type_copy_1d_2d, coupler_type_copy_1d_3d
module procedure coupler_type_copy_2d_2d, coupler_type_copy_2d_3d
module procedure coupler_type_copy_3d_2d, coupler_type_copy_3d_3d
end interface coupler_type_copy
!> This is the interface to spawn one coupler_bc_type into another.
!> @ingroup coupler_types_mod
interface coupler_type_spawn
module procedure CT_spawn_1d_2d, CT_spawn_2d_2d, CT_spawn_3d_2d
module procedure CT_spawn_1d_3d, CT_spawn_2d_3d, CT_spawn_3d_3d
end interface coupler_type_spawn
!> This is the interface to copy the field data from one coupler_bc_type
!! to another of the same rank, size and decomposition.
!> @ingroup coupler_types_mod
interface coupler_type_copy_data
module procedure CT_copy_data_2d, CT_copy_data_3d, CT_copy_data_2d_3d
end interface coupler_type_copy_data
!> This is the interface to redistribute the field data from one coupler_bc_type
!! to another of the same rank and global size, but a different decomposition.
!> @ingroup coupler_types_mod
interface coupler_type_redistribute_data
module procedure CT_redistribute_data_2d, CT_redistribute_data_3d
end interface coupler_type_redistribute_data
!> This is the interface to rescale the field data in a coupler_bc_type.
!> @ingroup coupler_types_mod
interface coupler_type_rescale_data
module procedure CT_rescale_data_2d_r4, CT_rescale_data_3d_r4
module procedure CT_rescale_data_2d_r8, CT_rescale_data_3d_r8
end interface coupler_type_rescale_data
!> This is the interface to increment the field data from one coupler_bc_type
!! with the data from another. Both must have the same horizontal size and
!! decomposition, but a 2d type may be incremented by a 2d or 3d type
!> @ingroup coupler_types_mod
interface coupler_type_increment_data
module procedure CT_increment_data_2d_2d, CT_increment_data_3d_3d
module procedure CT_increment_data_2d_3d_r4, CT_increment_data_2d_3d_r8
end interface coupler_type_increment_data
!> This is the interface to extract a field in a coupler_bc_type into an array.
!> @ingroup coupler_types_mod
interface coupler_type_extract_data
module procedure CT_extract_data_2d_r4, CT_extract_data_2d_r8
module procedure CT_extract_data_3d_r4, CT_extract_data_3d_r8
module procedure CT_extract_data_3d_2d_r4, CT_extract_data_3d_2d_r8
end interface coupler_type_extract_data
!> This is the interface to set a field in a coupler_bc_type from an array.
!> @ingroup coupler_types_mod
interface coupler_type_set_data
module procedure CT_set_data_2d_r4, CT_set_data_3d_r4, CT_set_data_2d_3d_r4
module procedure CT_set_data_2d_r8, CT_set_data_3d_r8, CT_set_data_2d_3d_r8
end interface coupler_type_set_data
!> This is the interface to set diagnostics for the arrays in a coupler_bc_type.
!> @ingroup coupler_types_mod
interface coupler_type_set_diags
module procedure CT_set_diags_2d, CT_set_diags_3d
end interface coupler_type_set_diags
!> This is the interface to write out checksums for the elements of a coupler_bc_type.
!> @ingroup coupler_types_mod
interface coupler_type_write_chksums
module procedure CT_write_chksums_2d, CT_write_chksums_3d
end interface coupler_type_write_chksums
!> This is the interface to write out diagnostics of the arrays in a coupler_bc_type.
!> @ingroup coupler_types_mod
interface coupler_type_send_data
module procedure CT_send_data_2d, CT_send_data_3d
end interface coupler_type_send_data
!> This is the interface to override the values of the arrays in a coupler_bc_type.
!> @ingroup coupler_types_mod
interface coupler_type_data_override
module procedure CT_data_override_2d, CT_data_override_3d
end interface coupler_type_data_override
!> This is the interface to register the fields in a coupler_bc_type to be saved
!! in restart files.
!> @ingroup coupler_types_mod
interface coupler_type_register_restarts
#ifdef use_deprecated_io
module procedure mpp_io_CT_register_restarts_2d, mpp_io_CT_register_restarts_3d
module procedure mpp_io_CT_register_restarts_to_file_2d, mpp_io_CT_register_restarts_to_file_3d
#endif
module procedure CT_register_restarts_2d, CT_register_restarts_3d
end interface coupler_type_register_restarts
!> This is the interface to read in the fields in a coupler_bc_type that have
!! been saved in restart files.
!> @ingroup coupler_types_mod
interface coupler_type_restore_state
#ifdef use_deprecated_io
module procedure mpp_io_CT_restore_state_2d, mpp_io_CT_restore_state_3d
#endif
module procedure CT_restore_state_2d, CT_restore_state_3d
end interface coupler_type_restore_state
!> This function interface indicates whether a coupler_bc_type has been initialized.
!> @ingroup coupler_types_mod
interface coupler_type_initialized
module procedure CT_initialized_1d, CT_initialized_2d, CT_initialized_3d
end interface coupler_type_initialized
!> This is the interface to deallocate any data associated with a coupler_bc_type.
!> @ingroup coupler_types_mod
interface coupler_type_destructor
module procedure CT_destructor_1d, CT_destructor_2d, CT_destructor_3d
end interface coupler_type_destructor
contains
!> @addtogroup coupler_types_mod
!> @{
!> @brief Initialize the coupler types
subroutine coupler_types_init
logical, save :: module_is_initialized = .false.
! Return if already intialized
if (module_is_initialized) then
return
endif
! Write out the version of the file to the log file.
call write_version_number(trim(mod_name), version)
module_is_initialized = .true.
return
end subroutine coupler_types_init !}
!> @brief Copy fields from one coupler type to another. 1-D to 2-D version for generic coupler_type_copy.
!!
!! @throw FATAL, "Number of output fields exceeds zero"
subroutine coupler_type_copy_1d_2d(var_in, var_out, is, ie, js, je,&
& diag_name, axes, time, suffix)
type(coupler_1d_bc_type), intent(in) :: var_in !< variable to copy information from
type(coupler_2d_bc_type), intent(inout) :: var_out !< variable to copy information to
integer, intent(in) :: is !< lower bound of first dimension
integer, intent(in) :: ie !< upper bound of first dimension
integer, intent(in) :: js !< lower bound of second dimension
integer, intent(in) :: je !< upper bound of second dimension
character(len=*), intent(in) :: diag_name !< name for diagnostic file--if blank, then
!! don't register the fields
integer, dimension(:), intent(in) :: axes !< array of axes identifiers for diagnostic variable registration
type(time_type), intent(in) :: time !< model time variable for registering diagnostic field
character(len=*), intent(in), optional :: suffix !< optional suffix to make the name identifier unique
character(len=*), parameter :: error_header =&
& '==>Error from coupler_types_mod (coupler_type_copy_1d_2d):'
if (var_out%num_bcs > 0) then
! It is an error if the number of output fields exceeds zero, because it means this
! type has already been populated.
call mpp_error(FATAL, trim(error_header) // ' Number of output fields exceeds zero')
endif
if (var_in%num_bcs >= 0)&
& call CT_spawn_1d_2d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), suffix)
if ((var_out%num_bcs > 0) .and. (diag_name .ne. ' '))&
& call CT_set_diags_2d(var_out, diag_name, axes, time)
end subroutine coupler_type_copy_1d_2d
!> @brief Copy fields from one coupler type to another. 1-D to 3-D version for generic coupler_type_copy.
!!
!!
!! @throw FATAL, "Number of output fields is exceeds zero"
subroutine coupler_type_copy_1d_3d(var_in, var_out, is, ie, js, je, kd,&
& diag_name, axes, time, suffix)
type(coupler_1d_bc_type), intent(in) :: var_in !< variable to copy information from
type(coupler_3d_bc_type), intent(inout) :: var_out !< variable to copy information to
integer, intent(in) :: is !< lower bound of first dimension
integer, intent(in) :: ie !< upper bound of first dimension
integer, intent(in) :: js !< lower bound of second dimension
integer, intent(in) :: je !< upper bound of second dimension
integer, intent(in) :: kd !< third dimension
character(len=*), intent(in) :: diag_name !< name for diagnostic file--if blank, then
!! don't register the fields
integer, dimension(:), intent(in) :: axes !< array of axes identifiers for diagnostic variable registration
type(time_type), intent(in) :: time !< model time variable for registering diagnostic field
character(len=*), intent(in), optional :: suffix !< optional suffix to make the name identifier unique
character(len=*), parameter :: error_header =&
& '==>Error from coupler_types_mod (coupler_type_copy_1d_3d):'
if (var_out%num_bcs > 0) then
! It is an error if the number of output fields exceeds zero, because it means this
! type has already been populated.
call mpp_error(FATAL, trim(error_header) // ' Number of output fields exceeds zero')
endif
if (var_in%num_bcs >= 0)&
& call CT_spawn_1d_3d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), (/1, kd/), suffix)
if ((var_out%num_bcs > 0) .and. (diag_name .ne. ' '))&
& call CT_set_diags_3d(var_out, diag_name, axes, time)
end subroutine coupler_type_copy_1d_3d
!> @brief Copy fields from one coupler type to another. 2-D to 2-D version for generic coupler_type_copy.
!!
!! @throw FATAL, "Number of output fields is exceeds zero"
subroutine coupler_type_copy_2d_2d(var_in, var_out, is, ie, js, je,&
& diag_name, axes, time, suffix)
type(coupler_2d_bc_type), intent(in) :: var_in !< variable to copy information from
type(coupler_2d_bc_type), intent(inout) :: var_out !< variable to copy information to
integer, intent(in) :: is !< lower bound of first dimension
integer, intent(in) :: ie !< upper bound of first dimension
integer, intent(in) :: js !< lower bound of second dimension
integer, intent(in) :: je !< upper bound of second dimension
character(len=*), intent(in) :: diag_name !< name for diagnostic file--if blank, then
!! don't register the fields
integer, dimension(:), intent(in) :: axes !< array of axes identifiers for diagnostic variable registration
type(time_type), intent(in) :: time !< model time variable for registering diagnostic field
character(len=*), intent(in), optional :: suffix !< optional suffix to make the name identifier unique
character(len=*), parameter :: error_header =&
& '==>Error from coupler_types_mod (coupler_type_copy_2d_2d):'
if (var_out%num_bcs > 0) then
! It is an error if the number of output fields exceeds zero, because it means this
! type has already been populated.
call mpp_error(FATAL, trim(error_header) // ' Number of output fields exceeds zero')
endif
if (var_in%num_bcs >= 0)&
& call CT_spawn_2d_2d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), suffix)
if ((var_out%num_bcs > 0) .and. (diag_name .ne. ' '))&
& call CT_set_diags_2d(var_out, diag_name, axes, time)
end subroutine coupler_type_copy_2d_2d
!> @brief Copy fields from one coupler type to another. 2-D to 3-D version for generic coupler_type_copy.
!!
!! @throw FATAL, "Number of output fields is exceeds zero"
subroutine coupler_type_copy_2d_3d(var_in, var_out, is, ie, js, je, kd,&
& diag_name, axes, time, suffix)
type(coupler_2d_bc_type), intent(in) :: var_in !< variable to copy information from
type(coupler_3d_bc_type), intent(inout) :: var_out !< variable to copy information to
integer, intent(in) :: is !< lower bound of first dimension
integer, intent(in) :: ie !< upper bound of first dimension
integer, intent(in) :: js !< lower bound of second dimension
integer, intent(in) :: je !< upper bound of second dimension
integer, intent(in) :: kd !< third dimension
character(len=*), intent(in) :: diag_name !< name for diagnostic file--if blank, then
!! don't register the fields
integer, dimension(:), intent(in) :: axes !< array of axes identifiers for diagnostic variable registration
type(time_type), intent(in) :: time !< model time variable for registering diagnostic field
character(len=*), intent(in), optional :: suffix !< optional suffix to make the name identifier unique
character(len=*), parameter :: error_header =&
& '==>Error from coupler_types_mod (coupler_type_copy_2d_3d):'
if (var_out%num_bcs > 0) then
! It is an error if the number of output fields exceeds zero, because it means this
! type has already been populated.
call mpp_error(FATAL, trim(error_header) // ' Number of output fields exceeds zero')
endif
if (var_in%num_bcs >= 0)&
& call CT_spawn_2d_3d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), (/1, kd/), suffix)
if ((var_out%num_bcs > 0) .and. (diag_name .ne. ' '))&
& call CT_set_diags_3d(var_out, diag_name, axes, time)
end subroutine coupler_type_copy_2d_3d
!> @brief Copy fields from one coupler type to another. 3-D to 2-D version for generic coupler_type_copy.
!!
!! @throw FATAL, "Number of output fields is exceeds zero"
subroutine coupler_type_copy_3d_2d(var_in, var_out, is, ie, js, je,&
& diag_name, axes, time, suffix)
type(coupler_3d_bc_type), intent(in) :: var_in !< variable to copy information from
type(coupler_2d_bc_type), intent(inout) :: var_out !< variable to copy information to
integer, intent(in) :: is !< lower bound of first dimension
integer, intent(in) :: ie !< upper bound of first dimension
integer, intent(in) :: js !< lower bound of second dimension
integer, intent(in) :: je !< upper bound of second dimension
character(len=*), intent(in) :: diag_name !< name for diagnostic file--if blank, then
!! don't register the fields
integer, dimension(:), intent(in) :: axes !< array of axes identifiers for diagnostic variable registration
type(time_type), intent(in) :: time !< model time variable for registering diagnostic field
character(len=*), intent(in), optional :: suffix !< optional suffix to make the name identifier unique
character(len=*), parameter :: error_header =&
& '==>Error from coupler_types_mod (coupler_type_copy_3d_2d):'
if (var_out%num_bcs > 0) then
! It is an error if the number of output fields exceeds zero, because it means this
! type has already been populated.
call mpp_error(FATAL, trim(error_header) // ' Number of output fields exceeds zero')
endif
if (var_in%num_bcs >= 0)&
& call CT_spawn_3d_2d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), suffix)
if ((var_out%num_bcs > 0) .and. (diag_name .ne. ' '))&
& call CT_set_diags_2d(var_out, diag_name, axes, time)
end subroutine coupler_type_copy_3d_2d
!> @brief Copy fields from one coupler type to another. 3-D to 3-D version for generic coupler_type_copy.
!!
!! @throw FATAL, "Number of output fields exceeds zero"
subroutine coupler_type_copy_3d_3d(var_in, var_out, is, ie, js, je, kd,&
& diag_name, axes, time, suffix)
type(coupler_3d_bc_type), intent(in) :: var_in !< variable to copy information from
type(coupler_3d_bc_type), intent(inout) :: var_out !< variable to copy information to
integer, intent(in) :: is !< lower bound of first dimension
integer, intent(in) :: ie !< upper bound of first dimension
integer, intent(in) :: js !< lower bound of second dimension
integer, intent(in) :: je !< upper bound of second dimension
integer, intent(in) :: kd !< third dimension
character(len=*), intent(in) :: diag_name !< name for diagnostic file--if blank, then
!! don't register the fields
integer, dimension(:), intent(in) :: axes !< array of axes identifiers for diagnostic variable registration
type(time_type), intent(in) :: time !< model time variable for registering diagnostic field
character(len=*), intent(in), optional :: suffix !< optional suffix to make the name identifier unique
character(len=*), parameter :: error_header =&
& '==>Error from coupler_types_mod (coupler_type_copy_3d_3d):'
if (var_out%num_bcs > 0) then
! It is an error if the number of output fields exceeds zero, because it means this
! type has already been populated.
call mpp_error(FATAL, trim(error_header) // ' Number of output fields exceeds zero')
endif
if (var_in%num_bcs >= 0)&
& call CT_spawn_3d_3d(var_in, var_out, (/ is, is, ie, ie /), (/ js, js, je, je /), (/1, kd/), suffix)
if ((var_out%num_bcs > 0) .and. (diag_name .ne. ' '))&
& call CT_set_diags_3d(var_out, diag_name, axes, time)
end subroutine coupler_type_copy_3d_3d
!> @brief Generate one coupler type using another as a template. 1-D to 2-D version for generic coupler_type_spawn.
!!
!! @throw FATAL, "The output type has already been initialized"
!! @throw FATAL, "The parent type has not been initialized"
!! @throw FATAL, "Disordered i-dimension index bound list"
!! @throw FATAL, "Disordered j-dimension index bound list"
!! @throw FATAL, "var%bc already assocated"
!! @throw FATAL, "var%bc('n')%field already associated"
!! @throw FATAL, "var%bc('n')%field('m')%values already associated"
subroutine CT_spawn_1d_2d(var_in, var, idim, jdim, suffix, as_needed)
type(coupler_1d_bc_type), intent(in) :: var_in !< structure from which to copy information
type(coupler_2d_bc_type), intent(inout) :: var !< structure into which to copy information
integer, dimension(4), intent(in) :: idim !< The data and computational domain extents of
!! the first dimension in a non-decreasing list
integer, dimension(4), intent(in) :: jdim !< The data and computational domain extents of
!! the second dimension in a non-decreasing list
character(len=*), optional, intent(in) :: suffix !< optional suffix to make the name identifier unique
logical, optional, intent(in) :: as_needed !< Only do the spawn if the target type (var)
!! is not set and the parent type (var_in) is set.
character(len=*), parameter :: error_header =&
& '==>Error from coupler_types_mod (CT_spawn_1d_2d):'
character(len=400) :: error_msg
integer :: m, n
if (present(as_needed)) then
if (as_needed) then
if ((var%set) .or. (.not.var_in%set)) return
endif
endif
if (var%set)&
& call mpp_error(FATAL, trim(error_header) // ' The output type has already been initialized.')
if (.not.var_in%set)&
& call mpp_error(FATAL, trim(error_header) // ' The parent type has not been initialized.')
! check only one kind is used
if(var_in%num_bcs .gt. 0) then
if(associated(var_in%bc) .eqv. associated(var_in%bc_r4)) then
if( associated(var_in%bc) ) then
call mpp_error(FATAL, error_header//"var_in%bc and var_in%bc_r4 are both intialized,"//&
" only one should be associated per type.")
else
call mpp_error(FATAL, error_header//"var_in%bc and var_in%bc_r4 are both uninitialized,"//&
" one must be associated to copy field data.")
endif
endif
endif
var%num_bcs = var_in%num_bcs
var%set = .true.
if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) then
write (error_msg, *) trim(error_header), ' Disordered i-dimension index bound list ', idim
call mpp_error(FATAL, trim(error_msg))
endif
if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) then
write (error_msg, *) trim(error_header), ' Disordered j-dimension index bound list ', jdim
call mpp_error(FATAL, trim(error_msg))
endif
var%isd = idim(1) ; var%isc = idim(2) ; var%iec = idim(3) ; var%ied = idim(4)
var%jsd = jdim(1) ; var%jsc = jdim(2) ; var%jec = jdim(3) ; var%jed = jdim(4)
if (var%num_bcs > 0) then
if (associated(var_in%bc)) then
if (associated(var%bc)) then
call mpp_error(FATAL, trim(error_header) // ' var%bc already associated')
endif
allocate ( var%bc(var%num_bcs) )
do n = 1, var%num_bcs
var%bc(n)%name = var_in%bc(n)%name
var%bc(n)%atm_tr_index = var_in%bc(n)%atm_tr_index
var%bc(n)%flux_type = var_in%bc(n)%flux_type
var%bc(n)%implementation = var_in%bc(n)%implementation
var%bc(n)%ice_restart_file = var_in%bc(n)%ice_restart_file
var%bc(n)%ocean_restart_file = var_in%bc(n)%ocean_restart_file
var%bc(n)%use_atm_pressure = var_in%bc(n)%use_atm_pressure
var%bc(n)%use_10m_wind_speed = var_in%bc(n)%use_10m_wind_speed
var%bc(n)%pass_through_ice = var_in%bc(n)%pass_through_ice
var%bc(n)%mol_wt = var_in%bc(n)%mol_wt
var%bc(n)%num_fields = var_in%bc(n)%num_fields
if (associated(var%bc(n)%field)) then
write (error_msg, *) trim(error_header), ' var%bc(', n, ')%field already associated'
call mpp_error(FATAL, trim(error_msg))
endif
allocate ( var%bc(n)%field(var%bc(n)%num_fields) )
do m = 1, var%bc(n)%num_fields
if (present(suffix)) then
var%bc(n)%field(m)%name = trim(var_in%bc(n)%field(m)%name) // trim(suffix)
else
var%bc(n)%field(m)%name = var_in%bc(n)%field(m)%name
endif
var%bc(n)%field(m)%long_name = var_in%bc(n)%field(m)%long_name
var%bc(n)%field(m)%units = var_in%bc(n)%field(m)%units
var%bc(n)%field(m)%may_init = var_in%bc(n)%field(m)%may_init
var%bc(n)%field(m)%mean = var_in%bc(n)%field(m)%mean
if (associated(var%bc(n)%field(m)%values)) then
write (error_msg, *) trim(error_header),&
& ' var%bc(', n, ')%field(', m, ')%values already associated'
call mpp_error(FATAL, trim(error_msg))
endif
! Note that this may be allocating a zero-sized array, which is legal in Fortran.
allocate ( var%bc(n)%field(m)%values(var%isd:var%ied,var%jsd:var%jed) )
var%bc(n)%field(m)%values(:,:) = 0.0_r8_kind
enddo
enddo
else if( associated(var_in%bc_r4)) then
if (associated(var%bc_r4)) then
call mpp_error(FATAL, trim(error_header) // ' var%bc_r4 already associated')
endif
allocate ( var%bc_r4(var%num_bcs) )
do n = 1, var%num_bcs
var%bc_r4(n)%name = var_in%bc_r4(n)%name
var%bc_r4(n)%atm_tr_index = var_in%bc_r4(n)%atm_tr_index
var%bc_r4(n)%flux_type = var_in%bc_r4(n)%flux_type
var%bc_r4(n)%implementation = var_in%bc_r4(n)%implementation
var%bc_r4(n)%ice_restart_file = var_in%bc_r4(n)%ice_restart_file
var%bc_r4(n)%ocean_restart_file = var_in%bc_r4(n)%ocean_restart_file
var%bc_r4(n)%use_atm_pressure = var_in%bc_r4(n)%use_atm_pressure
var%bc_r4(n)%use_10m_wind_speed = var_in%bc_r4(n)%use_10m_wind_speed
var%bc_r4(n)%pass_through_ice = var_in%bc_r4(n)%pass_through_ice
var%bc_r4(n)%mol_wt = var_in%bc_r4(n)%mol_wt
var%bc_r4(n)%num_fields = var_in%bc_r4(n)%num_fields
if (associated(var%bc_r4(n)%field)) then
write (error_msg, *) trim(error_header), ' var%bc_r4(', n, ')%field already associated'
call mpp_error(FATAL, trim(error_msg))
endif
allocate ( var%bc_r4(n)%field(var%bc_r4(n)%num_fields) )
do m = 1, var%bc_r4(n)%num_fields
if (present(suffix)) then
var%bc_r4(n)%field(m)%name = trim(var_in%bc_r4(n)%field(m)%name) // trim(suffix)
else
var%bc_r4(n)%field(m)%name = var_in%bc_r4(n)%field(m)%name
endif
var%bc_r4(n)%field(m)%long_name = var_in%bc_r4(n)%field(m)%long_name
var%bc_r4(n)%field(m)%units = var_in%bc_r4(n)%field(m)%units
var%bc_r4(n)%field(m)%may_init = var_in%bc_r4(n)%field(m)%may_init
var%bc_r4(n)%field(m)%mean = var_in%bc_r4(n)%field(m)%mean
if (associated(var%bc_r4(n)%field(m)%values)) then
write (error_msg, *) trim(error_header),&
& ' var%bc_r4(', n, ')%field(', m, ')%values already associated'
call mpp_error(FATAL, trim(error_msg))
endif
! Note that this may be allocating a zero-sized array, which is legal in Fortran.
allocate ( var%bc_r4(n)%field(m)%values(var%isd:var%ied,var%jsd:var%jed) )
var%bc_r4(n)%field(m)%values(:,:) = 0.0_r4_kind
enddo
enddo
else
call mpp_error(FATAL, error_header//"passed in type has unassociated coupler_field_type"// &
" pointers for both bc and bc_r4")
endif
endif
end subroutine CT_spawn_1d_2d
!> @brief Generate one coupler type using another as a template. 1-D to 3-D version for generic CT_spawn.
!!
!! @throw FATAL, "The output type has already been initialized"
!! @throw FATAL, "The parent type has not been initialized"
!! @throw FATAL, "Disordered i-dimension index bound list"
!! @throw FATAL, "Disordered j-dimension index bound list"
!! @throw FATAL, "var%bc already assocated"
!! @throw FATAL, "var%bc('n')%field already associated"
!! @throw FATAL, "var%bc('n')%field('m')%values already associated"
subroutine CT_spawn_1d_3d(var_in, var, idim, jdim, kdim, suffix, as_needed)
type(coupler_1d_bc_type), intent(in) :: var_in !< structure from which to copy information
type(coupler_3d_bc_type), intent(inout) :: var !< structure into which to copy information
integer, dimension(4), intent(in) :: idim !< The data and computational domain extents of
!! the first dimension in a non-decreasing list
integer, dimension(4), intent(in) :: jdim !< The data and computational domain extents of
!! the second dimension in a non-decreasing list
integer, dimension(2), intent(in) :: kdim !< The array extents of the third dimension in
!! a non-decreasing list
character(len=*), optional, intent(in) :: suffix !< optional suffix to make the name identifier unique
logical, optional, intent(in) :: as_needed !< Only do the spawn if the target type (var)
!! is not set and the parent type (var_in) is set.
character(len=*), parameter :: error_header =&
& '==>Error from coupler_types_mod (CT_spawn_1d_3d):'
character(len=400) :: error_msg
integer :: m, n
if (present(as_needed)) then
if (as_needed) then
if ((var%set) .or. (.not.var_in%set)) return
endif
endif
if (var%set)&
& call mpp_error(FATAL, trim(error_header) // ' The output type has already been initialized.')
if (.not.var_in%set)&
& call mpp_error(FATAL, trim(error_header) // ' The parent type has not been initialized.')
! check only one kind is used
if(var_in%num_bcs .gt. 0) then
if(associated(var_in%bc) .eqv. associated(var_in%bc_r4)) then
if( associated(var_in%bc)) then
call mpp_error(FATAL, error_header//"var_in%bc and var_in%bc_r4 are both intialized,"// &
" only one should be associated per type")
else
call mpp_error(FATAL, error_header//"var_in%bc and var_in%bc_r4 are both unintialized,"// &
" one must be associated to copy field data")
endif
endif
endif
var%num_bcs = var_in%num_bcs
var%set = .true.
! Store the array extents that are to be used with this bc_type.
if ((idim(1) > idim(2)) .or. (idim(3) > idim(4))) then
write (error_msg, *) trim(error_header), ' Disordered i-dimension index bound list ', idim
call mpp_error(FATAL, trim(error_msg))
endif
if ((jdim(1) > jdim(2)) .or. (jdim(3) > jdim(4))) then
write (error_msg, *) trim(error_header), ' Disordered j-dimension index bound list ', jdim
call mpp_error(FATAL, trim(error_msg))
endif
var%isd = idim(1) ; var%isc = idim(2) ; var%iec = idim(3) ; var%ied = idim(4)
var%jsd = jdim(1) ; var%jsc = jdim(2) ; var%jec = jdim(3) ; var%jed = jdim(4)
var%ks = kdim(1) ; var%ke = kdim(2)
if (var%num_bcs > 0) then
if (kdim(1) > kdim(2)) then
write (error_msg, *) trim(error_header), ' Disordered k-dimension index bound list ', kdim
call mpp_error(FATAL, trim(error_msg))
endif
if( associated(var_in%bc)) then
if (associated(var%bc)) then
call mpp_error(FATAL, trim(error_header) // ' var%bc already associated')
endif
allocate ( var%bc(var%num_bcs) )
do n = 1, var%num_bcs
var%bc(n)%name = var_in%bc(n)%name
var%bc(n)%atm_tr_index = var_in%bc(n)%atm_tr_index
var%bc(n)%flux_type = var_in%bc(n)%flux_type
var%bc(n)%implementation = var_in%bc(n)%implementation
var%bc(n)%ice_restart_file = var_in%bc(n)%ice_restart_file
var%bc(n)%ocean_restart_file = var_in%bc(n)%ocean_restart_file
var%bc(n)%use_atm_pressure = var_in%bc(n)%use_atm_pressure
var%bc(n)%use_10m_wind_speed = var_in%bc(n)%use_10m_wind_speed
var%bc(n)%pass_through_ice = var_in%bc(n)%pass_through_ice
var%bc(n)%mol_wt = var_in%bc(n)%mol_wt
var%bc(n)%num_fields = var_in%bc(n)%num_fields
if (associated(var%bc(n)%field)) then
write (error_msg, *) trim(error_header), ' var%bc(', n, ')%field already associated'
call mpp_error(FATAL, trim(error_msg))
endif
allocate ( var%bc(n)%field(var%bc(n)%num_fields) )
do m = 1, var%bc(n)%num_fields
if (present(suffix)) then
var%bc(n)%field(m)%name = trim(var_in%bc(n)%field(m)%name) // trim(suffix)
else
var%bc(n)%field(m)%name = var_in%bc(n)%field(m)%name
endif
var%bc(n)%field(m)%long_name = var_in%bc(n)%field(m)%long_name
var%bc(n)%field(m)%units = var_in%bc(n)%field(m)%units
var%bc(n)%field(m)%may_init = var_in%bc(n)%field(m)%may_init
var%bc(n)%field(m)%mean = var_in%bc(n)%field(m)%mean
if (associated(var%bc(n)%field(m)%values)) then