@@ -41,12 +41,12 @@ module ice_bergs_fmsio
4141use ice_bergs_framework, only: force_all_pes_traj
4242use ice_bergs_framework, only: check_for_duplicates_in_parallel
4343use ice_bergs_framework, only: split_id, id_from_2_ints, generate_id
44- ! for MTS/DEM/fracture/footloose:
44+ ! for MTS/DEM/fracture/footloose/basins :
4545use ice_bergs_framework, only: mts,save_bond_traj
4646use ice_bergs_framework, only: push_bond_posn, append_bond_posn
4747use ice_bergs_framework, only: pack_bond_traj_into_buffer2,unpack_bond_traj_from_buffer2
4848use ice_bergs_framework, only: dem, iceberg_bonds_on
49- use ice_bergs_framework, only: footloose
49+ use ice_bergs_framework, only: footloose, use_berg_origin_basins
5050
5151
5252implicit none ; private
@@ -56,7 +56,7 @@ module ice_bergs_fmsio
5656public ice_bergs_io_init
5757public read_restart_bergs, write_restart_bergs, write_trajectory, write_bond_trajectory
5858public read_restart_calving, read_restart_bonds
59- public read_ocean_depth
59+ public read_ocean_depth, read_ice_sheet_basins
6060
6161! Local Vars
6262integer , parameter :: file_format_major_version= 0
@@ -181,7 +181,8 @@ subroutine write_restart_bergs(bergs, time_stamp)
181181 first_berg_ine, &
182182 other_berg_jne, &
183183 other_berg_ine, &
184- broken
184+ broken, &
185+ basin
185186
186187
187188integer :: grdi, grdj
@@ -247,6 +248,7 @@ subroutine write_restart_bergs(bergs, time_stamp)
247248 allocate (ang_accel(nbergs))
248249 allocate (rot(nbergs))
249250 endif
251+ if (use_berg_origin_basins) allocate (basin(nbergs))
250252
251253 filename = trim (" icebergs.res.nc" )
252254 call set_domain(bergs% grd% domain)
@@ -322,6 +324,10 @@ subroutine write_restart_bergs(bergs, time_stamp)
322324 id = register_restart_field(bergs_restart,filename,' rot' ,rot,&
323325 longname= ' dem accumulated rotation' ,units= ' rad' )
324326 endif
327+ if (use_berg_origin_basins) then
328+ id = register_restart_field(bergs_restart,filename,' basin' ,basin,&
329+ longname= ' ice-sheet basin of origin' ,units= ' none' )
330+ endif
325331
326332 ! Checking if any icebergs are static in order to decide whether to save static_berg
327333 n_static_bergs = 0
@@ -376,6 +382,7 @@ subroutine write_restart_bergs(bergs, time_stamp)
376382 ang_accel(i) = this% ang_accel
377383 rot(i) = this% rot
378384 endif
385+ if (use_berg_origin_basins) basin(i) = this% basin
379386 this= >this% next
380387 enddo
381388 enddo ; enddo
@@ -426,6 +433,8 @@ subroutine write_restart_bergs(bergs, time_stamp)
426433 rot)
427434 endif
428435
436+ if (use_berg_origin_basins) deallocate (basin)
437+
429438 deallocate ( &
430439 ine, &
431440 jne, &
@@ -655,7 +664,8 @@ subroutine read_restart_bergs(bergs,Time)
655664 iceberg_num,&
656665 id_cnt, &
657666 id_ij, &
658- start_year
667+ start_year, &
668+ basin
659669
660670! integer, allocatable, dimension(:,:) :: iceberg_counter_grd
661671
@@ -738,6 +748,10 @@ subroutine read_restart_bergs(bergs,Time)
738748 allocate (ang_accel(nbergs_in_file))
739749 allocate (rot(nbergs_in_file))
740750 endif
751+ if (use_berg_origin_basins) then
752+ allocate (localberg% basin)
753+ allocate (basin(nbergs_in_file))
754+ endif
741755
742756 call read_unlimited_axis(filename,' lon' ,lon,domain= grd% domain)
743757 call read_unlimited_axis(filename,' lat' ,lat,domain= grd% domain)
@@ -784,6 +798,11 @@ subroutine read_restart_bergs(bergs,Time)
784798 call read_real_vector(filename,' ang_accel' ,ang_accel,grd% domain,value_if_not_in_file= 0 .)
785799 call read_real_vector(filename,' rot' ,rot ,grd% domain,value_if_not_in_file= 0 .)
786800 endif
801+
802+ if (use_berg_origin_basins) then
803+ call read_int_vector(filename,' basin' ,basin,grd% domain,value_if_not_in_file= 0 )
804+ endif
805+
787806 elseif (bergs% require_restart) then
788807 stop ' read_restart_bergs, RESTART NOT FOUND!'
789808 endif
@@ -867,6 +886,10 @@ subroutine read_restart_bergs(bergs,Time)
867886 localberg% rot = rot(k)
868887 endif
869888
889+ if (use_berg_origin_basins) then
890+ localberg% basin = basin(k)
891+ endif
892+
870893 if (really_debug) lres= is_point_in_cell(grd, localberg% lon, localberg% lat, localberg% ine, localberg% jne, explain= .true. )
871894 lres= pos_within_cell(grd, localberg% lon, localberg% lat, localberg% ine, localberg% jne, localberg% xi, localberg% yj)
872895 ! call add_new_berg_to_list(bergs%first, localberg)
@@ -927,6 +950,7 @@ subroutine read_restart_bergs(bergs,Time)
927950 ang_accel, &
928951 rot)
929952 endif
953+ if (use_berg_origin_basins) deallocate (basin)
930954
931955 if (replace_iceberg_num) then
932956 deallocate (iceberg_num)
@@ -1032,6 +1056,7 @@ subroutine generate_bergs(bergs,Time)
10321056 allocate (localberg% ang_accel)
10331057 allocate (localberg% rot)
10341058 endif
1059+ if (use_berg_origin_basins) allocate (localberg% basin)
10351060
10361061 do j= grd% jsc,grd% jec; do i= grd% isc,grd% iec
10371062 if (grd% msk(i,j)>0 . .and. abs (grd% latc(i,j))>80.0 ) then
@@ -1081,6 +1106,9 @@ subroutine generate_bergs(bergs,Time)
10811106 localberg% ang_accel= 0 .
10821107 localberg% rot= 0 .
10831108 endif
1109+ if (use_berg_origin_basins) then
1110+ localberg% basin= 0
1111+ endif
10841112
10851113 ! Berg A
10861114 call loc_set_berg_pos(grd, 0.9 , 0.5 , 1 ., 0 ., localberg)
@@ -1549,7 +1577,7 @@ subroutine read_ocean_depth(grd)
15491577! Local variables
15501578character (len= 37 ) :: filename
15511579
1552- ! Read stored ice
1580+ ! Read depth
15531581 filename= trim (restart_input_dir)// ' topog.nc'
15541582 if (file_exist(filename)) then
15551583 if (mpp_pe().eq. mpp_root_pe()) write (* ,' (2a)' ) &
@@ -1571,6 +1599,33 @@ subroutine read_ocean_depth(grd)
15711599 ! call grd_chksum2(bergs%grd, bergs%grd%ocean_depth, 'read_ocean_depth, ocean_depth')
15721600end subroutine read_ocean_depth
15731601
1602+ ! > Read ice-sheet basins from file
1603+ subroutine read_ice_sheet_basins (grd )
1604+ ! Arguments
1605+ type (icebergs_gridded), pointer :: grd ! < Container for gridded fields
1606+ ! Local variables
1607+ character (len= 37 ) :: filename
1608+
1609+ ! Read sub_basin
1610+ filename= trim (restart_input_dir)// ' ice_sheet_basins.nc'
1611+ if (file_exist(filename)) then
1612+ if (mpp_pe().eq. mpp_root_pe()) write (* ,' (2a)' ) &
1613+ ' KID, read_ice_sheet_basins: reading ' ,filename
1614+ if (field_exist(filename, ' sub_basin' )) then
1615+ if (verbose.and. mpp_pe().eq. mpp_root_pe()) write (* ,' (a)' ) &
1616+ ' KID, read_ice_sheet_basins: reading sub_basins from ice-shelf basins file.'
1617+ call read_data(filename, ' sub_basin' , grd% ice_sheet_basins, grd% domain)
1618+ else
1619+ if (verbose.and. mpp_pe().eq. mpp_root_pe()) write (* ,' (a)' ) &
1620+ ' KID, read_ice_sheet_basins: sub_basin WAS NOT FOUND in the file. Setting to 0.'
1621+ ! grd%ice_sheet_basins(:,:)=0.
1622+ endif
1623+ else
1624+ call error_mesg(' KID, read_ice_sheet_basins' , ' ice_sheet_basins.nc not found!' , FATAL)
1625+ endif
1626+ end subroutine read_ice_sheet_basins
1627+
1628+
15741629! > Write a trajectory-based diagnostics file
15751630subroutine write_trajectory (trajectory , save_short_traj , save_fl_traj , traj_name )
15761631! Arguments
@@ -1586,7 +1641,7 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
15861641integer :: cnid, hiid, hsid
15871642integer :: mid, smid, did, wid, lid, mbid, mflbid, mflbbid, hdid, nbid, odid, flkid
15881643integer :: axnid,aynid,bxnid,bynid,axnfid,aynfid,bxnfid,bynfid, msid
1589- integer :: avid, aaid, rid
1644+ integer :: avid, aaid, rid, baid
15901645character (len= 70 ) :: filename
15911646character (len= 7 ) :: pe_name
15921647type (xyt), pointer :: this, next
@@ -1763,6 +1818,9 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
17631818 rid = inq_varid(ncid, ' rot' )
17641819 endif
17651820
1821+ if (use_berg_origin_basins) then
1822+ baid = inq_varid(ncid, ' basin' )
1823+ endif
17661824 endif
17671825 else
17681826 ! Dimensions
@@ -1833,6 +1891,10 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
18331891 aaid = def_var(ncid, ' ang_accel' , NF_DOUBLE, i_dim)
18341892 rid = def_var(ncid, ' rot' , NF_DOUBLE, i_dim)
18351893 endif
1894+
1895+ if (use_berg_origin_basins) then
1896+ baid = def_var(ncid, ' basin' , NF_INT, i_dim)
1897+ endif
18361898 endif
18371899
18381900 ! Attributes
@@ -1950,6 +2012,10 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
19502012 call put_att(ncid, rid, ' long_name' , ' accumulated rotation' )
19512013 call put_att(ncid, rid, ' units' , ' rad' )
19522014 endif
2015+ if (use_berg_origin_basins) then
2016+ call put_att(ncid, baid, ' long_name' , ' ice-sheet basin of origin' )
2017+ call put_att(ncid, baid, ' units' , ' none' )
2018+ endif
19532019 endif
19542020 endif
19552021
@@ -2031,6 +2097,9 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
20312097 call put_double(ncid, rid, i, this% rot)
20322098 endif
20332099
2100+ if (use_berg_origin_basins) then
2101+ call put_int(ncid, baid, i, this% basin)
2102+ endif
20342103 endif
20352104 next= >this% next
20362105 deallocate (this)
0 commit comments