forked from NOAA-GFDL/icebergs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicebergs_framework.F90
More file actions
4815 lines (4335 loc) · 204 KB
/
icebergs_framework.F90
File metadata and controls
4815 lines (4335 loc) · 204 KB
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
!> Provides utilites for managing bergs in linked lists, and bonds between bergs
module ice_bergs_framework
! This file is part of NOAA-GFDL/icebergs. See LICENSE.md for the license.
use constants_mod, only: radius, pi, omega, HLF
use mpp_domains_mod, only: domain2D
use mpp_mod, only: mpp_npes, mpp_pe, mpp_root_pe, mpp_sum, mpp_min, mpp_max, NULL_PE
use mpp_mod, only: mpp_send, mpp_recv, mpp_sync_self, mpp_pe, mpp_root_pe, mpp_chksum
use mpp_mod, only: COMM_TAG_1, COMM_TAG_2, COMM_TAG_3, COMM_TAG_4
use mpp_mod, only: COMM_TAG_5, COMM_TAG_6, COMM_TAG_7, COMM_TAG_8
use mpp_mod, only: COMM_TAG_9, COMM_TAG_10
use fms_mod, only: stdlog, stderr, error_mesg, FATAL, WARNING
use time_manager_mod, only: time_type, get_date, get_time, set_date, operator(-)
implicit none ; private
integer :: buffer_width=28 ! This should be a parameter
integer :: buffer_width_traj=32 ! This should be a parameter
integer, parameter :: nclasses=10 ! Number of ice bergs classes
!Local Vars
! Global data (minimal for debugging)
logical :: folded_north_on_pe = .false. !< If true, indicates the presence of the tri-polar grid
logical :: verbose=.false. !< Be verbose to stderr
logical :: budget=.true. !< Calculate budgets
logical :: debug=.false. !< Turn on debugging
logical :: really_debug=.false. !< Turn on debugging
logical :: parallel_reprod=.true. !< Reproduce across different PE decompositions
logical :: use_slow_find=.true. !< Use really slow (but robust) find_cell for reading restarts
logical :: ignore_ij_restart=.false. !< Read i,j location from restart if available (needed to use restarts on different grids)
logical :: generate_test_icebergs=.false. !< Create icebergs in absence of a restart file
logical :: use_roundoff_fix=.true. !< Use a "fix" for the round-off discrepancy between is_point_in_cell() and pos_within_cell()
logical :: old_bug_rotated_weights=.false. !< Skip the rotation of off-center weights for rotated halo updates
logical :: make_calving_reproduce=.false. !< Make the calving.res.nc file reproduce across pe count changes.
logical :: old_bug_bilin=.true. !< If true, uses the inverted bilinear function (use False to get correct answer)
character(len=10) :: restart_input_dir = 'INPUT/' !< Directory to look for restart files
integer, parameter :: delta_buf=25 !< Size by which to increment buffers
real, parameter :: pi_180=pi/180. !< Converts degrees to radians
logical :: fix_restart_dates=.true. !< After a restart, check that bergs were created before the current model date
logical :: do_unit_tests=.false. !< Conduct some unit tests
logical :: force_all_pes_traj=.false. !< Force all pes write trajectory files regardless of io_layout
!Public params !Niki: write a subroutine to expose these
public nclasses,buffer_width,buffer_width_traj
public verbose, really_debug, debug, restart_input_dir,make_calving_reproduce,old_bug_bilin,use_roundoff_fix
public ignore_ij_restart, use_slow_find,generate_test_icebergs,old_bug_rotated_weights,budget
public orig_read, force_all_pes_traj
!Public types
public icebergs_gridded, xyt, iceberg, icebergs, buffer, bond
!Public subs
public ice_bergs_framework_init
public send_bergs_to_other_pes
public update_halo_icebergs
public pack_traj_into_buffer2, unpack_traj_from_buffer2
public increase_ibuffer
public add_new_berg_to_list, count_out_of_order, check_for_duplicates
public insert_berg_into_list, create_iceberg, delete_iceberg_from_list, destroy_iceberg
public print_fld,print_berg, print_bergs,record_posn, push_posn, append_posn, check_position
public move_trajectory, move_all_trajectories
public form_a_bond, connect_all_bonds, show_all_bonds, bond_address_update
public find_cell, find_cell_by_search, count_bergs, is_point_in_cell, pos_within_cell, count_bonds
public sum_mass, sum_heat, bilin, yearday, bergs_chksum, list_chksum, count_bergs_in_list
public checksum_gridded
public grd_chksum2,grd_chksum3
public fix_restart_dates, offset_berg_dates
public move_berg_between_cells
public find_individual_iceberg
public monitor_a_berg
public is_point_within_xi_yj_bounds
public test_check_for_duplicate_ids_in_list
public check_for_duplicates_in_parallel
public split_id, id_from_2_ints, generate_id, cij_from_old_id, convert_old_id
!> Container for gridded fields
type :: icebergs_gridded
type(domain2D), pointer :: domain !< MPP parallel domain
integer :: halo !< Nominal halo width
integer :: isc !< Start i-index of computational domain
integer :: iec !< End i-index of computational domain
integer :: jsc !< Start j-index of computational domain
integer :: jec !< End j-index of computational domain
integer :: isd !< Start i-index of data domain
integer :: ied !< End i-index of data domain
integer :: jsd !< Start j-index of data domain
integer :: jed !< End j-index of data domain
integer :: isg !< Start i-index of global domain
integer :: ieg !< End i-index of global domain
integer :: jsg !< Start j-index of global domain
integer :: jeg !< End j-index of global domain
integer :: my_pe !< MPI PE index
integer :: pe_N !< MPI PE index of PE to the north
integer :: pe_S !< MPI PE index of PE to the south
integer :: pe_E !< MPI PE index of PE to the east
integer :: pe_W !< MPI PE index of PE to the west
logical :: grid_is_latlon !< Flag to say whether the coordinate is in lat-lon degrees, or meters
logical :: grid_is_regular !< Flag to say whether point in cell can be found assuming regular Cartesian grid
real :: Lx !< Length of the domain in x direction
real, dimension(:,:), pointer :: lon=>null() !< Longitude of cell corners (degree E)
real, dimension(:,:), pointer :: lat=>null() !< Latitude of cell corners (degree N)
real, dimension(:,:), pointer :: lonc=>null() !< Longitude of cell centers (degree E)
real, dimension(:,:), pointer :: latc=>null() !< Latitude of cell centers (degree N)
real, dimension(:,:), pointer :: dx=>null() !< Length of cell edge (m)
real, dimension(:,:), pointer :: dy=>null() !< Length of cell edge (m)
real, dimension(:,:), pointer :: area=>null() !< Area of cell (m^2)
real, dimension(:,:), pointer :: msk=>null() !< Ocean-land mask (1=ocean)
real, dimension(:,:), pointer :: cos=>null() !< Cosine from rotation matrix to lat-lon coords
real, dimension(:,:), pointer :: sin=>null() !< Sine from rotation matrix to lat-lon coords
real, dimension(:,:), pointer :: ocean_depth=>NULL() !< Depth of ocean (m)
real, dimension(:,:), pointer :: uo=>null() !< Ocean zonal flow (m/s)
real, dimension(:,:), pointer :: vo=>null() !< Ocean meridional flow (m/s)
real, dimension(:,:), pointer :: ui=>null() !< Ice zonal flow (m/s)
real, dimension(:,:), pointer :: vi=>null() !< Ice meridional flow (m/s)
real, dimension(:,:), pointer :: ua=>null() !< Atmosphere zonal flow (m/s)
real, dimension(:,:), pointer :: va=>null() !< Atmosphere meridional flow (m/s)
real, dimension(:,:), pointer :: ssh=>null() !< Sea surface height (m)
real, dimension(:,:), pointer :: sst=>null() !< Sea surface temperature (oC)
real, dimension(:,:), pointer :: sss=>null() !< Sea surface salinity (psu)
real, dimension(:,:), pointer :: cn=>null() !< Sea-ice concentration (0 to 1)
real, dimension(:,:), pointer :: hi=>null() !< Sea-ice thickness (m)
real, dimension(:,:), pointer :: calving=>null() !< Calving mass rate [frozen runoff] (kg/s) (into stored ice)
real, dimension(:,:), pointer :: calving_hflx=>null() !< Calving heat flux [heat content of calving] (W/m2) (into stored ice)
real, dimension(:,:), pointer :: floating_melt=>null() !< Net melting rate to icebergs + bits (kg/s/m^2)
real, dimension(:,:), pointer :: berg_melt=>null() !< Melting+erosion rate of icebergs (kg/s/m^2)
real, dimension(:,:), pointer :: melt_buoy=>null() !< Buoyancy component of melting rate (kg/s/m^2)
real, dimension(:,:), pointer :: melt_eros=>null() !< Erosion component of melting rate (kg/s/m^2)
real, dimension(:,:), pointer :: melt_conv=>null() !< Convective component of melting rate (kg/s/m^2)
real, dimension(:,:), pointer :: bergy_src=>null() !< Mass flux from berg erosion into bergy bits (kg/s/m^2)
real, dimension(:,:), pointer :: bergy_melt=>null() !< Melting rate of bergy bits (kg/s/m^2)
real, dimension(:,:), pointer :: bergy_mass=>null() !< Mass distribution of bergy bits (kg/s/m^2)
real, dimension(:,:), pointer :: spread_mass=>null() !< Mass of icebergs after spreading (kg/m^2)
real, dimension(:,:), pointer :: spread_mass_old=>null() !< Mass of icebergs after spreading old (kg/m^2)
real, dimension(:,:), pointer :: spread_area=>null() !< Area of icebergs after spreading (m^2/m^2)
real, dimension(:,:), pointer :: u_iceberg=>null() !< Average iceberg velocity in grid cell (mass weighted - but not spread mass weighted)
real, dimension(:,:), pointer :: v_iceberg=>null() !< Average iceberg velocity in grid cell (mass weighted - but not spread mass weighted)
real, dimension(:,:), pointer :: spread_uvel=>null() !< Average iceberg velocity in grid cell (spread area weighted)
real, dimension(:,:), pointer :: spread_vvel=>null() !< Average iceberg velocity in grid cell (spread area weighted)
real, dimension(:,:), pointer :: ustar_iceberg=>null() !< Frictional velocity below icebergs to be passed to ocean
real, dimension(:,:), pointer :: virtual_area=>null() !< Virtual surface coverage by icebergs (m^2)
real, dimension(:,:), pointer :: mass=>null() !< Mass distribution (kg/m^2)
real, dimension(:,:,:), pointer :: mass_on_ocean=>null() !< Mass distribution partitioned by neighbor (kg)
real, dimension(:,:,:), pointer :: area_on_ocean=>null() !< Area distribution partitioned by neighbor (m^2)
real, dimension(:,:,:), pointer :: Uvel_on_ocean=>null() !< zonal velocity distribution partitioned by neighbor (m^2* m/s)
real, dimension(:,:,:), pointer :: Vvel_on_ocean=>null() !< meridional momentum distribution partitioned by neighbor (m^2 m/s)
real, dimension(:,:), pointer :: tmp=>null() !< Temporary work space
real, dimension(:,:), pointer :: tmpc=>null() !< Temporary work space
real, dimension(:,:,:), pointer :: stored_ice=>null() !< Accumulated ice mass flux at calving locations (kg)
real, dimension(:,:), pointer :: rmean_calving=>null() !< Running mean for ice calving
real, dimension(:,:), pointer :: rmean_calving_hflx=>null() !< Running mean for ice calving
real, dimension(:,:), pointer :: stored_heat=>null() !< Heat content of stored ice (J)
real, dimension(:,:,:), pointer :: real_calving=>null() !< Calving rate into iceberg class at calving locations (kg/s)
real, dimension(:,:), pointer :: iceberg_heat_content=>null() !< Distributed heat content of bergs (J/m^2)
real, dimension(:,:), pointer :: parity_x=>null() !< X component of vector point from i,j to i+1,j+1 (for detecting tri-polar fold)
real, dimension(:,:), pointer :: parity_y=>null() !< Y component of vector point from i,j to i+1,j+1 (for detecting tri-polar fold)
integer, dimension(:,:), pointer :: iceberg_counter_grd=>null() !< Counts icebergs created for naming purposes
logical :: rmean_calving_initialized = .false. !< True if rmean_calving(:,:) has been filled with meaningful data
logical :: rmean_calving_hflx_initialized = .false. !< True if rmean_calving_hflx(:,:) has been filled with meaningful data
real :: coastal_drift=0. ! A velocity added to ocean currents to cause bergs to drift away from land cells
real :: tidal_drift=0. ! Amplitude of a stochastic tidal velocity added to ocean currents to cause bergs to drift randomly
!>@{
!! Diagnostic handle
integer :: id_uo=-1, id_vo=-1, id_calving=-1, id_stored_ice=-1, id_accum=-1, id_unused=-1, id_floating_melt=-1
integer :: id_melt_buoy=-1, id_melt_eros=-1, id_melt_conv=-1, id_virtual_area=-1, id_real_calving=-1
integer :: id_calving_hflx_in=-1, id_stored_heat=-1, id_melt_hflx=-1, id_heat_content=-1
integer :: id_mass=-1, id_ui=-1, id_vi=-1, id_ua=-1, id_va=-1, id_sst=-1, id_cn=-1, id_hi=-1
integer :: id_bergy_src=-1, id_bergy_melt=-1, id_bergy_mass=-1, id_berg_melt=-1
integer :: id_rmean_calving=-1, id_rmean_calving_hflx=-1
integer :: id_spread_mass=-1, id_spread_area=-1
integer :: id_ssh=-1, id_fax=-1, id_fay=-1
integer :: id_count=-1, id_chksum=-1, id_u_iceberg=-1, id_v_iceberg=-1, id_sss=-1, id_ustar_iceberg
integer :: id_spread_uvel=-1, id_spread_vvel=-1
integer :: id_melt_m_per_year=-1
integer :: id_ocean_depth=-1
!>@}
real :: clipping_depth=0. !< The effective depth at which to clip the weight felt by the ocean [m].
end type icebergs_gridded
!> A link in the trajectory record (diagnostic)
type :: xyt
real :: lon !< Longitude of berg (degree N or unit of grid coordinate)
real :: lat !< Latitude of berg (degree N or unit of grid coordinate)
real :: day !< Day of this record (days)
real :: mass !< Mass of berg (kg)
real :: thickness !< Thickness of berg (m)
real :: width !< Width of berg (m)
real :: length !< Length of berg (m)
real :: uvel !< Zonal velocity of berg (m/s)
real :: vvel !< Meridional velocity of berg (m/s)
real :: axn
real :: ayn
real :: bxn
real :: byn
real :: uvel_old
real :: vvel_old
real :: lat_old
real :: lon_old
real :: uo !< Zonal velocity of ocean (m/s)
real :: vo !< Meridional velocity of ocean (m/s)
real :: ui !< Zonal velocity of ice (m/s)
real :: vi !< Meridional velocity of ice (m/s)
real :: ua !< Zonal velocity of atmosphere (m/s)
real :: va !< Meridional velocity of atmosphere (m/s)
real :: ssh_x !< Zonal gradient of sea-surface height (nondim)
real :: ssh_y !< Meridional gradient of sea-surface height (nondim)
real :: sst !< Sea-surface temperature (Celsius)
real :: sss !< Sea-surface salinity (1e-3)
real :: cn !< Sea-ice concentration (nondim)
real :: hi !< Sea-ice thickness (m)
real :: halo_berg
real :: static_berg
real :: mass_of_bits !< Mass of bergy bits (kg)
real :: heat_density !< Heat density of berg (???)
integer :: year !< Year of this record (years)
integer(kind=8) :: id = -1 !< Iceberg identifier
type(xyt), pointer :: next=>null() !< Next link in list
end type xyt
!> An iceberg object, used as a link in a linked list
type :: iceberg
type(iceberg), pointer :: prev=>null() !< Previous link in list
type(iceberg), pointer :: next=>null() !< Next link in list
! State variables (specific to the iceberg, needed for restarts)
real :: lon !< Longitude of berg (degree N or unit of grid coordinate)
real :: lat !< Latitude of berg (degree E or unit of grid coordinate)
real :: uvel !< Zonal velocity of berg (m/s)
real :: vvel !< Meridional velocity of berg (m/s)
real :: mass !< Mass of berg (kg)
real :: thickness !< Thickness of berg (m)
real :: width !< Width of berg (m)
real :: length !< Length of berg (m)
real :: axn
real :: ayn
real :: bxn
real :: byn
real :: uvel_old
real :: vvel_old
real :: lon_old
real :: lat_old
real :: start_lon !< Longitude where berg was created (degree N or unit of grid coordinate)
real :: start_lat !< Latitude where berg was created (degree E or unit of grid coordinate)
real :: start_day !< Day that berg was created (days)
real :: start_mass !< Mass berg had when created (kg)
real :: mass_scaling !< Multiplier to scale mass when interpreting berg as a cloud of bergs (nondim)
real :: mass_of_bits !< Mass of bergy bits following berg (kg)
real :: heat_density !< Heat density of berg (???)
real :: halo_berg ! Equal to zero for bergs on computational domain, and =1 for bergs on the halo
real :: static_berg ! Equal to 1 for icebergs which are static (not allowed to move). Might be extended to grounding later.
integer :: start_year !< Year that berg was created (years)
integer(kind=8) :: id !< Iceberg identifier
integer :: ine !< Nearest i-index in NE direction (for convenience)
integer :: jne !< Nearest j-index in NE direction (for convenience)
real :: xi !< Non-dimensional x-coordinate within current cell (0..1)
real :: yj !< Non-dimensional y-coordinate within current cell (0..1)
! Environment variables (as seen by the iceberg)
real :: uo !< Zonal velocity of ocean (m/s)
real :: vo !< Meridional velocity of ocean (m/s)
real :: ui !< Zonal velocity of ice (m/s)
real :: vi !< Meridional velocity of ice (m/s)
real :: ua !< Zonal velocity of atmosphere (m/s)
real :: va !< Meridional velocity of atmosphere (m/s)
real :: ssh_x !< Zonal gradient of sea-surface height (nondim)
real :: ssh_y !< Meridional gradient of sea-surface height (nondim)
real :: sst !< Sea-surface temperature (Celsius)
real :: sss !< Sea-surface salinity (1e-3)
real :: cn !< Sea-ice concentration (nondim)
real :: hi !< Sea-ice thickness (m)
type(xyt), pointer :: trajectory=>null() !< Trajectory for this berg
type(bond), pointer :: first_bond=>null() !< First element of bond list.
end type iceberg
!> A bond object connecting two bergs, used as a link in a linked list
type :: bond
type(bond), pointer :: prev_bond=>null() !< Previous link in list
type(bond), pointer :: next_bond=>null() !< Next link in list
type(iceberg), pointer :: other_berg=>null()
integer(kind=8) :: other_id !< ID of other berg
integer :: other_berg_ine
integer :: other_berg_jne
end type bond
! A dynamic buffer, used for communication, that packs types into rectangular memory
type :: buffer
integer :: size=0 !< Size of buffer
real, dimension(:,:), pointer :: data !< Buffer memory
end type buffer
!> A wrapper for the iceberg linked list (since an array of pointers is not allowed)
type :: linked_list
type(iceberg), pointer :: first=>null() !< Pointer to the beginning of a linked list of bergs
end type linked_list
!> Container for all types and memory
type :: icebergs !; private !Niki: Ask Alistair why this is private. ice_bergs_io cannot compile if this is private!
type(icebergs_gridded), pointer :: grd !< Container with all gridded data
type(linked_list), dimension(:,:), allocatable :: list !< Linked list of icebergs
type(xyt), pointer :: trajectories=>null() !< A linked list for detached segments of trajectories
real :: dt !< Time-step between iceberg calls
!! \todo Should make dt adaptive?
integer :: current_year !< Current year (years)
real :: current_yearday !< Current year-day, 1.00-365.99, (days)
integer :: traj_sample_hrs !< Period between sampling for trajectories (hours)
integer :: traj_write_hrs !< Period between writing of trajectories (hours)
integer :: verbose_hrs !< Period between terminal status reports (hours)
integer :: max_bonds
!>@{
!! Handles for clocks
integer :: clock, clock_mom, clock_the, clock_int, clock_cal, clock_com, clock_ini, clock_ior, clock_iow, clock_dia
integer :: clock_trw, clock_trp
!>@}
real :: rho_bergs !< Density of icebergs [kg/m^3]
real :: spring_coef !< Spring constant for iceberg interactions
real :: bond_coef !< Spring constant for iceberg bonds
real :: radial_damping_coef !< Coefficient for relative iceberg motion damping (radial component) -Alon
real :: tangental_damping_coef !< Coefficient for relative iceberg motion damping (tangential component) -Alon
real :: LoW_ratio !< Initial ratio L/W for newly calved icebergs
real :: bergy_bit_erosion_fraction !< Fraction of erosion melt flux to divert to bergy bits
real :: sicn_shift !< Shift of sea-ice concentration in erosion flux modulation (0<sicn_shift<1)
real :: lat_ref=0. !< Reference latitude for f-plane (when this option is on)
real :: u_override=0.0 !< Overrides the u velocity of icebergs (for ocean testing)
real :: v_override=0.0 !< Overrides the v velocity of icebergs (for ocean testing)
real :: utide_icebergs= 0. !< Tidal speeds, set to zero for now.
real :: ustar_icebergs_bg=0.001 !< Background u_star under icebergs. This should be linked to a value felt by the ocean boundary layer
real :: cdrag_icebergs = 1.5e-3 !< Momentum Drag coef, taken from HJ99 (Holland and Jenkins 1999)
real :: initial_orientation=0. !< Iceberg orientation relative to this angle (in degrees). Used for hexagonal mass spreading.
real :: Gamma_T_3EQ=0.022 !< Non-dimensional heat-transfer coefficient
real :: melt_cutoff=-1.0 !< Minimum ocean thickness for melting to occur (is not applied for values < 0)
logical :: const_gamma=.True. !< If true uses a constant heat transfer coefficient, from which the salt transfer is calculated
real, dimension(:), pointer :: initial_mass, distribution, mass_scaling
real, dimension(:), pointer :: initial_thickness, initial_width, initial_length
logical :: restarted=.false. !< Indicate whether we read state from a restart or not
logical :: use_operator_splitting=.true. !< Use first order operator splitting for thermodynamics
logical :: add_weight_to_ocean=.true. !< Add weight of bergs to ocean
logical :: passive_mode=.false. !< Add weight of icebergs + bits to ocean
logical :: time_average_weight=.false. !< Time average the weight on the ocean
logical :: Runge_not_Verlet=.True. !< True=Runge-Kutta, False=Verlet.
logical :: use_mixed_melting=.False. !< If true, then the melt is determined partly using 3 eq model partly using iceberg parameterizations (according to iceberg bond number)
logical :: apply_thickness_cutoff_to_gridded_melt=.False. !< Prevents melt for ocean thickness below melt_cuttoff (applied to gridded melt fields)
logical :: apply_thickness_cutoff_to_bergs_melt=.False. !< Prevents melt for ocean thickness below melt_cuttoff (applied to bergs)
logical :: use_updated_rolling_scheme=.false. !< True to use the aspect ratio based rolling scheme rather than incorrect version of WM scheme (set tip_parameter=1000. for correct WM scheme)
logical :: pass_fields_to_ocean_model=.False. !< Iceberg area, mass and ustar fields are prepared to pass to ocean model
logical :: use_mixed_layer_salinity_for_thermo=.False. !< If true, then model uses ocean salinity for 3 and 2 equation melt model.
logical :: find_melt_using_spread_mass=.False. !< If true, then the model calculates ice loss by looping at the spread_mass before and after.
logical :: Use_three_equation_model=.True. !< Uses 3 equation model for melt when ice shelf type thermodynamics are used.
logical :: melt_icebergs_as_ice_shelf=.False. !< Uses iceshelf type thermodynamics
logical :: Iceberg_melt_without_decay=.False. !< Allows icebergs meltwater fluxes to enter the ocean, without the iceberg decaying or changing shape.
logical :: add_iceberg_thickness_to_SSH=.False. !< Adds the iceberg contribution to SSH.
logical :: override_iceberg_velocities=.False. !< Allows you to set a fixed iceberg velocity for all non-static icebergs.
logical :: use_f_plane=.False. !< Flag to use a f-plane for the rotation
logical :: rotate_icebergs_for_mass_spreading=.True. !< Flag allows icebergs to rotate for spreading their mass (in hexagonal spreading mode)
logical :: set_melt_rates_to_zero=.False. !< Sets all melt rates to zero, for testing purposes (thermodynamics routine is still run)
logical :: hexagonal_icebergs=.False. !< True treats icebergs as rectangles, False as hexagonal elements (for the purpose of mass spreading)
logical :: allow_bergs_to_roll=.True. !< Allows icebergs to roll over when rolling conditions are met
logical :: ignore_missing_restart_bergs=.False. !< True Allows the model to ignore icebergs missing in the restart.
logical :: Static_icebergs=.False. !< True= icebergs do no move
logical :: only_interactive_forces=.False. !< Icebergs only feel interactive forces, and not ocean, wind...
logical :: halo_debugging=.False. !< Use for debugging halos (remove when its working)
logical :: save_short_traj=.True. !< True saves only lon,lat,time,id in iceberg_trajectory.nc
logical :: ignore_traj=.False. !< If true, then model does not write trajectory data at all
logical :: iceberg_bonds_on=.False. !< True=Allow icebergs to have bonds, False=don't allow.
logical :: manually_initialize_bonds=.False. !< True= Bonds are initialize manually.
logical :: use_new_predictive_corrective =.False. !< Flag to use Bob's predictive corrective iceberg scheme- Added by Alon
logical :: interactive_icebergs_on=.false. !< Turn on/off interactions between icebergs - Added by Alon
logical :: critical_interaction_damping_on=.true. !< Sets the damping on relative iceberg velocity to critical value - Added by Alon
logical :: use_old_spreading=.true. !< If true, spreads iceberg mass as if the berg is one grid cell wide
logical :: read_ocean_depth_from_file=.false. !< If true, ocean depth is read from a file.
integer(kind=8) :: debug_iceberg_with_id = -1 !< If positive, monitors a berg with this id
real :: speed_limit=0. !< CFL speed limit for a berg [m/s]
real :: tau_calving=0. !< Time scale for smoothing out calving field (years)
real :: tip_parameter=0. !< parameter to override iceberg rolling critical ratio (use zero to get parameter directly from ice and seawater densities)
real :: grounding_fraction=0. !< Fraction of water column depth at which grounding occurs
type(buffer), pointer :: obuffer_n=>null() !< Buffer for outgoing bergs to the north
type(buffer), pointer :: ibuffer_n=>null() !< Buffer for incoming bergs from the north
type(buffer), pointer :: obuffer_s=>null() !< Buffer for outgoing bergs to the south
type(buffer), pointer :: ibuffer_s=>null() !< Buffer for incoming bergs from the south
type(buffer), pointer :: obuffer_e=>null() !< Buffer for outgoing bergs to the east
type(buffer), pointer :: ibuffer_e=>null() !< Buffer for incoming bergs from the east
type(buffer), pointer :: obuffer_w=>null() !< Buffer for outgoing bergs to the west
type(buffer), pointer :: ibuffer_w=>null() !< Buffer for incoming bergs from the west
type(buffer), pointer :: obuffer_io=>null() !< Buffer for outgoing bergs during i/o
type(buffer), pointer :: ibuffer_io=>null() !< Buffer for incoming bergs during i/o
! Budgets
real :: net_calving_received=0., net_calving_returned=0.
real :: net_incoming_calving=0., net_outgoing_calving=0.
real :: net_incoming_calving_heat=0., net_outgoing_calving_heat=0.
real :: net_incoming_calving_heat_used=0., net_heat_to_bergs=0.
real :: stored_start=0., stored_end=0.
real :: rmean_calving_start=0., rmean_calving_end=0.
real :: rmean_calving_hflx_start=0., rmean_calving_hflx_end=0.
real :: stored_heat_start=0., stored_heat_end=0., net_heat_to_ocean=0.
real :: net_calving_used=0., net_calving_to_bergs=0.
real :: floating_mass_start=0., floating_mass_end=0.
real :: floating_heat_start=0., floating_heat_end=0.
real :: icebergs_mass_start=0., icebergs_mass_end=0.
real :: bergy_mass_start=0., bergy_mass_end=0.
real :: spread_mass_start=0., spread_mass_end=0.
real :: spread_area_start=0., spread_area_end=0.
real :: u_iceberg_start=0., u_iceberg_end=0.
real :: v_iceberg_start=0., v_iceberg_end=0.
real :: spread_uvel_start=0., spread_uvel_end=0.
real :: spread_vvel_start=0., spread_vvel_end=0.
real :: ustar_iceberg_start=0., ustar_iceberg_end=0.
real :: returned_mass_on_ocean=0.
real :: returned_area_on_ocean=0.
real :: net_melt=0., berg_melt=0., bergy_src=0., bergy_melt=0.
integer :: nbergs_calved=0, nbergs_melted=0, nbergs_start=0, nbergs_end=0
integer :: nspeeding_tickets=0
integer :: nbonds=0
integer, dimension(:), pointer :: nbergs_calved_by_class=>null()
end type icebergs
!> Read original restarts. Needs to be module global so can be public to icebergs_mod.
!! \todo Remove when backward compatibility no longer needed
logical :: orig_read=.false.
!> Version of file provided by CPP macro (usually set to git hash)
#ifdef _FILE_VERSION
character(len=128) :: version = _FILE_VERSION !< Version of file
#else
character(len=128) :: version = 'unknown' !< Version of file
#endif
!> Set a value in the buffer at position (counter,n) after incrementing counter
interface push_buffer_value
module procedure push_buffer_rvalue, push_buffer_ivalue
end interface
!> Get a value in the buffer at position (counter,n) after incrementing counter
interface pull_buffer_value
module procedure pull_buffer_rvalue, pull_buffer_ivalue
end interface
contains
!> Initializes parallel framework
subroutine ice_bergs_framework_init(bergs, &
gni, gnj, layout, io_layout, axes, dom_x_flags, dom_y_flags, &
dt, Time, ice_lon, ice_lat, ice_wet, ice_dx, ice_dy, ice_area, &
cos_rot, sin_rot, ocean_depth, maskmap, fractional_area)
use mpp_parameter_mod, only: SCALAR_PAIR, CGRID_NE, BGRID_NE, CORNER, AGRID
use mpp_domains_mod, only: mpp_update_domains, mpp_define_domains
use mpp_domains_mod, only: mpp_get_compute_domain, mpp_get_data_domain, mpp_get_global_domain
use mpp_domains_mod, only: CYCLIC_GLOBAL_DOMAIN, FOLD_NORTH_EDGE
use mpp_domains_mod, only: mpp_get_neighbor_pe, NORTH, SOUTH, EAST, WEST
use mpp_domains_mod, only: mpp_define_io_domain
use mpp_mod, only: mpp_clock_begin, mpp_clock_end, mpp_clock_id, input_nml_file
use mpp_mod, only: CLOCK_COMPONENT, CLOCK_SUBCOMPONENT, CLOCK_LOOP
use fms_mod, only: open_namelist_file, check_nml_error, close_file
use fms_mod, only: clock_flag_default
use diag_manager_mod, only: register_diag_field, register_static_field, send_data
use diag_manager_mod, only: diag_axis_init
! Arguments
type(icebergs), pointer :: bergs !< Container for all types and memory
integer, intent(in) :: gni !< Number grid cells in i-direction
integer, intent(in) :: gnj !< Number grid cells in j-direction
integer, intent(in) :: layout(2) !< Number of processing cores in i,j direction
integer, intent(in) :: io_layout(2) !< Number of i/o cores in i,j direction
integer, intent(in) :: axes(2) !< Diagnostic axes
integer, intent(in) :: dom_x_flags !< Domain flags in i-direction
integer, intent(in) :: dom_y_flags !< Domain flags in j-direction
real, intent(in) :: dt !< Time-step (s)
type (time_type), intent(in) :: Time !< Current model time
real, dimension(:,:), intent(in) :: ice_lon !< Longitude of cell corners using NE convention (degree E)
real, dimension(:,:), intent(in) :: ice_lat !< Latitude of cell corners using NE conventino (degree N)
real, dimension(:,:), intent(in) :: ice_wet !< Wet/dry mask (1 is wet, 0 is dry) of cell centers
real, dimension(:,:), intent(in) :: ice_dx !< Zonal length of cell on northern side (m)
real, dimension(:,:), intent(in) :: ice_dy !< Meridional length of cell on eastern side (m)
real, dimension(:,:), intent(in) :: ice_area !< Area of cells (m^2, or non-dim is fractional_area=True)
real, dimension(:,:), intent(in) :: cos_rot !< Cosine from rotation matrix to lat-lon coords
real, dimension(:,:), intent(in) :: sin_rot !< Sine from rotation matrix to lat-lon coords
real, dimension(:,:), intent(in),optional :: ocean_depth !< Depth of ocean bottom (m)
logical, intent(in), optional :: maskmap(:,:) !< Masks out parallel cores
logical, intent(in), optional :: fractional_area !< If true, ice_area contains cell area as fraction of entire spherical surface
! Namelist parameters (and defaults)
integer :: halo=4 ! Width of halo region
integer :: traj_sample_hrs=24 ! Period between sampling of position for trajectory storage
integer :: traj_write_hrs=480 ! Period between writing sampled trajectories to disk
integer :: verbose_hrs=24 ! Period between verbose messages
integer :: max_bonds=6 ! Maximum number of iceberg bond passed between processors
real :: rho_bergs=850. ! Density of icebergs
real :: spring_coef=1.e-8 ! Spring constant for iceberg interactions (this seems to be the highest stable value)
real :: bond_coef=1.e-8 ! Spring constant for iceberg bonds - not being used right now
real :: radial_damping_coef=1.e-4 ! Coefficient for relative iceberg motion damping (radial component) -Alon
real :: tangental_damping_coef=2.e-5 ! Coefficient for relative iceberg motion damping (tangential component) -Alon
real :: LoW_ratio=1.5 ! Initial ratio L/W for newly calved icebergs
real :: bergy_bit_erosion_fraction=0. ! Fraction of erosion melt flux to divert to bergy bits
real :: sicn_shift=0. ! Shift of sea-ice concentration in erosion flux modulation (0<sicn_shift<1)
real :: lat_ref=0. ! Reference latitude for f-plane (when this option is on)
real :: u_override=0.0 ! Overrides the u velocity of icebergs (for ocean testing)
real :: v_override=0.0 ! Overrides the v velocity of icebergs (for ocean testing)
real :: Lx=360. ! Length of domain in x direction, used for periodicity (use a huge number for non-periodic)
real :: initial_orientation=0. ! Iceberg orientation relative to this angle (in degrees). Used for hexagonal mass spreading.
real :: utide_icebergs= 0. ! Tidal speeds, set to zero for now.
real :: ustar_icebergs_bg=0.001 ! Background u_star under icebergs. This should be linked to a value felt by the ocean boundary layer
real :: cdrag_icebergs = 1.5e-3 ! Momentum Drag coef, taken from HJ99 (Holland and Jenkins 1999)
real :: Gamma_T_3EQ=0.022 ! Non-dimensional heat-transfer coefficient
real :: melt_cutoff=-1.0 ! Minimum ocean thickness for melting to occur (is not applied for values < 0)
logical :: const_gamma=.True. ! If true uses a constant heat transfer coefficient, from which the salt transfer is calculated
logical :: use_operator_splitting=.true. ! Use first order operator splitting for thermodynamics
logical :: add_weight_to_ocean=.true. ! Add weight of icebergs + bits to ocean
logical :: passive_mode=.false. ! Add weight of icebergs + bits to ocean
logical :: time_average_weight=.false. ! Time average the weight on the ocean
real :: speed_limit=0. ! CFL speed limit for a berg
real :: tau_calving=0. ! Time scale for smoothing out calving field (years)
real :: tip_parameter=0. ! Parameter to override iceberg rolling critical ratio (use zero to get parameter directly from ice and seawater densities
real :: grounding_fraction=0. ! Fraction of water column depth at which grounding occurs
real :: coastal_drift=0. ! A velocity added to ocean currents to cause bergs to drift away from land cells
real :: tidal_drift=0. ! Amplitude of a stochastic tidal velocity added to ocean currents to cause bergs to drift randomly
logical :: Runge_not_Verlet=.True. ! True=Runge Kutta, False=Verlet.
logical :: use_mixed_melting=.False. ! If true, then the melt is determined partly using 3 eq model partly using iceberg parameterizations (according to iceberg bond number)
logical :: apply_thickness_cutoff_to_gridded_melt=.False. ! Prevents melt for ocean thickness below melt_cuttoff (applied to gridded melt fields)
logical :: apply_thickness_cutoff_to_bergs_melt=.False. ! Prevents melt for ocean thickness below melt_cuttoff (applied to bergs)
logical :: use_updated_rolling_scheme=.false. ! Use the corrected Rolling Scheme rather than the erroneous one
logical :: pass_fields_to_ocean_model=.False. ! Iceberg area, mass and ustar fields are prepared to pass to ocean model
logical :: use_mixed_layer_salinity_for_thermo=.False. ! If true, then model uses ocean salinity for 3 and 2 equation melt model.
logical :: find_melt_using_spread_mass=.False. ! If true, then the model calculates ice loss by looping at the spread_mass before and after.
logical :: Use_three_equation_model=.True. ! Uses 3 equation model for melt when ice shelf type thermodynamics are used.
logical :: melt_icebergs_as_ice_shelf=.False. ! Uses iceshelf type thermodynamics
logical :: Iceberg_melt_without_decay=.False. ! Allows icebergs meltwater fluxes to enter the ocean, without the iceberg decaying or changing shape.
logical :: add_iceberg_thickness_to_SSH=.False. ! Adds the iceberg contribution to SSH.
logical :: override_iceberg_velocities=.False. ! Allows you to set a fixed iceberg velocity for all non-static icebergs.
logical :: use_f_plane=.False. ! Flag to use a f-plane for the rotation
logical :: grid_is_latlon=.True. ! True means that the grid is specified in lat lon, and uses to radius of the earth to convert to distance
logical :: grid_is_regular=.True. ! Flag to say whether point in cell can be found assuming regular Cartesian grid
logical :: rotate_icebergs_for_mass_spreading=.True. ! Flag allows icebergs to rotate for spreading their mass (in hexagonal spreading mode)
logical :: set_melt_rates_to_zero=.False. ! Sets all melt rates to zero, for testing purposes (thermodynamics routine is still run)
logical :: allow_bergs_to_roll=.True. ! Allows icebergs to roll over when rolling conditions are met
logical :: hexagonal_icebergs=.False. ! True treats icebergs as rectangles, False as hexagonal elements (for the purpose of mass spreading)
logical :: ignore_missing_restart_bergs=.False. ! True Allows the model to ignore icebergs missing in the restart.
logical :: Static_icebergs=.False. ! True= icebergs do no move
logical :: only_interactive_forces=.False. ! Icebergs only feel interactive forces, and not ocean, wind...
logical :: halo_debugging=.False. ! Use for debugging halos (remove when its working)
logical :: save_short_traj=.True. ! True saves only lon,lat,time,id in iceberg_trajectory.nc
logical :: ignore_traj=.False. ! If true, then model does not traj trajectory data at all
logical :: iceberg_bonds_on=.False. ! True=Allow icebergs to have bonds, False=don't allow.
logical :: manually_initialize_bonds=.False. ! True= Bonds are initialize manually.
logical :: use_new_predictive_corrective =.False. ! Flag to use Bob's predictive corrective iceberg scheme- Added by Alon
logical :: interactive_icebergs_on=.false. ! Turn on/off interactions between icebergs - Added by Alon
logical :: critical_interaction_damping_on=.true. ! Sets the damping on relative iceberg velocity to critical value - Added by Alon
logical :: do_unit_tests=.false. ! Conduct some unit tests
logical :: input_freq_distribution=.false. ! Flag to show if input distribution is freq or mass dist (=1 if input is a freq dist, =0 to use an input mass dist)
logical :: read_old_restarts=.false. ! Legacy option that does nothing
logical :: use_old_spreading=.true. ! If true, spreads iceberg mass as if the berg is one grid cell wide
logical :: read_ocean_depth_from_file=.false. ! If true, ocean depth is read from a file.
real, dimension(nclasses) :: initial_mass=(/8.8e7, 4.1e8, 3.3e9, 1.8e10, 3.8e10, 7.5e10, 1.2e11, 2.2e11, 3.9e11, 7.4e11/) ! Mass thresholds between iceberg classes (kg)
real, dimension(nclasses) :: distribution=(/0.24, 0.12, 0.15, 0.18, 0.12, 0.07, 0.03, 0.03, 0.03, 0.02/) ! Fraction of calving to apply to this class (non-dim) ,
real, dimension(nclasses) :: mass_scaling=(/2000, 200, 50, 20, 10, 5, 2, 1, 1, 1/) ! Ratio between effective and real iceberg mass (non-dim)
real, dimension(nclasses) :: initial_thickness=(/40., 67., 133., 175., 250., 250., 250., 250., 250., 250./) ! Total thickness of newly calved bergs (m)
integer(kind=8) :: debug_iceberg_with_id = -1 ! If positive, monitors a berg with this id
namelist /icebergs_nml/ verbose, budget, halo, traj_sample_hrs, initial_mass, traj_write_hrs, max_bonds, save_short_traj,Static_icebergs, &
distribution, mass_scaling, initial_thickness, verbose_hrs, spring_coef,bond_coef, radial_damping_coef, tangental_damping_coef, only_interactive_forces, &
rho_bergs, LoW_ratio, debug, really_debug, use_operator_splitting, bergy_bit_erosion_fraction, iceberg_bonds_on, manually_initialize_bonds, ignore_missing_restart_bergs, &
parallel_reprod, use_slow_find, sicn_shift, add_weight_to_ocean, passive_mode, ignore_ij_restart, use_new_predictive_corrective, halo_debugging, hexagonal_icebergs, &
time_average_weight, generate_test_icebergs, speed_limit, fix_restart_dates, use_roundoff_fix, Runge_not_Verlet, interactive_icebergs_on, critical_interaction_damping_on, &
old_bug_rotated_weights, make_calving_reproduce,restart_input_dir, orig_read, old_bug_bilin,do_unit_tests,grounding_fraction, input_freq_distribution, force_all_pes_traj, &
allow_bergs_to_roll,set_melt_rates_to_zero,lat_ref,initial_orientation,rotate_icebergs_for_mass_spreading,grid_is_latlon,Lx,use_f_plane,use_old_spreading, &
grid_is_regular,override_iceberg_velocities,u_override,v_override,add_iceberg_thickness_to_SSH,Iceberg_melt_without_decay,melt_icebergs_as_ice_shelf, &
Use_three_equation_model,find_melt_using_spread_mass,use_mixed_layer_salinity_for_thermo,utide_icebergs,ustar_icebergs_bg,cdrag_icebergs, pass_fields_to_ocean_model, &
const_gamma, Gamma_T_3EQ, ignore_traj, debug_iceberg_with_id,use_updated_rolling_scheme, tip_parameter, read_old_restarts, tau_calving, read_ocean_depth_from_file, melt_cutoff,&
apply_thickness_cutoff_to_gridded_melt, apply_thickness_cutoff_to_bergs_melt, use_mixed_melting, coastal_drift, tidal_drift
! Local variables
integer :: ierr, iunit, i, j, id_class, axes3d(3), is,ie,js,je,np
type(icebergs_gridded), pointer :: grd
real :: lon_mod, big_number
logical :: lerr
integer :: stdlogunit, stderrunit
real :: Total_mass !Added by Alon
! Get the stderr and stdlog unit numbers
stderrunit=stderr()
stdlogunit=stdlog()
write(stdlogunit,*) "ice_bergs_framework: "//trim(version)
! Read namelist parameters
!write(stderrunit,*) 'diamonds: reading namelist'
#ifdef INTERNAL_FILE_NML
read (input_nml_file, nml=icebergs_nml, iostat=ierr)
#else
iunit = open_namelist_file()
read (iunit, icebergs_nml,iostat=ierr)
call close_file (iunit)
#endif
ierr = check_nml_error(ierr,'icebergs_nml')
if (really_debug) debug=.true. ! One implies the other...
write (stdlogunit, icebergs_nml)
! Allocate overall structure
!write(stderrunit,*) 'diamonds: allocating bergs'
allocate(bergs)
allocate(bergs%grd)
grd=>bergs%grd ! For convenience to avoid bergs%grd%X
!write(stderrunit,*) 'diamonds: allocating domain'
allocate(grd%domain)
! Clocks
bergs%clock=mpp_clock_id( 'Icebergs', flags=clock_flag_default, grain=CLOCK_COMPONENT )
bergs%clock_mom=mpp_clock_id( 'Icebergs-momentum', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
bergs%clock_the=mpp_clock_id( 'Icebergs-thermodyn', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
bergs%clock_int=mpp_clock_id( 'Icebergs-interface', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
bergs%clock_cal=mpp_clock_id( 'Icebergs-calving', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
bergs%clock_com=mpp_clock_id( 'Icebergs-communication', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
bergs%clock_ini=mpp_clock_id( 'Icebergs-initialization', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
bergs%clock_ior=mpp_clock_id( 'Icebergs-I/O read', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
bergs%clock_iow=mpp_clock_id( 'Icebergs-I/O write', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
bergs%clock_dia=mpp_clock_id( 'Icebergs-diagnostics', flags=clock_flag_default, grain=CLOCK_SUBCOMPONENT )
call mpp_clock_begin(bergs%clock)
call mpp_clock_begin(bergs%clock_ini)
! Set up iceberg domain
!write(stderrunit,*) 'diamonds: defining domain'
call mpp_define_domains( (/1,gni,1,gnj/), layout, grd%domain, &
maskmap=maskmap, &
xflags=dom_x_flags, xhalo=halo, &
yflags=dom_y_flags, yhalo=halo, name='diamond')
call mpp_define_io_domain(grd%domain, io_layout)
!write(stderrunit,*) 'diamond: get compute domain'
call mpp_get_compute_domain( grd%domain, grd%isc, grd%iec, grd%jsc, grd%jec )
call mpp_get_data_domain( grd%domain, grd%isd, grd%ied, grd%jsd, grd%jed )
call mpp_get_global_domain( grd%domain, grd%isg, grd%ieg, grd%jsg, grd%jeg )
call mpp_get_neighbor_pe(grd%domain, NORTH, grd%pe_N)
call mpp_get_neighbor_pe(grd%domain, SOUTH, grd%pe_S)
call mpp_get_neighbor_pe(grd%domain, EAST, grd%pe_E)
call mpp_get_neighbor_pe(grd%domain, WEST, grd%pe_W)
folded_north_on_pe = ((dom_y_flags == FOLD_NORTH_EDGE) .and. (grd%jec == gnj))
!write(stderrunit,'(a,6i4)') 'diamonds, icebergs_init: pe,n,s,e,w =',mpp_pe(),grd%pe_N,grd%pe_S,grd%pe_E,grd%pe_W, NULL_PE
!if (verbose) &
!write(stderrunit,'(a,i3,a,4i4,a,4f8.2)') 'diamonds, icebergs_init: (',mpp_pe(),') [ij][se]c=', &
! grd%isc,grd%iec,grd%jsc,grd%jec, &
! ' [lon|lat][min|max]=', minval(ice_lon),maxval(ice_lon),minval(ice_lat),maxval(ice_lat)
!write(stderrunit,*) 'diamonds, int args = ', mpp_pe(),gni, gnj, layout, axes
! Allocate grid of pointers
allocate( bergs%list(grd%isd:grd%ied, grd%jsd:grd%jed) )
do j = grd%jsd,grd%jed ; do i = grd%isd,grd%ied
bergs%list(i,j)%first => null()
enddo ; enddo
big_number=1.0E15
!write(stderrunit,*) 'diamonds: allocating grid'
allocate( grd%lon(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%lon(:,:)=big_number
allocate( grd%lat(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%lat(:,:)=big_number
allocate( grd%lonc(grd%isd:grd%ied, grd%jsd:grd%jed) );grd%lon(:,:)=big_number
allocate( grd%latc(grd%isd:grd%ied, grd%jsd:grd%jed) );grd%lat(:,:)=big_number
allocate( grd%dx(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%dx(:,:)=0.
allocate( grd%dy(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%dy(:,:)=0.
allocate( grd%area(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%area(:,:)=0.
allocate( grd%msk(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%msk(:,:)=0.
allocate( grd%cos(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%cos(:,:)=1.
allocate( grd%sin(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%sin(:,:)=0.
allocate( grd%ocean_depth(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%ocean_depth(:,:)=0.
allocate( grd%calving(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%calving(:,:)=0.
allocate( grd%calving_hflx(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%calving_hflx(:,:)=0.
allocate( grd%stored_heat(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%stored_heat(:,:)=0.
allocate( grd%floating_melt(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%floating_melt(:,:)=0.
allocate( grd%berg_melt(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%berg_melt(:,:)=0.
allocate( grd%melt_buoy(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%melt_buoy(:,:)=0.
allocate( grd%melt_eros(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%melt_eros(:,:)=0.
allocate( grd%melt_conv(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%melt_conv(:,:)=0.
allocate( grd%bergy_src(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%bergy_src(:,:)=0.
allocate( grd%bergy_melt(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%bergy_melt(:,:)=0.
allocate( grd%bergy_mass(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%bergy_mass(:,:)=0.
allocate( grd%spread_mass(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%spread_mass(:,:)=0.
allocate( grd%spread_mass_old(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%spread_mass_old(:,:)=0.
allocate( grd%spread_area(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%spread_area(:,:)=0.
allocate( grd%u_iceberg(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%u_iceberg(:,:)=0.
allocate( grd%v_iceberg(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%v_iceberg(:,:)=0.
allocate( grd%spread_uvel(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%spread_uvel(:,:)=0.
allocate( grd%spread_vvel(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%spread_vvel(:,:)=0.
allocate( grd%ustar_iceberg(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%ustar_iceberg(:,:)=0.
allocate( grd%virtual_area(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%virtual_area(:,:)=0.
allocate( grd%mass(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%mass(:,:)=0.
allocate( grd%mass_on_ocean(grd%isd:grd%ied, grd%jsd:grd%jed, 9) ); grd%mass_on_ocean(:,:,:)=0.
allocate( grd%area_on_ocean(grd%isd:grd%ied, grd%jsd:grd%jed, 9) ); grd%area_on_ocean(:,:,:)=0.
allocate( grd%Uvel_on_ocean(grd%isd:grd%ied, grd%jsd:grd%jed, 9) ); grd%Uvel_on_ocean(:,:,:)=0.
allocate( grd%Vvel_on_ocean(grd%isd:grd%ied, grd%jsd:grd%jed, 9) ); grd%Vvel_on_ocean(:,:,:)=0.
allocate( grd%stored_ice(grd%isd:grd%ied, grd%jsd:grd%jed, nclasses) ); grd%stored_ice(:,:,:)=0.
allocate( grd%rmean_calving(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%rmean_calving(:,:)=0.
allocate( grd%rmean_calving_hflx(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%rmean_calving_hflx(:,:)=0.
allocate( grd%real_calving(grd%isd:grd%ied, grd%jsd:grd%jed, nclasses) ); grd%real_calving(:,:,:)=0.
allocate( grd%uo(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%uo(:,:)=0.
allocate( grd%vo(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%vo(:,:)=0.
allocate( grd%ui(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%ui(:,:)=0.
allocate( grd%vi(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%vi(:,:)=0.
allocate( grd%ua(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%ua(:,:)=0.
allocate( grd%va(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%va(:,:)=0.
allocate( grd%ssh(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%ssh(:,:)=0.
allocate( grd%sst(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%sst(:,:)=0.
allocate( grd%sss(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%sss(:,:)=0.
allocate( grd%cn(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%cn(:,:)=0.
allocate( grd%hi(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%hi(:,:)=0.
allocate( grd%tmp(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%tmp(:,:)=0.
allocate( grd%tmpc(grd%isc:grd%iec, grd%jsc:grd%jec) ); grd%tmpc(:,:)=0.
allocate( bergs%nbergs_calved_by_class(nclasses) ); bergs%nbergs_calved_by_class(:)=0
allocate( grd%parity_x(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%parity_x(:,:)=1.
allocate( grd%parity_y(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%parity_y(:,:)=1.
allocate( grd%iceberg_counter_grd(grd%isd:grd%ied, grd%jsd:grd%jed) ); grd%iceberg_counter_grd(:,:)=0
!write(stderrunit,*) 'diamonds: copying grid'
! Copy data declared on ice model computational domain
is=grd%isc; ie=grd%iec; js=grd%jsc; je=grd%jec
grd%lon(is:ie,js:je)=ice_lon(:,:)
grd%lat(is:ie,js:je)=ice_lat(:,:)
grd%area(is:ie,js:je)=ice_area(:,:) !sis2 has *(4.*pi*radius*radius)
!!!!!!!!!!!!!!!debugging!!!!!!!!!!!!!!!!!!
!if (mpp_pe().eq.5) then
! write(stderrunit,'(a3,32i7)') 'LB',(i,i=grd%isd,grd%ied)
! do j=grd%jed,grd%jsd,-1
! write(stderrunit,'(i3,32f7.1)') j,(grd%lon(i,j),i=grd%isd,grd%ied)
! enddo
! write(stderrunit,'(a3,32i7)') 'Ice lon',(i,i=grd%isd,grd%ied)
! do j=grd%jed,grd%jsd,-1
! write(stderrunit,'(i3,32f7.1)') j,(ice_lon(i,j),i=grd%isd,grd%ied)
! enddo
! write(stderrunit,'(a3,32i7)') 'LA',(i,i=grd%isd,grd%ied)
! do j=grd%jed,grd%jsd,-1
! write(stderrunit,'(i3,32f7.1)') j,(grd%lon(i,j),i=grd%isd,grd%ied)
! enddo
!endif
!!!!!!!!!!!!!!!debugging!!!!!!!!!!!!!!!!!!
!For SIS not to change answers
if(present(fractional_area)) then
if(fractional_area) grd%area(is:ie,js:je)=ice_area(:,:) *(4.*pi*radius*radius)
endif
if(present(ocean_depth)) grd%ocean_depth(is:ie,js:je)=ocean_depth(:,:)
! Copy data declared on ice model data domain
is=grd%isc-1; ie=grd%iec+1; js=grd%jsc-1; je=grd%jec+1
grd%dx(is:ie,js:je)=ice_dx(:,:)
grd%dy(is:ie,js:je)=ice_dy(:,:)
grd%msk(is:ie,js:je)=ice_wet(:,:)
grd%cos(is:ie,js:je)=cos_rot(:,:)
grd%sin(is:ie,js:je)=sin_rot(:,:)
call mpp_update_domains(grd%lon, grd%domain, position=CORNER)
call mpp_update_domains(grd%lat, grd%domain, position=CORNER)
call mpp_update_domains(grd%dy, grd%dx, grd%domain, gridtype=CGRID_NE, flags=SCALAR_PAIR)
call mpp_update_domains(grd%area, grd%domain)
call mpp_update_domains(grd%msk, grd%domain)
call mpp_update_domains(grd%cos, grd%domain, position=CORNER)
call mpp_update_domains(grd%sin, grd%domain, position=CORNER)
call mpp_update_domains(grd%ocean_depth, grd%domain)
call mpp_update_domains(grd%parity_x, grd%parity_y, grd%domain, gridtype=AGRID) ! If either parity_x/y is -ve, we need rotation of vectors
! Sanitize lon and lat in the southern halo
do j=grd%jsc-1,grd%jsd,-1; do i=grd%isd,grd%ied
if (grd%lon(i,j).ge.big_number) grd%lon(i,j)=grd%lon(i,j+1)
if (grd%lat(i,j).ge.big_number) grd%lat(i,j)=2.*grd%lat(i,j+1)-grd%lat(i,j+2)
enddo; enddo
! fix halos on edge of the domain
!1) South
do j=grd%jsc-1,grd%jsd,-1; do i=grd%isd,grd%ied
if (grd%lon(i,j).ge.big_number) grd%lon(i,j)=2.*grd%lon(i,j+1)-grd%lon(i,j+2)
if (grd%lat(i,j).ge.big_number) grd%lat(i,j)=2.*grd%lat(i,j+1)-grd%lat(i,j+2)
enddo; enddo
!2) North
do j=grd%jec+1,grd%jed; do i=grd%isd,grd%ied
if (grd%lon(i,j).ge.big_number) grd%lon(i,j)=2.*grd%lon(i,j-1)-grd%lon(i,j-2)
if (grd%lat(i,j).ge.big_number) grd%lat(i,j)=2.*grd%lat(i,j-1)-grd%lat(i,j-2)
enddo; enddo
!3) West
do i=grd%isc-1,grd%isd,-1; do j=grd%jsd,grd%jed
if (grd%lon(i,j).ge.big_number) grd%lon(i,j)=2.*grd%lon(i+1,j)-grd%lon(i+2,j)
if (grd%lat(i,j).ge.big_number) grd%lat(i,j)=2.*grd%lat(i+1,j)-grd%lat(i+2,j)
enddo; enddo
!4) East
do i=grd%iec+1,grd%ied; do j=grd%jsd,grd%jed
if (grd%lon(i,j).ge.big_number) grd%lon(i,j)=2.*grd%lon(i-1,j)-grd%lon(i-2,j)
if (grd%lat(i,j).ge.big_number) grd%lat(i,j)=2.*grd%lat(i-1,j)-grd%lat(i-2,j)
enddo; enddo
if (.not. present(maskmap)) then ! Using a maskmap causes tickles this sanity check
do j=grd%jsd,grd%jed; do i=grd%isd,grd%ied
!if (grd%lon(i,j).ge.big_number) write(stderrunit,*) 'bad lon: ',mpp_pe(),i-grd%isc+1,j-grd%jsc+1,grd%lon(i,j)
!if (grd%lat(i,j).ge.big_number) write(stderrunit,*) 'bad lat: ',mpp_pe(),i-grd%isc+1,j-grd%jsc+1,grd%lat(i,j)
enddo; enddo
endif
if ((Lx.gt.1E15 ) .and. (mpp_pe().eq.mpp_root_pe())) then
call error_mesg('diamonds, framework', 'Model does not enjoy the domain being larger than 1E15. Not sure why. Probably to do with floating point precision.', WARNING)
endif
if ((.not. grid_is_latlon) .and. (Lx.eq.360.)) then
if (mpp_pe().eq.mpp_root_pe()) then
call error_mesg('diamonds, framework', 'Since the lat/lon grid is off, the x-direction is being set as non-periodic. Set Lx not equal to 360 override.', WARNING)
endif
Lx=-1.
endif
!The fix to reproduce across PE layout change, from AJA
if (Lx>0.) then
j=grd%jsc; do i=grd%isc+1,grd%ied
lon_mod = apply_modulo_around_point(grd%lon(i,j),grd%lon(i-1,j),Lx)
if (abs(grd%lon(i,j)-lon_mod)>(Lx/2.)) &
grd%lon(i,j)= lon_mod
enddo
j=grd%jsc; do i=grd%isc-1,grd%isd,-1
lon_mod = apply_modulo_around_point(grd%lon(i,j),grd%lon(i+1,j) ,Lx)
if (abs(grd%lon(i,j)- lon_mod )>(Lx/2.)) &
grd%lon(i,j)= lon_mod
enddo
do j=grd%jsc+1,grd%jed; do i=grd%isd,grd%ied
lon_mod = apply_modulo_around_point(grd%lon(i,j),grd%lon(i,j-1) ,Lx)
if (abs(grd%lon(i,j)-(lon_mod ))>(Lx/2.)) &
grd%lon(i,j)= lon_mod
enddo; enddo
do j=grd%jsc-1,grd%jsd,-1; do i=grd%isd,grd%ied
lon_mod = apply_modulo_around_point(grd%lon(i,j),grd%lon(i,j+1) ,Lx)
if (abs(grd%lon(i,j)- lon_mod )>(Lx/2.)) &
grd%lon(i,j)= lon_mod
enddo; enddo
endif
! lonc, latc used for searches
do j=grd%jsd+1,grd%jed; do i=grd%isd+1,grd%ied
grd%lonc(i,j)=0.25*( (grd%lon(i,j)+grd%lon(i-1,j-1)) &
+(grd%lon(i-1,j)+grd%lon(i,j-1)) )
grd%latc(i,j)=0.25*( (grd%lat(i,j)+grd%lat(i-1,j-1)) &
+(grd%lat(i-1,j)+grd%lat(i,j-1)) )
enddo; enddo
if (debug) then
write(stderrunit,'(a,i3,a,4i4,a,4f8.2)') 'diamonds, icebergs_init: (',mpp_pe(),') [ij][se]c=', &
grd%isc,grd%iec,grd%jsc,grd%jec, &
' [lon|lat][min|max]=', minval(grd%lon),maxval(grd%lon),minval(grd%lat),maxval(grd%lat)
endif
!if (mpp_pe().eq.5) then
! write(stderrunit,'(a3,32i7)') 'Lon',(i,i=grd%isd,grd%ied)
! do j=grd%jed,grd%jsd,-1
! write(stderrunit,'(i3,32f7.1)') j,(grd%lon(i,j),i=grd%isd,grd%ied)
! enddo
! write(stderrunit,'(a3,32i7)') 'Lat',(i,i=grd%isd,grd%ied)
! do j=grd%jed,grd%jsd,-1
! write(stderrunit,'(i3,32f7.1)') j,(grd%lat(i,j),i=grd%isd,grd%ied)
! enddo
! write(stderrunit,'(a3,32i7)') 'Msk',(i,i=grd%isd,grd%ied)
! do j=grd%jed,grd%jsd,-1
! write(stderrunit,'(i3,32f7.1)') j,(grd%msk(i,j),i=grd%isd,grd%ied)
! enddo
!endif
! Final check for NaN's in the latlon grid:
do j=grd%jsd+1,grd%jed; do i=grd%isd+1,grd%ied
if (grd%lat(i,j) .ne. grd%lat(i,j)) then
write(stderrunit,*) 'Lat not defined properly', mpp_pe(),i,j,grd%lat(i,j)
call error_mesg('diamonds,grid defining', 'Latitude contains NaNs', FATAL)
endif
if (grd%lon(i,j) .ne. grd%lon(i,j)) then
write(stderrunit,*) 'Lon not defined properly', mpp_pe(),i,j,grd%lon(i,j)
call error_mesg('diamonds, grid defining', 'Longatudes contains NaNs', FATAL)
endif
enddo; enddo
!Added by Alon - If a freq distribution is input, we have to convert the freq distribution to a mass flux distribution)
if (input_freq_distribution) then
Total_mass=0.
do j=1,nclasses
Total_mass=Total_mass+(distribution(j)*initial_mass(j))
enddo
do j=1,nclasses
distribution(j)=(distribution(j)*initial_mass(j))/Total_mass
enddo
endif
if ((halo .lt. 3) .and. (rotate_icebergs_for_mass_spreading .and. iceberg_bonds_on) ) then
halo=3
call error_mesg('diamonds, framework', 'Setting iceberg halos =3, since halos must be >= 3 for rotating icebergs for mass spreading', WARNING)
elseif ((halo .lt. 2) .and. (interactive_icebergs_on .or. iceberg_bonds_on) ) then
halo=2
call error_mesg('diamonds, framework', 'Setting iceberg halos =2, since halos must be >= 2 for interactions', WARNING)
endif
if (interactive_icebergs_on) then
if (Runge_not_Verlet) then
!Runge_not_Verlet=.false. ! Iceberg interactions only with Verlet
call error_mesg('diamonds, framework', 'It is unlcear whther interactive icebergs work with Runge Kutta stepping.', WARNING)
endif
endif
if (.not.interactive_icebergs_on) then
if (iceberg_bonds_on) then
!iceberg_bonds_on=.false.
call error_mesg('diamonds, framework', 'Interactive icebergs off requires iceberg bonds off (turning bonds off).', WARNING)
endif
endif
if (.not. iceberg_bonds_on) then
max_bonds=0
else
buffer_width=buffer_width+(max_bonds*4) ! Increase buffer width to include bonds being passed between processors
endif
if (save_short_traj) buffer_width_traj=6 ! This is the length of the short buffer used for abrevated traj
if (ignore_traj) buffer_width_traj=0 ! If this is true, then all traj files should be ignored
! Parameters
bergs%dt=dt
bergs%traj_sample_hrs=traj_sample_hrs
bergs%traj_write_hrs=traj_write_hrs
bergs%save_short_traj=save_short_traj
bergs%ignore_traj=ignore_traj
bergs%verbose_hrs=verbose_hrs
bergs%grd%halo=halo
bergs%grd%Lx=Lx
bergs%grd%grid_is_latlon=grid_is_latlon
bergs%grd%grid_is_regular=grid_is_regular
bergs%max_bonds=max_bonds
bergs%rho_bergs=rho_bergs
bergs%spring_coef=spring_coef
bergs%bond_coef=bond_coef
bergs%radial_damping_coef=radial_damping_coef
bergs%tangental_damping_coef=tangental_damping_coef
bergs%LoW_ratio=LoW_ratio
bergs%use_operator_splitting=use_operator_splitting
bergs%bergy_bit_erosion_fraction=bergy_bit_erosion_fraction
bergs%sicn_shift=sicn_shift
bergs%passive_mode=passive_mode
bergs%time_average_weight=time_average_weight
bergs%speed_limit=speed_limit
bergs%tau_calving=tau_calving
bergs%tip_parameter=tip_parameter
bergs%use_updated_rolling_scheme=use_updated_rolling_scheme !Alon
bergs%Runge_not_Verlet=Runge_not_Verlet
bergs%use_mixed_melting=use_mixed_melting
bergs%apply_thickness_cutoff_to_bergs_melt=apply_thickness_cutoff_to_bergs_melt
bergs%apply_thickness_cutoff_to_gridded_melt=apply_thickness_cutoff_to_gridded_melt
bergs%melt_cutoff=melt_cutoff
bergs%read_ocean_depth_from_file=read_ocean_depth_from_file
bergs%const_gamma=const_gamma
bergs%Gamma_T_3EQ=Gamma_T_3EQ
bergs%pass_fields_to_ocean_model=pass_fields_to_ocean_model
bergs%ustar_icebergs_bg=ustar_icebergs_bg
bergs%utide_icebergs=utide_icebergs
bergs%cdrag_icebergs=cdrag_icebergs
bergs%use_mixed_layer_salinity_for_thermo=use_mixed_layer_salinity_for_thermo
bergs%find_melt_using_spread_mass=find_melt_using_spread_mass
bergs%Use_three_equation_model=Use_three_equation_model
bergs%melt_icebergs_as_ice_shelf=melt_icebergs_as_ice_shelf
bergs%Iceberg_melt_without_decay=Iceberg_melt_without_decay
bergs%add_iceberg_thickness_to_SSH=add_iceberg_thickness_to_SSH
bergs%override_iceberg_velocities=override_iceberg_velocities
bergs%use_f_plane=use_f_plane
bergs%rotate_icebergs_for_mass_spreading=rotate_icebergs_for_mass_spreading
bergs%lat_ref=lat_ref
bergs%u_override=u_override
bergs%v_override=v_override
bergs%initial_orientation=initial_orientation
bergs%set_melt_rates_to_zero=set_melt_rates_to_zero
bergs%allow_bergs_to_roll=allow_bergs_to_roll
bergs%hexagonal_icebergs=hexagonal_icebergs
bergs%ignore_missing_restart_bergs=ignore_missing_restart_bergs
bergs%Static_icebergs=Static_icebergs
bergs%only_interactive_forces=only_interactive_forces
bergs%halo_debugging=halo_debugging
bergs%iceberg_bonds_on=iceberg_bonds_on !Alon
bergs%manually_initialize_bonds=manually_initialize_bonds !Alon
bergs%critical_interaction_damping_on=critical_interaction_damping_on !Alon
bergs%interactive_icebergs_on=interactive_icebergs_on !Alon
bergs%use_new_predictive_corrective=use_new_predictive_corrective !Alon
bergs%grounding_fraction=grounding_fraction
bergs%add_weight_to_ocean=add_weight_to_ocean
bergs%use_old_spreading=use_old_spreading
bergs%debug_iceberg_with_id=debug_iceberg_with_id
allocate( bergs%initial_mass(nclasses) ); bergs%initial_mass(:)=initial_mass(:)
allocate( bergs%distribution(nclasses) ); bergs%distribution(:)=distribution(:)
allocate( bergs%mass_scaling(nclasses) ); bergs%mass_scaling(:)=mass_scaling(:)
allocate( bergs%initial_thickness(nclasses) ); bergs%initial_thickness(:)=initial_thickness(:)
allocate( bergs%initial_width(nclasses) )
allocate( bergs%initial_length(nclasses) )
bergs%initial_width(:)=sqrt(initial_mass(:)/(LoW_ratio*rho_bergs*initial_thickness(:)))
bergs%initial_length(:)=LoW_ratio*bergs%initial_width(:)