Skip to content

Commit

Permalink
read and write when iceumask, icenmask and iceemask are not allocated
Browse files Browse the repository at this point in the history
  • Loading branch information
TillRasmussen authored and Till Rasmussen committed Nov 16, 2022
1 parent 780fda9 commit fffe822
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 70 deletions.
156 changes: 91 additions & 65 deletions cicecore/cicedynB/infrastructure/ice_restart_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ subroutine dumpfile(filename_spec)
use ice_blocks, only: nx_block, ny_block
use ice_domain, only: nblocks
use ice_domain_size, only: nilyr, nslyr, ncat, max_blocks
use ice_dyn_shared, only: iceUmask, iceEmask, iceNmask
use ice_dyn_shared, only: iceUmask, iceEmask, iceNmask, kdyn
use ice_flux, only: scale_factor, swvdr, swvdf, swidr, swidf, &
strocnxT_iavg, strocnyT_iavg, sst, frzmlt, &
stressp_1, stressp_2, stressp_3, stressp_4, &
Expand Down Expand Up @@ -215,45 +215,52 @@ subroutine dumpfile(filename_spec)
!-----------------------------------------------------------------
! ice mask for dynamics
!-----------------------------------------------------------------

!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
work1(i,j,iblk) = c0
if (iceUmask(i,j,iblk)) work1(i,j,iblk) = c1
enddo
enddo
enddo
!$OMP END PARALLEL DO
call write_restart_field(nu_dump,0,work1,'ruf8','iceumask',1,diag)

if (grid_ice == 'CD' .or. grid_ice == 'C') then

if (kdyn > 0) then
!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
work1(i,j,iblk) = c0
if (iceNmask(i,j,iblk)) work1(i,j,iblk) = c1
if (iceUmask(i,j,iblk)) work1(i,j,iblk) = c1
enddo
enddo
enddo
!$OMP END PARALLEL DO
call write_restart_field(nu_dump,0,work1,'ruf8','icenmask',1,diag)
call write_restart_field(nu_dump,0,work1,'ruf8','iceumask',1,diag)

!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
work1(i,j,iblk) = c0
if (iceEmask(i,j,iblk)) work1(i,j,iblk) = c1
enddo
if (grid_ice == 'CD' .or. grid_ice == 'C') then

!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
work1(i,j,iblk) = c0
if (iceNmask(i,j,iblk)) work1(i,j,iblk) = c1
enddo
enddo
enddo
enddo
!$OMP END PARALLEL DO
call write_restart_field(nu_dump,0,work1,'ruf8','iceemask',1,diag)
!$OMP END PARALLEL DO
call write_restart_field(nu_dump,0,work1,'ruf8','icenmask',1,diag)

!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
work1(i,j,iblk) = c0
if (iceEmask(i,j,iblk)) work1(i,j,iblk) = c1
enddo
enddo
enddo
!$OMP END PARALLEL DO
call write_restart_field(nu_dump,0,work1,'ruf8','iceemask',1,diag)
endif
else
work1(:,:,:) = c0
call write_restart_field(nu_dump,0,work1,'ruf8','iceumask',1,diag)
if (grid_ice == 'CD' .or. grid_ice == 'C') then
call write_restart_field(nu_dump,0,work1,'ruf8','icenmask',1,diag)
call write_restart_field(nu_dump,0,work1,'ruf8','iceemask',1,diag)
endif
endif

! for mixed layer model
Expand All @@ -277,7 +284,7 @@ subroutine restartfile (ice_ic)
use ice_domain, only: nblocks, halo_info
use ice_domain_size, only: nilyr, nslyr, ncat, &
max_blocks
use ice_dyn_shared, only: iceUmask, iceEmask, iceNmask
use ice_dyn_shared, only: iceUmask, iceEmask, iceNmask,kdyn
use ice_flux, only: scale_factor, swvdr, swvdf, swidr, swidf, &
strocnxT_iavg, strocnyT_iavg, sst, frzmlt, &
stressp_1, stressp_2, stressp_3, stressp_4, &
Expand Down Expand Up @@ -524,57 +531,76 @@ subroutine restartfile (ice_ic)
!-----------------------------------------------------------------
! ice mask for dynamics
!-----------------------------------------------------------------
if (my_task == master_task) &
write(nu_diag,*) 'ice mask for dynamics'

call read_restart_field(nu_restart,0,work1,'ruf8', &
'iceumask',1,diag,field_loc_center, field_type_scalar)

iceUmask(:,:,:) = .false.
!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
if (work1(i,j,iblk) > p5) iceUmask(i,j,iblk) = .true.
enddo
enddo
enddo
!$OMP END PARALLEL DO
if (kdyn > 0) then

if (grid_ice == 'CD' .or. grid_ice == 'C') then

if (query_field(nu_restart,'icenmask')) then
if (my_task == master_task) &
write(nu_diag,*) 'ice mask for dynamics'
if (query_field(nu_restart,'iceumask')) then
call read_restart_field(nu_restart,0,work1,'ruf8', &
'icenmask',1,diag,field_loc_center, field_type_scalar)
'iceumask',1,diag,field_loc_center, field_type_scalar)

iceNmask(:,:,:) = .false.
iceUmask(:,:,:) = .false.
!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
if (work1(i,j,iblk) > p5) iceNmask(i,j,iblk) = .true.
if (work1(i,j,iblk) > p5) iceUmask(i,j,iblk) = .true.
enddo
enddo
enddo
!$OMP END PARALLEL DO
endif

if (query_field(nu_restart,'iceemask')) then
call read_restart_field(nu_restart,0,work1,'ruf8', &
'iceemask',1,diag,field_loc_center, field_type_scalar)

iceEmask(:,:,:) = .false.
!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
if (work1(i,j,iblk) > p5) iceEmask(i,j,iblk) = .true.
if (grid_ice == 'CD' .or. grid_ice == 'C') then

if (query_field(nu_restart,'icenmask')) then
call read_restart_field(nu_restart,0,work1,'ruf8', &
'icenmask',1,diag,field_loc_center, field_type_scalar)

iceNmask(:,:,:) = .false.
!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
if (work1(i,j,iblk) > p5) iceNmask(i,j,iblk) = .true.
enddo
enddo
enddo
!$OMP END PARALLEL DO
endif

if (query_field(nu_restart,'iceemask')) then
call read_restart_field(nu_restart,0,work1,'ruf8', &
'iceemask',1,diag,field_loc_center, field_type_scalar)

iceEmask(:,:,:) = .false.
!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
do j = 1, ny_block
do i = 1, nx_block
if (work1(i,j,iblk) > p5) iceEmask(i,j,iblk) = .true.
enddo
enddo
enddo
enddo
!$OMP END PARALLEL DO
!$OMP END PARALLEL DO
endif
endif
else
if (my_task == master_task) &
write(nu_diag,*) 'ice mask for dynamics - not used, however mandatory to read in binary files'
if (query_field(nu_restart,'iceumask')) then
call read_restart_field(nu_restart,0,work1,'ruf8', &
'iceumask',1,diag,field_loc_center, field_type_scalar)
endif
if (grid_ice == 'CD' .or. grid_ice == 'C') then
if (query_field(nu_restart,'icenmask')) then
call read_restart_field(nu_restart,0,work1,'ruf8', &
'icenmask',1,diag,field_loc_center, field_type_scalar)
endif
if (query_field(nu_restart,'iceemask')) then
call read_restart_field(nu_restart,0,work1,'ruf8', &
'iceemask',1,diag,field_loc_center, field_type_scalar)
endif
endif

endif

! set Tsfcn to c0 on land
Expand Down
7 changes: 2 additions & 5 deletions cicecore/cicedynB/infrastructure/io/io_pio2/ice_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,8 @@ logical function query_field(nu,vname)

query_field = .false.

if (my_task == master_task) then
status = pio_inq_varid(File,trim(vname),vardesc)
if (status == PIO_noerr) query_field = .true.
endif
call broadcast_scalar(query_field,master_task)
status = pio_inq_varid(File,trim(vname),vardesc)
if (status == PIO_noerr) query_field = .true.

end function query_field

Expand Down

0 comments on commit fffe822

Please sign in to comment.