asmbkg.F90 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. MODULE asmbkg
  2. !!======================================================================
  3. !! *** MODULE asmtrj -> asmbkg ***
  4. !! Assimilation trajectory interface: Write to file the background state and the model state trajectory
  5. !!======================================================================
  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. !! ! 2010-01 (A. Vidard) split asm_trj_wri into tam_trj_wri and asm_bkg_wri
  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
  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
  42. #if defined key_traldf_c2d
  43. USE ldfeiv ! eddy induced velocity coef. (ldf_eiv routine)
  44. #endif
  45. #if defined key_lim2
  46. USE ice_2
  47. #endif
  48. #if defined key_lim3
  49. USE ice
  50. #endif
  51. IMPLICIT NONE
  52. PRIVATE
  53. PUBLIC asm_bkg_wri !: Write out the background state
  54. !!----------------------------------------------------------------------
  55. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  56. !! $Id: asmbkg.F90 2355 2015-05-20 07:11:50Z ufla $
  57. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  58. !!----------------------------------------------------------------------
  59. CONTAINS
  60. SUBROUTINE asm_bkg_wri( kt )
  61. !!-----------------------------------------------------------------------
  62. !! *** ROUTINE asm_bkg_wri ***
  63. !!
  64. !! ** Purpose : Write to file the background state for later use in the
  65. !! inner loop of data assimilation or for direct initialization
  66. !! in the outer loop.
  67. !!
  68. !! ** Method : Write out the background state for use in the Jb term
  69. !! in the cost function and for use with direct initialization
  70. !! at analysis time.
  71. !!-----------------------------------------------------------------------
  72. INTEGER, INTENT( IN ) :: kt ! Current time-step
  73. !
  74. CHARACTER (LEN=50) :: cl_asmbkg
  75. CHARACTER (LEN=50) :: cl_asmdin
  76. LOGICAL :: llok ! Check if file exists
  77. INTEGER :: inum ! File unit number
  78. REAL(wp) :: zdate ! Date
  79. !!-----------------------------------------------------------------------
  80. ! !-------------------------------------------
  81. IF( kt == nitbkg_r ) THEN ! Write out background at time step nitbkg_r
  82. ! !-----------------------------------========
  83. !
  84. WRITE(cl_asmbkg, FMT='(A,".nc")' ) TRIM( c_asmbkg )
  85. cl_asmbkg = TRIM( cl_asmbkg )
  86. INQUIRE( FILE = cl_asmbkg, EXIST = llok )
  87. !
  88. IF( .NOT. llok ) THEN
  89. IF(lwp) WRITE(numout,*) ' Setting up assimilation background file '// TRIM( c_asmbkg )
  90. !
  91. ! ! Define the output file
  92. CALL iom_open( c_asmbkg, inum, ldwrt = .TRUE., kiolib = jprstlib)
  93. !
  94. IF( nitbkg_r == nit000 - 1 ) THEN ! Treat special case when nitbkg = 0
  95. zdate = REAL( ndastp )
  96. #if defined key_zdftke
  97. ! lk_zdftke=T : Read turbulent kinetic energy ( en )
  98. IF(lwp) WRITE(numout,*) ' Reading TKE (en) from restart...'
  99. CALL tke_rst( nit000, 'READ' ) ! lk_zdftke=T : Read turbulent kinetic energy ( en )
  100. #endif
  101. ELSE
  102. zdate = REAL( ndastp )
  103. ENDIF
  104. !
  105. ! ! Write the information
  106. CALL iom_rstput( kt, nitbkg_r, inum, 'rdastp' , zdate )
  107. CALL iom_rstput( kt, nitbkg_r, inum, 'un' , un )
  108. CALL iom_rstput( kt, nitbkg_r, inum, 'vn' , vn )
  109. CALL iom_rstput( kt, nitbkg_r, inum, 'tn' , tsn(:,:,:,jp_tem) )
  110. CALL iom_rstput( kt, nitbkg_r, inum, 'sn' , tsn(:,:,:,jp_sal) )
  111. CALL iom_rstput( kt, nitbkg_r, inum, 'sshn' , sshn )
  112. #if defined key_zdftke
  113. CALL iom_rstput( kt, nitbkg_r, inum, 'en' , en )
  114. #endif
  115. CALL iom_rstput( kt, nitbkg_r, inum, 'gcx' , gcx )
  116. !
  117. CALL iom_close( inum )
  118. ENDIF
  119. !
  120. ENDIF
  121. ! !-------------------------------------------
  122. IF( kt == nitdin_r ) THEN ! Write out background at time step nitdin_r
  123. ! !-----------------------------------========
  124. !
  125. WRITE(cl_asmdin, FMT='(A,".nc")' ) TRIM( c_asmdin )
  126. cl_asmdin = TRIM( cl_asmdin )
  127. INQUIRE( FILE = cl_asmdin, EXIST = llok )
  128. !
  129. IF( .NOT. llok ) THEN
  130. IF(lwp) WRITE(numout,*) ' Setting up assimilation background file '// TRIM( c_asmdin )
  131. !
  132. ! ! Define the output file
  133. CALL iom_open( c_asmdin, inum, ldwrt = .TRUE., kiolib = jprstlib)
  134. !
  135. IF( nitdin_r == nit000 - 1 ) THEN ! Treat special case when nitbkg = 0
  136. zdate = REAL( ndastp )
  137. ELSE
  138. zdate = REAL( ndastp )
  139. ENDIF
  140. !
  141. ! ! Write the information
  142. CALL iom_rstput( kt, nitdin_r, inum, 'rdastp' , zdate )
  143. CALL iom_rstput( kt, nitdin_r, inum, 'un' , un )
  144. CALL iom_rstput( kt, nitdin_r, inum, 'vn' , vn )
  145. CALL iom_rstput( kt, nitdin_r, inum, 'tn' , tsn(:,:,:,jp_tem) )
  146. CALL iom_rstput( kt, nitdin_r, inum, 'sn' , tsn(:,:,:,jp_sal) )
  147. CALL iom_rstput( kt, nitdin_r, inum, 'sshn' , sshn )
  148. #if defined key_lim2 || defined key_lim3
  149. IF(( nn_ice == 2 ) .OR. ( nn_ice == 3 )) THEN
  150. IF(ALLOCATED(frld)) THEN
  151. CALL iom_rstput( kt, nitdin_r, inum, 'iceconc', 1.0 - frld(:,:) )
  152. ELSE
  153. CALL ctl_warn('Ice concentration not written to background as ice variable frld not allocated on this timestep')
  154. ENDIF
  155. ENDIF
  156. #endif
  157. !
  158. CALL iom_close( inum )
  159. ENDIF
  160. !
  161. ENDIF
  162. !
  163. END SUBROUTINE asm_bkg_wri
  164. !!======================================================================
  165. END MODULE asmbkg