[3] | 1 | MODULE restart |
---|
| 2 | !!====================================================================== |
---|
| 3 | !! *** MODULE restart *** |
---|
| 4 | !! Ocean restart : write the ocean restart file |
---|
[508] | 5 | !!====================================================================== |
---|
[2528] | 6 | !! History : OPA ! 1999-11 (M. Imbard) Original code |
---|
| 7 | !! NEMO 1.0 ! 2002-08 (G. Madec) F90: Free form |
---|
| 8 | !! 2.0 ! 2006-07 (S. Masson) use IOM for restart |
---|
| 9 | !! 3.3 ! 2010-04 (M. Leclair, G. Madec) modified LF-RA |
---|
| 10 | !! - - ! 2010-10 (C. Ethe, G. Madec) TRC-TRA merge (T-S in 4D) |
---|
[508] | 11 | !!---------------------------------------------------------------------- |
---|
[3] | 12 | |
---|
| 13 | !!---------------------------------------------------------------------- |
---|
[508] | 14 | !! rst_opn : open the ocean restart file |
---|
| 15 | !! rst_write : write the ocean restart file |
---|
| 16 | !! rst_read : read the ocean restart file |
---|
[3] | 17 | !!---------------------------------------------------------------------- |
---|
[2528] | 18 | USE oce ! ocean dynamics and tracers |
---|
[3] | 19 | USE dom_oce ! ocean space and time domain |
---|
| 20 | USE phycst ! physical constants |
---|
[508] | 21 | USE in_out_manager ! I/O manager |
---|
| 22 | USE iom ! I/O module |
---|
[544] | 23 | USE eosbn2 ! equation of state (eos bn2 routine) |
---|
[579] | 24 | USE trdmld_oce ! ocean active mixed layer tracers trends variables |
---|
[3680] | 25 | USE divcur ! hor. divergence and curl (div & cur routines) |
---|
[4206] | 26 | USE sbc_ice, ONLY : lk_lim3 |
---|
[5746] | 27 | ! for ln_rstdate.... |
---|
| 28 | USE ioipsl, ONLY : ju2ymds ! for calendar |
---|
[3] | 29 | |
---|
| 30 | IMPLICIT NONE |
---|
| 31 | PRIVATE |
---|
| 32 | |
---|
[4292] | 33 | PUBLIC rst_opn ! routine called by step module |
---|
| 34 | PUBLIC rst_write ! routine called by step module |
---|
| 35 | PUBLIC rst_read ! routine called by istate module |
---|
| 36 | PUBLIC rst_read_open ! routine called in rst_read and (possibly) in dom_vvl_init |
---|
[3] | 37 | |
---|
[508] | 38 | !! * Substitutions |
---|
[2528] | 39 | # include "domzgr_substitute.h90" |
---|
[508] | 40 | # include "vectopt_loop_substitute.h90" |
---|
[3] | 41 | !!---------------------------------------------------------------------- |
---|
[2528] | 42 | !! NEMO/OPA 3.3 , NEMO Consortium (2010) |
---|
[888] | 43 | !! $Id$ |
---|
[2528] | 44 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
[359] | 45 | !!---------------------------------------------------------------------- |
---|
[3] | 46 | CONTAINS |
---|
| 47 | |
---|
[508] | 48 | SUBROUTINE rst_opn( kt ) |
---|
| 49 | !!--------------------------------------------------------------------- |
---|
| 50 | !! *** ROUTINE rst_opn *** |
---|
| 51 | !! |
---|
| 52 | !! ** Purpose : + initialization (should be read in the namelist) of nitrst |
---|
| 53 | !! + open the restart when we are one time step before nitrst |
---|
| 54 | !! - restart header is defined when kt = nitrst-1 |
---|
| 55 | !! - restart data are written when kt = nitrst |
---|
| 56 | !! + define lrst_oce to .TRUE. when we need to define or write the restart |
---|
| 57 | !!---------------------------------------------------------------------- |
---|
| 58 | INTEGER, INTENT(in) :: kt ! ocean time-step |
---|
| 59 | !! |
---|
| 60 | CHARACTER(LEN=20) :: clkt ! ocean time-step deine as a character |
---|
| 61 | CHARACTER(LEN=50) :: clname ! ice output restart file name |
---|
[5746] | 62 | ! Included for ln_rstdate |
---|
| 63 | INTEGER :: iyear, imonth, iday |
---|
| 64 | REAL (wp) :: zsec |
---|
| 65 | |
---|
[508] | 66 | !!---------------------------------------------------------------------- |
---|
| 67 | ! |
---|
[783] | 68 | IF( kt == nit000 ) THEN ! default definitions |
---|
| 69 | lrst_oce = .FALSE. |
---|
| 70 | nitrst = nitend |
---|
[508] | 71 | ENDIF |
---|
[783] | 72 | IF( MOD( kt - 1, nstock ) == 0 ) THEN |
---|
| 73 | ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment |
---|
| 74 | nitrst = kt + nstock - 1 ! define the next value of nitrst for restart writing |
---|
| 75 | IF( nitrst > nitend ) nitrst = nitend ! make sure we write a restart at the end of the run |
---|
| 76 | ENDIF |
---|
| 77 | ! to get better performances with NetCDF format: |
---|
| 78 | ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1) |
---|
| 79 | ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1 |
---|
| 80 | IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN |
---|
[5746] | 81 | ! changes for ln_rstdate.... |
---|
| 82 | ! ! beware of the format used to write kt (default is i8.8, that should be large enough...) |
---|
| 83 | ! IF( nitrst > 999999999 ) THEN ; WRITE(clkt, * ) nitrst |
---|
| 84 | ! ELSE ; WRITE(clkt, '(i8.8)') nitrst |
---|
| 85 | IF ( ln_rstdate ) THEN |
---|
| 86 | CALL ju2ymds( fjulday + rdttra(1) / rday, iyear, imonth, iday, zsec ) |
---|
| 87 | WRITE(clkt, '(i4.4,2i2.2)') iyear, imonth, iday |
---|
| 88 | ELSE |
---|
| 89 | ! beware of the format used to write kt (default is i8.8, that should be large enough...) |
---|
| 90 | IF( nitrst > 999999999 ) THEN ; WRITE(clkt, * ) nitrst |
---|
| 91 | ELSE ; WRITE(clkt, '(i8.8)') nitrst |
---|
| 92 | ENDIF |
---|
| 93 | ! end |
---|
[508] | 94 | ENDIF |
---|
| 95 | ! create the file |
---|
[1229] | 96 | clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out) |
---|
[611] | 97 | IF(lwp) THEN |
---|
| 98 | WRITE(numout,*) |
---|
[632] | 99 | SELECT CASE ( jprstlib ) |
---|
[783] | 100 | CASE ( jprstdimg ) ; WRITE(numout,*) ' open ocean restart binary file: '//clname |
---|
| 101 | CASE DEFAULT ; WRITE(numout,*) ' open ocean restart NetCDF file: '//clname |
---|
[632] | 102 | END SELECT |
---|
[2528] | 103 | IF ( snc4set%luse ) WRITE(numout,*) ' opened for NetCDF4 chunking and compression' |
---|
[1130] | 104 | IF( kt == nitrst - 1 ) THEN ; WRITE(numout,*) ' kt = nitrst - 1 = ', kt |
---|
| 105 | ELSE ; WRITE(numout,*) ' kt = ' , kt |
---|
[611] | 106 | ENDIF |
---|
| 107 | ENDIF |
---|
[2528] | 108 | ! |
---|
[547] | 109 | CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib ) |
---|
[508] | 110 | lrst_oce = .TRUE. |
---|
| 111 | ENDIF |
---|
| 112 | ! |
---|
| 113 | END SUBROUTINE rst_opn |
---|
| 114 | |
---|
| 115 | |
---|
[3] | 116 | SUBROUTINE rst_write( kt ) |
---|
| 117 | !!--------------------------------------------------------------------- |
---|
| 118 | !! *** ROUTINE rstwrite *** |
---|
| 119 | !! |
---|
[632] | 120 | !! ** Purpose : Write restart fields in the format corresponding to jprstlib |
---|
[3] | 121 | !! |
---|
[508] | 122 | !! ** Method : Write in numrow when kt == nitrst in NetCDF |
---|
[2528] | 123 | !! file, save fields which are necessary for restart |
---|
[3] | 124 | !!---------------------------------------------------------------------- |
---|
[508] | 125 | INTEGER, INTENT(in) :: kt ! ocean time-step |
---|
[3] | 126 | !!---------------------------------------------------------------------- |
---|
[1239] | 127 | |
---|
[2528] | 128 | CALL iom_rstput( kt, nitrst, numrow, 'rdt' , rdt ) ! dynamics time step |
---|
| 129 | CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1) ) ! surface tracer time step |
---|
[3] | 130 | |
---|
[2528] | 131 | CALL iom_rstput( kt, nitrst, numrow, 'ub' , ub ) ! before fields |
---|
| 132 | CALL iom_rstput( kt, nitrst, numrow, 'vb' , vb ) |
---|
[3294] | 133 | CALL iom_rstput( kt, nitrst, numrow, 'tb' , tsb(:,:,:,jp_tem) ) |
---|
| 134 | CALL iom_rstput( kt, nitrst, numrow, 'sb' , tsb(:,:,:,jp_sal) ) |
---|
[2528] | 135 | CALL iom_rstput( kt, nitrst, numrow, 'rotb' , rotb ) |
---|
| 136 | CALL iom_rstput( kt, nitrst, numrow, 'hdivb' , hdivb ) |
---|
| 137 | CALL iom_rstput( kt, nitrst, numrow, 'sshb' , sshb ) |
---|
| 138 | ! |
---|
| 139 | CALL iom_rstput( kt, nitrst, numrow, 'un' , un ) ! now fields |
---|
| 140 | CALL iom_rstput( kt, nitrst, numrow, 'vn' , vn ) |
---|
[3294] | 141 | CALL iom_rstput( kt, nitrst, numrow, 'tn' , tsn(:,:,:,jp_tem) ) |
---|
| 142 | CALL iom_rstput( kt, nitrst, numrow, 'sn' , tsn(:,:,:,jp_sal) ) |
---|
[2528] | 143 | CALL iom_rstput( kt, nitrst, numrow, 'rotn' , rotn ) |
---|
| 144 | CALL iom_rstput( kt, nitrst, numrow, 'hdivn' , hdivn ) |
---|
| 145 | CALL iom_rstput( kt, nitrst, numrow, 'sshn' , sshn ) |
---|
| 146 | CALL iom_rstput( kt, nitrst, numrow, 'rhop' , rhop ) |
---|
[1545] | 147 | #if defined key_zdfkpp |
---|
[2528] | 148 | CALL iom_rstput( kt, nitrst, numrow, 'rhd' , rhd ) |
---|
[1483] | 149 | #endif |
---|
[4206] | 150 | IF( lk_lim3 ) THEN |
---|
[4205] | 151 | CALL iom_rstput( kt, nitrst, numrow, 'iatte' , iatte ) !clem modif |
---|
| 152 | CALL iom_rstput( kt, nitrst, numrow, 'oatte' , oatte ) !clem modif |
---|
[4206] | 153 | ENDIF |
---|
[508] | 154 | IF( kt == nitrst ) THEN |
---|
| 155 | CALL iom_close( numrow ) ! close the restart file (only at last time step) |
---|
[579] | 156 | IF( .NOT. lk_trdmld ) lrst_oce = .FALSE. |
---|
[3] | 157 | ENDIF |
---|
[508] | 158 | ! |
---|
[3] | 159 | END SUBROUTINE rst_write |
---|
| 160 | |
---|
[4292] | 161 | SUBROUTINE rst_read_open |
---|
| 162 | !!---------------------------------------------------------------------- |
---|
| 163 | !! *** ROUTINE rst_read_open *** |
---|
| 164 | !! |
---|
| 165 | !! ** Purpose : Open read files for restart (format fixed by jprstlib ) |
---|
| 166 | !! |
---|
| 167 | !! ** Method : Use a non-zero, positive value of numror to assess whether or not |
---|
| 168 | !! the file has already been opened |
---|
| 169 | !!---------------------------------------------------------------------- |
---|
| 170 | INTEGER :: jlibalt = jprstlib |
---|
| 171 | LOGICAL :: llok |
---|
| 172 | !!---------------------------------------------------------------------- |
---|
[3] | 173 | |
---|
[4292] | 174 | IF( numror .LE. 0 ) THEN |
---|
| 175 | IF(lwp) THEN ! Contol prints |
---|
| 176 | WRITE(numout,*) |
---|
| 177 | SELECT CASE ( jprstlib ) |
---|
| 178 | CASE ( jpnf90 ) ; WRITE(numout,*) 'rst_read : read oce NetCDF restart file' |
---|
| 179 | CASE ( jprstdimg ) ; WRITE(numout,*) 'rst_read : read oce binary restart file' |
---|
| 180 | END SELECT |
---|
| 181 | IF ( snc4set%luse ) WRITE(numout,*) 'rst_read : configured with NetCDF4 support' |
---|
| 182 | WRITE(numout,*) '~~~~~~~~' |
---|
| 183 | ENDIF |
---|
| 184 | |
---|
| 185 | IF ( jprstlib == jprstdimg ) THEN |
---|
| 186 | ! eventually read netcdf file (monobloc) for restarting on different number of processors |
---|
| 187 | ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90 |
---|
| 188 | INQUIRE( FILE = TRIM(cn_ocerst_in)//'.nc', EXIST = llok ) |
---|
| 189 | IF ( llok ) THEN ; jlibalt = jpnf90 ; ELSE ; jlibalt = jprstlib ; ENDIF |
---|
| 190 | ENDIF |
---|
| 191 | CALL iom_open( cn_ocerst_in, numror, kiolib = jlibalt ) |
---|
| 192 | ENDIF |
---|
| 193 | END SUBROUTINE rst_read_open |
---|
| 194 | |
---|
[3] | 195 | SUBROUTINE rst_read |
---|
| 196 | !!---------------------------------------------------------------------- |
---|
| 197 | !! *** ROUTINE rst_read *** |
---|
| 198 | !! |
---|
[632] | 199 | !! ** Purpose : Read files for restart (format fixed by jprstlib ) |
---|
[3] | 200 | !! |
---|
[1531] | 201 | !! ** Method : Read in restart.nc file fields which are necessary for restart |
---|
[3] | 202 | !!---------------------------------------------------------------------- |
---|
[1130] | 203 | REAL(wp) :: zrdt, zrdttra1 |
---|
[4292] | 204 | INTEGER :: jk |
---|
[1473] | 205 | LOGICAL :: llok |
---|
[3] | 206 | !!---------------------------------------------------------------------- |
---|
| 207 | |
---|
[4292] | 208 | CALL rst_read_open ! open restart for reading (if not already opened) |
---|
[3] | 209 | |
---|
[544] | 210 | ! Check dynamics and tracer time-step consistency and force Euler restart if changed |
---|
[746] | 211 | IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 ) THEN |
---|
[544] | 212 | CALL iom_get( numror, 'rdt', zrdt ) |
---|
| 213 | IF( zrdt /= rdt ) neuler = 0 |
---|
| 214 | ENDIF |
---|
[746] | 215 | IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 ) THEN |
---|
[544] | 216 | CALL iom_get( numror, 'rdttra1', zrdttra1 ) |
---|
| 217 | IF( zrdttra1 /= rdttra(1) ) neuler = 0 |
---|
| 218 | ENDIF |
---|
[1607] | 219 | ! |
---|
[3680] | 220 | IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN |
---|
| 221 | CALL iom_get( numror, jpdom_autoglo, 'ub' , ub ) ! before fields |
---|
| 222 | CALL iom_get( numror, jpdom_autoglo, 'vb' , vb ) |
---|
| 223 | CALL iom_get( numror, jpdom_autoglo, 'tb' , tsb(:,:,:,jp_tem) ) |
---|
| 224 | CALL iom_get( numror, jpdom_autoglo, 'sb' , tsb(:,:,:,jp_sal) ) |
---|
| 225 | CALL iom_get( numror, jpdom_autoglo, 'rotb' , rotb ) |
---|
| 226 | CALL iom_get( numror, jpdom_autoglo, 'hdivb' , hdivb ) |
---|
| 227 | CALL iom_get( numror, jpdom_autoglo, 'sshb' , sshb ) |
---|
| 228 | ELSE |
---|
| 229 | neuler = 0 |
---|
| 230 | ENDIF |
---|
| 231 | ! |
---|
| 232 | CALL iom_get( numror, jpdom_autoglo, 'un' , un ) ! now fields |
---|
| 233 | CALL iom_get( numror, jpdom_autoglo, 'vn' , vn ) |
---|
| 234 | CALL iom_get( numror, jpdom_autoglo, 'tn' , tsn(:,:,:,jp_tem) ) |
---|
| 235 | CALL iom_get( numror, jpdom_autoglo, 'sn' , tsn(:,:,:,jp_sal) ) |
---|
| 236 | CALL iom_get( numror, jpdom_autoglo, 'sshn' , sshn ) |
---|
| 237 | IF( iom_varid( numror, 'rotn', ldstop = .FALSE. ) > 0 ) THEN |
---|
| 238 | CALL iom_get( numror, jpdom_autoglo, 'rotn' , rotn ) |
---|
| 239 | CALL iom_get( numror, jpdom_autoglo, 'hdivn' , hdivn ) |
---|
| 240 | ELSE |
---|
| 241 | CALL div_cur( 0 ) ! Horizontal divergence & Relative vorticity |
---|
| 242 | ENDIF |
---|
| 243 | IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN |
---|
| 244 | CALL iom_get( numror, jpdom_autoglo, 'rhop' , rhop ) ! now potential density |
---|
| 245 | ELSE |
---|
[4313] | 246 | CALL eos ( tsn, rhd, rhop, fsdept_n(:,:,:) ) |
---|
[3680] | 247 | ENDIF |
---|
[1545] | 248 | #if defined key_zdfkpp |
---|
| 249 | IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN |
---|
[3680] | 250 | CALL iom_get( numror, jpdom_autoglo, 'rhd' , rhd ) ! now in situ density anomaly |
---|
[1545] | 251 | ELSE |
---|
[4313] | 252 | CALL eos( tsn, rhd, fsdept_n(:,:,:) ) ! compute rhd |
---|
[1545] | 253 | ENDIF |
---|
[1483] | 254 | #endif |
---|
[2528] | 255 | ! |
---|
[508] | 256 | IF( neuler == 0 ) THEN ! Euler restart (neuler=0) |
---|
[3294] | 257 | tsb (:,:,:,:) = tsn (:,:,:,:) ! all before fields set to now values |
---|
| 258 | ub (:,:,:) = un (:,:,:) |
---|
| 259 | vb (:,:,:) = vn (:,:,:) |
---|
| 260 | rotb (:,:,:) = rotn (:,:,:) |
---|
| 261 | hdivb(:,:,:) = hdivn(:,:,:) |
---|
| 262 | sshb (:,:) = sshn (:,:) |
---|
[3] | 263 | ENDIF |
---|
[508] | 264 | ! |
---|
[4206] | 265 | IF( lk_lim3 ) THEN |
---|
| 266 | CALL iom_get( numror, jpdom_autoglo, 'iatte' , iatte ) ! clem modif |
---|
| 267 | CALL iom_get( numror, jpdom_autoglo, 'oatte' , oatte ) ! clem modif |
---|
| 268 | ENDIF |
---|
[4205] | 269 | ! |
---|
[508] | 270 | END SUBROUTINE rst_read |
---|
[473] | 271 | |
---|
[3] | 272 | !!===================================================================== |
---|
| 273 | END MODULE restart |
---|