[268] | 1 | MODULE trcrst |
---|
[335] | 2 | !!====================================================================== |
---|
[1801] | 3 | !! *** MODULE trcrst *** |
---|
| 4 | !! TOP : Manage the passive tracer restart |
---|
[335] | 5 | !!====================================================================== |
---|
[1801] | 6 | !! History : - ! 1991-03 () original code |
---|
| 7 | !! 1.0 ! 2005-03 (O. Aumont, A. El Moussaoui) F90 |
---|
| 8 | !! - ! 2005-10 (C. Ethe) print control |
---|
| 9 | !! 2.0 ! 2005-10 (C. Ethe, G. Madec) revised architecture |
---|
[274] | 10 | !!---------------------------------------------------------------------- |
---|
[945] | 11 | #if defined key_top |
---|
[335] | 12 | !!---------------------------------------------------------------------- |
---|
[945] | 13 | !! 'key_top' TOP models |
---|
| 14 | !!---------------------------------------------------------------------- |
---|
[1801] | 15 | !!---------------------------------------------------------------------- |
---|
[6140] | 16 | !! trc_rst : Restart for passive tracer |
---|
[945] | 17 | !! trc_rst_opn : open restart file |
---|
| 18 | !! trc_rst_read : read restart file |
---|
| 19 | !! trc_rst_wri : write restart file |
---|
| 20 | !!---------------------------------------------------------------------- |
---|
[335] | 21 | USE oce_trc |
---|
| 22 | USE trc |
---|
[616] | 23 | USE iom |
---|
[2528] | 24 | USE daymod |
---|
[6140] | 25 | |
---|
[335] | 26 | IMPLICIT NONE |
---|
| 27 | PRIVATE |
---|
[1801] | 28 | |
---|
[945] | 29 | PUBLIC trc_rst_opn ! called by ??? |
---|
| 30 | PUBLIC trc_rst_read ! called by ??? |
---|
| 31 | PUBLIC trc_rst_wri ! called by ??? |
---|
[3294] | 32 | PUBLIC trc_rst_cal |
---|
[1801] | 33 | |
---|
[6140] | 34 | !!---------------------------------------------------------------------- |
---|
| 35 | !! NEMO/TOP 3.7 , NEMO Consortium (2010) |
---|
| 36 | !! $Id$ |
---|
| 37 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
| 38 | !!---------------------------------------------------------------------- |
---|
[268] | 39 | CONTAINS |
---|
[335] | 40 | |
---|
[616] | 41 | SUBROUTINE trc_rst_opn( kt ) |
---|
| 42 | !!---------------------------------------------------------------------- |
---|
| 43 | !! *** trc_rst_opn *** |
---|
| 44 | !! |
---|
| 45 | !! ** purpose : output of sea-trc variable in a netcdf file |
---|
| 46 | !!---------------------------------------------------------------------- |
---|
| 47 | INTEGER, INTENT(in) :: kt ! number of iteration |
---|
| 48 | ! |
---|
| 49 | CHARACTER(LEN=20) :: clkt ! ocean time-step define as a character |
---|
| 50 | CHARACTER(LEN=50) :: clname ! trc output restart file name |
---|
[5341] | 51 | CHARACTER(LEN=256) :: clpath ! full path to ocean output restart file |
---|
[616] | 52 | !!---------------------------------------------------------------------- |
---|
| 53 | ! |
---|
[2528] | 54 | IF( lk_offline ) THEN |
---|
[3294] | 55 | IF( kt == nittrc000 ) THEN |
---|
[2528] | 56 | lrst_trc = .FALSE. |
---|
[5341] | 57 | IF( ln_rst_list ) THEN |
---|
| 58 | nrst_lst = 1 |
---|
| 59 | nitrst = nstocklist( nrst_lst ) |
---|
| 60 | ELSE |
---|
| 61 | nitrst = nitend |
---|
| 62 | ENDIF |
---|
[2528] | 63 | ENDIF |
---|
| 64 | |
---|
[5341] | 65 | IF( .NOT. ln_rst_list .AND. MOD( kt - 1, nstock ) == 0 ) THEN |
---|
[3294] | 66 | ! we use kt - 1 and not kt - nittrc000 to keep the same periodicity from the beginning of the experiment |
---|
[2528] | 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 | ELSE |
---|
[3294] | 71 | IF( kt == nittrc000 ) lrst_trc = .FALSE. |
---|
[1655] | 72 | ENDIF |
---|
| 73 | |
---|
[2528] | 74 | ! to get better performances with NetCDF format: |
---|
| 75 | ! we open and define the tracer restart file one tracer time step before writing the data (-> at nitrst - 2*nn_dttrc + 1) |
---|
| 76 | ! except if we write tracer restart files every tracer time step or if a tracer restart file was writen at nitend - 2*nn_dttrc + 1 |
---|
[3294] | 77 | IF( kt == nitrst - 2*nn_dttrc .OR. nstock == nn_dttrc .OR. ( kt == nitend - nn_dttrc .AND. .NOT. lrst_trc ) ) THEN |
---|
[616] | 78 | ! beware of the format used to write kt (default is i8.8, that should be large enough) |
---|
[945] | 79 | IF( nitrst > 1.0e9 ) THEN ; WRITE(clkt,* ) nitrst |
---|
| 80 | ELSE ; WRITE(clkt,'(i8.8)') nitrst |
---|
[616] | 81 | ENDIF |
---|
| 82 | ! create the file |
---|
| 83 | IF(lwp) WRITE(numout,*) |
---|
[1254] | 84 | clname = TRIM(cexper)//"_"//TRIM(ADJUSTL(clkt))//"_"//TRIM(cn_trcrst_out) |
---|
[5341] | 85 | clpath = TRIM(cn_trcrst_outdir) |
---|
| 86 | IF( clpath(LEN_TRIM(clpath):) /= '/' ) clpath = TRIM(clpath) // '/' |
---|
| 87 | IF(lwp) WRITE(numout,*) & |
---|
| 88 | ' open trc restart.output NetCDF file: ',TRIM(clpath)//clname |
---|
| 89 | CALL iom_open( TRIM(clpath)//TRIM(clname), numrtw, ldwrt = .TRUE., kiolib = jprstlib ) |
---|
[616] | 90 | lrst_trc = .TRUE. |
---|
| 91 | ENDIF |
---|
| 92 | ! |
---|
| 93 | END SUBROUTINE trc_rst_opn |
---|
| 94 | |
---|
[1801] | 95 | SUBROUTINE trc_rst_read |
---|
[945] | 96 | !!---------------------------------------------------------------------- |
---|
| 97 | !! *** trc_rst_opn *** |
---|
[335] | 98 | !! |
---|
[945] | 99 | !! ** purpose : read passive tracer fields in restart files |
---|
| 100 | !!---------------------------------------------------------------------- |
---|
[1801] | 101 | INTEGER :: jn |
---|
[1287] | 102 | |
---|
[945] | 103 | !!---------------------------------------------------------------------- |
---|
[3294] | 104 | ! |
---|
[945] | 105 | IF(lwp) WRITE(numout,*) |
---|
[3294] | 106 | IF(lwp) WRITE(numout,*) 'trc_rst_read : read data in the TOP restart file' |
---|
[945] | 107 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~' |
---|
[350] | 108 | |
---|
[945] | 109 | ! READ prognostic variables and computes diagnostic variable |
---|
[494] | 110 | DO jn = 1, jptra |
---|
[1801] | 111 | CALL iom_get( numrtr, jpdom_autoglo, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) ) |
---|
[335] | 112 | END DO |
---|
[1077] | 113 | |
---|
[1287] | 114 | DO jn = 1, jptra |
---|
[1801] | 115 | CALL iom_get( numrtr, jpdom_autoglo, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) ) |
---|
[1077] | 116 | END DO |
---|
[945] | 117 | ! |
---|
| 118 | END SUBROUTINE trc_rst_read |
---|
[494] | 119 | |
---|
[945] | 120 | SUBROUTINE trc_rst_wri( kt ) |
---|
| 121 | !!---------------------------------------------------------------------- |
---|
| 122 | !! *** trc_rst_wri *** |
---|
[335] | 123 | !! |
---|
[945] | 124 | !! ** purpose : write passive tracer fields in restart files |
---|
| 125 | !!---------------------------------------------------------------------- |
---|
| 126 | INTEGER, INTENT( in ) :: kt ! ocean time-step index |
---|
[335] | 127 | !! |
---|
[1287] | 128 | INTEGER :: jn |
---|
| 129 | REAL(wp) :: zarak0 |
---|
[945] | 130 | !!---------------------------------------------------------------------- |
---|
[3294] | 131 | ! |
---|
[6140] | 132 | CALL iom_rstput( kt, nitrst, numrtw, 'rdttrc1', rdttrc ) ! passive tracer time step |
---|
[1801] | 133 | ! prognostic variables |
---|
| 134 | ! -------------------- |
---|
[1100] | 135 | DO jn = 1, jptra |
---|
| 136 | CALL iom_rstput( kt, nitrst, numrtw, 'TRN'//ctrcnm(jn), trn(:,:,:,jn) ) |
---|
| 137 | END DO |
---|
[1077] | 138 | |
---|
[1100] | 139 | DO jn = 1, jptra |
---|
| 140 | CALL iom_rstput( kt, nitrst, numrtw, 'TRB'//ctrcnm(jn), trb(:,:,:,jn) ) |
---|
| 141 | END DO |
---|
[3680] | 142 | ! |
---|
[1287] | 143 | IF( kt == nitrst ) THEN |
---|
[1119] | 144 | CALL trc_rst_stat ! statistics |
---|
[1100] | 145 | CALL iom_close( numrtw ) ! close the restart file (only at last time step) |
---|
[4990] | 146 | #if ! defined key_trdmxl_trc |
---|
[1100] | 147 | lrst_trc = .FALSE. |
---|
[1177] | 148 | #endif |
---|
[5341] | 149 | IF( lk_offline .AND. ln_rst_list ) THEN |
---|
| 150 | nrst_lst = nrst_lst + 1 |
---|
| 151 | nitrst = nstocklist( nrst_lst ) |
---|
| 152 | ENDIF |
---|
[1287] | 153 | ENDIF |
---|
[945] | 154 | ! |
---|
[1801] | 155 | END SUBROUTINE trc_rst_wri |
---|
[268] | 156 | |
---|
[1801] | 157 | |
---|
[1287] | 158 | SUBROUTINE trc_rst_cal( kt, cdrw ) |
---|
| 159 | !!--------------------------------------------------------------------- |
---|
| 160 | !! *** ROUTINE trc_rst_cal *** |
---|
| 161 | !! |
---|
| 162 | !! ** Purpose : Read or write calendar in restart file: |
---|
| 163 | !! |
---|
| 164 | !! WRITE(READ) mode: |
---|
| 165 | !! kt : number of time step since the begining of the experiment at the |
---|
| 166 | !! end of the current(previous) run |
---|
| 167 | !! adatrj(0) : number of elapsed days since the begining of the experiment at the |
---|
| 168 | !! end of the current(previous) run (REAL -> keep fractions of day) |
---|
| 169 | !! ndastp : date at the end of the current(previous) run (coded as yyyymmdd integer) |
---|
| 170 | !! |
---|
| 171 | !! According to namelist parameter nrstdt, |
---|
[3294] | 172 | !! nn_rsttr = 0 no control on the date (nittrc000 is arbitrary). |
---|
| 173 | !! nn_rsttr = 1 we verify that nittrc000 is equal to the last |
---|
[1287] | 174 | !! time step of previous run + 1. |
---|
| 175 | !! In both those options, the exact duration of the experiment |
---|
| 176 | !! since the beginning (cumulated duration of all previous restart runs) |
---|
[3294] | 177 | !! is not stored in the restart and is assumed to be (nittrc000-1)*rdt. |
---|
[1287] | 178 | !! This is valid is the time step has remained constant. |
---|
| 179 | !! |
---|
[2528] | 180 | !! nn_rsttr = 2 the duration of the experiment in days (adatrj) |
---|
[1287] | 181 | !! has been stored in the restart file. |
---|
| 182 | !!---------------------------------------------------------------------- |
---|
| 183 | INTEGER , INTENT(in) :: kt ! ocean time-step |
---|
| 184 | CHARACTER(len=*), INTENT(in) :: cdrw ! "READ"/"WRITE" flag |
---|
| 185 | ! |
---|
[3294] | 186 | INTEGER :: jlibalt = jprstlib |
---|
| 187 | LOGICAL :: llok |
---|
[2528] | 188 | REAL(wp) :: zkt, zrdttrc1 |
---|
[1287] | 189 | REAL(wp) :: zndastp |
---|
| 190 | |
---|
| 191 | ! Time domain : restart |
---|
| 192 | ! --------------------- |
---|
| 193 | |
---|
| 194 | IF( TRIM(cdrw) == 'READ' ) THEN |
---|
[3294] | 195 | |
---|
| 196 | IF(lwp) WRITE(numout,*) |
---|
| 197 | IF(lwp) WRITE(numout,*) 'trc_rst_cal : read the TOP restart file for calendar' |
---|
| 198 | IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~' |
---|
| 199 | |
---|
[5513] | 200 | IF( ln_rsttr ) THEN |
---|
| 201 | CALL iom_open( TRIM(cn_trcrst_indir)//'/'//cn_trcrst_in, numrtr, kiolib = jlibalt ) |
---|
| 202 | CALL iom_get ( numrtr, 'kt', zkt ) ! last time-step of previous run |
---|
[3294] | 203 | |
---|
[5513] | 204 | IF(lwp) THEN |
---|
| 205 | WRITE(numout,*) ' *** Info read in restart : ' |
---|
| 206 | WRITE(numout,*) ' previous time-step : ', NINT( zkt ) |
---|
| 207 | WRITE(numout,*) ' *** restart option' |
---|
| 208 | SELECT CASE ( nn_rsttr ) |
---|
| 209 | CASE ( 0 ) ; WRITE(numout,*) ' nn_rsttr = 0 : no control of nittrc000' |
---|
| 210 | CASE ( 1 ) ; WRITE(numout,*) ' nn_rsttr = 1 : no control the date at nittrc000 (use ndate0 read in the namelist)' |
---|
| 211 | CASE ( 2 ) ; WRITE(numout,*) ' nn_rsttr = 2 : calendar parameters read in restart' |
---|
| 212 | END SELECT |
---|
| 213 | WRITE(numout,*) |
---|
| 214 | ENDIF |
---|
| 215 | ! Control of date |
---|
| 216 | IF( nittrc000 - NINT( zkt ) /= nn_dttrc .AND. nn_rsttr /= 0 ) & |
---|
| 217 | & CALL ctl_stop( ' ===>>>> : problem with nittrc000 for the restart', & |
---|
| 218 | & ' verify the restart file or rerun with nn_rsttr = 0 (namelist)' ) |
---|
[1287] | 219 | ENDIF |
---|
[5513] | 220 | ! |
---|
[5504] | 221 | IF( lk_offline ) THEN |
---|
| 222 | ! ! set the date in offline mode |
---|
| 223 | IF( ln_rsttr .AND. nn_rsttr == 2 ) THEN |
---|
[2528] | 224 | CALL iom_get( numrtr, 'ndastp', zndastp ) |
---|
| 225 | ndastp = NINT( zndastp ) |
---|
| 226 | CALL iom_get( numrtr, 'adatrj', adatrj ) |
---|
[5504] | 227 | ELSE |
---|
[2528] | 228 | ndastp = ndate0 - 1 ! ndate0 read in the namelist in dom_nam |
---|
[6140] | 229 | adatrj = ( REAL( nittrc000-1, wp ) * rdt ) / rday |
---|
[2528] | 230 | ! note this is wrong if time step has changed during run |
---|
| 231 | ENDIF |
---|
| 232 | ! |
---|
| 233 | IF(lwp) THEN |
---|
| 234 | WRITE(numout,*) ' *** Info used values : ' |
---|
| 235 | WRITE(numout,*) ' date ndastp : ', ndastp |
---|
| 236 | WRITE(numout,*) ' number of elapsed days since the begining of run : ', adatrj |
---|
| 237 | WRITE(numout,*) |
---|
| 238 | ENDIF |
---|
| 239 | ! |
---|
[5504] | 240 | IF( ln_rsttr ) THEN ; neuler = 1 |
---|
| 241 | ELSE ; neuler = 0 |
---|
| 242 | ENDIF |
---|
| 243 | ! |
---|
[2528] | 244 | CALL day_init ! compute calendar |
---|
| 245 | ! |
---|
[1287] | 246 | ENDIF |
---|
| 247 | ! |
---|
| 248 | ELSEIF( TRIM(cdrw) == 'WRITE' ) THEN |
---|
| 249 | ! |
---|
| 250 | IF( kt == nitrst ) THEN |
---|
| 251 | IF(lwp) WRITE(numout,*) |
---|
| 252 | IF(lwp) WRITE(numout,*) 'trc_wri : write the TOP restart file (NetCDF) at it= ', kt, ' date= ', ndastp |
---|
| 253 | IF(lwp) WRITE(numout,*) '~~~~~~~' |
---|
| 254 | ENDIF |
---|
| 255 | CALL iom_rstput( kt, nitrst, numrtw, 'kt' , REAL( kt , wp) ) ! time-step |
---|
| 256 | CALL iom_rstput( kt, nitrst, numrtw, 'ndastp' , REAL( ndastp, wp) ) ! date |
---|
| 257 | CALL iom_rstput( kt, nitrst, numrtw, 'adatrj' , adatrj ) ! number of elapsed days since |
---|
| 258 | ! ! the begining of the run [s] |
---|
| 259 | ENDIF |
---|
| 260 | |
---|
| 261 | END SUBROUTINE trc_rst_cal |
---|
| 262 | |
---|
[1119] | 263 | |
---|
| 264 | SUBROUTINE trc_rst_stat |
---|
| 265 | !!---------------------------------------------------------------------- |
---|
| 266 | !! *** trc_rst_stat *** |
---|
| 267 | !! |
---|
| 268 | !! ** purpose : Compute tracers statistics |
---|
| 269 | !!---------------------------------------------------------------------- |
---|
[3294] | 270 | INTEGER :: jk, jn |
---|
| 271 | REAL(wp) :: ztraf, zmin, zmax, zmean, zdrift |
---|
[5385] | 272 | REAL(wp), DIMENSION(jpi,jpj,jpk) :: zvol |
---|
[1119] | 273 | !!---------------------------------------------------------------------- |
---|
| 274 | |
---|
| 275 | IF( lwp ) THEN |
---|
| 276 | WRITE(numout,*) |
---|
| 277 | WRITE(numout,*) ' ----TRACER STAT---- ' |
---|
| 278 | WRITE(numout,*) |
---|
| 279 | ENDIF |
---|
[3294] | 280 | ! |
---|
[5385] | 281 | DO jk = 1, jpk |
---|
[6140] | 282 | zvol(:,:,jk) = e1e2t(:,:) * e3t_a(:,:,jk) * tmask(:,:,jk) |
---|
[5385] | 283 | END DO |
---|
| 284 | ! |
---|
[1119] | 285 | DO jn = 1, jptra |
---|
[5385] | 286 | ztraf = glob_sum( trn(:,:,:,jn) * zvol(:,:,:) ) |
---|
[3294] | 287 | zmin = MINVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) ) |
---|
| 288 | zmax = MAXVAL( trn(:,:,:,jn), mask= ((tmask*SPREAD(tmask_i,DIM=3,NCOPIES=jpk).NE.0.)) ) |
---|
[1119] | 289 | IF( lk_mpp ) THEN |
---|
[3294] | 290 | CALL mpp_min( zmin ) ! min over the global domain |
---|
| 291 | CALL mpp_max( zmax ) ! max over the global domain |
---|
[1119] | 292 | END IF |
---|
[3294] | 293 | zmean = ztraf / areatot |
---|
| 294 | zdrift = ( ( ztraf - trai(jn) ) / ( trai(jn) + 1.e-12 ) ) * 100._wp |
---|
| 295 | IF(lwp) WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), zmean, zmin, zmax, zdrift |
---|
[1119] | 296 | END DO |
---|
[3294] | 297 | WRITE(numout,*) |
---|
| 298 | 9000 FORMAT(' tracer nb :',i2,' name :',a10,' mean :',e18.10,' min :',e18.10, & |
---|
| 299 | & ' max :',e18.10,' drift :',e18.10, ' %') |
---|
| 300 | ! |
---|
[1119] | 301 | END SUBROUTINE trc_rst_stat |
---|
| 302 | |
---|
[268] | 303 | #else |
---|
[945] | 304 | !!---------------------------------------------------------------------- |
---|
| 305 | !! Dummy module : No passive tracer |
---|
| 306 | !!---------------------------------------------------------------------- |
---|
[335] | 307 | CONTAINS |
---|
[945] | 308 | SUBROUTINE trc_rst_read ! Empty routines |
---|
[616] | 309 | END SUBROUTINE trc_rst_read |
---|
[945] | 310 | SUBROUTINE trc_rst_wri( kt ) |
---|
[335] | 311 | INTEGER, INTENT ( in ) :: kt |
---|
[616] | 312 | WRITE(*,*) 'trc_rst_wri: You should not have seen this print! error?', kt |
---|
[945] | 313 | END SUBROUTINE trc_rst_wri |
---|
[268] | 314 | #endif |
---|
[945] | 315 | |
---|
[2528] | 316 | !!---------------------------------------------------------------------- |
---|
| 317 | !! NEMO/TOP 3.3 , NEMO Consortium (2010) |
---|
[5341] | 318 | !! $Id$ |
---|
[2528] | 319 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
[945] | 320 | !!====================================================================== |
---|
[335] | 321 | END MODULE trcrst |
---|