Skip to content

Commit

Permalink
Split convert_old_id() in cij_from_old_id()
Browse files Browse the repository at this point in the history
- When reading the 32-bit iceberg_num from restarts we will need to
  recover the starting i,j for the berg.
- Also removed comments abotu moving read_restart_calving().
  • Loading branch information
adcroft committed Jun 18, 2017
1 parent 3038a47 commit 08ea446
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 1 addition & 2 deletions icebergs.F90
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,14 @@ subroutine icebergs_init(bergs, &

call mpp_clock_begin(bergs%clock_ior)
call ice_bergs_io_init(bergs,io_layout)
call read_restart_calving(bergs) !This is moved to before restart_bergs (by Alon) so that generate icebergs can have the correct counter
call read_restart_calving(bergs)
if (orig_read) then
call error_mesg('diamonds, icebergs_init: ', 'Parameter "orig_read" is no longer supported!', FATAL)
else
call read_restart_bergs(bergs,Time)
endif
call bergs_chksum(bergs, 'read_restart bergs')
if (fix_restart_dates) call offset_berg_dates(bergs,Time)
!call read_restart_calving(bergs)
call mpp_clock_end(bergs%clock_ior)

if (really_debug) call print_bergs(stderrunit,bergs,'icebergs_init, initial status')
Expand Down
23 changes: 18 additions & 5 deletions icebergs_framework.F90
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module ice_bergs_framework
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, convert_old_id
public split_id, id_from_2_ints, generate_id, cij_from_old_id, convert_old_id

!> Container for gridded fields
type :: icebergs_gridded
Expand Down Expand Up @@ -2394,6 +2394,22 @@ integer(kind=8) function convert_old_id(grd, old_id)
integer :: cnt ! Counter component
integer :: ij ! Hash of i,j
integer :: i,j ! Cell indexes

call cij_from_old_id(grd, old_id, cnt, i, j)
ij = ij_component_of_id(grd, i, j)
convert_old_id = id_from_2_ints( cnt, ij )

end function convert_old_id

!> Recover i,j an old 32-bit id
subroutine cij_from_old_id(grd, old_id, cnt, i, j)
type(icebergs_gridded), pointer :: grd !< Container for gridded fields
integer, intent(in) :: old_id !< 32-bit iceberg id
integer, intent(out) :: cnt !< Counter component of old id
integer, intent(out) :: i !< i-index of calving cell
integer, intent(out) :: j !< j-index of calving cell
! Local variables
integer :: ij ! Hash of i,j
integer :: iNg, jNg, ncells ! Shape and size of the global grid

! Number cells in the grid
Expand All @@ -2410,10 +2426,7 @@ integer(kind=8) function convert_old_id(grd, old_id)
j = ij / iNg
i = mod( ij, iNg )

ij = ij_component_of_id(grd, i, j)
convert_old_id = id_from_2_ints( cnt, ij )

end function convert_old_id
end subroutine cij_from_old_id

!> Calculate the location-derived component of an iceberg id which is a hash of the i,j-indexes for the cell
integer function ij_component_of_id(grd, i, j)
Expand Down

0 comments on commit 08ea446

Please sign in to comment.