forked from NOAA-GFDL/FMScoupler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoupler_main.F90
1878 lines (1629 loc) · 85.7 KB
/
coupler_main.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 General Public License
!
! This program is free software; you can redistribute it and/or modify it and
! are expected to follow the terms of the GNU General Public License
! as published by the Free Software Foundation; either version 2 of
! the License, or (at your option) any later version.
!
! MOM 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.
!
! For the full text of the GNU General Public License,
! write to: Free Software Foundation, Inc.,
! 675 Mass Ave, Cambridge, MA 02139, USA.
! or see: http://www.gnu.org/licenses/gpl.html
!-----------------------------------------------------------------------
!
!> \mainpage
!!
!! \brief coupler_main couples component models for atmosphere, ocean,
!! land and sea ice on independent grids. It also controls the time integration.
!!
!! \author Bruce Wyman <[email protected]>
!! \author V. Balaji <[email protected]>
!!
!! This version couples model components representing atmosphere, ocean, land
!! and sea ice on independent grids. Each model component is represented by a
!! data type giving the instantaneous model state.
!!
!! The component models are coupled to allow implicit vertical diffusion of
!! heat and moisture at the interfaces of the atmosphere, land, and ice models.
!! As a result, the atmosphere, land, and ice models all use the same time step.
!! The atmospheric model has been separated into down and up calls that
!! correspond to the down and up sweeps of the standard tridiagonal elimination.
!!
!! The ocean interface uses explicit mixing. Fluxes to and from the ocean must
!! be passed through the ice model. This includes atmospheric fluxes as well as
!! fluxes from the land to the ocean (runoff).
!!
!! This program contains the model's main time loop. Each iteration of the
!! main time loop is one coupled (slow) time step. Within this slow time step
!! loop is a fast time step loop, using the atmospheric time step, where the
!! tridiagonal vertical diffusion equations are solved. Exchange between sea
!! ice and ocean occurs once every slow timestep.
!!
!! \section coupler_namelists Namelists
!!
!! The three components of coupler: coupler_main, flux_exchange_mod, and surface_flux_mod
!! are configured through three namelists
!! * \ref coupler_config "coupler_nml"
!! * \ref flux_exchange_config "flux_exchange_nml"
!! * \ref surface_flux_config "surface_flux_nml"
!!
!!
!! \note
!! -# If no value is set for current_date, start_date, or calendar (or default value
!! specified) then the value from restart file "INPUT/coupler.res" will be used.
!! If neither a namelist value or restart file value exist the program will fail.
!! -# The actual run length will be the sum of months, days, hours, minutes, and
!! seconds. A run length of zero is not a valid option.
!! -# The run length must be an intergal multiple of the coupling timestep dt_cpld.
!!
!! \section Main Program Example
!!
!! ~~~~~~~~~~{.f90}
!! DO slow time steps (ocean)
!! call flux_ocean_to_ice
!!
!! call ICE_SLOW_UP
!!
!! DO fast time steps (atmos)
!! call flux_calculation
!!
!! call ATMOS_DOWN
!!
!! call flux_down_from_atmos
!!
!! call LAND_FAST
!!
!! call ICE_FAST
!!
!! call flux_up_to_atmos
!!
!! call ATMOS_UP
!! END DO
!!
!! call ICE_SLOW_DN
!!
!! call flux_ice_to_ocean
!!
!! call OCEAN
!! END DO
!! ~~~~~~~~~~
!> \page coupler_config Coupler Configuration
!!
!! coupler_main is configured via the coupler_nml namelist in the `input.nml` file.
!! The following table contains the available namelist variables.
!!
!! | Variable Name | Type | Default Value | Description |
!! | ------------------------ | --------------------- | --------------- | ----------- |
!! | current_date | integer, dimension(6) | (/0,0,0,0,0,0/) | The date that the current integration starts with. |
!! | force_date_from_namelist | logical | .FALSE. | Flag that determines whether the namelist variable current_date should override the date in the restart file INPUT/coupler.res. If the restart file does not exist then force_date_from_namelist has not effect, the value of current_date will be used. |
!! | calendar | character(len=17) | '' | The calendar type used by the current integration. Valid values are consistent with the time_manager module: 'julian', 'noleap', or 'thirty_day'. The value 'no_calendar' can not be used because the time_manager's date function are used. All values must be lowercase. |
!! | months | integer | 0 | The number of months that the current integration will be run for. |
!! | days | integer | 0 | The number of days that the current integration will be run for. |
!! | hours | integer | 0 | The number of hours that the current integration will be run for. |
!! | minutes | integer | 0 | The number of minutes that the current integration will be run for. |
!! | seconds | integer | 0 | The number of seconds that the current integration will be run for. |
!! | dt_atmos | integer | 0 | Atmospheric model time step in seconds, including the fast coupling with land and sea ice. |
!! | dt_cpld | integer | 0 | Time step in seconds for coupling between ocean and atmospheric models: must be an integral multiple of dt_atmos and dt_ocean. This is the "slow" timestep. |
!! | do_atmos, do_ocean, do_ice, do_land, do_flux | logical | .TRUE. | If true (default), that particular model component (atmos, etc.) is run. If false, the execution of that component is skipped. This is used when ALL the output fields sent by that component to the coupler have been overridden using the data_override feature. For advanced users only: if you're not sure, you should leave these values at TRUE. |
!! | concurrent | logical | .FALSE. | If true, the ocean executes concurrently with the atmosphere-land-ocean on a separate set of PEs. If false (default), the execution is serial: call atmos... followed by call ocean... If using concurrent execution, you must set one of atmos_npes and ocean_npes, see below. |
!! | do_concurrent_radiation | logical | .FALSE. ! If true then radiation is done concurrently
!! | atmos_npes, ocean_npes | integer | none | If concurrent is set to true, we use these to set the list of PEs on which each component runs. At least one of them must be set to a number between 0 and NPES. If exactly one of these two is set non-zero, the other is set to the remainder from NPES. If both are set non-zero they must add up to NPES. |
!! | atmos_nthreads, ocean_nthreads | integer | 1 | We set here the number of OpenMP threads to use separately for each component (default 1) |
!! | radiation_nthreads | integer | 1 | Number of threads to use for the concurrent radiation
!! | use_lag_fluxes | logical | .TRUE. | If true, then mom4 is forced with SBCs from one coupling timestep ago If false, then mom4 is forced with most recent SBCs. For a leapfrog MOM coupling with dt_cpld=dt_ocean, lag fluxes can be shown to be stable and current fluxes to be unconditionally unstable. For dt_cpld>dt_ocean there is probably sufficient damping. use_lag_fluxes is set to TRUE by default. |
!! | restart_interval | integer, dimension(6) | (/0,0,0,0,0,0/) | The time interval that write out intermediate restart file. The format is (yr,mo,day,hr,min,sec). When restart_interval is all zero, no intermediate restart file will be written out. |
!! | do_debug | logical | .FALSE. | If .TRUE. print additional debugging messages |
!! | do_chksum | logical | .FALSE. | Turns on/off checksum of certain variables |
!!
!! \note
!! -# If no value is set for current_date, start_date, or calendar (or default value specified) then the value from restart
!! file "INPUT/coupler.res" will be used. If neither a namelist value or restart file value exist the program will fail.
!! -# The actual run length will be the sum of months, days, hours, minutes, and seconds. A run length of zero is not a
!! valid option.
!! -# The run length must be an intergal multiple of the coupling timestep dt_cpld.
!> \throw FATAL, "no namelist value for current_date"
!! A namelist value for current_date must be given if no restart file for
!! coupler_main (INPUT/coupler.res) is found.
!! \throw FATAL, "invalid namelist value for calendar"
!! The value of calendar must be 'julian', 'noleap', or 'thirty_day'.
!! See the namelist documentation.
!! \throw FATAL, "no namelist value for calendar"
!! If no restart file is present, then a namelist value for calendar
!! must be specified.
!! \throw FATAL, "initial time is greater than current time"
!! If a restart file is present, then the namelist value for either
!! current_date or start_date was incorrectly set.
!! \throw FATAL, "run length must be multiple of ocean time step"
!! There must be an even number of ocean time steps for the requested run length.
!! \throw FATAL, "final time does not match expected ending time"
!! This error should probably not occur because of checks done at initialization time.
program coupler_main
use constants_mod, only: constants_init
use time_manager_mod, only: time_type, set_calendar_type, set_time
use time_manager_mod, only: set_date, get_date, days_in_month, month_name
use time_manager_mod, only: operator(+), operator(-), operator (<)
use time_manager_mod, only: operator (>), operator ( /= ), operator ( / )
use time_manager_mod, only: operator (*), THIRTY_DAY_MONTHS, JULIAN
use time_manager_mod, only: NOLEAP, NO_CALENDAR, INVALID_CALENDAR
use time_manager_mod, only: date_to_string, increment_date
use time_manager_mod, only: operator(>=), operator(<=), operator(==)
use fms_mod, only: open_namelist_file, field_exist, file_exist, check_nml_error
use fms_mod, only: uppercase, error_mesg, write_version_number
use fms_mod, only: fms_init, fms_end, stdout
use fms_mod, only: read_data, write_data
use fms_io_mod, only: fms_io_exit
use fms_io_mod, only: restart_file_type, register_restart_field, save_restart
use diag_manager_mod, only: diag_manager_init, diag_manager_end, diag_grid_end
use diag_manager_mod, only: DIAG_OCEAN, DIAG_OTHER, DIAG_ALL, get_base_date
use diag_manager_mod, only: diag_manager_set_time_end
use field_manager_mod, only: MODEL_ATMOS, MODEL_LAND, MODEL_ICE
use tracer_manager_mod, only: tracer_manager_init, get_tracer_index
use tracer_manager_mod, only: get_number_tracers, get_tracer_names, NO_TRACER
use coupler_types_mod, only: coupler_types_init
use data_override_mod, only: data_override_init
!
! model interfaces used to couple the component models:
! atmosphere, land, ice, and ocean
!
use atmos_model_mod, only: atmos_model_init, atmos_model_end
use atmos_model_mod, only: update_atmos_model_dynamics
use atmos_model_mod, only: update_atmos_model_down
use atmos_model_mod, only: update_atmos_model_up
use atmos_model_mod, only: atmos_data_type
use atmos_model_mod, only: land_ice_atmos_boundary_type
use atmos_model_mod, only: atmos_data_type_chksum
use atmos_model_mod, only: lnd_ice_atm_bnd_type_chksum
use atmos_model_mod, only: lnd_atm_bnd_type_chksum
use atmos_model_mod, only: ice_atm_bnd_type_chksum
use atmos_model_mod, only: atmos_model_restart
use atmos_model_mod, only: update_atmos_model_radiation
use atmos_model_mod, only: update_atmos_model_state
use land_model_mod, only: land_model_init, land_model_end
use land_model_mod, only: land_data_type, atmos_land_boundary_type
use land_model_mod, only: update_land_model_fast, update_land_model_slow
use land_model_mod, only: atm_lnd_bnd_type_chksum
use land_model_mod, only: land_data_type_chksum
use land_model_mod, only: land_model_restart
use ice_model_mod, only: ice_model_init, ice_model_end
use ice_model_mod, only: update_ice_model_slow_up
use ice_model_mod, only: update_ice_model_fast
use ice_model_mod, only: update_ice_model_slow_dn
use ice_model_mod, only: ice_data_type, land_ice_boundary_type
use ice_model_mod, only: ocean_ice_boundary_type, atmos_ice_boundary_type
use ice_model_mod, only: ice_model_restart
use ice_model_mod, only: ice_data_type_chksum, ocn_ice_bnd_type_chksum
use ice_model_mod, only: atm_ice_bnd_type_chksum, lnd_ice_bnd_type_chksum
use ocean_model_mod, only: update_ocean_model, ocean_model_init
use ocean_model_mod, only: ocean_model_end, ocean_public_type, ocean_state_type, ice_ocean_boundary_type
use ocean_model_mod, only: ocean_model_restart
use ocean_model_mod, only: ocean_public_type_chksum, ice_ocn_bnd_type_chksum
!
! flux_ calls translate information between model grids - see flux_exchange.f90
!
use flux_exchange_mod, only: flux_exchange_init
use flux_exchange_mod, only: sfc_boundary_layer
use flux_exchange_mod, only: generate_sfc_xgrid
use flux_exchange_mod, only: flux_down_from_atmos
use flux_exchange_mod, only: flux_up_to_atmos
use flux_exchange_mod, only: flux_land_to_ice
use flux_exchange_mod, only: flux_ice_to_ocean
use flux_exchange_mod, only: flux_ocean_to_ice
use flux_exchange_mod, only: flux_check_stocks, flux_init_stocks, flux_ice_to_ocean_stocks, flux_ocean_from_ice_stocks
use atmos_tracer_driver_mod, only: atmos_tracer_driver_gather_data
use mpp_mod, only: mpp_clock_id, mpp_clock_begin, mpp_clock_end, mpp_chksum
use mpp_mod, only: mpp_init, mpp_pe, mpp_npes, mpp_root_pe, mpp_sync
use mpp_mod, only: stderr, stdlog, mpp_error, NOTE, FATAL, WARNING
use mpp_mod, only: mpp_set_current_pelist, mpp_declare_pelist
use mpp_mod, only: input_nml_file
use mpp_io_mod, only: mpp_open, mpp_close, mpp_io_clock_on
use mpp_io_mod, only: MPP_NATIVE, MPP_RDONLY, MPP_DELETE
use mpp_domains_mod, only: mpp_broadcast_domain
use memutils_mod, only: print_memuse_stats
implicit none
!-----------------------------------------------------------------------
character(len=128) :: version = '$Id$'
character(len=128) :: tag = '$Name$'
!-----------------------------------------------------------------------
!---- model defined-types ----
type (atmos_data_type) :: Atm
type (land_data_type) :: Land
type (ice_data_type) :: Ice
! allow members of ocean type to be aliased (ap)
type (ocean_public_type), target :: Ocean
type (ocean_state_type), pointer :: Ocean_state => NULL()
type(atmos_land_boundary_type) :: Atmos_land_boundary
type(atmos_ice_boundary_type) :: Atmos_ice_boundary
type(land_ice_atmos_boundary_type) :: Land_ice_atmos_boundary
type(land_ice_boundary_type) :: Land_ice_boundary
type(ice_ocean_boundary_type) :: Ice_ocean_boundary
type(ocean_ice_boundary_type) :: Ocean_ice_boundary
!-----------------------------------------------------------------------
! ----- coupled model time -----
type (time_type) :: Time, Time_init, Time_end, &
Time_step_atmos, Time_step_cpld
type(time_type) :: Time_atmos, Time_ocean
integer :: num_atmos_calls, na
integer :: num_cpld_calls, nc
!------ for intermediate restart
type(restart_file_type), allocatable :: Ice_bc_restart(:), Ocn_bc_restart(:)
character(len=64), allocatable :: ice_bc_restart_file(:), ocn_bc_restart_file(:)
integer :: num_ice_bc_restart=0, num_ocn_bc_restart=0
type(time_type) :: Time_restart, Time_restart_current, Time_start
character(len=32) :: timestamp
! ----- coupled model initial date -----
integer :: date_init(6) = (/ 0, 0, 0, 0, 0, 0 /)
integer :: calendar_type = INVALID_CALENDAR
!-----------------------------------------------------------------------
!------ namelist interface -------
integer, dimension(6) :: restart_interval = (/ 0, 0, 0, 0, 0, 0/) !< The time interval that write out intermediate restart file.
!! The format is (yr,mo,day,hr,min,sec). When restart_interval
!! is all zero, no intermediate restart file will be written out
integer, dimension(6) :: current_date = (/ 0, 0, 0, 0, 0, 0 /) !< The date that the current integration starts with. (See
!! force_date_from_namelist.)
character(len=17) :: calendar = ' ' !< The calendar type used by the current integration. Valid values are
!! consistent with the time_manager module: 'julian', 'noleap', or 'thirty_day'.
!! The value 'no_calendar' cannot be used because the time_manager's date
!! functions are used. All values must be lower case.
logical :: force_date_from_namelist = .false. !< Flat that determines whether the namelist variable current_date should override
!! the date in the restart file `INPUT/coupler.res`. If the restart file does not
!! exist then force_date_from_namelist has no effect, the value of current_date
!! will be used.
integer :: months=0 !< Number of months the current integration will be run for
integer :: days=0 !< Number of days the current integration will be run for
integer :: hours=0 !< Number of hours the current integration will be run for
integer :: minutes=0 !< Number of minutes the current integration will be run for
integer :: seconds=0 !< Number of seconds the current integration will be run for
integer :: dt_atmos = 0 !< Atmospheric model time step in seconds, including the fat coupling with land and sea ice
integer :: dt_cpld = 0 !< Time step in seconds for coupling between ocean and atmospheric models. This must be an integral
!! multiple of dt_atmos and dt_ocean. This is the "slow" timestep.
integer :: atmos_npes=0 !< The number of MPI tasks to use for the atmosphere
integer :: ocean_npes=0 !< The number of MPI tasks to use for the ocean
integer :: ice_npes=0 !< The number of MPI tasks to use for the ice
integer :: land_npes=0 !< The number of MPI tasks to use for the land
integer :: atmos_nthreads=1 !< Number of OpenMP threads to use in the atmosphere
integer :: ocean_nthreads=1 !< Number of OpenMP threads to use in the ocean
integer :: radiation_nthreads=1 !< Number of threads to use for the radiation.
logical :: do_atmos =.true. !< Indicates if this component should be executed. If .FALSE., then execution is skipped. This is used
!! This is used when ALL the output fields sent by this component to the coupler have been overridden
!! using the data_override feature. This is for advanced users only.
logical :: do_land =.true. !< See do_atmos
logical :: do_ice =.true. !< See do_atmos
logical :: do_ocean=.true. !< See do_atmos
logical :: do_flux =.true. !< See do_atmos
logical :: concurrent=.FALSE. !< If .TRUE., the ocean executes concurrently with the atmosphere-land-ice on a separate set of PEs.
!! If .FALSE., the execution is serial: call atmos... followed by call ocean...
logical :: do_concurrent_radiation=.FALSE. !< If .TRUE. then radiation is done concurrently
logical :: use_lag_fluxes=.TRUE. !< If .TRUE., then mom4 is forced with SBCs from one coupling timestep ago. If .FALSE., then mom4
!! if forced with most recent SBCs. For a leapfrog MOM coupling with dt_cpld=dt_ocean, lag fluxes
!! can be shown to be stable and current fluxes to be unconditionally unstable. For dt_cpld>gt_ocean
!! there is probably sufficient damping.
logical :: do_chksum=.FALSE.
logical :: do_debug=.FALSE.
integer :: check_stocks = 0 ! -1: never 0: at end of run only n>0: every n coupled steps
namelist /coupler_nml/ current_date, calendar, force_date_from_namelist, &
months, days, hours, minutes, seconds, dt_cpld, dt_atmos, &
do_atmos, do_land, do_ice, do_ocean, do_flux, &
atmos_npes, ocean_npes, ice_npes, land_npes, &
atmos_nthreads, ocean_nthreads, radiation_nthreads, &
concurrent, do_concurrent_radiation, use_lag_fluxes, &
check_stocks, restart_interval, do_debug, do_chksum
integer :: initClock, mainClock, termClock
integer :: newClock0, newClock1, newClock2, newClock3, newClock4, newClock5, newClock6, newClock7, &
newClock8, newClock9, newClock10, newClock11, newClock12, newClock13, newClock14, newClocka, &
newClockb, newClockc, newClockd, newClocke, newClockf, newClockg, newClockh, newClocki, &
newClockj, newClockk, newClockl
integer :: id_atmos_model_init, id_land_model_init, id_ice_model_init
integer :: id_ocean_model_init, id_flux_exchange_init
character(len=80) :: text
character(len=48), parameter :: mod_name = 'coupler_main_mod'
integer :: outunit
integer :: ensemble_id = 1
integer, allocatable :: ensemble_pelist(:, :)
integer :: conc_nthreads = 1
integer :: omp_get_thread_num, omp_get_num_threads
real :: omp_get_wtime
real :: dsec, omp_sec(2)=0.0, imb_sec(2)=0.0
!#######################################################################
call mpp_init()
!these clocks are on the global pelist
initClock = mpp_clock_id( 'Initialization' )
call mpp_clock_begin(initClock)
call fms_init
call constants_init
call coupler_init
if(do_chksum) call coupler_chksum('coupler_init+', 0)
call mpp_set_current_pelist()
call mpp_clock_end (initClock) !end initialization
call mpp_clock_begin(mainClock) !begin main loop
!-----------------------------------------------------------------------
!------ ocean/slow-ice integration loop ------
if(check_stocks >= 0) then
call mpp_set_current_pelist()
call flux_init_stocks(Time, Atm, Land, Ice, Ocean_state)
endif
if( Atm%pe )then
call mpp_set_current_pelist(Atm%pelist)
newClock1 = mpp_clock_id( 'generate_sfc_xgrid' )
endif
call mpp_set_current_pelist()
newClock2 = mpp_clock_id( 'flux_ocean_to_ice' )
newClock3 = mpp_clock_id( 'flux_ice_to_ocean' )
newClock4 = mpp_clock_id( 'flux_check_stocks' )
if( Atm%pe )then
call mpp_set_current_pelist(Atm%pelist)
newClock5 = mpp_clock_id( 'ATM' )
newClock6 = mpp_clock_id( ' ATM: update_ice_model_slow_up' )
newClock7 = mpp_clock_id( ' ATM: atmos loop' )
newClocka = mpp_clock_id( ' A-L: atmos_tracer_driver_gather_data' )
newClockb = mpp_clock_id( ' A-L: sfc_boundary_layer' )
newClockl = mpp_clock_id( ' A-L: update_atmos_model_dynamics')
if (.not. do_concurrent_radiation) then
newClockj = mpp_clock_id( ' A-L: serial radiation' )
endif
newClockc = mpp_clock_id( ' A-L: update_atmos_model_down' )
newClockd = mpp_clock_id( ' A-L: flux_down_from_atmos' )
newClocke = mpp_clock_id( ' A-L: update_land_model_fast' )
newClockf = mpp_clock_id( ' A-L: update_ice_model_fast' )
newClockg = mpp_clock_id( ' A-L: flux_up_to_atmos' )
newClockh = mpp_clock_id( ' A-L: update_atmos_model_up' )
if (do_concurrent_radiation) then
newClockj = mpp_clock_id( ' A-L: concurrent radiation' )
newClocki = mpp_clock_id( ' A-L: concurrent atmos' )
endif
newClockk = mpp_clock_id( ' A-L: update_atmos_model_state')
newClock8 = mpp_clock_id( ' ATM: update_land_model_slow' )
newClock9 = mpp_clock_id( ' ATM: flux_land_to_ice' )
newClock10 = mpp_clock_id( ' ATM: update_ice_model_slow_dn' )
newClock11 = mpp_clock_id( ' ATM: flux_ice_to_ocean_stocks' )
endif
if( Ocean%is_ocean_pe )then
call mpp_set_current_pelist(Ocean%pelist)
newClock12 = mpp_clock_id( 'OCN' )
endif
call mpp_set_current_pelist()
newClock13 = mpp_clock_id( 'intermediate restart' )
newClock14 = mpp_clock_id( 'final flux_check_stocks' )
do nc = 1, num_cpld_calls
if(do_chksum) call coupler_chksum('top_of_coupled_loop+', nc)
if( Atm%pe )then
call mpp_set_current_pelist(Atm%pelist)
call mpp_clock_begin(newClock1)
call generate_sfc_xgrid( Land, Ice )
call mpp_clock_end(newClock1)
end if
call mpp_set_current_pelist()
if(do_chksum) then
if (Atm%pe) then
call mpp_set_current_pelist(Atm%pelist)
call atmos_ice_land_chksum('MAIN_LOOP-', nc, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
endif
if (Ocean%is_ocean_pe) then
call mpp_set_current_pelist(Ocean%pelist)
call ocean_chksum('MAIN_LOOP-', nc, Ocean, Ice_ocean_boundary)
endif
call mpp_set_current_pelist()
endif
! Calls to flux_ocean_to_ice and flux_ice_to_ocean are all PE communication
! points when running concurrently. The calls are placed next to each other in
! concurrent mode to avoid multiple synchronizations within the main loop.
! This is only possible in the serial case when use_lag_fluxes.
call mpp_clock_begin(newClock2)
call flux_ocean_to_ice( Time, Ocean, Ice, Ocean_ice_boundary )
call mpp_clock_end(newClock2)
if(do_chksum) then
call coupler_chksum('flux_ocn2ice+', nc)
if (Atm%pe) then
call mpp_set_current_pelist(Atm%pelist)
call atmos_ice_land_chksum('fluxocn2ice+', nc, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
endif
if (Ocean%is_ocean_pe) then
call mpp_set_current_pelist(Ocean%pelist)
call ocean_public_type_chksum('fluxocn2ice+', nc, Ocean)
endif
call mpp_set_current_pelist()
endif
! Update Ice_ocean_boundary; first iteration is supplied by restart
if( use_lag_fluxes )then
call mpp_clock_begin(newClock3)
call flux_ice_to_ocean( Time, Ice, Ocean, Ice_ocean_boundary )
call mpp_clock_end(newClock3)
end if
! Update Ice_ocean_boundary; first iteration is supplied by restart
! To print the value of frazil heat flux at the right time the following block
! needs to sit here rather than at the end of the coupler loop.
if(check_stocks > 0) then
call mpp_clock_begin(newClock4)
if(check_stocks*((nc-1)/check_stocks) == nc-1 .AND. nc > 1) then
call mpp_set_current_pelist()
call flux_check_stocks(Time=Time, Atm=Atm, Lnd=Land, Ice=Ice, Ocn_state=Ocean_state)
endif
call mpp_clock_end(newClock4)
endif
if( Atm%pe )then
call mpp_set_current_pelist(Atm%pelist)
call mpp_clock_begin(newClock5)
call mpp_clock_begin(newClock6)
if (do_ice .AND. Ice%pe) then
if(ice_npes .NE. atmos_npes) call mpp_set_current_pelist(Ice%pelist)
call update_ice_model_slow_up( Ocean_ice_boundary, Ice )
endif
if(ice_npes .NE. atmos_npes) call mpp_set_current_pelist(Atm%pelist)
call mpp_clock_end(newClock6)
if(do_chksum) call atmos_ice_land_chksum('update_ice_slow_up+', nc, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
!-----------------------------------------------------------------------
! ------ atmos/fast-land/fast-ice integration loop -------
call mpp_clock_begin(newClock7)
do na = 1, num_atmos_calls
if(do_chksum) call atmos_ice_land_chksum('top_of_atmos_loop-', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
Time_atmos = Time_atmos + Time_step_atmos
if (do_atmos) then
call mpp_clock_begin(newClocka)
call atmos_tracer_driver_gather_data(Atm%fields, Atm%tr_bot)
call mpp_clock_end(newClocka)
endif
if (do_flux) then
call mpp_clock_begin(newClockb)
call sfc_boundary_layer( REAL(dt_atmos), Time_atmos, &
Atm, Land, Ice, Land_ice_atmos_boundary )
if(do_chksum) call atmos_ice_land_chksum('sfc+', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
call mpp_clock_end(newClockb)
end if
!$OMP PARALLEL &
!$OMP& NUM_THREADS(conc_nthreads) &
!$OMP& DEFAULT(NONE) &
!$OMP& SHARED(atmos_nthreads, radiation_nthreads, nc, na, num_atmos_calls, atmos_npes, land_npes, ice_npes) &
!$OMP& SHARED(Time_atmos, Atm, Land, Ice, Land_ice_atmos_boundary, Atmos_land_boundary, Atmos_ice_boundary) &
!$OMP& SHARED(Ocean_ice_boundary) &
!$OMP& SHARED(do_debug, do_chksum, do_atmos, do_land, do_ice, do_concurrent_radiation, omp_sec, imb_sec) &
!$OMP& SHARED(newClockc, newClockd, newClocke, newClockf, newClockg, newClockh, newClocki, newClockj, newClockl)
!$ if (omp_get_thread_num() == 0) then
!$OMP PARALLEL &
!$OMP& NUM_THREADS(1) &
!$OMP& DEFAULT(NONE) &
!$OMP& PRIVATE(dsec) &
!$OMP& SHARED(atmos_nthreads, radiation_nthreads, nc, na, num_atmos_calls, atmos_npes, land_npes, ice_npes) &
!$OMP& SHARED(Time_atmos, Atm, Land, Ice, Land_ice_atmos_boundary, Atmos_land_boundary, Atmos_ice_boundary) &
!$OMP& SHARED(Ocean_ice_boundary) &
!$OMP& SHARED(do_debug, do_chksum, do_atmos, do_land, do_ice, do_concurrent_radiation, omp_sec, imb_sec) &
!$OMP& SHARED(newClockc, newClockd, newClocke, newClockf, newClockg, newClockh, newClocki, newClockj, newClockl)
!$ call omp_set_num_threads(atmos_nthreads)
!$ dsec=omp_get_wtime()
if (do_concurrent_radiation) call mpp_clock_begin(newClocki)
! ---- atmosphere dynamics ----
if (do_atmos) then
call mpp_clock_begin(newClockl)
call update_atmos_model_dynamics( Atm )
call mpp_clock_end(newClockl)
endif
if(do_chksum) call atmos_ice_land_chksum('update_atmos_model_dynamics', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
if (do_debug) call print_memuse_stats( 'update dyn')
! ---- SERIAL atmosphere radiation ----
if (.not.do_concurrent_radiation) then
call mpp_clock_begin(newClockj)
call update_atmos_model_radiation( Land_ice_atmos_boundary, Atm )
call mpp_clock_end(newClockj)
endif
if(do_chksum) call atmos_ice_land_chksum('update_atmos_model_radiation(ser)', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
if (do_debug) call print_memuse_stats( 'update serial rad')
! ---- atmosphere down ----
if (do_atmos) then
call mpp_clock_begin(newClockc)
call update_atmos_model_down( Land_ice_atmos_boundary, Atm )
call mpp_clock_end(newClockc)
endif
if(do_chksum) call atmos_ice_land_chksum('update_atmos_down+', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
if (do_debug) call print_memuse_stats( 'update down')
call mpp_clock_begin(newClockd)
call flux_down_from_atmos( Time_atmos, Atm, Land, Ice, &
Land_ice_atmos_boundary, &
Atmos_land_boundary, &
Atmos_ice_boundary )
call mpp_clock_end(newClockd)
if(do_chksum) call atmos_ice_land_chksum('flux_down_from_atmos+', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
! --------------------------------------------------------------
! ---- land model ----
call mpp_clock_begin(newClocke)
if (do_land .AND. land%pe) then
if(land_npes .NE. atmos_npes) call mpp_set_current_pelist(Land%pelist)
call update_land_model_fast( Atmos_land_boundary, Land )
endif
if(land_npes .NE. atmos_npes) call mpp_set_current_pelist(Atm%pelist)
call mpp_clock_end(newClocke)
if(do_chksum) call atmos_ice_land_chksum('update_land_fast+', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
if (do_debug) call print_memuse_stats( 'update land')
! ---- ice model ----
call mpp_clock_begin(newClockf)
if (do_ice .AND. Ice%pe) then
if(ice_npes .NE. atmos_npes)call mpp_set_current_pelist(Ice%pelist)
call update_ice_model_fast( Atmos_ice_boundary, Ice )
endif
if(ice_npes .NE. atmos_npes) call mpp_set_current_pelist(Atm%pelist)
call mpp_clock_end(newClockf)
if(do_chksum) call atmos_ice_land_chksum('update_ice_fast+', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
if (do_debug) call print_memuse_stats( 'update ice')
! --------------------------------------------------------------
! ---- atmosphere up ----
call mpp_clock_begin(newClockg)
call flux_up_to_atmos( Time_atmos, Land, Ice, Land_ice_atmos_boundary, &
& Atmos_land_boundary, Atmos_ice_boundary )
call mpp_clock_end(newClockg)
if(do_chksum) call atmos_ice_land_chksum('flux_up2atmos+', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
call mpp_clock_begin(newClockh)
if (do_atmos) &
call update_atmos_model_up( Land_ice_atmos_boundary, Atm)
call mpp_clock_end(newClockh)
if(do_chksum) call atmos_ice_land_chksum('update_atmos_up+', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
if (do_debug) call print_memuse_stats( 'update up')
!--------------
if (do_concurrent_radiation) call mpp_clock_end(newClocki)
!$ omp_sec(1) = omp_sec(1) + (omp_get_wtime() - dsec)
!$OMP END PARALLEL
!$ endif
!$ if (omp_get_thread_num() == max(0,omp_get_num_threads()-1)) then
! ---- atmosphere radiation ----
if (do_concurrent_radiation) then
!$OMP PARALLEL &
!$OMP& NUM_THREADS(1) &
!$OMP& DEFAULT(NONE) &
!$OMP& PRIVATE(dsec) &
!$OMP& SHARED(Atm, Land, Ice, Land_ice_atmos_boundary, Atmos_ice_boundary, Ocean_ice_boundary, Atmos_land_boundary) &
!$OMP& SHARED(do_chksum, do_debug, omp_sec, num_atmos_calls, na, radiation_nthreads) &
!$OMP& SHARED(newClockj)
!$ call omp_set_num_threads(radiation_nthreads)
!$ dsec=omp_get_wtime()
call mpp_clock_begin(newClockj)
call update_atmos_model_radiation( Land_ice_atmos_boundary, Atm )
call mpp_clock_end(newClockj)
!$ omp_sec(2) = omp_sec(2) + (omp_get_wtime() - dsec)
!---CANNOT PUT AN MPP_CHKSUM HERE AS IT REQUIRES THE ABILITY TO HAVE TWO DIFFERENT OPENMP THREADS
!---INSIDE OF MPI AT THE SAME TIME WHICH IS NOT CURRENTLY ALLOWED
! if (do_chksum) call atmos_ice_land_chksum('update_atmos_model_radiation(conc)', (nc-1)*num_atmos_calls+na, &
! Atm, Land, Ice, Land_ice_atmos_boundary, Atmos_ice_boundary, &
! Ocean_ice_boundary, Atmos_land_boundary)
if (do_debug) call print_memuse_stats( 'update concurrent rad')
!$OMP END PARALLEL
endif
!$ endif
!$ imb_sec(omp_get_thread_num()+1) = imb_sec(omp_get_thread_num()+1) - omp_get_wtime()
!$OMP END PARALLEL
!$ imb_sec(1) = imb_sec(1) + omp_get_wtime()
!$ if (do_concurrent_radiation) imb_sec(2) = imb_sec(2) + omp_get_wtime()
!$ call omp_set_num_threads(atmos_nthreads+(conc_nthreads-1)*radiation_nthreads)
call mpp_clock_begin(newClockk)
call update_atmos_model_state( Atm )
if (do_chksum) call atmos_ice_land_chksum('update_atmos_model_state+', (nc-1)*num_atmos_calls+na, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
if (do_debug) call print_memuse_stats( 'update state')
call mpp_clock_end(newClockk)
enddo ! end of na (fast loop)
call mpp_clock_end(newClock7)
call mpp_clock_begin(newClock8)
! ------ end of atmospheric time step loop -----
if (do_land .AND. Land%pe) then
if(land_npes .NE. atmos_npes) call mpp_set_current_pelist(Land%pelist)
call update_land_model_slow(Atmos_land_boundary,Land)
endif
if(land_npes .NE. atmos_npes) call mpp_set_current_pelist(Atm%pelist)
!-----------------------------------------------------------------------
call mpp_clock_end(newClock8)
if(do_chksum) call atmos_ice_land_chksum('update_land_slow+', nc, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
!
! need flux call to put runoff and p_surf on ice grid
!
call mpp_clock_begin(newClock9)
call flux_land_to_ice( Time, Land, Ice, Land_ice_boundary )
call mpp_clock_end(newClock9)
if(do_chksum) call atmos_ice_land_chksum('fluxlnd2ice+', nc, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
Atmos_ice_boundary%p = 0.0 ! call flux_atmos_to_ice_slow ?
! ------ slow-ice model ------
if (do_ice) then
call mpp_clock_begin(newClock10)
if( Ice%pe ) then
if(ice_npes .NE. atmos_npes) call mpp_set_current_pelist(Ice%pelist)
call update_ice_model_slow_dn( Atmos_ice_boundary, &
& Land_ice_boundary, Ice )
endif
if(ice_npes .NE. atmos_npes) call mpp_set_current_pelist(Atm%pelist)
call mpp_clock_end(newClock10)
if(do_chksum) call atmos_ice_land_chksum('update_ice_slow_dn+', nc, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
call mpp_clock_begin(newClock11)
if( Ice%pe ) then
if(ice_npes .NE. atmos_npes) call mpp_set_current_pelist(Ice%pelist)
call flux_ice_to_ocean_stocks(Ice)
endif
if(ice_npes .NE. atmos_npes) call mpp_set_current_pelist(Atm%pelist)
call mpp_clock_end(newClock11)
if(do_chksum) call atmos_ice_land_chksum('fluxice2ocn_stocks+', nc, Atm, Land, Ice, &
Land_ice_atmos_boundary, Atmos_ice_boundary, &
Ocean_ice_boundary, Atmos_land_boundary)
endif
Time = Time_atmos
call mpp_clock_end(newClock5)
end if !Atm%pe block
if( .NOT.use_lag_fluxes )then !this will serialize
call mpp_set_current_pelist()
call flux_ice_to_ocean( Time, Ice, Ocean, Ice_ocean_boundary )
end if
if( Ocean%is_ocean_pe )then
call mpp_set_current_pelist(Ocean%pelist)
call mpp_clock_begin(newClock12)
if (do_chksum) call ocean_chksum('update_ocean_model-', nc, Ocean, Ice_ocean_boundary)
! update_ocean_model since fluxes don't change here
if (do_ocean) &
call update_ocean_model( Ice_ocean_boundary, Ocean_state, Ocean, &
Time_ocean, Time_step_cpld )
if (do_chksum) call ocean_chksum('update_ocean_model+', nc, Ocean, Ice_ocean_boundary)
! Get stocks from "Ice_ocean_boundary" and add them to Ocean stocks.
! This call is just for record keeping of stocks transfer and
! does not modify either Ocean or Ice_ocean_boundary
call flux_ocean_from_ice_stocks(Ocean_state, Ocean, Ice_ocean_boundary)
Time_ocean = Time_ocean + Time_step_cpld
!-----------------------------------------------------------------------
Time = Time_ocean
call mpp_clock_end(newClock12)
end if
!--- write out intermediate restart file when needed.
if( Time >= Time_restart ) then
Time_restart_current = Time
Time_restart = increment_date(Time, restart_interval(1), restart_interval(2), &
restart_interval(3), restart_interval(4), restart_interval(5), restart_interval(6) )
timestamp = date_to_string(time_restart_current)
outunit= stdout()
write(outunit,*) '=> NOTE from program coupler: intermediate restart file is written and ', &
trim(timestamp),' is appended as prefix to each restart file name'
if( Atm%pe )then
call atmos_model_restart(Atm, timestamp)
call land_model_restart(timestamp)
call ice_model_restart(Ice, timestamp)
endif
if( Ocean%is_ocean_pe) then
call ocean_model_restart(Ocean_state, timestamp)
endif
call coupler_restart(Time, Time_restart_current, timestamp)
end if
!--------------
if(do_chksum) call coupler_chksum('MAIN_LOOP+', nc)
write( text,'(a,i6)' )'Main loop at coupling timestep=', nc
call print_memuse_stats(text)
outunit= stdout()
if (mpp_pe() == mpp_root_pe() .and. Atm%pe .and. do_concurrent_radiation) then
write(outunit,102) 'At coupling step ', nc,' of ',num_cpld_calls, &
' Atm & Rad (imbalance): ',omp_sec(1),' (',imb_sec(1),') ',omp_sec(2),' (',imb_sec(2),')'
endif
omp_sec(:)=0.
imb_sec(:)=0.
call flush(outunit)
enddo
102 FORMAT(A17,i5,A4,i5,A24,f10.4,A2,f10.4,A3,f10.4,A2,f10.4,A1)
call mpp_set_current_pelist()
call mpp_clock_begin(newClock14)
if(check_stocks >= 0) then
call mpp_set_current_pelist()
call flux_check_stocks(Time=Time, Atm=Atm, Lnd=Land, Ice=Ice, Ocn_state=Ocean_state)
endif
call mpp_clock_end(newClock14)
call mpp_set_current_pelist()
!-----------------------------------------------------------------------
call mpp_clock_end(mainClock)
call mpp_clock_begin(termClock)
if(do_chksum) call coupler_chksum('coupler_end-', nc)
call coupler_end
call mpp_clock_end(termClock)
call print_memuse_stats( 'Memory HiWaterMark', always=.TRUE. )
call fms_end
!-----------------------------------------------------------------------
contains
!#######################################################################
!> \brief Initialize all defined exchange grids and all boundary maps
subroutine coupler_init
use ensemble_manager_mod, only : ensemble_manager_init, get_ensemble_id,ensemble_pelist_setup
use ensemble_manager_mod, only : get_ensemble_size, get_ensemble_pelist
!
!-----------------------------------------------------------------------
! local parameters
!-----------------------------------------------------------------------
!
character(len=64), parameter :: sub_name = 'coupler_init'
character(len=256), parameter :: error_header = &
'==>Error from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
character(len=256), parameter :: note_header = &
'==>Note from ' // trim(mod_name) // '(' // trim(sub_name) // '):'
integer :: unit, ierr, io, m, i, outunit, logunit, errunit
integer :: date(6)
type (time_type) :: Run_length
character(len=9) :: month
integer :: pe, npes
integer :: ens_siz(6), ensemble_size
integer :: atmos_pe_start=0, atmos_pe_end=0, &
ocean_pe_start=0, ocean_pe_end=0
integer :: n
integer :: diag_model_subset=DIAG_ALL
logical :: other_fields_exist
character(len=256) :: err_msg
integer :: date_restart(6)
character(len=64) :: filename, fieldname
integer :: id_restart, l
integer :: omp_get_thread_num, omp_get_num_threads
integer :: get_cpu_affinity, base_cpu
character(len=8) :: walldate
character(len=10) :: walltime
character(len=5) :: wallzone
integer :: wallvalues(8)
!-----------------------------------------------------------------------
outunit = stdout()
errunit = stderr()
logunit = stdlog()
if( mpp_pe().EQ.mpp_root_pe() ) then
call DATE_AND_TIME(walldate, walltime, wallzone, wallvalues)
write(errunit,*) 'Entering coupler_init at '&
//trim(walldate)//' '//trim(walltime)
endif
!----- write version to logfile -------
call write_version_number(version, tag)
!----- read namelist -------
#ifdef INTERNAL_FILE_NML
read (input_nml_file, coupler_nml, iostat=io)
ierr = check_nml_error (io, 'coupler_nml')
#else
unit = open_namelist_file()
ierr=1; do while (ierr /= 0)
read (unit, nml=coupler_nml, iostat=io, end=10)
ierr = check_nml_error (io, 'coupler_nml')
enddo
10 call mpp_close(unit)
#endif
!---- when concurrent is set true and mpp_io_nml io_clock_on is set true, the model
!---- will crash with error message "MPP_CLOCK_BEGIN: cannot change pelist context of a clock",
!---- so need to make sure it will not happen
if(concurrent) then
if(mpp_io_clock_on()) then
call error_mesg ('program coupler', 'when coupler_nml variable concurrent is set to true, '// &
'mpp_io_nml variable io_clock_non can not be set to true.', FATAL )
endif
endif
!----- read date and calendar type from restart file -----
if( file_exist('INPUT/coupler.res') )then
!Balaji: currently written in binary, needs form=MPP_NATIVE
call mpp_open( unit, 'INPUT/coupler.res', action=MPP_RDONLY )
read( unit,*,err=999 )calendar_type
read( unit,* )date_init
read( unit,* )date
goto 998 !back to fortran-4
!read old-style coupler.res
999 call mpp_close(unit)
call mpp_open( unit, 'INPUT/coupler.res', action=MPP_RDONLY, form=MPP_NATIVE )
read(unit)calendar_type
read(unit)date
998 call mpp_close(unit)
else
force_date_from_namelist = .true.
endif
!----- use namelist value (either no restart or override flag on) ---
if ( force_date_from_namelist ) then
if ( sum(current_date) <= 0 ) then
call error_mesg ('program coupler', &
'no namelist value for base_date or current_date', FATAL)
else
date = current_date
endif
!----- override calendar type with namelist value -----
select case( uppercase(trim(calendar)) )
case( 'JULIAN' )
calendar_type = JULIAN
case( 'NOLEAP' )
calendar_type = NOLEAP
case( 'THIRTY_DAY' )
calendar_type = THIRTY_DAY_MONTHS
case( 'NO_CALENDAR' )
calendar_type = NO_CALENDAR
end select
endif
call set_calendar_type (calendar_type, err_msg)
if(err_msg /= '') then
call mpp_error(FATAL, 'ERROR in coupler_init: '//trim(err_msg))
endif
if( concurrent .AND. .NOT.use_lag_fluxes )call mpp_error( WARNING, &
'coupler_init: you have set concurrent=TRUE and use_lag_fluxes=FALSE &
& in coupler_nml. When not using lag fluxes, components &
& will synchronize at two points, and thus run serially.' )
!Check with the ensemble_manager module for the size of ensemble
!and PE counts for each member of the ensemble.
!
!NOTE: ensemble_manager_init renames all the output files (restart and diagnostics)
! to show which ensemble member they are coming from.
! There also need to be restart files for each member of the ensemble in INPUT.
!
!NOTE: if the ensemble_size=1 the input/output files will not be renamed.