trcstp.F90 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. MODULE trcstp
  2. !!======================================================================
  3. !! *** MODULE trcstp ***
  4. !! Time-stepping : time loop of opa for passive tracer
  5. !!======================================================================
  6. !! History : 1.0 ! 2004-03 (C. Ethe) Original
  7. !!----------------------------------------------------------------------
  8. #if defined key_top
  9. !!----------------------------------------------------------------------
  10. !! trc_stp : passive tracer system time-stepping
  11. !!----------------------------------------------------------------------
  12. USE oce_trc ! ocean dynamics and active tracers variables
  13. USE sbc_oce
  14. USE trc
  15. USE trctrp ! passive tracers transport
  16. USE trcsms ! passive tracers sources and sinks
  17. USE prtctl_trc ! Print control for debbuging
  18. USE trcdia
  19. USE trcwri
  20. USE trcrst
  21. USE trdtrc_oce
  22. USE trdmxl_trc
  23. USE iom
  24. USE in_out_manager
  25. USE trcsub
  26. IMPLICIT NONE
  27. PRIVATE
  28. PUBLIC trc_stp ! called by step
  29. REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE :: qsr_arr ! save qsr during TOP time-step
  30. REAL(wp) :: rdt_sampl
  31. INTEGER :: nb_rec_per_day, ktdcy
  32. REAL(wp) :: rsecfst, rseclast
  33. LOGICAL :: llnew
  34. !! * Substitutions
  35. # include "domzgr_substitute.h90"
  36. !!----------------------------------------------------------------------
  37. !! NEMO/TOP 3.3 , NEMO Consortium (2010)
  38. !! $Id: trcstp.F90 4990 2014-12-15 16:42:49Z timgraham $
  39. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  40. !!----------------------------------------------------------------------
  41. CONTAINS
  42. SUBROUTINE trc_stp( kt )
  43. !!-------------------------------------------------------------------
  44. !! *** ROUTINE trc_stp ***
  45. !!
  46. !! ** Purpose : Time loop of opa for passive tracer
  47. !!
  48. !! ** Method :
  49. !! Compute the passive tracers trends
  50. !! Update the passive tracers
  51. !!-------------------------------------------------------------------
  52. INTEGER, INTENT( in ) :: kt ! ocean time-step index
  53. INTEGER :: jk, jn ! dummy loop indices
  54. REAL(wp) :: ztrai
  55. CHARACTER (len=25) :: charout
  56. !!-------------------------------------------------------------------
  57. !
  58. IF( nn_timing == 1 ) CALL timing_start('trc_stp')
  59. !
  60. IF( kt == nittrc000 .AND. lk_trdmxl_trc ) CALL trd_mxl_trc_init ! trends: Mixed-layer
  61. !
  62. IF( lk_vvl ) THEN ! update ocean volume due to ssh temporal evolution
  63. DO jk = 1, jpk
  64. cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
  65. END DO
  66. IF( lk_degrad ) cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:) ! degrad option: reduction by facvol
  67. areatot = glob_sum( cvol(:,:,:) )
  68. ENDIF
  69. !
  70. IF( l_trcdm2dc ) CALL trc_mean_qsr( kt )
  71. !
  72. IF( nn_dttrc /= 1 ) CALL trc_sub_stp( kt ) ! averaging physical variables for sub-stepping
  73. !
  74. IF( MOD( kt , nn_dttrc ) == 0 ) THEN ! only every nn_dttrc time step
  75. !
  76. IF(ln_ctl) THEN
  77. WRITE(charout,FMT="('kt =', I4,' d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
  78. CALL prt_ctl_trc_info(charout)
  79. ENDIF
  80. !
  81. tra(:,:,:,:) = 0.e0
  82. !
  83. IF( .NOT.lk_offline ) CALL trc_rst_opn ( kt ) ! Open tracer restart file
  84. IF( lrst_trc ) CALL trc_rst_cal ( kt, 'WRITE' ) ! calendar
  85. IF( lk_iomput ) THEN ; CALL trc_wri ( kt ) ! output of passive tracers with iom I/O manager
  86. ELSE ; CALL trc_dia ( kt ) ! output of passive tracers with old I/O manager
  87. ENDIF
  88. CALL trc_sms ( kt ) ! tracers: sinks and sources
  89. CALL trc_trp ( kt ) ! transport of passive tracers
  90. IF( kt == nittrc000 ) THEN
  91. CALL iom_close( numrtr ) ! close input tracer restart file
  92. IF(lwm) CALL FLUSH( numont ) ! flush namelist output
  93. ENDIF
  94. IF( lrst_trc ) CALL trc_rst_wri ( kt ) ! write tracer restart file
  95. IF( lk_trdmxl_trc ) CALL trd_mxl_trc ( kt ) ! trends: Mixed-layer
  96. !
  97. IF( nn_dttrc /= 1 ) CALL trc_sub_reset( kt ) ! resetting physical variables when sub-stepping
  98. !
  99. ENDIF
  100. !
  101. ztrai = 0._wp ! content of all tracers
  102. DO jn = 1, jptra
  103. ztrai = ztrai + glob_sum( trn(:,:,:,jn) * cvol(:,:,:) )
  104. END DO
  105. IF( lwp ) WRITE(numstr,9300) kt, ztrai / areatot
  106. 9300 FORMAT(i10,D23.16)
  107. !
  108. IF( nn_timing == 1 ) CALL timing_stop('trc_stp')
  109. !
  110. END SUBROUTINE trc_stp
  111. SUBROUTINE trc_mean_qsr( kt )
  112. !!----------------------------------------------------------------------
  113. !! *** ROUTINE trc_mean_qsr ***
  114. !!
  115. !! ** Purpose : Compute daily mean qsr for biogeochemical model in case
  116. !! of diurnal cycle
  117. !!
  118. !! ** Method : store in TOP the qsr every hour ( or every time-step if the latter
  119. !! is greater than 1 hour ) and then, compute the mean with
  120. !! a moving average over 24 hours.
  121. !! In coupled mode, the sampling is done at every coupling frequency
  122. !!----------------------------------------------------------------------
  123. INTEGER, INTENT(in) :: kt
  124. INTEGER :: jn
  125. REAL(wp) :: zkt, zrec
  126. CHARACTER(len=1) :: cl1 ! 1 character
  127. CHARACTER(len=2) :: cl2 ! 2 characters
  128. IF( kt == nittrc000 ) THEN
  129. IF( ln_cpl ) THEN
  130. rdt_sampl = rday / ncpl_qsr_freq
  131. nb_rec_per_day = ncpl_qsr_freq
  132. ELSE
  133. rdt_sampl = MAX( 3600., rdttrc(1) )
  134. nb_rec_per_day = INT( rday / rdt_sampl )
  135. ENDIF
  136. !
  137. IF( lwp ) THEN
  138. WRITE(numout,*)
  139. WRITE(numout,*) ' Sampling frequency dt = ', rdt_sampl, 's',' Number of sampling per day nrec = ', nb_rec_per_day
  140. WRITE(numout,*)
  141. ENDIF
  142. !
  143. ALLOCATE( qsr_arr(jpi,jpj,nb_rec_per_day ) )
  144. !
  145. ! !* Restart: read in restart file
  146. IF( ln_rsttr .AND. nn_rsttr /= 0 .AND. iom_varid( numrtr, 'qsr_mean' , ldstop = .FALSE. ) > 0 &
  147. & .AND. iom_varid( numrtr, 'qsr_arr_1', ldstop = .FALSE. ) > 0 &
  148. & .AND. iom_varid( numrtr, 'ktdcy' , ldstop = .FALSE. ) > 0 &
  149. & .AND. iom_varid( numrtr, 'nrdcy' , ldstop = .FALSE. ) > 0 ) THEN
  150. CALL iom_get( numrtr, 'ktdcy', zkt )
  151. rsecfst = INT( zkt ) * rdttrc(1)
  152. IF(lwp) WRITE(numout,*) 'trc_qsr_mean: qsr_mean read in the restart file at time-step rsecfst =', rsecfst, ' s '
  153. CALL iom_get( numrtr, jpdom_autoglo, 'qsr_mean', qsr_mean ) ! A mean of qsr
  154. CALL iom_get( numrtr, 'nrdcy', zrec ) ! Number of record per days
  155. IF( INT( zrec ) == nb_rec_per_day ) THEN
  156. DO jn = 1, nb_rec_per_day
  157. IF( jn <= 9 ) THEN
  158. WRITE(cl1,'(i1)') jn
  159. CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) ) ! A mean of qsr
  160. ELSE
  161. WRITE(cl2,'(i2.2)') jn
  162. CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) ) ! A mean of qsr
  163. ENDIF
  164. ENDDO
  165. ELSE
  166. DO jn = 1, nb_rec_per_day
  167. qsr_arr(:,:,jn) = qsr_mean(:,:)
  168. ENDDO
  169. ENDIF
  170. ELSE !* no restart: set from nit000 values
  171. IF(lwp) WRITE(numout,*) 'trc_qsr_mean: qsr_mean set to nit000 values'
  172. rsecfst = kt * rdttrc(1)
  173. !
  174. qsr_mean(:,:) = qsr(:,:)
  175. DO jn = 1, nb_rec_per_day
  176. qsr_arr(:,:,jn) = qsr_mean(:,:)
  177. ENDDO
  178. ENDIF
  179. !
  180. ENDIF
  181. !
  182. rseclast = kt * rdttrc(1)
  183. !
  184. llnew = ( rseclast - rsecfst ) .ge. rdt_sampl ! new shortwave to store
  185. IF( llnew ) THEN
  186. ktdcy = kt
  187. IF( lwp .AND. kt < nittrc000 + 100 ) WRITE(numout,*) ' New shortwave to sample for TOP at time kt = ', ktdcy, &
  188. & ' time = ', rseclast/3600.,'hours '
  189. rsecfst = rseclast
  190. DO jn = 1, nb_rec_per_day - 1
  191. qsr_arr(:,:,jn) = qsr_arr(:,:,jn+1)
  192. ENDDO
  193. qsr_arr (:,:,nb_rec_per_day) = qsr(:,:)
  194. qsr_mean(:,: ) = SUM( qsr_arr(:,:,:), 3 ) / nb_rec_per_day
  195. ENDIF
  196. !
  197. IF( lrst_trc ) THEN !* Write the mean of qsr in restart file
  198. IF(lwp) WRITE(numout,*)
  199. IF(lwp) WRITE(numout,*) 'trc_mean_qsr : write qsr_mean in restart file kt =', kt
  200. IF(lwp) WRITE(numout,*) '~~~~~~~'
  201. zkt = REAL( ktdcy, wp )
  202. zrec = REAL( nb_rec_per_day, wp )
  203. CALL iom_rstput( kt, nitrst, numrtw, 'ktdcy', zkt )
  204. CALL iom_rstput( kt, nitrst, numrtw, 'nrdcy', zrec )
  205. DO jn = 1, nb_rec_per_day
  206. IF( jn <= 9 ) THEN
  207. WRITE(cl1,'(i1)') jn
  208. CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )
  209. ELSE
  210. WRITE(cl2,'(i2.2)') jn
  211. CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )
  212. ENDIF
  213. ENDDO
  214. CALL iom_rstput( kt, nitrst, numrtw, 'qsr_mean', qsr_mean(:,:) )
  215. ENDIF
  216. !
  217. END SUBROUTINE trc_mean_qsr
  218. #else
  219. !!----------------------------------------------------------------------
  220. !! Default key NO passive tracers
  221. !!----------------------------------------------------------------------
  222. CONTAINS
  223. SUBROUTINE trc_stp( kt ) ! Empty routine
  224. WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
  225. END SUBROUTINE trc_stp
  226. #endif
  227. !!======================================================================
  228. END MODULE trcstp