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