@@ -44,12 +44,12 @@ module ice_bergs_fms2io
4444use ice_bergs_framework, only: force_all_pes_traj
4545use ice_bergs_framework, only: check_for_duplicates_in_parallel
4646use ice_bergs_framework, only: split_id, id_from_2_ints, generate_id
47- ! for MTS/DEM/fracture/footloose:
47+ ! for MTS/DEM/fracture/footloose/basins :
4848use ice_bergs_framework, only: mts,save_bond_traj
4949use ice_bergs_framework, only: push_bond_posn, append_bond_posn
5050use ice_bergs_framework, only: pack_bond_traj_into_buffer2,unpack_bond_traj_from_buffer2
5151use ice_bergs_framework, only: dem, iceberg_bonds_on
52- use ice_bergs_framework, only: footloose
52+ use ice_bergs_framework, only: footloose, use_berg_origin_basins
5353
5454
5555implicit none ; private
@@ -59,7 +59,7 @@ module ice_bergs_fms2io
5959public ice_bergs_io_init
6060public read_restart_bergs, write_restart_bergs, write_trajectory, write_bond_trajectory
6161public read_restart_calving, read_restart_bonds
62- public read_ocean_depth
62+ public read_ocean_depth, read_ice_sheet_basins
6363
6464! Local Vars
6565integer , parameter :: file_format_major_version= 0
@@ -187,7 +187,8 @@ subroutine write_restart_bergs(bergs, time_stamp)
187187 first_berg_ine, &
188188 other_berg_jne, &
189189 other_berg_ine, &
190- broken
190+ broken, &
191+ basin
191192
192193
193194integer :: grdi, grdj
@@ -258,6 +259,7 @@ subroutine write_restart_bergs(bergs, time_stamp)
258259 allocate (ang_accel(nbergs))
259260 allocate (rot(nbergs))
260261 endif
262+ if (use_berg_origin_basins) allocate (basin(nbergs))
261263
262264 i = 0
263265 do grdj = bergs% grd% jsc,bergs% grd% jec ; do grdi = bergs% grd% isc,bergs% grd% iec
@@ -296,6 +298,7 @@ subroutine write_restart_bergs(bergs, time_stamp)
296298 ang_accel(i) = this% ang_accel
297299 rot(i) = this% rot
298300 endif
301+ if (use_berg_origin_basins) basin(i) = this% basin
299302 this= >this% next
300303 enddo
301304 enddo ; enddo
@@ -393,6 +396,10 @@ subroutine write_restart_bergs(bergs, time_stamp)
393396 dim_names_1d,longname= ' dem accumulated rotation' ,units= ' rad' )
394397 endif
395398
399+ if (use_berg_origin_basins) then
400+ call register_restart_field_wrap(fileobj,' basin' ,basin,&
401+ dim_names_1d,longname= ' ice-sheet basin of origin' ,units= ' none' )
402+ endif
396403 ! Checking if any icebergs are static in order to decide whether to save static_berg
397404 n_static_bergs = 0
398405 do grdj = bergs% grd% jsc,bergs% grd% jec ; do grdi = bergs% grd% isc,bergs% grd% iec
@@ -457,6 +464,8 @@ subroutine write_restart_bergs(bergs, time_stamp)
457464 rot)
458465 endif
459466
467+ if (use_berg_origin_basins) deallocate (basin)
468+
460469 deallocate ( &
461470 ine, &
462471 jne, &
@@ -711,7 +720,8 @@ subroutine read_restart_bergs(bergs,Time)
711720 iceberg_num,&
712721 id_cnt, &
713722 id_ij, &
714- start_year
723+ start_year, &
724+ basin
715725
716726type (FmsNetcdfDomainFile_t) :: fileobj ! < Fms2_io fileobj
717727character (len= 1 ), dimension (1 ) :: dim_names_1d
@@ -809,6 +819,10 @@ subroutine read_restart_bergs(bergs,Time)
809819 allocate (ang_accel(nbergs_in_file))
810820 allocate (rot(nbergs_in_file))
811821 endif
822+ if (use_berg_origin_basins) then
823+ allocate (localberg% basin)
824+ allocate (basin(nbergs_in_file))
825+ endif
812826
813827 call register_restart_field(fileobj,' lon' ,lon,dim_names_1d)
814828 call register_restart_field(fileobj,' lat' ,lat,dim_names_1d)
@@ -858,6 +872,11 @@ subroutine read_restart_bergs(bergs,Time)
858872 call register_restart_field(fileobj,' ang_accel' ,ang_accel,dim_names_1d,is_optional= .true. )
859873 call register_restart_field(fileobj,' rot' ,rot ,dim_names_1d,is_optional= .true. )
860874 endif
875+
876+ if (use_berg_origin_basins) then
877+ basin = 0
878+ call register_restart_field(fileobj,' basin' ,basin ,dim_names_1d,is_optional= .true. )
879+ endif
861880 call read_restart(fileobj)
862881 call close_file(fileobj)
863882 elseif (bergs% require_restart) then
@@ -943,6 +962,10 @@ subroutine read_restart_bergs(bergs,Time)
943962 localberg% rot = rot(k)
944963 endif
945964
965+ if (use_berg_origin_basins) then
966+ localberg% basin = basin(k)
967+ endif
968+
946969 if (really_debug) lres= is_point_in_cell(grd, localberg% lon, localberg% lat, localberg% ine, localberg% jne, explain= .true. )
947970 lres= pos_within_cell(grd, localberg% lon, localberg% lat, localberg% ine, localberg% jne, localberg% xi, localberg% yj)
948971 ! call add_new_berg_to_list(bergs%first, localberg)
@@ -1001,6 +1024,7 @@ subroutine read_restart_bergs(bergs,Time)
10011024 ang_accel, &
10021025 rot)
10031026 endif
1027+ if (use_berg_origin_basins) deallocate (basin)
10041028
10051029 if (replace_iceberg_num) then
10061030 deallocate (iceberg_num)
@@ -1076,6 +1100,7 @@ subroutine generate_bergs(bergs,Time)
10761100 allocate (localberg% ang_accel)
10771101 allocate (localberg% rot)
10781102 endif
1103+ if (use_berg_origin_basins) allocate (localberg% basin)
10791104
10801105 do j= grd% jsc,grd% jec; do i= grd% isc,grd% iec
10811106 if (grd% msk(i,j)>0 . .and. abs (grd% latc(i,j))>80.0 ) then
@@ -1125,6 +1150,9 @@ subroutine generate_bergs(bergs,Time)
11251150 localberg% ang_accel= 0 .
11261151 localberg% rot= 0 .
11271152 endif
1153+ if (use_berg_origin_basins) then
1154+ localberg% basin= 0
1155+ endif
11281156
11291157 ! Berg A
11301158 call loc_set_berg_pos(grd, 0.9 , 0.5 , 1 ., 0 ., localberg)
@@ -1603,7 +1631,7 @@ subroutine read_ocean_depth(grd)
16031631! Local variables
16041632character (len= 37 ) :: filename
16051633type (FmsNetcdfDomainFile_t) :: fileobj ! < Fms2_io fileobj
1606- ! Read stored ice
1634+ ! Read depth
16071635 filename= trim (restart_input_dir)// ' topog.nc'
16081636 if (open_file(fileobj, filename, " read" , grd% domain)) then
16091637 if (mpp_pe().eq. mpp_root_pe()) write (* ,' (2a)' ) &
@@ -1627,6 +1655,34 @@ subroutine read_ocean_depth(grd)
16271655 ! call grd_chksum2(bergs%grd, bergs%grd%ocean_depth, 'read_ocean_depth, ocean_depth')
16281656end subroutine read_ocean_depth
16291657
1658+ ! > Read ice-sheet basins from file
1659+ subroutine read_ice_sheet_basins (grd )
1660+ ! Arguments
1661+ type (icebergs_gridded), pointer :: grd ! < Container for gridded fields
1662+ ! Local variables
1663+ character (len= 37 ) :: filename, actual_filename
1664+ type (FmsNetcdfDomainFile_t) :: fileobj ! < Fms2_io fileobj
1665+ ! Read sub_basin
1666+ filename= trim (restart_input_dir)// ' ice_sheet_basins.nc'
1667+ if (open_file(fileobj, filename, " read" , grd% domain)) then
1668+ if (mpp_pe().eq. mpp_root_pe()) write (* ,' (3a)' ) &
1669+ ' KID, read_ice_sheet_basins: reading ' ,actual_filename, filename
1670+ call register_axis_wrapper(fileobj)
1671+ if (variable_exists(fileobj, " sub_basin" )) then
1672+ if (verbose.and. mpp_pe().eq. mpp_root_pe()) write (* ,' (a)' ) &
1673+ ' KID, read_ice_sheet_basins: reading sub_basins from ice-shelf basins file.'
1674+ call read_data(fileobj, ' sub_basin' , grd% ice_sheet_basins)
1675+ else
1676+ call error_mesg(' KID, read_ice_sheet_basins' , &
1677+ ' variable sub_basin ice_sheet_basins.nc not found in ice_sheet_basins.nc!' , FATAL)
1678+ endif
1679+ call close_file(fileobj)
1680+ else
1681+ call error_mesg(' KID, read_ice_sheet_basins' , ' ice_sheet_basins.nc not found!' , FATAL)
1682+ endif
1683+
1684+ end subroutine read_ice_sheet_basins
1685+
16301686! > Write a trajectory-based diagnostics file
16311687subroutine write_trajectory (trajectory , save_short_traj , save_fl_traj , traj_name )
16321688! Arguments
@@ -1642,7 +1698,7 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
16421698integer :: cnid, hiid, hsid
16431699integer :: mid, smid, did, wid, lid, mbid, mflbid, mflbbid, hdid, nbid, odid, flkid
16441700integer :: axnid,aynid,bxnid,bynid,axnfid,aynfid,bxnfid,bynfid, msid
1645- integer :: avid, aaid, rid
1701+ integer :: avid, aaid, rid, baid
16461702character (len= 70 ) :: filename
16471703character (len= 7 ) :: pe_name
16481704type (xyt), pointer :: this, next
@@ -1819,6 +1875,9 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
18191875 rid = inq_varid(ncid, ' rot' )
18201876 endif
18211877
1878+ if (use_berg_origin_basins) then
1879+ baid = inq_varid(ncid, ' basin' )
1880+ endif
18221881 endif
18231882 else
18241883 ! Dimensions
@@ -1889,6 +1948,10 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
18891948 aaid = def_var(ncid, ' ang_accel' , NF_DOUBLE, i_dim)
18901949 rid = def_var(ncid, ' rot' , NF_DOUBLE, i_dim)
18911950 endif
1951+
1952+ if (use_berg_origin_basins) then
1953+ baid = def_var(ncid, ' basin' , NF_INT, i_dim)
1954+ endif
18921955 endif
18931956
18941957 ! Attributes
@@ -2006,6 +2069,10 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
20062069 call put_att(ncid, rid, ' long_name' , ' accumulated rotation' )
20072070 call put_att(ncid, rid, ' units' , ' rad' )
20082071 endif
2072+ if (use_berg_origin_basins) then
2073+ call put_att(ncid, baid, ' long_name' , ' ice-sheet basin of origin' )
2074+ call put_att(ncid, baid, ' units' , ' none' )
2075+ endif
20092076 endif
20102077 endif
20112078
@@ -2087,6 +2154,9 @@ subroutine write_trajectory(trajectory, save_short_traj, save_fl_traj, traj_name
20872154 call put_double(ncid, rid, i, this% rot)
20882155 endif
20892156
2157+ if (use_berg_origin_basins) then
2158+ call put_int(ncid, baid, i, this% basin)
2159+ endif
20902160 endif
20912161 next= >this% next
20922162 deallocate (this)
0 commit comments