LCOV - code coverage report
Current view: top level - cicecore/cicedyn/infrastructure - ice_restart_driver.F90 (source / functions) Hit Total Coverage
Test: 231018-211459:8916b9ff2c:1:quick Lines: 195 471 41.40 %
Date: 2023-10-18 15:30:36 Functions: 2 3 66.67 %

          Line data    Source code
       1             : !=======================================================================
       2             : 
       3             : ! Read and write ice model restart files
       4             : !
       5             : ! authors Elizabeth C. Hunke, LANL
       6             : !         William H. Lipscomb LANL
       7             : !         David Bailey, NCAR
       8             : !
       9             : ! 2004-05: Block structure added by William Lipscomb
      10             : !          Restart module separated from history module
      11             : ! 2006 ECH: Accepted some CESM code into mainstream CICE
      12             : !           Converted to free source form (F90)
      13             : ! 2008 ECH: Rearranged order in which internal stresses are written and read
      14             : ! 2010 ECH: Changed eice, esno to qice, qsno
      15             : ! 2012 ECH: Added routines for reading/writing extended grid
      16             : ! 2013 DAB: Added generic interfaces for writing restart fields.
      17             : 
      18             :       module ice_restart_driver
      19             : 
      20             :       use ice_kinds_mod
      21             :       use ice_arrays_column, only: oceanmixed_ice
      22             :       use ice_communicate, only: my_task, master_task
      23             :       use ice_constants, only: c0, c1, p5, &
      24             :           field_loc_center, field_loc_NEcorner, &   ! LCOV_EXCL_LINE
      25             :           field_loc_Eface, field_loc_Nface, &   ! LCOV_EXCL_LINE
      26             :           field_type_scalar, field_type_vector
      27             :       use ice_restart_shared, only: restart_dir, pointer_file, &
      28             :           runid, use_restart_time, lenstr, restart_coszen
      29             :       use ice_restart
      30             :       use ice_exit, only: abort_ice
      31             :       use ice_fileunits, only: nu_diag, nu_rst_pointer, nu_restart, nu_dump
      32             :       use icepack_intfc, only: icepack_warnings_flush, icepack_warnings_aborted
      33             :       use icepack_intfc, only: icepack_aggregate
      34             :       use icepack_intfc, only: icepack_query_tracer_indices, icepack_query_tracer_sizes
      35             : 
      36             :       implicit none
      37             :       private
      38             :       public :: dumpfile, restartfile, restartfile_v4
      39             : 
      40             : !=======================================================================
      41             : 
      42             :       contains
      43             : 
      44             : !=======================================================================
      45             : 
      46             : !=======================================================================
      47             : !---! these subroutines write/read Fortran unformatted data files ..
      48             : !=======================================================================
      49             : 
      50             : ! Dumps all values needed for a restart
      51             : ! author Elizabeth C. Hunke, LANL
      52             : 
      53          37 :       subroutine dumpfile(filename_spec)
      54             : 
      55             :       use ice_blocks, only: nx_block, ny_block
      56             :       use ice_domain, only: nblocks
      57             :       use ice_domain_size, only: nilyr, nslyr, ncat, max_blocks
      58             :       use ice_dyn_shared, only: iceUmask, iceEmask, iceNmask, kdyn
      59             :       use ice_flux, only: scale_factor, swvdr, swvdf, swidr, swidf, &
      60             :           strocnxT_iavg, strocnyT_iavg, sst, frzmlt, &   ! LCOV_EXCL_LINE
      61             :           stressp_1, stressp_2, stressp_3, stressp_4, &   ! LCOV_EXCL_LINE
      62             :           stressm_1, stressm_2, stressm_3, stressm_4, &   ! LCOV_EXCL_LINE
      63             :           stress12_1, stress12_2, stress12_3, stress12_4, &   ! LCOV_EXCL_LINE
      64             :           stresspT, stressmT, stress12T, &   ! LCOV_EXCL_LINE
      65             :           stresspU, stressmU, stress12U
      66             :       use ice_flux, only: coszen
      67             :       use ice_grid, only: grid_ice, tmask
      68             :       use ice_state, only: aicen, vicen, vsnon, trcrn, uvel, vvel, &
      69             :                            uvelE, vvelE, uvelN, vvelN
      70             : 
      71             :       character(len=char_len_long), intent(in), optional :: filename_spec
      72             : 
      73             :       ! local variables
      74             : 
      75             :       integer (kind=int_kind) :: &
      76             :           i, j, k, iblk, &     ! counting indices   ! LCOV_EXCL_LINE
      77             :           nt_Tsfc, nt_sice, nt_qice, nt_qsno
      78             : 
      79             :       logical (kind=log_kind) :: diag
      80             : 
      81             :       real (kind=dbl_kind), dimension (nx_block,ny_block,max_blocks) :: &
      82       41798 :          work1
      83             : 
      84             :       character (len=3) :: nchar
      85             : 
      86             :       character(len=*), parameter :: subname = '(dumpfile)'
      87             : 
      88             :       call icepack_query_tracer_indices(nt_Tsfc_out=nt_Tsfc, nt_sice_out=nt_sice, &
      89          49 :            nt_qice_out=nt_qice, nt_qsno_out=nt_qsno)
      90          49 :       call icepack_warnings_flush(nu_diag)
      91          49 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
      92           0 :          file=__FILE__, line=__LINE__)
      93             : 
      94          49 :       if (present(filename_spec)) then
      95           0 :          call init_restart_write(filename_spec)
      96             :       else
      97          49 :          call init_restart_write
      98             :       endif
      99             : 
     100          49 :       diag = .true.
     101             : 
     102             :       !-----------------------------------------------------------------
     103             :       ! Zero out tracers over land
     104             :       !-----------------------------------------------------------------
     105             : 
     106          24 :       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     107          74 :       do iblk = 1, nblocks
     108        1848 :          do j = 1, ny_block
     109       69323 :          do i = 1, nx_block
     110      886524 :             if (.not. tmask(i,j,iblk)) trcrn(i,j,:,:,iblk) = c0
     111             :          enddo
     112             :          enddo
     113             :       enddo
     114             :       !$OMP END PARALLEL DO
     115             : 
     116             :       !-----------------------------------------------------------------
     117             :       ! state variables
     118             :       ! Tsfc is the only tracer written to binary files.  All other
     119             :       ! tracers are written to their own dump/restart binary files.
     120             :       !-----------------------------------------------------------------
     121             : 
     122          49 :       call write_restart_field(nu_dump,0,aicen(:,:,:,:),'ruf8','aicen',ncat,diag)
     123          49 :       call write_restart_field(nu_dump,0,vicen(:,:,:,:),'ruf8','vicen',ncat,diag)
     124          49 :       call write_restart_field(nu_dump,0,vsnon(:,:,:,:),'ruf8','vsnon',ncat,diag)
     125          49 :       call write_restart_field(nu_dump,0,trcrn(:,:,nt_Tsfc,:,:),'ruf8','Tsfcn',ncat,diag)
     126             : 
     127         392 :       do k=1,nilyr
     128         343 :          write(nchar,'(i3.3)') k
     129           0 :          call write_restart_field(nu_dump,0,trcrn(:,:,nt_sice+k-1,:,:),'ruf8', &
     130         392 :                                  'sice'//trim(nchar),ncat,diag)
     131             :       enddo
     132             : 
     133         392 :       do k=1,nilyr
     134         343 :          write(nchar,'(i3.3)') k
     135           0 :          call write_restart_field(nu_dump,0,trcrn(:,:,nt_qice+k-1,:,:),'ruf8', &
     136         392 :                                  'qice'//trim(nchar),ncat,diag)
     137             :       enddo
     138             : 
     139          98 :       do k=1,nslyr
     140          49 :          write(nchar,'(i3.3)') k
     141           0 :          call write_restart_field(nu_dump,0,trcrn(:,:,nt_qsno+k-1,:,:),'ruf8', &
     142          98 :                                  'qsno'//trim(nchar),ncat,diag)
     143             :       enddo
     144             : 
     145             :       !-----------------------------------------------------------------
     146             :       ! velocity
     147             :       !-----------------------------------------------------------------
     148          49 :       call write_restart_field(nu_dump,0,uvel,'ruf8','uvel',1,diag)
     149          49 :       call write_restart_field(nu_dump,0,vvel,'ruf8','vvel',1,diag)
     150             : 
     151          49 :       if (grid_ice == 'CD') then
     152           0 :          call write_restart_field(nu_dump,0,uvelE,'ruf8','uvelE',1,diag)
     153           0 :          call write_restart_field(nu_dump,0,vvelE,'ruf8','vvelE',1,diag)
     154           0 :          call write_restart_field(nu_dump,0,uvelN,'ruf8','uvelN',1,diag)
     155           0 :          call write_restart_field(nu_dump,0,vvelN,'ruf8','vvelN',1,diag)
     156             :       endif
     157             : 
     158          49 :       if (grid_ice == 'C') then
     159           0 :          call write_restart_field(nu_dump,0,uvelE,'ruf8','uvelE',1,diag)
     160           0 :          call write_restart_field(nu_dump,0,vvelN,'ruf8','vvelN',1,diag)
     161             :       endif
     162             : 
     163             :       !-----------------------------------------------------------------
     164             :       ! radiation fields
     165             :       !-----------------------------------------------------------------
     166             : 
     167          49 :       if (restart_coszen) call write_restart_field(nu_dump,0,coszen,'ruf8','coszen',1,diag)
     168             : 
     169          49 :       call write_restart_field(nu_dump,0,scale_factor,'ruf8','scale_factor',1,diag)
     170             : 
     171          49 :       call write_restart_field(nu_dump,0,swvdr,'ruf8','swvdr',1,diag)
     172          49 :       call write_restart_field(nu_dump,0,swvdf,'ruf8','swvdf',1,diag)
     173          49 :       call write_restart_field(nu_dump,0,swidr,'ruf8','swidr',1,diag)
     174          49 :       call write_restart_field(nu_dump,0,swidf,'ruf8','swidf',1,diag)
     175             : 
     176             :       !-----------------------------------------------------------------
     177             :       ! ocean stress (for bottom heat flux in thermo)
     178             :       !-----------------------------------------------------------------
     179          49 :       call write_restart_field(nu_dump,0,strocnxT_iavg,'ruf8','strocnxT',1,diag)
     180          49 :       call write_restart_field(nu_dump,0,strocnyT_iavg,'ruf8','strocnyT',1,diag)
     181             : 
     182             :       !-----------------------------------------------------------------
     183             :       ! internal stress
     184             :       !-----------------------------------------------------------------
     185          49 :       call write_restart_field(nu_dump,0,stressp_1,'ruf8','stressp_1',1,diag)
     186          49 :       call write_restart_field(nu_dump,0,stressp_3,'ruf8','stressp_3',1,diag)
     187          49 :       call write_restart_field(nu_dump,0,stressp_2,'ruf8','stressp_2',1,diag)
     188          49 :       call write_restart_field(nu_dump,0,stressp_4,'ruf8','stressp_4',1,diag)
     189             : 
     190          49 :       call write_restart_field(nu_dump,0,stressm_1,'ruf8','stressm_1',1,diag)
     191          49 :       call write_restart_field(nu_dump,0,stressm_3,'ruf8','stressm_3',1,diag)
     192          49 :       call write_restart_field(nu_dump,0,stressm_2,'ruf8','stressm_2',1,diag)
     193          49 :       call write_restart_field(nu_dump,0,stressm_4,'ruf8','stressm_4',1,diag)
     194             : 
     195          49 :       call write_restart_field(nu_dump,0,stress12_1,'ruf8','stress12_1',1,diag)
     196          49 :       call write_restart_field(nu_dump,0,stress12_3,'ruf8','stress12_3',1,diag)
     197          49 :       call write_restart_field(nu_dump,0,stress12_2,'ruf8','stress12_2',1,diag)
     198          49 :       call write_restart_field(nu_dump,0,stress12_4,'ruf8','stress12_4',1,diag)
     199             : 
     200          49 :       if (grid_ice == 'CD') then
     201           0 :          call write_restart_field(nu_dump,0,stresspT ,'ruf8','stresspT' ,1,diag)
     202           0 :          call write_restart_field(nu_dump,0,stressmT ,'ruf8','stressmT' ,1,diag)
     203           0 :          call write_restart_field(nu_dump,0,stress12T,'ruf8','stress12T',1,diag)
     204           0 :          call write_restart_field(nu_dump,0,stresspU ,'ruf8','stresspU' ,1,diag)
     205           0 :          call write_restart_field(nu_dump,0,stressmU ,'ruf8','stressmU' ,1,diag)
     206           0 :          call write_restart_field(nu_dump,0,stress12U,'ruf8','stress12U',1,diag)
     207             :       endif
     208             : 
     209          49 :       if (grid_ice == 'C') then
     210           0 :          call write_restart_field(nu_dump,0,stresspT ,'ruf8','stresspT' ,1,diag)
     211           0 :          call write_restart_field(nu_dump,0,stressmT ,'ruf8','stressmT' ,1,diag)
     212           0 :          call write_restart_field(nu_dump,0,stress12U,'ruf8','stress12U',1,diag)
     213             :       endif
     214             : 
     215             :       !-----------------------------------------------------------------
     216             :       ! ice mask for dynamics
     217             :       !-----------------------------------------------------------------
     218          49 :       if (kdyn > 0) then
     219          24 :          !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     220          74 :          do iblk = 1, nblocks
     221        1848 :             do j = 1, ny_block
     222       69323 :             do i = 1, nx_block
     223       67524 :                work1(i,j,iblk) = c0
     224       69274 :                if (iceUmask(i,j,iblk)) work1(i,j,iblk) = c1
     225             :             enddo
     226             :             enddo
     227             :          enddo
     228             :          !$OMP END PARALLEL DO
     229          49 :          call write_restart_field(nu_dump,0,work1,'ruf8','iceumask',1,diag)
     230             : 
     231          49 :          if (grid_ice == 'CD' .or. grid_ice == 'C') then
     232             : 
     233           0 :             !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     234           0 :             do iblk = 1, nblocks
     235           0 :                do j = 1, ny_block
     236           0 :                do i = 1, nx_block
     237           0 :                   work1(i,j,iblk) = c0
     238           0 :                   if (iceNmask(i,j,iblk)) work1(i,j,iblk) = c1
     239             :                enddo
     240             :                enddo
     241             :             enddo
     242             :             !$OMP END PARALLEL DO
     243           0 :             call write_restart_field(nu_dump,0,work1,'ruf8','icenmask',1,diag)
     244             : 
     245           0 :             !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     246           0 :             do iblk = 1, nblocks
     247           0 :                do j = 1, ny_block
     248           0 :                do i = 1, nx_block
     249           0 :                   work1(i,j,iblk) = c0
     250           0 :                   if (iceEmask(i,j,iblk)) work1(i,j,iblk) = c1
     251             :                enddo
     252             :                enddo
     253             :             enddo
     254             :             !$OMP END PARALLEL DO
     255           0 :             call write_restart_field(nu_dump,0,work1,'ruf8','iceemask',1,diag)
     256             :          endif
     257             :       else
     258           0 :          work1(:,:,:) = c0
     259           0 :          call write_restart_field(nu_dump,0,work1,'ruf8','iceumask',1,diag)
     260           0 :          if (grid_ice == 'CD' .or. grid_ice == 'C') then
     261           0 :             call write_restart_field(nu_dump,0,work1,'ruf8','icenmask',1,diag)
     262           0 :             call write_restart_field(nu_dump,0,work1,'ruf8','iceemask',1,diag)
     263             :          endif
     264             :       endif
     265             : 
     266             :       ! for mixed layer model
     267          49 :       if (oceanmixed_ice) then
     268          49 :          call write_restart_field(nu_dump,0,sst,'ruf8','sst',1,diag)
     269          49 :          call write_restart_field(nu_dump,0,frzmlt,'ruf8','frzmlt',1,diag)
     270             :       endif
     271             : 
     272          49 :       end subroutine dumpfile
     273             : 
     274             : !=======================================================================
     275             : 
     276             : ! Restarts from a dump
     277             : ! author Elizabeth C. Hunke, LANL
     278             : 
     279          29 :       subroutine restartfile (ice_ic)
     280             : 
     281          12 :       use ice_boundary, only: ice_HaloUpdate_stress
     282             :       use ice_blocks, only: nghost, nx_block, ny_block
     283             :       use ice_calendar, only: istep0, npt, calendar
     284             :       use ice_domain, only: nblocks, halo_info
     285             :       use ice_domain_size, only: nilyr, nslyr, ncat, &
     286             :           max_blocks
     287             :       use ice_dyn_shared, only: iceUmask, iceEmask, iceNmask,kdyn
     288             :       use ice_flux, only: scale_factor, swvdr, swvdf, swidr, swidf, &
     289             :           strocnxT_iavg, strocnyT_iavg, sst, frzmlt, &   ! LCOV_EXCL_LINE
     290             :           stressp_1, stressp_2, stressp_3, stressp_4, &   ! LCOV_EXCL_LINE
     291             :           stressm_1, stressm_2, stressm_3, stressm_4, &   ! LCOV_EXCL_LINE
     292             :           stress12_1, stress12_2, stress12_3, stress12_4, &   ! LCOV_EXCL_LINE
     293             :           stresspT, stressmT, stress12T, &   ! LCOV_EXCL_LINE
     294             :           stresspU, stressmU, stress12U
     295             :       use ice_flux, only: coszen, Tf
     296             :       use ice_grid, only: tmask, grid_type, grid_ice, grid_average_X2Y
     297             :       use ice_state, only: trcr_depend, aice, vice, vsno, trcr, &
     298             :           aice0, aicen, vicen, vsnon, trcrn, aice_init, uvel, vvel, &   ! LCOV_EXCL_LINE
     299             :           uvelE, vvelE, uvelN, vvelN, &   ! LCOV_EXCL_LINE
     300             :           trcr_base, nt_strata, n_trcr_strata
     301             : 
     302             :       character (*), optional :: ice_ic
     303             : 
     304             :       ! local variables
     305             : 
     306             :       integer (kind=int_kind) :: &
     307             :          i, j, k, iblk, &     ! counting indices   ! LCOV_EXCL_LINE
     308             :          ntrcr, &             ! number of tracers   ! LCOV_EXCL_LINE
     309             :          nt_Tsfc, nt_sice, nt_qice, nt_qsno
     310             : 
     311             :       logical (kind=log_kind) :: &
     312             :          diag
     313             : 
     314             :       real (kind=dbl_kind), dimension (nx_block,ny_block,max_blocks) :: &
     315       27858 :          work1
     316             : 
     317             :       character (len=3) :: nchar
     318             : 
     319             :       character(len=*), parameter :: subname = '(restartfile)'
     320             : 
     321          29 :       call icepack_query_tracer_sizes(ntrcr_out=ntrcr)
     322          29 :       call icepack_warnings_flush(nu_diag)
     323          29 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
     324           0 :           file=__FILE__, line=__LINE__)
     325             : 
     326             :       call icepack_query_tracer_indices(nt_Tsfc_out=nt_Tsfc, nt_sice_out=nt_sice, &
     327          29 :            nt_qice_out=nt_qice, nt_qsno_out=nt_qsno)
     328          29 :       call icepack_warnings_flush(nu_diag)
     329          29 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
     330           0 :          file=__FILE__, line=__LINE__)
     331             : 
     332          29 :       call init_restart_read(ice_ic)
     333          29 :       call calendar()
     334             : 
     335          29 :       diag = .true.
     336             : 
     337             :       !-----------------------------------------------------------------
     338             :       ! state variables
     339             :       ! Tsfc is the only tracer read in this file.  All other
     340             :       ! tracers are in their own dump/restart files.
     341             :       !-----------------------------------------------------------------
     342          29 :       if (my_task == master_task) &
     343           6 :            write(nu_diag,*) ' min/max area, vol ice, vol snow, Tsfc'
     344             : 
     345             :       call read_restart_field(nu_restart,0,aicen,'ruf8', &
     346          29 :               'aicen',ncat,diag,field_loc_center, field_type_scalar)
     347             :       call read_restart_field(nu_restart,0,vicen,'ruf8', &
     348          29 :               'vicen',ncat,diag,field_loc_center, field_type_scalar)
     349             :       call read_restart_field(nu_restart,0,vsnon,'ruf8', &
     350          29 :               'vsnon',ncat,diag,field_loc_center, field_type_scalar)
     351           0 :       call read_restart_field(nu_restart,0,trcrn(:,:,nt_Tsfc,:,:),'ruf8', &
     352          29 :               'Tsfcn',ncat,diag,field_loc_center, field_type_scalar)
     353             : 
     354          29 :       if (my_task == master_task) &
     355           6 :          write(nu_diag,*) 'min/max sice for each layer'
     356         232 :       do k=1,nilyr
     357         203 :          write(nchar,'(i3.3)') k
     358           0 :          call read_restart_field(nu_restart,0,trcrn(:,:,nt_sice+k-1,:,:),'ruf8', &
     359         232 :               'sice'//trim(nchar),ncat,diag,field_loc_center,field_type_scalar)
     360             :       enddo
     361             : 
     362          29 :       if (my_task == master_task) &
     363           6 :          write(nu_diag,*) 'min/max qice for each layer'
     364         232 :       do k=1,nilyr
     365         203 :          write(nchar,'(i3.3)') k
     366           0 :          call read_restart_field(nu_restart,0,trcrn(:,:,nt_qice+k-1,:,:),'ruf8', &
     367         232 :               'qice'//trim(nchar),ncat,diag,field_loc_center,field_type_scalar)
     368             :       enddo
     369             : 
     370          29 :       if (my_task == master_task) &
     371           6 :          write(nu_diag,*) 'min/max qsno for each layer'
     372          58 :       do k=1,nslyr
     373          29 :          write(nchar,'(i3.3)') k
     374           0 :          call read_restart_field(nu_restart,0,trcrn(:,:,nt_qsno+k-1,:,:),'ruf8', &
     375          58 :               'qsno'//trim(nchar),ncat,diag,field_loc_center,field_type_scalar)
     376             :       enddo
     377             : 
     378             :       !-----------------------------------------------------------------
     379             :       ! velocity
     380             :       !-----------------------------------------------------------------
     381          29 :       if (my_task == master_task) &
     382           6 :            write(nu_diag,*) 'min/max velocity components'
     383             : 
     384             :       call read_restart_field(nu_restart,0,uvel,'ruf8', &
     385          29 :            'uvel',1,diag,field_loc_NEcorner, field_type_vector)
     386             :       call read_restart_field(nu_restart,0,vvel,'ruf8', &
     387          29 :            'vvel',1,diag,field_loc_NEcorner, field_type_vector)
     388             : 
     389          29 :       if (grid_ice == 'CD') then
     390           0 :          if (query_field(nu_restart,'uvelE')) &
     391             :             call read_restart_field(nu_restart,0,uvelE,'ruf8', &   ! LCOV_EXCL_LINE
     392           0 :                  'uvelE',1,diag,field_loc_Eface, field_type_vector)
     393           0 :          if (query_field(nu_restart,'vvelE')) &
     394             :             call read_restart_field(nu_restart,0,vvelE,'ruf8', &   ! LCOV_EXCL_LINE
     395           0 :                  'vvelE',1,diag,field_loc_Eface, field_type_vector)
     396           0 :          if (query_field(nu_restart,'uvelN')) &
     397             :             call read_restart_field(nu_restart,0,uvelN,'ruf8', &   ! LCOV_EXCL_LINE
     398           0 :                  'uvelN',1,diag,field_loc_Nface, field_type_vector)
     399           0 :          if (query_field(nu_restart,'vvelN')) &
     400             :             call read_restart_field(nu_restart,0,vvelN,'ruf8', &   ! LCOV_EXCL_LINE
     401           0 :                  'vvelN',1,diag,field_loc_Nface, field_type_vector)
     402             :       endif
     403             : 
     404          29 :       if (grid_ice == 'C') then
     405           0 :          if (query_field(nu_restart,'uvelE')) &
     406             :             call read_restart_field(nu_restart,0,uvelE,'ruf8', &   ! LCOV_EXCL_LINE
     407           0 :                  'uvelE',1,diag,field_loc_Eface, field_type_vector)
     408           0 :          if (query_field(nu_restart,'vvelN')) &
     409             :             call read_restart_field(nu_restart,0,vvelN,'ruf8', &   ! LCOV_EXCL_LINE
     410           0 :                  'vvelN',1,diag,field_loc_Nface, field_type_vector)
     411             :       endif
     412             : 
     413             :       !-----------------------------------------------------------------
     414             :       ! radiation fields
     415             :       !-----------------------------------------------------------------
     416             : 
     417          29 :       if (my_task == master_task) &
     418           6 :          write(nu_diag,*) 'radiation fields'
     419             : 
     420          29 :       if (restart_coszen) call read_restart_field(nu_restart,0,coszen,'ruf8', &
     421           0 :            'coszen',1,diag)
     422             :       call read_restart_field(nu_restart,0,scale_factor,'ruf8', &
     423          29 :            'scale_factor',1,diag, field_loc_center, field_type_scalar)
     424             :       call read_restart_field(nu_restart,0,swvdr,'ruf8', &
     425          29 :            'swvdr',1,diag,field_loc_center, field_type_scalar)
     426             :       call read_restart_field(nu_restart,0,swvdf,'ruf8', &
     427          29 :            'swvdf',1,diag,field_loc_center, field_type_scalar)
     428             :       call read_restart_field(nu_restart,0,swidr,'ruf8', &
     429          29 :            'swidr',1,diag,field_loc_center, field_type_scalar)
     430             :       call read_restart_field(nu_restart,0,swidf,'ruf8', &
     431          29 :            'swidf',1,diag,field_loc_center, field_type_scalar)
     432             : 
     433             :       !-----------------------------------------------------------------
     434             :       ! ocean stress
     435             :       !-----------------------------------------------------------------
     436          29 :       if (my_task == master_task) &
     437           6 :            write(nu_diag,*) 'min/max ocean stress components'
     438             : 
     439             :       call read_restart_field(nu_restart,0,strocnxT_iavg,'ruf8', &
     440          29 :            'strocnxT',1,diag,field_loc_center, field_type_vector)
     441             :       call read_restart_field(nu_restart,0,strocnyT_iavg,'ruf8', &
     442          29 :            'strocnyT',1,diag,field_loc_center, field_type_vector)
     443             : 
     444             :       !-----------------------------------------------------------------
     445             :       ! internal stress
     446             :       ! The stress tensor must be read and scattered in pairs in order
     447             :       ! to properly match corner values across a tripole grid cut.
     448             :       !-----------------------------------------------------------------
     449          29 :       if (my_task == master_task) write(nu_diag,*) &
     450           6 :            'internal stress components'
     451             : 
     452             :       call read_restart_field(nu_restart,0,stressp_1,'ruf8', &
     453          29 :            'stressp_1',1,diag,field_loc_center,field_type_scalar) ! stressp_1
     454             :       call read_restart_field(nu_restart,0,stressp_3,'ruf8', &
     455          29 :            'stressp_3',1,diag,field_loc_center,field_type_scalar) ! stressp_3
     456             :       call read_restart_field(nu_restart,0,stressp_2,'ruf8', &
     457          29 :            'stressp_2',1,diag,field_loc_center,field_type_scalar) ! stressp_2
     458             :       call read_restart_field(nu_restart,0,stressp_4,'ruf8', &
     459          29 :            'stressp_4',1,diag,field_loc_center,field_type_scalar) ! stressp_4
     460             : 
     461             :       call read_restart_field(nu_restart,0,stressm_1,'ruf8', &
     462          29 :            'stressm_1',1,diag,field_loc_center,field_type_scalar) ! stressm_1
     463             :       call read_restart_field(nu_restart,0,stressm_3,'ruf8', &
     464          29 :            'stressm_3',1,diag,field_loc_center,field_type_scalar) ! stressm_3
     465             :       call read_restart_field(nu_restart,0,stressm_2,'ruf8', &
     466          29 :            'stressm_2',1,diag,field_loc_center,field_type_scalar) ! stressm_2
     467             :       call read_restart_field(nu_restart,0,stressm_4,'ruf8', &
     468          29 :            'stressm_4',1,diag,field_loc_center,field_type_scalar) ! stressm_4
     469             : 
     470             :       call read_restart_field(nu_restart,0,stress12_1,'ruf8', &
     471          29 :            'stress12_1',1,diag,field_loc_center,field_type_scalar) ! stress12_1
     472             :       call read_restart_field(nu_restart,0,stress12_3,'ruf8', &
     473          29 :            'stress12_3',1,diag,field_loc_center,field_type_scalar) ! stress12_1
     474             : 
     475             :       call read_restart_field(nu_restart,0,stress12_2,'ruf8', &
     476          29 :            'stress12_2',1,diag,field_loc_center,field_type_scalar) ! stress12_2
     477             :       call read_restart_field(nu_restart,0,stress12_4,'ruf8', &
     478          29 :            'stress12_4',1,diag,field_loc_center,field_type_scalar) ! stress12_4
     479             : 
     480          29 :       if (grid_ice == 'CD' .or. grid_ice == 'C') then
     481           0 :          if (query_field(nu_restart,'stresspT')) &
     482             :             call read_restart_field(nu_restart,0,stresspT,'ruf8', &   ! LCOV_EXCL_LINE
     483           0 :                'stresspT' ,1,diag,field_loc_center,field_type_scalar) ! stresspT
     484           0 :          if (query_field(nu_restart,'stressmT')) &
     485             :             call read_restart_field(nu_restart,0,stressmT,'ruf8', &   ! LCOV_EXCL_LINE
     486           0 :                'stressmT' ,1,diag,field_loc_center,field_type_scalar) ! stressmT
     487           0 :          if (query_field(nu_restart,'stress12T')) &
     488             :             call read_restart_field(nu_restart,0,stress12T,'ruf8', &   ! LCOV_EXCL_LINE
     489           0 :                'stress12T',1,diag,field_loc_center,field_type_scalar) ! stress12T
     490           0 :          if (query_field(nu_restart,'stresspU')) &
     491             :             call read_restart_field(nu_restart,0,stresspU,'ruf8', &   ! LCOV_EXCL_LINE
     492           0 :                'stresspU' ,1,diag,field_loc_NEcorner,field_type_scalar) ! stresspU
     493           0 :          if (query_field(nu_restart,'stressmU')) &
     494             :             call read_restart_field(nu_restart,0,stressmU,'ruf8', &   ! LCOV_EXCL_LINE
     495           0 :                'stressmU' ,1,diag,field_loc_NEcorner,field_type_scalar) ! stressmU
     496           0 :          if (query_field(nu_restart,'stress12U')) &
     497             :             call read_restart_field(nu_restart,0,stress12U,'ruf8', &   ! LCOV_EXCL_LINE
     498           0 :                'stress12U',1,diag,field_loc_NEcorner,field_type_scalar) ! stress12U
     499             :       endif
     500             : 
     501          29 :       if (trim(grid_type) == 'tripole') then
     502             :          call ice_HaloUpdate_stress(stressp_1, stressp_3, halo_info, &
     503           0 :                                     field_loc_center,  field_type_scalar)
     504             :          call ice_HaloUpdate_stress(stressp_3, stressp_1, halo_info, &
     505           0 :                                     field_loc_center,  field_type_scalar)
     506             :          call ice_HaloUpdate_stress(stressp_2, stressp_4, halo_info, &
     507           0 :                                     field_loc_center,  field_type_scalar)
     508             :          call ice_HaloUpdate_stress(stressp_4, stressp_2, halo_info, &
     509           0 :                                     field_loc_center,  field_type_scalar)
     510             : 
     511             :          call ice_HaloUpdate_stress(stressm_1, stressm_3, halo_info, &
     512           0 :                                     field_loc_center,  field_type_scalar)
     513             :          call ice_HaloUpdate_stress(stressm_3, stressm_1, halo_info, &
     514           0 :                                     field_loc_center,  field_type_scalar)
     515             :          call ice_HaloUpdate_stress(stressm_2, stressm_4, halo_info, &
     516           0 :                                     field_loc_center,  field_type_scalar)
     517             :          call ice_HaloUpdate_stress(stressm_4, stressm_2, halo_info, &
     518           0 :                                     field_loc_center,  field_type_scalar)
     519             : 
     520             :          call ice_HaloUpdate_stress(stress12_1, stress12_3, halo_info, &
     521           0 :                                     field_loc_center,  field_type_scalar)
     522             :          call ice_HaloUpdate_stress(stress12_3, stress12_1, halo_info, &
     523           0 :                                     field_loc_center,  field_type_scalar)
     524             :          call ice_HaloUpdate_stress(stress12_2, stress12_4, halo_info, &
     525           0 :                                     field_loc_center,  field_type_scalar)
     526             :          call ice_HaloUpdate_stress(stress12_4, stress12_2, halo_info, &
     527           0 :                                     field_loc_center,  field_type_scalar)
     528             :          ! TODO: CD-grid
     529             :       endif
     530             : 
     531             :       !-----------------------------------------------------------------
     532             :       ! ice mask for dynamics
     533             :       !-----------------------------------------------------------------
     534          29 :       if (kdyn > 0) then
     535             : 
     536          29 :          if (my_task == master_task) &
     537           6 :              write(nu_diag,*) 'ice mask for dynamics'
     538          29 :          if (query_field(nu_restart,'iceumask')) then
     539             :             call read_restart_field(nu_restart,0,work1,'ruf8', &
     540          29 :                 'iceumask',1,diag,field_loc_center, field_type_scalar)
     541             : 
     542       92872 :             iceUmask(:,:,:) = .false.
     543          20 :             !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     544          26 :             do iblk = 1, nblocks
     545         708 :                do j = 1, ny_block
     546       31211 :                do i = 1, nx_block
     547       31194 :                   if (work1(i,j,iblk) > p5) iceUmask(i,j,iblk) = .true.
     548             :                enddo
     549             :                enddo
     550             :             enddo
     551             :             !$OMP END PARALLEL DO
     552             :          endif
     553          29 :          if (grid_ice == 'CD' .or. grid_ice == 'C') then
     554             : 
     555           0 :             if (query_field(nu_restart,'icenmask')) then
     556             :                call read_restart_field(nu_restart,0,work1,'ruf8', &
     557           0 :                     'icenmask',1,diag,field_loc_center, field_type_scalar)
     558             : 
     559           0 :                iceNmask(:,:,:) = .false.
     560           0 :                !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     561           0 :                do iblk = 1, nblocks
     562           0 :                   do j = 1, ny_block
     563           0 :                   do i = 1, nx_block
     564           0 :                      if (work1(i,j,iblk) > p5) iceNmask(i,j,iblk) = .true.
     565             :                   enddo
     566             :                   enddo
     567             :                enddo
     568             :                !$OMP END PARALLEL DO
     569             :             endif
     570             : 
     571           0 :             if (query_field(nu_restart,'iceemask')) then
     572             :                call read_restart_field(nu_restart,0,work1,'ruf8', &
     573           0 :                     'iceemask',1,diag,field_loc_center, field_type_scalar)
     574             : 
     575           0 :                iceEmask(:,:,:) = .false.
     576           0 :                !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     577           0 :                do iblk = 1, nblocks
     578           0 :                   do j = 1, ny_block
     579           0 :                   do i = 1, nx_block
     580           0 :                      if (work1(i,j,iblk) > p5) iceEmask(i,j,iblk) = .true.
     581             :                   enddo
     582             :                   enddo
     583             :                enddo
     584             :                !$OMP END PARALLEL DO
     585             :             endif
     586             :          endif
     587             :       else
     588           0 :          if (my_task == master_task) &
     589           0 :             write(nu_diag,*) 'ice mask for dynamics - not used, however mandatory to read in binary files'
     590           0 :          if (query_field(nu_restart,'iceumask')) then
     591             :             call read_restart_field(nu_restart,0,work1,'ruf8', &
     592           0 :                'iceumask',1,diag,field_loc_center, field_type_scalar)
     593             :          endif
     594           0 :          if (grid_ice == 'CD' .or. grid_ice == 'C') then
     595           0 :             if (query_field(nu_restart,'icenmask')) then
     596             :                call read_restart_field(nu_restart,0,work1,'ruf8', &
     597           0 :                     'icenmask',1,diag,field_loc_center, field_type_scalar)
     598             :             endif
     599           0 :             if (query_field(nu_restart,'iceemask')) then
     600             :                call read_restart_field(nu_restart,0,work1,'ruf8', &
     601           0 :                     'iceemask',1,diag,field_loc_center, field_type_scalar)
     602             :             endif
     603             :          endif
     604             :       endif
     605             : 
     606             :       ! set Tsfcn to c0 on land
     607          20 :       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     608          26 :       do iblk = 1, nblocks
     609         708 :          do j = 1, ny_block
     610       31211 :          do i = 1, nx_block
     611       54894 :             if (.not. tmask(i,j,iblk)) trcrn(i,j,nt_Tsfc,:,iblk) = c0
     612             :          enddo
     613             :          enddo
     614             :       enddo
     615             :       !$OMP END PARALLEL DO
     616             : 
     617             :       ! for mixed layer model
     618          29 :       if (oceanmixed_ice) then
     619             : 
     620          29 :          if (my_task == master_task) &
     621           6 :               write(nu_diag,*) 'min/max sst, frzmlt'
     622             : 
     623             :          call read_restart_field(nu_restart,0,sst,'ruf8', &
     624          29 :               'sst',1,diag,field_loc_center, field_type_scalar)
     625             :          call read_restart_field(nu_restart,0,frzmlt,'ruf8', &
     626          29 :               'frzmlt',1,diag,field_loc_center, field_type_scalar)
     627             :       endif
     628             : 
     629             :       !-----------------------------------------------------------------
     630             :       ! Ensure unused stress values in west and south ghost cells are 0
     631             :       !-----------------------------------------------------------------
     632          20 :       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     633          26 :       do iblk = 1, nblocks
     634          34 :          do j = 1, nghost
     635         680 :          do i = 1, nx_block
     636         646 :             stressp_1 (i,j,iblk) = c0
     637         646 :             stressp_2 (i,j,iblk) = c0
     638         646 :             stressp_3 (i,j,iblk) = c0
     639         646 :             stressp_4 (i,j,iblk) = c0
     640         646 :             stressm_1 (i,j,iblk) = c0
     641         646 :             stressm_2 (i,j,iblk) = c0
     642         646 :             stressm_3 (i,j,iblk) = c0
     643         646 :             stressm_4 (i,j,iblk) = c0
     644         646 :             stress12_1(i,j,iblk) = c0
     645         646 :             stress12_2(i,j,iblk) = c0
     646         646 :             stress12_3(i,j,iblk) = c0
     647         663 :             stress12_4(i,j,iblk) = c0
     648             :          enddo
     649             :          enddo
     650         708 :          do j = 1, ny_block
     651        1341 :          do i = 1, nghost
     652         662 :             stressp_1 (i,j,iblk) = c0
     653         662 :             stressp_2 (i,j,iblk) = c0
     654         662 :             stressp_3 (i,j,iblk) = c0
     655         662 :             stressp_4 (i,j,iblk) = c0
     656         662 :             stressm_1 (i,j,iblk) = c0
     657         662 :             stressm_2 (i,j,iblk) = c0
     658         662 :             stressm_3 (i,j,iblk) = c0
     659         662 :             stressm_4 (i,j,iblk) = c0
     660         662 :             stress12_1(i,j,iblk) = c0
     661         662 :             stress12_2(i,j,iblk) = c0
     662         662 :             stress12_3(i,j,iblk) = c0
     663        1324 :             stress12_4(i,j,iblk) = c0
     664             :          enddo
     665             :          enddo
     666             :          ! TODO: CD-grid ?
     667             :       enddo
     668             :       !$OMP END PARALLEL DO
     669             : 
     670             :       !-----------------------------------------------------------------
     671             :       ! Ensure ice is binned in correct categories
     672             :       ! (should not be necessary unless restarting from a run with
     673             :       !  different category boundaries).
     674             :       !
     675             :       ! If called, this subroutine does not give exact restart.
     676             :       !-----------------------------------------------------------------
     677             : !!!      call cleanup_itd
     678             : 
     679             :       !-----------------------------------------------------------------
     680             :       ! compute aggregate ice state and open water area
     681             :       !-----------------------------------------------------------------
     682             : 
     683          20 :       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     684          26 :       do iblk = 1, nblocks
     685             : 
     686         708 :       do j = 1, ny_block
     687       31211 :       do i = 1, nx_block
     688       30532 :          if (tmask(i,j,iblk)) &
     689             :             call icepack_aggregate(ncat  = ncat,                  &   ! LCOV_EXCL_LINE
     690             :                                    aicen = aicen(i,j,:,iblk),     &   ! LCOV_EXCL_LINE
     691             :                                    trcrn = trcrn(i,j,:,:,iblk),   &   ! LCOV_EXCL_LINE
     692             :                                    vicen = vicen(i,j,:,iblk),     &   ! LCOV_EXCL_LINE
     693             :                                    vsnon = vsnon(i,j,:,iblk),     &   ! LCOV_EXCL_LINE
     694             :                                    aice  = aice (i,j,  iblk),     &   ! LCOV_EXCL_LINE
     695             :                                    trcr  = trcr (i,j,:,iblk),     &   ! LCOV_EXCL_LINE
     696             :                                    vice  = vice (i,j,  iblk),     &   ! LCOV_EXCL_LINE
     697             :                                    vsno  = vsno (i,j,  iblk),     &   ! LCOV_EXCL_LINE
     698             :                                    aice0 = aice0(i,j,  iblk),     &   ! LCOV_EXCL_LINE
     699             :                                    ntrcr = ntrcr,                 &   ! LCOV_EXCL_LINE
     700             :                                    trcr_depend   = trcr_depend,   &   ! LCOV_EXCL_LINE
     701             :                                    trcr_base     = trcr_base,     &   ! LCOV_EXCL_LINE
     702             :                                    n_trcr_strata = n_trcr_strata, &   ! LCOV_EXCL_LINE
     703             :                                    nt_strata     = nt_strata,     &   ! LCOV_EXCL_LINE
     704       25792 :                                    Tf            = Tf(i,j,iblk))
     705             : 
     706       31194 :          aice_init(i,j,iblk) = aice(i,j,iblk)
     707             :       enddo
     708             :       enddo
     709             : 
     710             :       enddo
     711             :       !$OMP END PARALLEL DO
     712             : 
     713          29 :       call icepack_warnings_flush(nu_diag)
     714          29 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
     715           0 :          file=__FILE__, line=__LINE__)
     716             : 
     717             :       ! if runid is bering then need to correct npt for istep0
     718          29 :       if (trim(runid) == 'bering') then
     719           0 :          npt = npt - istep0
     720             :       endif
     721             : 
     722          29 :       end subroutine restartfile
     723             : 
     724             : !=======================================================================
     725             : 
     726             : ! Restarts from a CICE v4.1 (binary) dump
     727             : ! author Elizabeth C. Hunke, LANL
     728             : 
     729           0 :       subroutine restartfile_v4 (ice_ic)
     730             : 
     731             :       use ice_broadcast, only: broadcast_scalar
     732             :       use ice_blocks, only: nghost, nx_block, ny_block
     733             :       use ice_calendar, only: istep0, istep1, timesecs, calendar, npt, &
     734             :           set_date_from_timesecs
     735             :       use ice_domain, only: nblocks, distrb_info
     736             :       use ice_domain_size, only: nilyr, nslyr, ncat, nx_global, ny_global, &
     737             :           max_blocks
     738             :       use ice_dyn_shared, only: iceUmask
     739             :       use ice_flux, only: scale_factor, swvdr, swvdf, swidr, swidf, &
     740             :           strocnxT_iavg, strocnyT_iavg, sst, frzmlt, Tf, &   ! LCOV_EXCL_LINE
     741             :           stressp_1, stressp_2, stressp_3, stressp_4, &   ! LCOV_EXCL_LINE
     742             :           stressm_1, stressm_2, stressm_3, stressm_4, &   ! LCOV_EXCL_LINE
     743             :           stress12_1, stress12_2, stress12_3, stress12_4
     744             :       use ice_gather_scatter, only: scatter_global_stress
     745             :       use ice_grid, only: tmask
     746             :       use ice_read_write, only: ice_open, ice_read, ice_read_global
     747             :       use ice_state, only: trcr_depend, aice, vice, vsno, trcr, &
     748             :           aice0, aicen, vicen, vsnon, trcrn, aice_init, uvel, vvel, &   ! LCOV_EXCL_LINE
     749             :           trcr_base, nt_strata, n_trcr_strata
     750             : 
     751             :       character (*), optional :: ice_ic
     752             : 
     753             :       ! local variables
     754             : 
     755             :       integer (kind=int_kind) :: &
     756             :          i, j, k, n, iblk, &     ! counting indices   ! LCOV_EXCL_LINE
     757             :          ntrcr, &                ! number of tracers   ! LCOV_EXCL_LINE
     758             :          nt_Tsfc, nt_sice, nt_qice, nt_qsno, &   ! LCOV_EXCL_LINE
     759             :          iignore                 ! dummy variable
     760             : 
     761             :       real (kind=real_kind) :: &
     762           0 :          rignore                 ! dummy variable
     763             : 
     764             :       character(len=char_len_long) :: &
     765             :          filename, filename0
     766             : 
     767             :       logical (kind=log_kind) :: &
     768             :          diag
     769             : 
     770             :       real (kind=dbl_kind), dimension (nx_block,ny_block,max_blocks) :: &
     771           0 :          work1
     772             : 
     773             :       real (kind=dbl_kind), dimension(:,:), allocatable :: &
     774           0 :          work_g1, work_g2
     775             : 
     776             :       real (kind=dbl_kind) :: &
     777           0 :          time_forc      ! historic, now local
     778             : 
     779             :       character(len=*), parameter :: subname = '(restartfile_v4)'
     780             : 
     781           0 :       call icepack_query_tracer_sizes(ntrcr_out=ntrcr)
     782           0 :       call icepack_warnings_flush(nu_diag)
     783           0 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
     784           0 :           file=__FILE__, line=__LINE__)
     785             : 
     786             :       call icepack_query_tracer_indices(nt_Tsfc_out=nt_Tsfc, nt_sice_out=nt_sice, &
     787           0 :            nt_qice_out=nt_qice, nt_qsno_out=nt_qsno)
     788           0 :       call icepack_warnings_flush(nu_diag)
     789           0 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
     790           0 :          file=__FILE__, line=__LINE__)
     791             : 
     792           0 :       if (present(ice_ic)) then
     793           0 :          filename = ice_ic
     794           0 :       elseif (my_task == master_task) then
     795           0 :          open(nu_rst_pointer,file=pointer_file)
     796           0 :          read(nu_rst_pointer,'(a)') filename0
     797           0 :          filename = trim(filename0)
     798           0 :          close(nu_rst_pointer)
     799           0 :          write(nu_diag,*) 'Read ',pointer_file(1:lenstr(pointer_file))
     800             :       endif
     801             : 
     802           0 :       call ice_open(nu_restart,filename,0)
     803             : 
     804           0 :       if (my_task == master_task) &
     805           0 :          write(nu_diag,*) 'Using restart dump=', trim(filename)
     806             : 
     807           0 :       if (use_restart_time) then
     808             : 
     809           0 :          if (my_task == master_task) then
     810           0 :             read (nu_restart) istep0,timesecs,time_forc
     811           0 :             write(nu_diag,*) 'Restart read at istep=',istep0,timesecs
     812             :          endif
     813           0 :          call broadcast_scalar(istep0,master_task)
     814           0 :          istep1 = istep0
     815           0 :          call broadcast_scalar(timesecs,master_task)
     816             : !         call broadcast_scalar(time_forc,master_task)
     817           0 :          call set_date_from_timesecs(timesecs)
     818           0 :          call calendar()
     819             : 
     820             :       else
     821             : 
     822           0 :          if (my_task == master_task) &
     823           0 :             read (nu_restart) iignore,rignore,rignore
     824             : 
     825             :       endif
     826             : 
     827           0 :       diag = .true.     ! write min/max diagnostics for field
     828             : 
     829             :       !-----------------------------------------------------------------
     830             :       ! state variables
     831             :       ! Tsfc is the only tracer read in this file.  All other
     832             :       ! tracers are in their own dump/restart files.
     833             :       !-----------------------------------------------------------------
     834           0 :       do n=1,ncat
     835           0 :          if (my_task == master_task) &
     836             :               write(nu_diag,*) 'cat ',n, &   ! LCOV_EXCL_LINE
     837           0 :                                ' min/max area, vol ice, vol snow, Tsfc'
     838             : 
     839           0 :          call ice_read(nu_restart,0,aicen(:,:,n,:),'ruf8',diag, &
     840           0 :                        field_loc_center, field_type_scalar)
     841           0 :          call ice_read(nu_restart,0,vicen(:,:,n,:),'ruf8',diag, &
     842           0 :                        field_loc_center, field_type_scalar)
     843           0 :          call ice_read(nu_restart,0,vsnon(:,:,n,:),'ruf8',diag, &
     844           0 :                        field_loc_center, field_type_scalar)
     845           0 :          call ice_read(nu_restart,0,trcrn(:,:,nt_Tsfc,n,:),'ruf8',diag, &
     846           0 :                        field_loc_center, field_type_scalar)
     847             : 
     848           0 :          if (my_task == master_task) &
     849           0 :               write(nu_diag,*) 'cat ',n, 'min/max sice for each layer'
     850           0 :          do k=1,nilyr
     851           0 :             call ice_read(nu_restart,0,trcrn(:,:,nt_sice+k-1,n,:),'ruf8',diag, &
     852           0 :                           field_loc_center, field_type_scalar)
     853             :          enddo
     854             : 
     855           0 :          if (my_task == master_task) &
     856           0 :               write(nu_diag,*) 'cat ',n, 'min/max qice for each layer'
     857           0 :          do k=1,nilyr
     858           0 :             call ice_read(nu_restart,0,trcrn(:,:,nt_qice+k-1,n,:),'ruf8',diag, &
     859           0 :                           field_loc_center, field_type_scalar)
     860             :          enddo
     861             : 
     862           0 :          if (my_task == master_task) &
     863           0 :               write(nu_diag,*) 'cat ',n, 'min/max qsno for each layer'
     864           0 :          do k=1,nslyr
     865           0 :             call ice_read(nu_restart,0,trcrn(:,:,nt_qsno+k-1,n,:),'ruf8',diag, &
     866           0 :                           field_loc_center, field_type_scalar)
     867             :          enddo
     868             :       enddo ! ncat
     869             : 
     870             :       !-----------------------------------------------------------------
     871             :       ! velocity
     872             :       !-----------------------------------------------------------------
     873           0 :       if (my_task == master_task) &
     874           0 :            write(nu_diag,*) 'min/max velocity components'
     875             : 
     876             :       call ice_read(nu_restart,0,uvel,'ruf8',diag, &
     877           0 :                        field_loc_NEcorner, field_type_vector)
     878             :       call ice_read(nu_restart,0,vvel,'ruf8',diag, &
     879           0 :                        field_loc_NEcorner, field_type_vector)
     880             : 
     881             :       !-----------------------------------------------------------------
     882             :       ! radiation fields
     883             :       !-----------------------------------------------------------------
     884             : 
     885           0 :       if (my_task == master_task) &
     886           0 :          write(nu_diag,*) 'radiation fields'
     887             : 
     888             :       call ice_read(nu_restart,0,scale_factor,'ruf8',diag, &
     889           0 :                     field_loc_center, field_type_scalar)
     890             :       call ice_read(nu_restart,0,swvdr,'ruf8',diag, &
     891           0 :                     field_loc_center, field_type_scalar)
     892             :       call ice_read(nu_restart,0,swvdf,'ruf8',diag, &
     893           0 :                     field_loc_center, field_type_scalar)
     894             :       call ice_read(nu_restart,0,swidr,'ruf8',diag, &
     895           0 :                     field_loc_center, field_type_scalar)
     896             :       call ice_read(nu_restart,0,swidf,'ruf8',diag, &
     897           0 :                     field_loc_center, field_type_scalar)
     898             : 
     899             :       !-----------------------------------------------------------------
     900             :       ! ocean stress
     901             :       !-----------------------------------------------------------------
     902           0 :       if (my_task == master_task) &
     903           0 :            write(nu_diag,*) 'min/max ocean stress components'
     904             : 
     905             :       call ice_read(nu_restart,0,strocnxT_iavg,'ruf8',diag, &
     906           0 :                        field_loc_center, field_type_vector)
     907             :       call ice_read(nu_restart,0,strocnyT_iavg,'ruf8',diag, &
     908           0 :                        field_loc_center, field_type_vector)
     909             : 
     910             :       !-----------------------------------------------------------------
     911             :       ! internal stress
     912             :       ! The stress tensor must be read and scattered in pairs in order
     913             :       ! to properly match corner values across a tripole grid cut.
     914             :       !-----------------------------------------------------------------
     915           0 :       if (my_task == master_task) write(nu_diag,*) &
     916           0 :            'internal stress components'
     917             : 
     918           0 :       allocate (work_g1(nx_global,ny_global), &
     919           0 :                 work_g2(nx_global,ny_global))
     920             : 
     921           0 :       call ice_read_global(nu_restart,0,work_g1,'ruf8',diag) ! stressp_1
     922           0 :       call ice_read_global(nu_restart,0,work_g2,'ruf8',diag) ! stressp_3
     923             :       call scatter_global_stress(stressp_1, work_g1, work_g2, &
     924           0 :                                  master_task, distrb_info)
     925             :       call scatter_global_stress(stressp_3, work_g2, work_g1, &
     926           0 :                                  master_task, distrb_info)
     927             : 
     928           0 :       call ice_read_global(nu_restart,0,work_g1,'ruf8',diag) ! stressp_2
     929           0 :       call ice_read_global(nu_restart,0,work_g2,'ruf8',diag) ! stressp_4
     930             :       call scatter_global_stress(stressp_2, work_g1, work_g2, &
     931           0 :                                  master_task, distrb_info)
     932             :       call scatter_global_stress(stressp_4, work_g2, work_g1, &
     933           0 :                                  master_task, distrb_info)
     934             : 
     935           0 :       call ice_read_global(nu_restart,0,work_g1,'ruf8',diag) ! stressm_1
     936           0 :       call ice_read_global(nu_restart,0,work_g2,'ruf8',diag) ! stressm_3
     937             :       call scatter_global_stress(stressm_1, work_g1, work_g2, &
     938           0 :                                  master_task, distrb_info)
     939             :       call scatter_global_stress(stressm_3, work_g2, work_g1, &
     940           0 :                                  master_task, distrb_info)
     941             : 
     942           0 :       call ice_read_global(nu_restart,0,work_g1,'ruf8',diag) ! stressm_2
     943           0 :       call ice_read_global(nu_restart,0,work_g2,'ruf8',diag) ! stressm_4
     944             :       call scatter_global_stress(stressm_2, work_g1, work_g2, &
     945           0 :                                  master_task, distrb_info)
     946             :       call scatter_global_stress(stressm_4, work_g2, work_g1, &
     947           0 :                                  master_task, distrb_info)
     948             : 
     949           0 :       call ice_read_global(nu_restart,0,work_g1,'ruf8',diag) ! stress12_1
     950           0 :       call ice_read_global(nu_restart,0,work_g2,'ruf8',diag) ! stress12_3
     951             :       call scatter_global_stress(stress12_1, work_g1, work_g2, &
     952           0 :                                  master_task, distrb_info)
     953             :       call scatter_global_stress(stress12_3, work_g2, work_g1, &
     954           0 :                                  master_task, distrb_info)
     955             : 
     956           0 :       call ice_read_global(nu_restart,0,work_g1,'ruf8',diag) ! stress12_2
     957           0 :       call ice_read_global(nu_restart,0,work_g2,'ruf8',diag) ! stress12_4
     958             :       call scatter_global_stress(stress12_2, work_g1, work_g2, &
     959           0 :                                  master_task, distrb_info)
     960             :       call scatter_global_stress(stress12_4, work_g2, work_g1, &
     961           0 :                                  master_task, distrb_info)
     962             : 
     963           0 :       deallocate (work_g1, work_g2)
     964             : 
     965             :       !-----------------------------------------------------------------
     966             :       ! ice mask for dynamics
     967             :       !-----------------------------------------------------------------
     968           0 :       if (my_task == master_task) &
     969           0 :            write(nu_diag,*) 'ice mask for dynamics'
     970             : 
     971             :       call ice_read(nu_restart,0,work1,'ruf8',diag, &
     972           0 :                     field_loc_center, field_type_scalar)
     973             : 
     974           0 :       iceUmask(:,:,:) = .false.
     975           0 :       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
     976           0 :       do iblk = 1, nblocks
     977           0 :          do j = 1, ny_block
     978           0 :          do i = 1, nx_block
     979           0 :             if (work1(i,j,iblk) > p5) iceUmask(i,j,iblk) = .true.
     980             :          enddo
     981             :          enddo
     982             :       enddo
     983             :       !$OMP END PARALLEL DO
     984             : 
     985             :       ! for mixed layer model
     986           0 :       if (oceanmixed_ice) then
     987             : 
     988           0 :          if (my_task == master_task) &
     989           0 :               write(nu_diag,*) 'min/max sst, frzmlt'
     990             : 
     991             :          call ice_read(nu_restart,0,sst,'ruf8',diag, &
     992           0 :                        field_loc_center, field_type_scalar)
     993             :          call ice_read(nu_restart,0,frzmlt,'ruf8',diag, &
     994           0 :                        field_loc_center, field_type_scalar)
     995             :       endif
     996             : 
     997           0 :       if (my_task == master_task) close(nu_restart)
     998             : 
     999             :       !-----------------------------------------------------------------
    1000             :       ! Ensure unused stress values in west and south ghost cells are 0
    1001             :       !-----------------------------------------------------------------
    1002           0 :       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
    1003           0 :       do iblk = 1, nblocks
    1004           0 :          do j = 1, nghost
    1005           0 :          do i = 1, nx_block
    1006           0 :             stressp_1 (i,j,iblk) = c0
    1007           0 :             stressp_2 (i,j,iblk) = c0
    1008           0 :             stressp_3 (i,j,iblk) = c0
    1009           0 :             stressp_4 (i,j,iblk) = c0
    1010           0 :             stressm_1 (i,j,iblk) = c0
    1011           0 :             stressm_2 (i,j,iblk) = c0
    1012           0 :             stressm_3 (i,j,iblk) = c0
    1013           0 :             stressm_4 (i,j,iblk) = c0
    1014           0 :             stress12_1(i,j,iblk) = c0
    1015           0 :             stress12_2(i,j,iblk) = c0
    1016           0 :             stress12_3(i,j,iblk) = c0
    1017           0 :             stress12_4(i,j,iblk) = c0
    1018             :          enddo
    1019             :          enddo
    1020           0 :          do j = 1, ny_block
    1021           0 :          do i = 1, nghost
    1022           0 :             stressp_1 (i,j,iblk) = c0
    1023           0 :             stressp_2 (i,j,iblk) = c0
    1024           0 :             stressp_3 (i,j,iblk) = c0
    1025           0 :             stressp_4 (i,j,iblk) = c0
    1026           0 :             stressm_1 (i,j,iblk) = c0
    1027           0 :             stressm_2 (i,j,iblk) = c0
    1028           0 :             stressm_3 (i,j,iblk) = c0
    1029           0 :             stressm_4 (i,j,iblk) = c0
    1030           0 :             stress12_1(i,j,iblk) = c0
    1031           0 :             stress12_2(i,j,iblk) = c0
    1032           0 :             stress12_3(i,j,iblk) = c0
    1033           0 :             stress12_4(i,j,iblk) = c0
    1034             :          enddo
    1035             :          enddo
    1036             :       enddo
    1037             :       !$OMP END PARALLEL DO
    1038             : 
    1039             :       !-----------------------------------------------------------------
    1040             :       ! Ensure ice is binned in correct categories
    1041             :       ! (should not be necessary unless restarting from a run with
    1042             :       !  different category boundaries).
    1043             :       !
    1044             :       ! If called, this subroutine does not give exact restart.
    1045             :       !-----------------------------------------------------------------
    1046             : !!!      call cleanup_itd
    1047             : 
    1048             :       !-----------------------------------------------------------------
    1049             :       ! compute aggregate ice state and open water area
    1050             :       !-----------------------------------------------------------------
    1051             : 
    1052           0 :       !$OMP PARALLEL DO PRIVATE(iblk,i,j)
    1053           0 :       do iblk = 1, nblocks
    1054             : 
    1055           0 :       do j = 1, ny_block
    1056           0 :       do i = 1, nx_block
    1057           0 :          if (tmask(i,j,iblk)) &
    1058             :             call icepack_aggregate(ncat  = ncat,                  &   ! LCOV_EXCL_LINE
    1059             :                                    aicen = aicen(i,j,:,iblk),     &   ! LCOV_EXCL_LINE
    1060             :                                    trcrn = trcrn(i,j,:,:,iblk),   &   ! LCOV_EXCL_LINE
    1061             :                                    vicen = vicen(i,j,:,iblk),     &   ! LCOV_EXCL_LINE
    1062             :                                    vsnon = vsnon(i,j,:,iblk),     &   ! LCOV_EXCL_LINE
    1063             :                                    aice  = aice (i,j,  iblk),     &   ! LCOV_EXCL_LINE
    1064             :                                    trcr  = trcr (i,j,:,iblk),     &   ! LCOV_EXCL_LINE
    1065             :                                    vice  = vice (i,j,  iblk),     &   ! LCOV_EXCL_LINE
    1066             :                                    vsno  = vsno (i,j,  iblk),     &   ! LCOV_EXCL_LINE
    1067             :                                    aice0 = aice0(i,j,  iblk),     &   ! LCOV_EXCL_LINE
    1068             :                                    ntrcr = ntrcr,                 &   ! LCOV_EXCL_LINE
    1069             :                                    trcr_depend   = trcr_depend,   &   ! LCOV_EXCL_LINE
    1070             :                                    trcr_base     = trcr_base,     &   ! LCOV_EXCL_LINE
    1071             :                                    n_trcr_strata = n_trcr_strata, &   ! LCOV_EXCL_LINE
    1072             :                                    nt_strata     = nt_strata,     &   ! LCOV_EXCL_LINE
    1073           0 :                                    Tf            = Tf(i,j,iblk))
    1074             : 
    1075           0 :          aice_init(i,j,iblk) = aice(i,j,iblk)
    1076             :       enddo
    1077             :       enddo
    1078             : 
    1079             :       enddo
    1080             :       !$OMP END PARALLEL DO
    1081             : 
    1082           0 :       call icepack_warnings_flush(nu_diag)
    1083           0 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
    1084           0 :          file=__FILE__, line=__LINE__)
    1085             : 
    1086             :       ! creates new file
    1087           0 :       filename = trim(restart_dir) // '/iced.converted'
    1088           0 :       call dumpfile(filename)
    1089           0 :       call final_restart
    1090             :       ! stop
    1091             : 
    1092             :       ! if runid is bering then need to correct npt for istep0
    1093           0 :       if (trim(runid) == 'bering') then
    1094           0 :          npt = npt - istep0
    1095             :       endif
    1096             : 
    1097           0 :       end subroutine restartfile_v4
    1098             : 
    1099             : !=======================================================================
    1100             : 
    1101             :       end module ice_restart_driver
    1102             : 
    1103             : !=======================================================================

Generated by: LCOV version 1.14-6-g40580cd