MODULE icerst !!====================================================================== !! *** MODULE icerst *** !! sea-ice : write/read the ice restart file !!====================================================================== !! History: 4.0 ! 2018 (many people) SI3 [aka Sea Ice cube] !!---------------------------------------------------------------------- #if defined key_si3 !!---------------------------------------------------------------------- !! 'key_si3' SI3 sea-ice model !!---------------------------------------------------------------------- !! ice_rst_opn : open restart file !! ice_rst_write : write restart file !! ice_rst_read : read restart file !!---------------------------------------------------------------------- USE ice ! sea-ice variables USE dom_oce ! ocean domain USE sbc_oce , ONLY : nn_fsbc, ln_cpl USE icectl ! USE in_out_manager ! I/O manager USE iom ! I/O manager library USE lib_mpp ! MPP library USE lib_fortran ! fortran utilities (glob_sum + no signed zero) IMPLICIT NONE PRIVATE PUBLIC ice_rst_opn ! called by icestp PUBLIC ice_rst_write ! called by icestp PUBLIC ice_rst_read ! called by ice_init !!---------------------------------------------------------------------- !! NEMO/ICE 4.0 , NEMO Consortium (2018) !! $Id: icerst.F90 8411 2017-08-07 16:09:12Z clem $ !! Software governed by the CeCILL licence (./LICENSE) !!---------------------------------------------------------------------- CONTAINS SUBROUTINE ice_rst_opn( kt ) !!---------------------------------------------------------------------- !! *** ice_rst_opn *** !! !! ** purpose : open restart file !!---------------------------------------------------------------------- INTEGER, INTENT(in) :: kt ! number of iteration ! CHARACTER(len=20) :: clkt ! ocean time-step define as a character CHARACTER(len=50) :: clname ! ice output restart file name CHARACTER(len=256) :: clpath ! full path to ice output restart file !!---------------------------------------------------------------------- ! IF( kt == nit000 ) lrst_ice = .FALSE. ! default definition ! in order to get better performances with NetCDF format, we open and define the ice restart file ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1 IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nstock == nn_fsbc & & .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN IF( nitrst <= nitend .AND. nitrst > 0 ) THEN ! beware of the format used to write kt (default is i8.8, that should be large enough...) IF( nitrst > 99999999 ) THEN ; WRITE(clkt, * ) nitrst ELSE ; WRITE(clkt, '(i8.8)') nitrst ENDIF ! create the file clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out) clpath = TRIM(cn_icerst_outdir) IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/' IF(lwp) THEN WRITE(numout,*) SELECT CASE ( jprstlib ) CASE DEFAULT WRITE(numout,*) ' open ice restart NetCDF file: ',TRIM(clpath)//clname END SELECT IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN WRITE(numout,*) ' kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp ELSE WRITE(numout,*) ' kt = ' , kt,' date= ', ndastp ENDIF ENDIF ! CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kiolib = jprstlib, kdlev = jpl ) lrst_ice = .TRUE. ENDIF ENDIF ! IF( ln_icectl ) CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' ) ! control print ! END SUBROUTINE ice_rst_opn SUBROUTINE ice_rst_write( kt ) !!---------------------------------------------------------------------- !! *** ice_rst_write *** !! !! ** purpose : write restart file !!---------------------------------------------------------------------- INTEGER, INTENT(in) :: kt ! number of iteration !! INTEGER :: jk ,jl ! dummy loop indices INTEGER :: iter CHARACTER(len=25) :: znam CHARACTER(len=2) :: zchar, zchar1 REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace !!---------------------------------------------------------------------- iter = kt + nn_fsbc - 1 ! ice restarts are written at kt == nitrst - nn_fsbc + 1 IF( iter == nitrst ) THEN IF(lwp) WRITE(numout,*) IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file kt =', kt IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~' ENDIF ! Write in numriw (if iter == nitrst) ! ------------------ ! ! calendar control CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) ) ! time-step CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter , wp ) ) ! date ! Prognostic variables CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i ) CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s ) CALL iom_rstput( iter, nitrst, numriw, 'sv_i', sv_i ) CALL iom_rstput( iter, nitrst, numriw, 'oa_i', oa_i ) CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i ) CALL iom_rstput( iter, nitrst, numriw, 't_su', t_su ) ! Melt ponds CALL iom_rstput( iter, nitrst, numriw, 'a_ip', a_ip ) CALL iom_rstput( iter, nitrst, numriw, 'v_ip', v_ip ) ! Snow enthalpy DO jk = 1, nlay_s WRITE(zchar1,'(I2.2)') jk znam = 'e_s'//'_l'//zchar1 z3d(:,:,:) = e_s(:,:,jk,:) CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) END DO ! Ice enthalpy DO jk = 1, nlay_i WRITE(zchar1,'(I2.2)') jk znam = 'e_i'//'_l'//zchar1 z3d(:,:,:) = e_i(:,:,jk,:) CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) END DO ! ice velocity CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) ! u_ice CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) ! v_ice ! fields needed for Met Office (Jules) coupling IF( ln_cpl ) THEN CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice ) CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice ) ENDIF ! ! close restart file ! ------------------ IF( iter == nitrst ) THEN CALL iom_close( numriw ) lrst_ice = .FALSE. ENDIF ! END SUBROUTINE ice_rst_write SUBROUTINE ice_rst_read !!---------------------------------------------------------------------- !! *** ice_rst_read *** !! !! ** purpose : read restart file !!---------------------------------------------------------------------- INTEGER :: jk, jl LOGICAL :: llok INTEGER :: id1 ! local integer INTEGER :: jlibalt = jprstlib CHARACTER(len=25) :: znam CHARACTER(len=2) :: zchar, zchar1 REAL(wp) :: zfice, ziter REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace !!---------------------------------------------------------------------- IF(lwp) THEN WRITE(numout,*) WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file' WRITE(numout,*) '~~~~~~~~~~~~' ENDIF CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kiolib = jprstlib, kdlev = jpl ) CALL iom_get( numrir, 'nn_fsbc', zfice ) CALL iom_get( numrir, 'kt_ice' , ziter ) IF(lwp) WRITE(numout,*) ' read ice restart file at time step : ', ziter IF(lwp) WRITE(numout,*) ' in any case we force it to nit000 - 1 : ', nit000 - 1 ! Control of date IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 ) & & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart', & & ' verify the file or rerun with the value 0 for the', & & ' control of time parameter nrstdt' ) IF( NINT(zfice) /= nn_fsbc .AND. ABS( nrstdt ) == 1 ) & & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart', & & ' verify the file or rerun with the value 0 for the', & & ' control of time parameter nrstdt' ) ! Prognostic variables CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i ) CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s ) CALL iom_get( numrir, jpdom_autoglo, 'sv_i', sv_i ) CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i ) CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i ) CALL iom_get( numrir, jpdom_autoglo, 't_su', t_su ) ! Melt ponds id1 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. ) IF( id1 > 0 ) THEN ! fields exist (melt ponds) CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip ) CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip ) ELSE ! start from rest IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds output then set it to zero' a_ip(:,:,:) = 0._wp v_ip(:,:,:) = 0._wp ENDIF ! Snow enthalpy DO jk = 1, nlay_s WRITE(zchar1,'(I2.2)') jk znam = 'e_s'//'_l'//zchar1 CALL iom_get( numrir, jpdom_autoglo, znam , z3d ) e_s(:,:,jk,:) = z3d(:,:,:) END DO ! Ice enthalpy DO jk = 1, nlay_i WRITE(zchar1,'(I2.2)') jk znam = 'e_i'//'_l'//zchar1 CALL iom_get( numrir, jpdom_autoglo, znam , z3d ) e_i(:,:,jk,:) = z3d(:,:,:) END DO ! ice velocity CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice ) CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice ) ! fields needed for Met Office (Jules) coupling IF( ln_cpl ) THEN CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice ) CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice ) ENDIF END SUBROUTINE ice_rst_read #else !!---------------------------------------------------------------------- !! Default option : Empty module NO SI3 sea-ice model !!---------------------------------------------------------------------- #endif !!====================================================================== END MODULE icerst