[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 |
---|
[2528] | 25 | USE domvvl ! variable volume |
---|
[3653] | 26 | USE divcur ! hor. divergence and curl (div & cur routines) |
---|
[3] | 27 | |
---|
| 28 | IMPLICIT NONE |
---|
| 29 | PRIVATE |
---|
| 30 | |
---|
[508] | 31 | PUBLIC rst_opn ! routine called by step module |
---|
| 32 | PUBLIC rst_write ! routine called by step module |
---|
| 33 | PUBLIC rst_read ! routine called by opa module |
---|
[3] | 34 | |
---|
[508] | 35 | !! * Substitutions |
---|
[2528] | 36 | # include "domzgr_substitute.h90" |
---|
[508] | 37 | # include "vectopt_loop_substitute.h90" |
---|
[3] | 38 | !!---------------------------------------------------------------------- |
---|
[2528] | 39 | !! NEMO/OPA 3.3 , NEMO Consortium (2010) |
---|
[888] | 40 | !! $Id$ |
---|
[2528] | 41 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
[359] | 42 | !!---------------------------------------------------------------------- |
---|
[3] | 43 | CONTAINS |
---|
| 44 | |
---|
[508] | 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 ! ice output restart file name |
---|
| 59 | !!---------------------------------------------------------------------- |
---|
| 60 | ! |
---|
[783] | 61 | IF( kt == nit000 ) THEN ! default definitions |
---|
| 62 | lrst_oce = .FALSE. |
---|
| 63 | nitrst = nitend |
---|
[508] | 64 | ENDIF |
---|
[783] | 65 | IF( MOD( kt - 1, nstock ) == 0 ) THEN |
---|
| 66 | ! we use kt - 1 and not kt - nit000 to keep the same periodicity from the beginning of the experiment |
---|
| 67 | nitrst = kt + nstock - 1 ! define the next value of nitrst for restart writing |
---|
| 68 | IF( nitrst > nitend ) nitrst = nitend ! make sure we write a restart at the end of the run |
---|
| 69 | ENDIF |
---|
| 70 | ! to get better performances with NetCDF format: |
---|
| 71 | ! we open and define the ocean restart file one time step before writing the data (-> at nitrst - 1) |
---|
| 72 | ! except if we write ocean restart files every time step or if an ocean restart file was writen at nitend - 1 |
---|
| 73 | IF( kt == nitrst - 1 .OR. nstock == 1 .OR. ( kt == nitend .AND. .NOT. lrst_oce ) ) THEN |
---|
| 74 | ! beware of the format used to write kt (default is i8.8, that should be large enough...) |
---|
| 75 | IF( nitrst > 999999999 ) THEN ; WRITE(clkt, * ) nitrst |
---|
| 76 | ELSE ; WRITE(clkt, '(i8.8)') nitrst |
---|
[508] | 77 | ENDIF |
---|
| 78 | ! create the file |
---|
[1229] | 79 | clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_ocerst_out) |
---|
[611] | 80 | IF(lwp) THEN |
---|
| 81 | WRITE(numout,*) |
---|
[632] | 82 | SELECT CASE ( jprstlib ) |
---|
[783] | 83 | CASE ( jprstdimg ) ; WRITE(numout,*) ' open ocean restart binary file: '//clname |
---|
| 84 | CASE DEFAULT ; WRITE(numout,*) ' open ocean restart NetCDF file: '//clname |
---|
[632] | 85 | END SELECT |
---|
[2528] | 86 | IF ( snc4set%luse ) WRITE(numout,*) ' opened for NetCDF4 chunking and compression' |
---|
[1130] | 87 | IF( kt == nitrst - 1 ) THEN ; WRITE(numout,*) ' kt = nitrst - 1 = ', kt |
---|
| 88 | ELSE ; WRITE(numout,*) ' kt = ' , kt |
---|
[611] | 89 | ENDIF |
---|
| 90 | ENDIF |
---|
[2528] | 91 | ! |
---|
[547] | 92 | CALL iom_open( clname, numrow, ldwrt = .TRUE., kiolib = jprstlib ) |
---|
[508] | 93 | lrst_oce = .TRUE. |
---|
| 94 | ENDIF |
---|
| 95 | ! |
---|
| 96 | END SUBROUTINE rst_opn |
---|
| 97 | |
---|
| 98 | |
---|
[3] | 99 | SUBROUTINE rst_write( kt ) |
---|
| 100 | !!--------------------------------------------------------------------- |
---|
| 101 | !! *** ROUTINE rstwrite *** |
---|
| 102 | !! |
---|
[632] | 103 | !! ** Purpose : Write restart fields in the format corresponding to jprstlib |
---|
[3] | 104 | !! |
---|
[508] | 105 | !! ** Method : Write in numrow when kt == nitrst in NetCDF |
---|
[2528] | 106 | !! file, save fields which are necessary for restart |
---|
[3] | 107 | !!---------------------------------------------------------------------- |
---|
[508] | 108 | INTEGER, INTENT(in) :: kt ! ocean time-step |
---|
[3] | 109 | !!---------------------------------------------------------------------- |
---|
[1239] | 110 | |
---|
[2528] | 111 | CALL iom_rstput( kt, nitrst, numrow, 'rdt' , rdt ) ! dynamics time step |
---|
| 112 | CALL iom_rstput( kt, nitrst, numrow, 'rdttra1', rdttra(1) ) ! surface tracer time step |
---|
[3] | 113 | |
---|
[2528] | 114 | CALL iom_rstput( kt, nitrst, numrow, 'ub' , ub ) ! before fields |
---|
| 115 | CALL iom_rstput( kt, nitrst, numrow, 'vb' , vb ) |
---|
[3294] | 116 | CALL iom_rstput( kt, nitrst, numrow, 'tb' , tsb(:,:,:,jp_tem) ) |
---|
| 117 | CALL iom_rstput( kt, nitrst, numrow, 'sb' , tsb(:,:,:,jp_sal) ) |
---|
[2528] | 118 | CALL iom_rstput( kt, nitrst, numrow, 'rotb' , rotb ) |
---|
| 119 | CALL iom_rstput( kt, nitrst, numrow, 'hdivb' , hdivb ) |
---|
| 120 | CALL iom_rstput( kt, nitrst, numrow, 'sshb' , sshb ) |
---|
| 121 | IF( lk_vvl ) CALL iom_rstput( kt, nitrst, numrow, 'fse3t_b', fse3t_b(:,:,:) ) |
---|
| 122 | ! |
---|
| 123 | CALL iom_rstput( kt, nitrst, numrow, 'un' , un ) ! now fields |
---|
| 124 | CALL iom_rstput( kt, nitrst, numrow, 'vn' , vn ) |
---|
[3294] | 125 | CALL iom_rstput( kt, nitrst, numrow, 'tn' , tsn(:,:,:,jp_tem) ) |
---|
| 126 | CALL iom_rstput( kt, nitrst, numrow, 'sn' , tsn(:,:,:,jp_sal) ) |
---|
[2528] | 127 | CALL iom_rstput( kt, nitrst, numrow, 'rotn' , rotn ) |
---|
| 128 | CALL iom_rstput( kt, nitrst, numrow, 'hdivn' , hdivn ) |
---|
| 129 | CALL iom_rstput( kt, nitrst, numrow, 'sshn' , sshn ) |
---|
| 130 | CALL iom_rstput( kt, nitrst, numrow, 'rhop' , rhop ) |
---|
[1545] | 131 | #if defined key_zdfkpp |
---|
[2528] | 132 | CALL iom_rstput( kt, nitrst, numrow, 'rhd' , rhd ) |
---|
[1483] | 133 | #endif |
---|
[508] | 134 | IF( kt == nitrst ) THEN |
---|
| 135 | CALL iom_close( numrow ) ! close the restart file (only at last time step) |
---|
[579] | 136 | IF( .NOT. lk_trdmld ) lrst_oce = .FALSE. |
---|
[3] | 137 | ENDIF |
---|
[508] | 138 | ! |
---|
[3] | 139 | END SUBROUTINE rst_write |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | SUBROUTINE rst_read |
---|
| 143 | !!---------------------------------------------------------------------- |
---|
| 144 | !! *** ROUTINE rst_read *** |
---|
| 145 | !! |
---|
[632] | 146 | !! ** Purpose : Read files for restart (format fixed by jprstlib ) |
---|
[3] | 147 | !! |
---|
[1531] | 148 | !! ** Method : Read in restart.nc file fields which are necessary for restart |
---|
[3] | 149 | !!---------------------------------------------------------------------- |
---|
[1130] | 150 | REAL(wp) :: zrdt, zrdttra1 |
---|
[2528] | 151 | INTEGER :: jk, jlibalt = jprstlib |
---|
[1473] | 152 | LOGICAL :: llok |
---|
[3] | 153 | !!---------------------------------------------------------------------- |
---|
| 154 | |
---|
[508] | 155 | IF(lwp) THEN ! Contol prints |
---|
| 156 | WRITE(numout,*) |
---|
[632] | 157 | SELECT CASE ( jprstlib ) |
---|
[1130] | 158 | CASE ( jpnf90 ) ; WRITE(numout,*) 'rst_read : read oce NetCDF restart file' |
---|
| 159 | CASE ( jprstdimg ) ; WRITE(numout,*) 'rst_read : read oce binary restart file' |
---|
[632] | 160 | END SELECT |
---|
[2528] | 161 | IF ( snc4set%luse ) WRITE(numout,*) 'rst_read : configured with NetCDF4 support' |
---|
[508] | 162 | WRITE(numout,*) '~~~~~~~~' |
---|
[3] | 163 | ENDIF |
---|
| 164 | |
---|
[1473] | 165 | IF ( jprstlib == jprstdimg ) THEN |
---|
| 166 | ! eventually read netcdf file (monobloc) for restarting on different number of processors |
---|
| 167 | ! if {cn_ocerst_in}.nc exists, then set jlibalt to jpnf90 |
---|
| 168 | INQUIRE( FILE = TRIM(cn_ocerst_in)//'.nc', EXIST = llok ) |
---|
| 169 | IF ( llok ) THEN ; jlibalt = jpnf90 ; ELSE ; jlibalt = jprstlib ; ENDIF |
---|
| 170 | ENDIF |
---|
| 171 | CALL iom_open( cn_ocerst_in, numror, kiolib = jlibalt ) |
---|
[3] | 172 | |
---|
[544] | 173 | ! Check dynamics and tracer time-step consistency and force Euler restart if changed |
---|
[746] | 174 | IF( iom_varid( numror, 'rdt', ldstop = .FALSE. ) > 0 ) THEN |
---|
[544] | 175 | CALL iom_get( numror, 'rdt', zrdt ) |
---|
| 176 | IF( zrdt /= rdt ) neuler = 0 |
---|
| 177 | ENDIF |
---|
[746] | 178 | IF( iom_varid( numror, 'rdttra1', ldstop = .FALSE. ) > 0 ) THEN |
---|
[544] | 179 | CALL iom_get( numror, 'rdttra1', zrdttra1 ) |
---|
| 180 | IF( zrdttra1 /= rdttra(1) ) neuler = 0 |
---|
| 181 | ENDIF |
---|
[1607] | 182 | ! |
---|
[3653] | 183 | IF( iom_varid( numror, 'ub', ldstop = .FALSE. ) > 0 ) THEN |
---|
| 184 | CALL iom_get( numror, jpdom_autoglo, 'ub' , ub ) ! before fields |
---|
| 185 | CALL iom_get( numror, jpdom_autoglo, 'vb' , vb ) |
---|
| 186 | CALL iom_get( numror, jpdom_autoglo, 'tb' , tsb(:,:,:,jp_tem) ) |
---|
| 187 | CALL iom_get( numror, jpdom_autoglo, 'sb' , tsb(:,:,:,jp_sal) ) |
---|
| 188 | CALL iom_get( numror, jpdom_autoglo, 'rotb' , rotb ) |
---|
| 189 | CALL iom_get( numror, jpdom_autoglo, 'hdivb' , hdivb ) |
---|
| 190 | CALL iom_get( numror, jpdom_autoglo, 'sshb' , sshb ) |
---|
| 191 | IF( lk_vvl ) CALL iom_get( numror, jpdom_autoglo, 'fse3t_b', fse3t_b(:,:,:) ) |
---|
| 192 | ELSE |
---|
| 193 | neuler = 0 |
---|
| 194 | ENDIF |
---|
| 195 | ! |
---|
| 196 | CALL iom_get( numror, jpdom_autoglo, 'un' , un ) ! now fields |
---|
| 197 | CALL iom_get( numror, jpdom_autoglo, 'vn' , vn ) |
---|
| 198 | CALL iom_get( numror, jpdom_autoglo, 'tn' , tsn(:,:,:,jp_tem) ) |
---|
| 199 | CALL iom_get( numror, jpdom_autoglo, 'sn' , tsn(:,:,:,jp_sal) ) |
---|
| 200 | CALL iom_get( numror, jpdom_autoglo, 'sshn' , sshn ) |
---|
| 201 | IF( iom_varid( numror, 'rotn', ldstop = .FALSE. ) > 0 ) THEN |
---|
| 202 | CALL iom_get( numror, jpdom_autoglo, 'rotn' , rotn ) |
---|
| 203 | CALL iom_get( numror, jpdom_autoglo, 'hdivn' , hdivn ) |
---|
| 204 | ELSE |
---|
| 205 | CALL div_cur( 0 ) ! Horizontal divergence & Relative vorticity |
---|
| 206 | ENDIF |
---|
| 207 | IF( iom_varid( numror, 'rhop', ldstop = .FALSE. ) > 0 ) THEN |
---|
| 208 | CALL iom_get( numror, jpdom_autoglo, 'rhop' , rhop ) ! now potential density |
---|
| 209 | ELSE |
---|
| 210 | CALL eos ( tsn, rhd, rhop ) |
---|
| 211 | ENDIF |
---|
[1545] | 212 | #if defined key_zdfkpp |
---|
| 213 | IF( iom_varid( numror, 'rhd', ldstop = .FALSE. ) > 0 ) THEN |
---|
[3653] | 214 | CALL iom_get( numror, jpdom_autoglo, 'rhd' , rhd ) ! now in situ density anomaly |
---|
[1545] | 215 | ELSE |
---|
[3653] | 216 | CALL eos( tsn, rhd ) ! compute rhd |
---|
[1545] | 217 | ENDIF |
---|
[1483] | 218 | #endif |
---|
[2528] | 219 | ! |
---|
[508] | 220 | IF( neuler == 0 ) THEN ! Euler restart (neuler=0) |
---|
[3294] | 221 | tsb (:,:,:,:) = tsn (:,:,:,:) ! all before fields set to now values |
---|
| 222 | ub (:,:,:) = un (:,:,:) |
---|
| 223 | vb (:,:,:) = vn (:,:,:) |
---|
| 224 | rotb (:,:,:) = rotn (:,:,:) |
---|
| 225 | hdivb(:,:,:) = hdivn(:,:,:) |
---|
| 226 | sshb (:,:) = sshn (:,:) |
---|
[2528] | 227 | IF( lk_vvl ) THEN |
---|
| 228 | DO jk = 1, jpk |
---|
| 229 | fse3t_b(:,:,jk) = fse3t_n(:,:,jk) |
---|
| 230 | END DO |
---|
| 231 | ENDIF |
---|
[3] | 232 | ENDIF |
---|
[508] | 233 | ! |
---|
| 234 | END SUBROUTINE rst_read |
---|
[473] | 235 | |
---|
[3] | 236 | !!===================================================================== |
---|
| 237 | END MODULE restart |
---|