limwri_dimg_2.h90 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. SUBROUTINE lim_wri_2(kt)
  2. !!----------------------------------------------------------------------
  3. !! NEMO/LIM2 3.3 , UCL - NEMO Consortium (2010)
  4. !! $Id: limwri_dimg_2.h90 3764 2013-01-23 14:33:04Z smasson $
  5. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  6. !!----------------------------------------------------------------------
  7. !!-------------------------------------------------------------------
  8. !! This routine computes the average of some variables and write it
  9. !! on the ouput files.
  10. !! ATTENTION cette routine n'est valable que si le pas de temps est
  11. !! egale a une fraction entiere de 1 jours.
  12. !! Diff 1-D 3-D : suppress common also included in etat
  13. !! suppress cmoymo 11-18
  14. !! modif : 03/06/98
  15. !!-------------------------------------------------------------------
  16. USE diadimg ! use of dia_wri_dimg
  17. INTEGER, INTENT(in) :: kt ! number of iteration
  18. INTEGER , SAVE :: nmoyice !: counter for averaging
  19. INTEGER , SAVE :: nwf !: number of fields to write on disk
  20. INTEGER, SAVE,DIMENSION (:), ALLOCATABLE :: nsubindex !: subindex to be saved
  21. INTEGER , SAVE :: nice, nhorid, ndim, niter, ndepid
  22. REAL(wp), SAVE, DIMENSION(:,:,:), ALLOCATABLE :: rcmoy
  23. INTEGER :: ji, jj, jf, ii ! dummy loop indices and array index
  24. INTEGER :: iyear, iday, imon !
  25. INTEGER :: ialloc
  26. CHARACTER(LEN=80) :: clname, cltext, clmode
  27. REAL(wp), DIMENSION(1) :: zdept
  28. REAL(wp) :: zsto, zsec, zjulian,zout
  29. REAL(wp) :: zindh, zinda, zindb, ztmu
  30. REAL(wp), POINTER, DIMENSION(:,:) :: zfield
  31. #if ! defined key_diainstant
  32. LOGICAL, PARAMETER :: ll_dia_inst=.false. ! local logical variable
  33. #else
  34. LOGICAL, PARAMETER :: ll_dia_inst=.true.
  35. #endif
  36. !!-------------------------------------------------------------------
  37. IF( .NOT. ALLOCATED(rcmoy) )THEN
  38. ALLOCATE(rcmoy(jpi,jpj,jpnoumax), STAT=ialloc )
  39. !
  40. IF( lk_mpp ) CALL mpp_sum ( ialloc )
  41. IF( ialloc /= 0 ) CALL ctl_warn('lim_wri_2 (limwri_dimg_2.h90) : failed to allocate arrays')
  42. ENDIF
  43. CALL wrk_alloc( jpi, jpj, zfield )
  44. IF ( kt == nit000 ) THEN
  45. !
  46. CALL lim_wri_init_2
  47. nwf = 0
  48. ii = 0
  49. IF (lwp ) THEN
  50. WRITE(numout,*) 'lim_wri_2 : Write ice outputs in dimg'
  51. WRITE(numout,*) '~~~~~~~~'
  52. WRITE(numout,*) ' According to namelist_ice, following fields saved:'
  53. DO jf =1, noumef
  54. IF (nc(jf) == 1 ) THEN
  55. WRITE(numout,* ) ' -',titn(jf), nam(jf), uni(jf)
  56. ENDIF
  57. END DO
  58. ENDIF
  59. DO jf = 1, noumef
  60. IF (nc(jf) == 1 ) nwf = nwf + 1
  61. END DO
  62. ALLOCATE( nsubindex (nwf) )
  63. DO jf = 1, noumef
  64. IF (nc(jf) == 1 ) THEN
  65. ii = ii +1
  66. nsubindex(ii) = jf
  67. END IF
  68. END DO
  69. rcmoy(:,:,:) = 0.0_wp
  70. zsto = rdt_ice
  71. zout = nwrite * rdt_ice / nn_fsbc
  72. zsec = 0.
  73. niter = 0
  74. zdept(1) = 0.
  75. nmoyice = 0
  76. ENDIF
  77. #if ! defined key_diainstant
  78. !-- Compute mean values
  79. zcmo(:,:, 1:jpnoumax ) = 0.e0
  80. DO jj = 2 , jpjm1
  81. DO ji = 2 , jpim1
  82. zindh = MAX( zzero , SIGN( zone , hicif(ji,jj) * (1.0 - frld(ji,jj) ) - 0.10 ) )
  83. zinda = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
  84. zindb = zindh * zinda
  85. zcmo(ji,jj,1) = hsnif (ji,jj)
  86. zcmo(ji,jj,2) = hicif (ji,jj)
  87. zcmo(ji,jj,3) = hicifp(ji,jj)
  88. zcmo(ji,jj,4) = frld (ji,jj)
  89. zcmo(ji,jj,5) = sist (ji,jj)
  90. zcmo(ji,jj,6) = fbif (ji,jj)
  91. IF (lk_lim2_vp) THEN
  92. ztmu = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) )
  93. zcmo(ji,jj,7) = zindb * ( u_ice(ji,jj ) * tmu(ji,jj ) + u_ice(ji+1,jj ) * tmu(ji+1,jj ) &
  94. & + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
  95. / ztmu
  96. zcmo(ji,jj,8) = zindb * ( v_ice(ji,jj ) * tmu(ji,jj ) + v_ice(ji+1,jj ) * tmu(ji+1,jj ) &
  97. & + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
  98. / ztmu
  99. ELSE
  100. zcmo(ji,jj,7) = zindb * ( u_ice(ji,jj ) * tmu(ji,jj) + u_ice(ji-1,jj) * tmu(ji-1,jj) )/ 2.0
  101. zcmo(ji,jj,8) = zindb * ( v_ice(ji,jj ) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) )/ 2.0
  102. ENDIF
  103. zcmo(ji,jj,9) = sst_m(ji,jj)
  104. zcmo(ji,jj,10) = sss_m(ji,jj)
  105. zcmo(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
  106. zcmo(ji,jj,12) = qsr(ji,jj)
  107. zcmo(ji,jj,13) = qns(ji,jj)
  108. ! See thersf for the coefficient
  109. zcmo(ji,jj,14) = - sfx (ji,jj) * rday * ( sss_m(ji,jj) + epsi16 ) / soce
  110. zcmo(ji,jj,15) = utau_ice(ji,jj)
  111. zcmo(ji,jj,16) = vtau_ice(ji,jj)
  112. zcmo(ji,jj,17) = qsr_ice(ji,jj,1)
  113. zcmo(ji,jj,18) = qns_ice(ji,jj,1)
  114. zcmo(ji,jj,19) = sprecip(ji,jj)
  115. END DO
  116. END DO
  117. ! Cumulates values between outputs
  118. rcmoy(:,:,:)= rcmoy(:,:,:) + zcmo(:,:,:)
  119. nmoyice = nmoyice + 1
  120. ! compute mean value if it is time to write on file
  121. IF ( MOD(kt+nn_fsbc-1-nit000+1,nwrite) == 0 ) THEN
  122. rcmoy(:,:,:) = rcmoy(:,:,:) / FLOAT(nmoyice)
  123. #else
  124. IF ( MOD(kt-nn_fsbc-1-nit000+1,nwrite) == 0 ) THEN
  125. ! case of instantaneaous output rcmoy(:,:, 1:jpnoumax ) = 0.e0
  126. DO jj = 2 , jpjm1
  127. DO ji = 2 , jpim1
  128. zindh = MAX( zzero , SIGN( zone , hicif(ji,jj) * (1.0 - frld(ji,jj) ) - 0.10 ) )
  129. zinda = MAX( zzero , SIGN( zone , ( 1.0 - frld(ji,jj) ) - 0.10 ) )
  130. zindb = zindh * zinda
  131. rcmoy(ji,jj,1) = hsnif (ji,jj)
  132. rcmoy(ji,jj,2) = hicif (ji,jj)
  133. rcmoy(ji,jj,3) = hicifp(ji,jj)
  134. rcmoy(ji,jj,4) = frld (ji,jj)
  135. rcmoy(ji,jj,5) = sist (ji,jj)
  136. rcmoy(ji,jj,6) = fbif (ji,jj)
  137. IF (lk_lim2_vp) THEN
  138. ztmu = MAX( 0.5 * zone , ( tmu(ji,jj) + tmu(ji+1,jj) + tmu(ji,jj+1) + tmu(ji+1,jj+1) ) )
  139. rcmoy(ji,jj,7) = zindb * ( u_ice(ji,jj ) * tmu(ji,jj ) + u_ice(ji+1,jj ) * tmu(ji+1,jj ) &
  140. & + u_ice(ji,jj+1) * tmu(ji,jj+1) + u_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
  141. / ztmu
  142. rcmoy(ji,jj,8) = zindb * ( v_ice(ji,jj ) * tmu(ji,jj ) + v_ice(ji+1,jj ) * tmu(ji+1,jj ) &
  143. & + v_ice(ji,jj+1) * tmu(ji,jj+1) + v_ice(ji+1,jj+1) * tmu(ji+1,jj+1) ) &
  144. / ztmu
  145. ELSE
  146. rcmoy(ji,jj,7) = zindb * ( u_ice(ji,jj ) * tmu(ji,jj) + u_ice(ji-1,jj) * tmu(ji-1,jj) )/ 2.0
  147. rcmoy(ji,jj,8) = zindb * ( v_ice(ji,jj ) * tmv(ji,jj) + v_ice(ji,jj-1) * tmv(ji,jj-1) )/ 2.0
  148. ENDIF
  149. rcmoy(ji,jj,9) = sst_m(ji,jj)
  150. rcmoy(ji,jj,10) = sss_m(ji,jj)
  151. rcmoy(ji,jj,11) = qns(ji,jj) + qsr(ji,jj)
  152. rcmoy(ji,jj,12) = qsr(ji,jj)
  153. rcmoy(ji,jj,13) = qns(ji,jj)
  154. ! See thersf for the coefficient
  155. rcmoy(ji,jj,14) = - sfx (ji,jj) * rday * ( sss_m(ji,jj) + epsi16 ) / soce
  156. rcmoy(ji,jj,15) = utau_ice(ji,jj)
  157. rcmoy(ji,jj,16) = vtau_ice(ji,jj)
  158. rcmoy(ji,jj,17) = qsr_ice(ji,jj,1)
  159. rcmoy(ji,jj,18) = qns_ice(ji,jj,1)
  160. rcmoy(ji,jj,19) = sprecip(ji,jj)
  161. END DO
  162. END DO
  163. #endif
  164. !
  165. niter = niter + 1
  166. DO jf = 1 , noumef
  167. zfield(:,:) = (rcmoy(:,:,jf) * cmulti(jf) + cadd(jf)) * tmask(:,:,1)
  168. SELECT CASE (jf)
  169. CASE ( 7, 8, 15, 16 ) ! velocity or stress fields (vectors)
  170. CALL lbc_lnk( zfield, 'T', -1. )
  171. CASE DEFAULT ! scalar fields
  172. CALL lbc_lnk( zfield, 'T', 1. )
  173. END SELECT
  174. rcmoy(:,:,jf) = zfield(:,:)
  175. END DO
  176. IF (ll_dia_inst) THEN
  177. clmode='instantaneous'
  178. ELSE
  179. WRITE(clmode,'(f5.1,a)' ) nwrite*rdt/86400.,' days average'
  180. END IF
  181. iyear = ndastp/10000
  182. imon = (ndastp-iyear*10000)/100
  183. iday = ndastp - imon*100 - iyear*10000
  184. WRITE(clname,9000) TRIM(cexper),'ICEMOD',iyear,imon,iday
  185. cltext=TRIM(cexper)//' ice modele output'//TRIM(clmode)
  186. CALL dia_wri_dimg (clname, cltext, rcmoy, nwf , 'I', nsubindex)
  187. 9000 FORMAT(a,"_",a,"_y",i4.4,"m",i2.2,"d",i2.2,".dimgproc")
  188. rcmoy(:,:,:) = 0.0
  189. nmoyice = 0
  190. END IF ! MOD(kt+nn_fsbc-1-nit000+1, nwrite == 0 ) !
  191. CALL wrk_dealloc( jpi,jpj, zfield )
  192. END SUBROUTINE lim_wri_2