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