[8586] | 1 | MODULE icerst |
---|
| 2 | !!====================================================================== |
---|
| 3 | !! *** MODULE icerst *** |
---|
| 4 | !! sea-ice : write/read the ice restart file |
---|
| 5 | !!====================================================================== |
---|
[9604] | 6 | !! History: 4.0 ! 2018 (many people) SI3 [aka Sea Ice cube] |
---|
[8586] | 7 | !!---------------------------------------------------------------------- |
---|
[9570] | 8 | #if defined key_si3 |
---|
[8586] | 9 | !!---------------------------------------------------------------------- |
---|
[9570] | 10 | !! 'key_si3' SI3 sea-ice model |
---|
[8586] | 11 | !!---------------------------------------------------------------------- |
---|
| 12 | !! ice_rst_opn : open restart file |
---|
| 13 | !! ice_rst_write : write restart file |
---|
| 14 | !! ice_rst_read : read restart file |
---|
| 15 | !!---------------------------------------------------------------------- |
---|
[11536] | 16 | USE ice ! sea-ice: variables |
---|
[8586] | 17 | USE dom_oce ! ocean domain |
---|
[11536] | 18 | USE phycst , ONLY : rt0 |
---|
[8948] | 19 | USE sbc_oce , ONLY : nn_fsbc, ln_cpl |
---|
[11536] | 20 | USE iceistate ! sea-ice: initial state |
---|
| 21 | USE icectl ! sea-ice: control |
---|
[8586] | 22 | ! |
---|
| 23 | USE in_out_manager ! I/O manager |
---|
| 24 | USE iom ! I/O manager library |
---|
[11717] | 25 | USE ioipsl, ONLY : ju2ymds ! for calendar |
---|
[8586] | 26 | USE lib_mpp ! MPP library |
---|
| 27 | USE lib_fortran ! fortran utilities (glob_sum + no signed zero) |
---|
| 28 | |
---|
| 29 | IMPLICIT NONE |
---|
| 30 | PRIVATE |
---|
| 31 | |
---|
| 32 | PUBLIC ice_rst_opn ! called by icestp |
---|
| 33 | PUBLIC ice_rst_write ! called by icestp |
---|
| 34 | PUBLIC ice_rst_read ! called by ice_init |
---|
| 35 | |
---|
| 36 | !!---------------------------------------------------------------------- |
---|
[9598] | 37 | !! NEMO/ICE 4.0 , NEMO Consortium (2018) |
---|
[10069] | 38 | !! $Id$ |
---|
[10068] | 39 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
[8586] | 40 | !!---------------------------------------------------------------------- |
---|
| 41 | CONTAINS |
---|
| 42 | |
---|
| 43 | SUBROUTINE ice_rst_opn( kt ) |
---|
| 44 | !!---------------------------------------------------------------------- |
---|
| 45 | !! *** ice_rst_opn *** |
---|
| 46 | !! |
---|
| 47 | !! ** purpose : open restart file |
---|
| 48 | !!---------------------------------------------------------------------- |
---|
| 49 | INTEGER, INTENT(in) :: kt ! number of iteration |
---|
| 50 | ! |
---|
[11717] | 51 | INTEGER :: iyear, imonth, iday |
---|
| 52 | REAL (wp) :: zsec |
---|
| 53 | REAL (wp) :: zfjulday |
---|
[8586] | 54 | CHARACTER(len=20) :: clkt ! ocean time-step define as a character |
---|
| 55 | CHARACTER(len=50) :: clname ! ice output restart file name |
---|
| 56 | CHARACTER(len=256) :: clpath ! full path to ice output restart file |
---|
| 57 | !!---------------------------------------------------------------------- |
---|
| 58 | ! |
---|
| 59 | IF( kt == nit000 ) lrst_ice = .FALSE. ! default definition |
---|
| 60 | |
---|
[11536] | 61 | IF( ln_rst_list .OR. nn_stock /= -1 ) THEN |
---|
[8586] | 62 | ! in order to get better performances with NetCDF format, we open and define the ice restart file |
---|
| 63 | ! one ice time step before writing the data (-> at nitrst - 2*nn_fsbc + 1), except if we write ice |
---|
| 64 | ! restart files every ice time step or if an ice restart file was writen at nitend - 2*nn_fsbc + 1 |
---|
[11536] | 65 | IF( kt == nitrst - 2*nn_fsbc + 1 .OR. nn_stock == nn_fsbc & |
---|
[8586] | 66 | & .OR. ( kt == nitend - nn_fsbc + 1 .AND. .NOT. lrst_ice ) ) THEN |
---|
| 67 | IF( nitrst <= nitend .AND. nitrst > 0 ) THEN |
---|
| 68 | ! beware of the format used to write kt (default is i8.8, that should be large enough...) |
---|
[11717] | 69 | IF ( ln_rstdate ) THEN |
---|
| 70 | zfjulday = fjulday + (2*nn_fsbc+1)*rdt / rday |
---|
| 71 | IF( ABS(zfjulday - REAL(NINT(zfjulday),wp)) < 0.1 / rday ) zfjulday = REAL(NINT(zfjulday),wp) ! avoid truncation error |
---|
| 72 | CALL ju2ymds( zfjulday, iyear, imonth, iday, zsec ) |
---|
| 73 | WRITE(clkt, '(i4.4,2i2.2)') iyear, imonth, iday |
---|
| 74 | ELSE |
---|
| 75 | IF( nitrst > 99999999 ) THEN ; WRITE(clkt, * ) nitrst |
---|
| 76 | ELSE ; WRITE(clkt, '(i8.8)') nitrst |
---|
| 77 | ENDIF |
---|
[8586] | 78 | ENDIF |
---|
| 79 | ! create the file |
---|
| 80 | clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_icerst_out) |
---|
| 81 | clpath = TRIM(cn_icerst_outdir) |
---|
| 82 | IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath)//'/' |
---|
| 83 | IF(lwp) THEN |
---|
| 84 | WRITE(numout,*) |
---|
[10425] | 85 | WRITE(numout,*) ' open ice restart NetCDF file: ',TRIM(clpath)//clname |
---|
[8586] | 86 | IF( kt == nitrst - 2*nn_fsbc + 1 ) THEN |
---|
| 87 | WRITE(numout,*) ' kt = nitrst - 2*nn_fsbc + 1 = ', kt,' date= ', ndastp |
---|
| 88 | ELSE |
---|
| 89 | WRITE(numout,*) ' kt = ' , kt,' date= ', ndastp |
---|
| 90 | ENDIF |
---|
| 91 | ENDIF |
---|
| 92 | ! |
---|
[10425] | 93 | CALL iom_open( TRIM(clpath)//TRIM(clname), numriw, ldwrt = .TRUE., kdlev = jpl ) |
---|
[8586] | 94 | lrst_ice = .TRUE. |
---|
| 95 | ENDIF |
---|
| 96 | ENDIF |
---|
[11536] | 97 | ENDIF |
---|
[8586] | 98 | ! |
---|
| 99 | IF( ln_icectl ) CALL ice_prt( kt, iiceprt, jiceprt, 1, ' - Beginning the time step - ' ) ! control print |
---|
[8817] | 100 | ! |
---|
[8586] | 101 | END SUBROUTINE ice_rst_opn |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | SUBROUTINE ice_rst_write( kt ) |
---|
| 105 | !!---------------------------------------------------------------------- |
---|
| 106 | !! *** ice_rst_write *** |
---|
| 107 | !! |
---|
| 108 | !! ** purpose : write restart file |
---|
| 109 | !!---------------------------------------------------------------------- |
---|
| 110 | INTEGER, INTENT(in) :: kt ! number of iteration |
---|
| 111 | !! |
---|
[10425] | 112 | INTEGER :: jk ! dummy loop indices |
---|
[8586] | 113 | INTEGER :: iter |
---|
| 114 | CHARACTER(len=25) :: znam |
---|
| 115 | CHARACTER(len=2) :: zchar, zchar1 |
---|
[8817] | 116 | REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace |
---|
[8586] | 117 | !!---------------------------------------------------------------------- |
---|
| 118 | |
---|
| 119 | iter = kt + nn_fsbc - 1 ! ice restarts are written at kt == nitrst - nn_fsbc + 1 |
---|
| 120 | |
---|
| 121 | IF( iter == nitrst ) THEN |
---|
| 122 | IF(lwp) WRITE(numout,*) |
---|
| 123 | IF(lwp) WRITE(numout,*) 'ice_rst_write : write ice restart file kt =', kt |
---|
| 124 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~' |
---|
| 125 | ENDIF |
---|
| 126 | |
---|
| 127 | ! Write in numriw (if iter == nitrst) |
---|
| 128 | ! ------------------ |
---|
| 129 | ! ! calendar control |
---|
| 130 | CALL iom_rstput( iter, nitrst, numriw, 'nn_fsbc', REAL( nn_fsbc, wp ) ) ! time-step |
---|
| 131 | CALL iom_rstput( iter, nitrst, numriw, 'kt_ice' , REAL( iter , wp ) ) ! date |
---|
[10425] | 132 | CALL iom_delay_rst( 'WRITE', 'ICE', numriw ) ! save only ice delayed global communication variables |
---|
[8586] | 133 | |
---|
[8817] | 134 | ! Prognostic variables |
---|
[11536] | 135 | CALL iom_rstput( iter, nitrst, numriw, 'v_i' , v_i ) |
---|
| 136 | CALL iom_rstput( iter, nitrst, numriw, 'v_s' , v_s ) |
---|
| 137 | CALL iom_rstput( iter, nitrst, numriw, 'sv_i' , sv_i ) |
---|
| 138 | CALL iom_rstput( iter, nitrst, numriw, 'a_i' , a_i ) |
---|
| 139 | CALL iom_rstput( iter, nitrst, numriw, 't_su' , t_su ) |
---|
| 140 | CALL iom_rstput( iter, nitrst, numriw, 'u_ice', u_ice ) |
---|
| 141 | CALL iom_rstput( iter, nitrst, numriw, 'v_ice', v_ice ) |
---|
| 142 | CALL iom_rstput( iter, nitrst, numriw, 'oa_i' , oa_i ) |
---|
| 143 | CALL iom_rstput( iter, nitrst, numriw, 'a_ip' , a_ip ) |
---|
| 144 | CALL iom_rstput( iter, nitrst, numriw, 'v_ip' , v_ip ) |
---|
[9271] | 145 | ! Snow enthalpy |
---|
| 146 | DO jk = 1, nlay_s |
---|
| 147 | WRITE(zchar1,'(I2.2)') jk |
---|
| 148 | znam = 'e_s'//'_l'//zchar1 |
---|
| 149 | z3d(:,:,:) = e_s(:,:,jk,:) |
---|
| 150 | CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) |
---|
| 151 | END DO |
---|
| 152 | ! Ice enthalpy |
---|
[8817] | 153 | DO jk = 1, nlay_i |
---|
| 154 | WRITE(zchar1,'(I2.2)') jk |
---|
[9123] | 155 | znam = 'e_i'//'_l'//zchar1 |
---|
[8817] | 156 | z3d(:,:,:) = e_i(:,:,jk,:) |
---|
| 157 | CALL iom_rstput( iter, nitrst, numriw, znam , z3d ) |
---|
[8586] | 158 | END DO |
---|
[8948] | 159 | ! fields needed for Met Office (Jules) coupling |
---|
| 160 | IF( ln_cpl ) THEN |
---|
[8933] | 161 | CALL iom_rstput( iter, nitrst, numriw, 'cnd_ice', cnd_ice ) |
---|
| 162 | CALL iom_rstput( iter, nitrst, numriw, 't1_ice' , t1_ice ) |
---|
| 163 | ENDIF |
---|
| 164 | ! |
---|
| 165 | |
---|
[8586] | 166 | ! close restart file |
---|
| 167 | ! ------------------ |
---|
| 168 | IF( iter == nitrst ) THEN |
---|
| 169 | CALL iom_close( numriw ) |
---|
| 170 | lrst_ice = .FALSE. |
---|
| 171 | ENDIF |
---|
| 172 | ! |
---|
| 173 | END SUBROUTINE ice_rst_write |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | SUBROUTINE ice_rst_read |
---|
| 177 | !!---------------------------------------------------------------------- |
---|
| 178 | !! *** ice_rst_read *** |
---|
| 179 | !! |
---|
| 180 | !! ** purpose : read restart file |
---|
| 181 | !!---------------------------------------------------------------------- |
---|
[10425] | 182 | INTEGER :: jk |
---|
[8817] | 183 | LOGICAL :: llok |
---|
[11536] | 184 | INTEGER :: id0, id1, id2, id3, id4 ! local integer |
---|
[8586] | 185 | CHARACTER(len=25) :: znam |
---|
| 186 | CHARACTER(len=2) :: zchar, zchar1 |
---|
[8817] | 187 | REAL(wp) :: zfice, ziter |
---|
| 188 | REAL(wp), DIMENSION(jpi,jpj,jpl) :: z3d ! 3D workspace |
---|
[8586] | 189 | !!---------------------------------------------------------------------- |
---|
| 190 | |
---|
| 191 | IF(lwp) THEN |
---|
| 192 | WRITE(numout,*) |
---|
| 193 | WRITE(numout,*) 'ice_rst_read: read ice NetCDF restart file' |
---|
| 194 | WRITE(numout,*) '~~~~~~~~~~~~' |
---|
| 195 | ENDIF |
---|
| 196 | |
---|
[10425] | 197 | CALL iom_open ( TRIM(cn_icerst_indir)//'/'//cn_icerst_in, numrir, kdlev = jpl ) |
---|
[8586] | 198 | |
---|
[11536] | 199 | ! test if v_i exists |
---|
| 200 | id0 = iom_varid( numrir, 'v_i' , ldstop = .FALSE. ) |
---|
[8586] | 201 | |
---|
[11536] | 202 | ! ! ------------------------------ ! |
---|
| 203 | IF( id0 > 0 ) THEN ! == case of a normal restart == ! |
---|
| 204 | ! ! ------------------------------ ! |
---|
| 205 | |
---|
| 206 | ! Time info |
---|
| 207 | CALL iom_get( numrir, 'nn_fsbc', zfice ) |
---|
| 208 | CALL iom_get( numrir, 'kt_ice' , ziter ) |
---|
| 209 | IF(lwp) WRITE(numout,*) ' read ice restart file at time step : ', ziter |
---|
| 210 | IF(lwp) WRITE(numout,*) ' in any case we force it to nit000 - 1 : ', nit000 - 1 |
---|
[8586] | 211 | |
---|
[11536] | 212 | ! Control of date |
---|
| 213 | IF( ( nit000 - NINT(ziter) ) /= 1 .AND. ABS( nrstdt ) == 1 ) & |
---|
| 214 | & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nit000 in ice restart', & |
---|
| 215 | & ' verify the file or rerun with the value 0 for the', & |
---|
| 216 | & ' control of time parameter nrstdt' ) |
---|
| 217 | IF( NINT(zfice) /= nn_fsbc .AND. ABS( nrstdt ) == 1 ) & |
---|
| 218 | & CALL ctl_stop( 'ice_rst_read ===>>>> : problem with nn_fsbc in ice restart', & |
---|
| 219 | & ' verify the file or rerun with the value 0 for the', & |
---|
| 220 | & ' control of time parameter nrstdt' ) |
---|
[10425] | 221 | |
---|
[11536] | 222 | ! --- mandatory fields --- ! |
---|
| 223 | CALL iom_get( numrir, jpdom_autoglo, 'v_i' , v_i ) |
---|
| 224 | CALL iom_get( numrir, jpdom_autoglo, 'v_s' , v_s ) |
---|
| 225 | CALL iom_get( numrir, jpdom_autoglo, 'sv_i' , sv_i ) |
---|
| 226 | CALL iom_get( numrir, jpdom_autoglo, 'a_i' , a_i ) |
---|
| 227 | CALL iom_get( numrir, jpdom_autoglo, 't_su' , t_su ) |
---|
| 228 | CALL iom_get( numrir, jpdom_autoglo, 'u_ice', u_ice ) |
---|
| 229 | CALL iom_get( numrir, jpdom_autoglo, 'v_ice', v_ice ) |
---|
| 230 | ! Snow enthalpy |
---|
| 231 | DO jk = 1, nlay_s |
---|
| 232 | WRITE(zchar1,'(I2.2)') jk |
---|
| 233 | znam = 'e_s'//'_l'//zchar1 |
---|
| 234 | CALL iom_get( numrir, jpdom_autoglo, znam , z3d ) |
---|
| 235 | e_s(:,:,jk,:) = z3d(:,:,:) |
---|
| 236 | END DO |
---|
| 237 | ! Ice enthalpy |
---|
| 238 | DO jk = 1, nlay_i |
---|
| 239 | WRITE(zchar1,'(I2.2)') jk |
---|
| 240 | znam = 'e_i'//'_l'//zchar1 |
---|
| 241 | CALL iom_get( numrir, jpdom_autoglo, znam , z3d ) |
---|
| 242 | e_i(:,:,jk,:) = z3d(:,:,:) |
---|
| 243 | END DO |
---|
| 244 | ! -- optional fields -- ! |
---|
| 245 | ! ice age |
---|
| 246 | id1 = iom_varid( numrir, 'oa_i' , ldstop = .FALSE. ) |
---|
| 247 | IF( id1 > 0 ) THEN ! fields exist |
---|
| 248 | CALL iom_get( numrir, jpdom_autoglo, 'oa_i', oa_i ) |
---|
| 249 | ELSE ! start from rest |
---|
| 250 | IF(lwp) WRITE(numout,*) ' ==>> previous run without ice age output then set it to zero' |
---|
| 251 | oa_i(:,:,:) = 0._wp |
---|
| 252 | ENDIF |
---|
| 253 | ! melt ponds |
---|
| 254 | id2 = iom_varid( numrir, 'a_ip' , ldstop = .FALSE. ) |
---|
| 255 | IF( id2 > 0 ) THEN ! fields exist |
---|
| 256 | CALL iom_get( numrir, jpdom_autoglo, 'a_ip' , a_ip ) |
---|
| 257 | CALL iom_get( numrir, jpdom_autoglo, 'v_ip' , v_ip ) |
---|
| 258 | ELSE ! start from rest |
---|
| 259 | IF(lwp) WRITE(numout,*) ' ==>> previous run without melt ponds output then set it to zero' |
---|
| 260 | a_ip(:,:,:) = 0._wp |
---|
| 261 | v_ip(:,:,:) = 0._wp |
---|
| 262 | ENDIF |
---|
| 263 | ! fields needed for Met Office (Jules) coupling |
---|
| 264 | IF( ln_cpl ) THEN |
---|
| 265 | id3 = iom_varid( numrir, 'cnd_ice' , ldstop = .FALSE. ) |
---|
| 266 | id4 = iom_varid( numrir, 't1_ice' , ldstop = .FALSE. ) |
---|
| 267 | IF( id3 > 0 .AND. id4 > 0 ) THEN ! fields exist |
---|
| 268 | CALL iom_get( numrir, jpdom_autoglo, 'cnd_ice', cnd_ice ) |
---|
| 269 | CALL iom_get( numrir, jpdom_autoglo, 't1_ice' , t1_ice ) |
---|
| 270 | ELSE ! start from rest |
---|
| 271 | IF(lwp) WRITE(numout,*) ' ==>> previous run without conductivity output then set it to zero' |
---|
| 272 | cnd_ice(:,:,:) = 0._wp |
---|
| 273 | t1_ice (:,:,:) = rt0 |
---|
| 274 | ENDIF |
---|
| 275 | ENDIF |
---|
[10425] | 276 | |
---|
[11536] | 277 | CALL iom_delay_rst( 'READ', 'ICE', numrir ) ! read only ice delayed global communication variables |
---|
| 278 | |
---|
| 279 | ! ! ---------------------------------- ! |
---|
| 280 | ELSE ! == case of a simplified restart == ! |
---|
| 281 | ! ! ---------------------------------- ! |
---|
| 282 | CALL ctl_warn('ice_rst_read: you are using a simplified ice restart') |
---|
| 283 | ! |
---|
| 284 | CALL ice_istate_init |
---|
| 285 | CALL ice_istate( nit000 ) |
---|
| 286 | ! |
---|
| 287 | IF( .NOT.ln_iceini .OR. .NOT.ln_iceini_file ) & |
---|
| 288 | & CALL ctl_stop('STOP', 'ice_rst_read: you need ln_ice_ini=T and ln_iceini_file=T') |
---|
| 289 | ! |
---|
[8933] | 290 | ENDIF |
---|
[8586] | 291 | |
---|
| 292 | END SUBROUTINE ice_rst_read |
---|
| 293 | |
---|
| 294 | #else |
---|
| 295 | !!---------------------------------------------------------------------- |
---|
[9570] | 296 | !! Default option : Empty module NO SI3 sea-ice model |
---|
[8586] | 297 | !!---------------------------------------------------------------------- |
---|
| 298 | #endif |
---|
| 299 | |
---|
| 300 | !!====================================================================== |
---|
| 301 | END MODULE icerst |
---|