[2128] | 1 | MODULE asmtrj |
---|
| 2 | !!====================================================================== |
---|
| 3 | !! *** MODULE asmtrj *** |
---|
[2399] | 4 | !! Assimilation trajectory interface: Write to file the background state and the model state trajectory |
---|
[2128] | 5 | !!====================================================================== |
---|
[2399] | 6 | !! History : ! 2007-03 (M. Martin) Met. Office version |
---|
| 7 | !! ! 2007-04 (A. Weaver) asm_trj_wri, original code |
---|
| 8 | !! ! 2007-03 (K. Mogensen) Adapt to NEMOVAR and use IOM instead of IOIPSL |
---|
| 9 | !! ! 2007-04 (A. Weaver) Name change (formally asmbkg.F90). Distinguish |
---|
| 10 | !! background states in Jb term and at analysis time. |
---|
| 11 | !! Include state trajectory routine (currently empty) |
---|
| 12 | !! ! 2007-07 (A. Weaver) Add tke_rst and flt_rst for case nitbkg=0 |
---|
| 13 | !! ! 2009-03 (F. Vigilant) Add hmlp (zdfmxl) for no tracer nmldp=2 |
---|
| 14 | !! ! 2009-06 (F. Vigilant) asm_trj_wri: special case when kt=nit000-1 |
---|
| 15 | !! ! 2009-07 (F. Vigilant) asm_trj_wri: add computation of eiv at restart |
---|
| 16 | !!---------------------------------------------------------------------- |
---|
[2128] | 17 | |
---|
| 18 | !!---------------------------------------------------------------------- |
---|
| 19 | !! 'key_asminc' : Switch on the assimilation increment interface |
---|
| 20 | !!---------------------------------------------------------------------- |
---|
| 21 | !! asm_bkg_wri : Write out the background state |
---|
| 22 | !! asm_trj_wri : Write out the model state trajectory (used with 4D-Var) |
---|
| 23 | !!---------------------------------------------------------------------- |
---|
| 24 | USE oce ! Dynamics and active tracers defined in memory |
---|
| 25 | USE sbc_oce ! Ocean surface boundary conditions |
---|
| 26 | USE zdf_oce ! Vertical mixing variables |
---|
| 27 | USE zdfddm ! Double diffusion mixing parameterization |
---|
| 28 | USE ldftra_oce ! Lateral tracer mixing coefficient defined in memory |
---|
| 29 | USE ldfslp ! Slopes of neutral surfaces |
---|
| 30 | USE tradmp ! Tracer damping |
---|
| 31 | #if defined key_zdftke |
---|
| 32 | USE zdftke ! TKE vertical physics |
---|
| 33 | #endif |
---|
| 34 | USE eosbn2 ! Equation of state (eos_bn2 routine) |
---|
| 35 | USE zdfmxl ! Mixed layer depth |
---|
[2399] | 36 | USE dom_oce, ONLY : ndastp |
---|
| 37 | USE sol_oce, ONLY : gcx ! Solver variables defined in memory |
---|
| 38 | USE in_out_manager ! I/O manager |
---|
| 39 | USE iom ! I/O module |
---|
| 40 | USE asmpar ! Parameters for the assmilation interface |
---|
| 41 | USE zdfmxl ! mixed layer depth |
---|
[2128] | 42 | #if defined key_traldf_c2d |
---|
[2399] | 43 | USE ldfeiv ! eddy induced velocity coef. (ldf_eiv routine) |
---|
[2128] | 44 | #endif |
---|
| 45 | |
---|
| 46 | IMPLICIT NONE |
---|
| 47 | PRIVATE |
---|
[2399] | 48 | |
---|
| 49 | PUBLIC asm_bkg_wri !: Write out the background state |
---|
| 50 | PUBLIC asm_trj_wri !: Write out the background state |
---|
[2128] | 51 | |
---|
[3211] | 52 | !! * Control permutation of array indices |
---|
| 53 | # include "oce_ftrans.h90" |
---|
| 54 | # include "sbc_oce_ftrans.h90" |
---|
| 55 | # include "zdf_oce_ftrans.h90" |
---|
| 56 | # include "zdfddm_ftrans.h90" |
---|
| 57 | # include "ldftra_oce_ftrans.h90" |
---|
| 58 | # include "ldfslp_ftrans.h90" |
---|
| 59 | # include "tradmp_ftrans.h90" |
---|
| 60 | #if defined key_zdftke |
---|
| 61 | # include "zdftke_ftrans.h90" |
---|
| 62 | #endif |
---|
| 63 | |
---|
[2287] | 64 | !!---------------------------------------------------------------------- |
---|
| 65 | !! NEMO/OPA 3.3 , NEMO Consortium (2010) |
---|
| 66 | !! $Id$ |
---|
[2399] | 67 | !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
[2287] | 68 | !!---------------------------------------------------------------------- |
---|
[2128] | 69 | CONTAINS |
---|
| 70 | |
---|
| 71 | SUBROUTINE asm_bkg_wri( kt ) |
---|
| 72 | !!----------------------------------------------------------------------- |
---|
| 73 | !! *** ROUTINE asm_bkg_wri *** |
---|
| 74 | !! |
---|
| 75 | !! ** Purpose : Write to file the background state for later use in the |
---|
| 76 | !! inner loop of data assimilation or for direct initialization |
---|
| 77 | !! in the outer loop. |
---|
| 78 | !! |
---|
| 79 | !! ** Method : Write out the background state for use in the Jb term |
---|
| 80 | !! in the cost function and for use with direct initialization |
---|
| 81 | !! at analysis time. |
---|
| 82 | !!----------------------------------------------------------------------- |
---|
| 83 | INTEGER, INTENT( IN ) :: kt ! Current time-step |
---|
[2399] | 84 | ! |
---|
[2128] | 85 | CHARACTER (LEN=50) :: cl_asmbkg |
---|
| 86 | CHARACTER (LEN=50) :: cl_asmdin |
---|
| 87 | LOGICAL :: llok ! Check if file exists |
---|
| 88 | INTEGER :: inum ! File unit number |
---|
| 89 | REAL(wp) :: zdate ! Date |
---|
[2399] | 90 | !!----------------------------------------------------------------------- |
---|
[2128] | 91 | |
---|
[2399] | 92 | ! !------------------------------------------- |
---|
| 93 | IF( kt == nitbkg_r ) THEN ! Write out background at time step nitbkg_r |
---|
| 94 | ! !-----------------------------------======== |
---|
| 95 | ! |
---|
[2128] | 96 | WRITE(cl_asmbkg, FMT='(A,".nc")' ) TRIM( c_asmbkg ) |
---|
| 97 | cl_asmbkg = TRIM( cl_asmbkg ) |
---|
| 98 | INQUIRE( FILE = cl_asmbkg, EXIST = llok ) |
---|
[2399] | 99 | ! |
---|
[2128] | 100 | IF( .NOT. llok ) THEN |
---|
[2399] | 101 | IF(lwp) WRITE(numout,*) ' Setting up assimilation background file '// TRIM( c_asmbkg ) |
---|
| 102 | ! |
---|
| 103 | ! ! Define the output file |
---|
[2128] | 104 | CALL iom_open( c_asmbkg, inum, ldwrt = .TRUE., kiolib = jprstlib) |
---|
[2399] | 105 | ! |
---|
| 106 | IF( nitbkg_r == nit000 - 1 ) THEN ! Treat special case when nitbkg = 0 |
---|
[2128] | 107 | zdate = REAL( ndastp ) |
---|
| 108 | #if defined key_zdftke |
---|
[2399] | 109 | ! lk_zdftke=T : Read turbulent kinetic energy ( en ) |
---|
[2128] | 110 | IF(lwp) WRITE(numout,*) ' Reading TKE (en) from restart...' |
---|
[2399] | 111 | CALL tke_rst( nit000, 'READ' ) ! lk_zdftke=T : Read turbulent kinetic energy ( en ) |
---|
| 112 | |
---|
[2128] | 113 | #endif |
---|
| 114 | ELSE |
---|
| 115 | zdate = REAL( ndastp ) |
---|
| 116 | ENDIF |
---|
[2399] | 117 | ! |
---|
| 118 | ! ! Write the information |
---|
[2128] | 119 | CALL iom_rstput( kt, nitbkg_r, inum, 'rdastp' , zdate ) |
---|
| 120 | CALL iom_rstput( kt, nitbkg_r, inum, 'un' , un ) |
---|
| 121 | CALL iom_rstput( kt, nitbkg_r, inum, 'vn' , vn ) |
---|
| 122 | CALL iom_rstput( kt, nitbkg_r, inum, 'tn' , tn ) |
---|
| 123 | CALL iom_rstput( kt, nitbkg_r, inum, 'sn' , sn ) |
---|
| 124 | CALL iom_rstput( kt, nitbkg_r, inum, 'sshn' , sshn ) |
---|
| 125 | #if defined key_zdftke |
---|
| 126 | CALL iom_rstput( kt, nitbkg_r, inum, 'en' , en ) |
---|
| 127 | #endif |
---|
| 128 | CALL iom_rstput( kt, nitbkg_r, inum, 'gcx' , gcx ) |
---|
[2399] | 129 | ! |
---|
[2128] | 130 | CALL iom_close( inum ) |
---|
| 131 | ENDIF |
---|
[2399] | 132 | ! |
---|
[2128] | 133 | ENDIF |
---|
| 134 | |
---|
[2399] | 135 | ! !------------------------------------------- |
---|
| 136 | IF( kt == nitdin_r ) THEN ! Write out background at time step nitdin_r |
---|
| 137 | ! !-----------------------------------======== |
---|
| 138 | ! |
---|
[2128] | 139 | WRITE(cl_asmdin, FMT='(A,".nc")' ) TRIM( c_asmdin ) |
---|
| 140 | cl_asmdin = TRIM( cl_asmdin ) |
---|
| 141 | INQUIRE( FILE = cl_asmdin, EXIST = llok ) |
---|
[2399] | 142 | ! |
---|
[2128] | 143 | IF( .NOT. llok ) THEN |
---|
[2399] | 144 | IF(lwp) WRITE(numout,*) ' Setting up assimilation background file '// TRIM( c_asmdin ) |
---|
| 145 | ! |
---|
| 146 | ! ! Define the output file |
---|
[2128] | 147 | CALL iom_open( c_asmdin, inum, ldwrt = .TRUE., kiolib = jprstlib) |
---|
[2399] | 148 | ! |
---|
| 149 | IF( nitdin_r == nit000 - 1 ) THEN ! Treat special case when nitbkg = 0 |
---|
[2128] | 150 | |
---|
| 151 | zdate = REAL( ndastp ) |
---|
| 152 | ELSE |
---|
| 153 | zdate = REAL( ndastp ) |
---|
| 154 | ENDIF |
---|
[2399] | 155 | ! |
---|
| 156 | ! ! Write the information |
---|
[2128] | 157 | CALL iom_rstput( kt, nitdin_r, inum, 'rdastp' , zdate ) |
---|
| 158 | CALL iom_rstput( kt, nitdin_r, inum, 'un' , un ) |
---|
| 159 | CALL iom_rstput( kt, nitdin_r, inum, 'vn' , vn ) |
---|
| 160 | CALL iom_rstput( kt, nitdin_r, inum, 'tn' , tn ) |
---|
| 161 | CALL iom_rstput( kt, nitdin_r, inum, 'sn' , sn ) |
---|
| 162 | CALL iom_rstput( kt, nitdin_r, inum, 'sshn' , sshn ) |
---|
[2399] | 163 | ! |
---|
[2128] | 164 | CALL iom_close( inum ) |
---|
| 165 | ENDIF |
---|
[2399] | 166 | ! |
---|
[2128] | 167 | ENDIF |
---|
[2399] | 168 | ! |
---|
[2128] | 169 | END SUBROUTINE asm_bkg_wri |
---|
| 170 | |
---|
[2399] | 171 | |
---|
[2128] | 172 | SUBROUTINE asm_trj_wri( kt ) |
---|
| 173 | !!----------------------------------------------------------------------- |
---|
| 174 | !! *** ROUTINE asm_trj_wri *** |
---|
| 175 | !! |
---|
[2399] | 176 | !! ** Purpose : Write to file the model state trajectory for use with 4D-Var. |
---|
[2128] | 177 | !!----------------------------------------------------------------------- |
---|
| 178 | INTEGER, INTENT( IN ) :: kt ! Current time-step |
---|
[2399] | 179 | ! |
---|
[2128] | 180 | INTEGER :: inum ! File unit number |
---|
| 181 | INTEGER :: it |
---|
| 182 | CHARACTER (LEN=50) :: cl_asmtrj |
---|
| 183 | REAL(wp) :: zdate ! Date |
---|
[2399] | 184 | !!----------------------------------------------------------------------- |
---|
[2128] | 185 | |
---|
| 186 | !------------------------------------------------------------------------ |
---|
| 187 | ! Write a single file for each trajectory time step |
---|
| 188 | !------------------------------------------------------------------------ |
---|
[2399] | 189 | IF( ( MOD( kt - nit000 + 1, nittrjfrq ) == 0 ) .OR. ( kt == nitend ) ) THEN |
---|
[2128] | 190 | |
---|
[2399] | 191 | IF( kt == nit000 - 1 ) THEN ! Treat special case when kt = nit000-1 |
---|
| 192 | ! |
---|
[2128] | 193 | #if defined key_zdftke |
---|
| 194 | IF(lwp) WRITE(numout,*) ' Computing zdf_tke coeff. form restart...' |
---|
| 195 | ! Compute the vertical eddy viscosity and diffusivity coefficients |
---|
| 196 | CALL zdf_tke( nit000 ) |
---|
| 197 | #endif |
---|
| 198 | #if defined key_zdfddm |
---|
| 199 | IF(lwp) WRITE(numout,*) ' Computing zdf_ddm coeff. from restart...' |
---|
| 200 | ! Compute the vertical eddy viscosity and diffusivity coefficients (salt effect) |
---|
| 201 | CALL zdf_ddm( nit000 ) |
---|
| 202 | #endif |
---|
| 203 | IF(lwp) WRITE(numout,*) ' Computing zdf_mxl coeff. from restart...' |
---|
| 204 | ! Compute the turbocline depth and the mixed layer depth |
---|
| 205 | CALL zdf_mxl( nit000 ) |
---|
| 206 | #if defined key_ldfslp |
---|
| 207 | IF(lwp) WRITE(numout,*) ' Compute the slopes of neutral surface...' |
---|
[2239] | 208 | CALL bn2( tsb, rn2 ) |
---|
[2128] | 209 | CALL ldf_slp( nit000, rhd, rn2 ) |
---|
| 210 | #endif |
---|
| 211 | #if defined key_traldf_c2d |
---|
| 212 | IF(lwp) WRITE(numout,*) ' Computing ldf_eiv coeff. from restart...' |
---|
| 213 | ! Compute eddy induced velocity coefficient |
---|
| 214 | IF( lk_traldf_eiv ) CALL ldf_eiv( nit000 ) |
---|
| 215 | #endif |
---|
[2399] | 216 | ENDIF |
---|
| 217 | ! |
---|
[2128] | 218 | it = kt - nit000 + 1 |
---|
[2399] | 219 | ! |
---|
| 220 | ! ! Define the output file |
---|
[2128] | 221 | WRITE(cl_asmtrj, FMT='(A,A,I5.5)' ) TRIM( c_asmtrj ), '_', it |
---|
| 222 | cl_asmtrj = TRIM( cl_asmtrj ) |
---|
| 223 | CALL iom_open( cl_asmtrj, inum, ldwrt = .TRUE., kiolib = jprstlib) |
---|
[2399] | 224 | ! |
---|
| 225 | ! ! Output trajectory fields |
---|
[2128] | 226 | CALL iom_rstput( it, it, inum, 'emp' , emp ) |
---|
| 227 | CALL iom_rstput( it, it, inum, 'emps' , emps ) |
---|
| 228 | CALL iom_rstput( it, it, inum, 'un' , un ) |
---|
| 229 | CALL iom_rstput( it, it, inum, 'vn' , vn ) |
---|
| 230 | CALL iom_rstput( it, it, inum, 'tn' , tn ) |
---|
| 231 | CALL iom_rstput( it, it, inum, 'sn' , sn ) |
---|
| 232 | CALL iom_rstput( it, it, inum, 'avmu' , avmu ) |
---|
| 233 | CALL iom_rstput( it, it, inum, 'avmv' , avmv ) |
---|
| 234 | CALL iom_rstput( it, it, inum, 'avt' , avt ) |
---|
| 235 | #if defined key_ldfslp |
---|
| 236 | CALL iom_rstput( it, it, inum, 'uslp' , uslp ) |
---|
| 237 | CALL iom_rstput( it, it, inum, 'vslp' , vslp ) |
---|
| 238 | CALL iom_rstput( it, it, inum, 'wslpi' , wslpi ) |
---|
| 239 | CALL iom_rstput( it, it, inum, 'wslpj' , wslpj ) |
---|
| 240 | #endif |
---|
| 241 | #if defined key_zdfddm |
---|
| 242 | CALL iom_rstput( it, it, inum, 'avs' , avs ) |
---|
| 243 | #endif |
---|
| 244 | CALL iom_rstput( it, it, inum, 'ta' , ta ) |
---|
| 245 | CALL iom_rstput( it, it, inum, 'sa' , sa ) |
---|
| 246 | CALL iom_rstput( it, it, inum, 'tb' , tb ) |
---|
| 247 | CALL iom_rstput( it, it, inum, 'sb' , sb ) |
---|
| 248 | #if defined key_tradmp |
---|
| 249 | CALL iom_rstput( it, it, inum, 'strdmp', strdmp ) |
---|
| 250 | CALL iom_rstput( it, it, inum, 'hmlp' , hmlp ) |
---|
| 251 | #endif |
---|
| 252 | CALL iom_rstput( it, it, inum, 'aeiu' , aeiu ) |
---|
| 253 | CALL iom_rstput( it, it, inum, 'aeiv' , aeiv ) |
---|
| 254 | CALL iom_rstput( it, it, inum, 'aeiw' , aeiw ) |
---|
[2399] | 255 | ! |
---|
[2128] | 256 | CALL iom_close( inum ) |
---|
| 257 | ENDIF |
---|
[2399] | 258 | ! |
---|
[2128] | 259 | END SUBROUTINE asm_trj_wri |
---|
| 260 | |
---|
[2399] | 261 | !!====================================================================== |
---|
[2128] | 262 | END MODULE asmtrj |
---|