flowri.F90 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. MODULE flowri
  2. !!======================================================================
  3. !! *** MODULE flowri ***
  4. !!
  5. !! write floats trajectory in ascii ln_flo_ascii = T
  6. !! or in netcdf ( IOM or IOSPSL ) ln_flo_ascii = F
  7. !!
  8. !!
  9. !!======================================================================
  10. !! History :
  11. !! 8.0 ! 99-09 (Y. Drillet) : Original code
  12. !! ! 00-06 (J.-M. Molines) : Profiling floats for CLS
  13. !! 8.5 ! 02-10 (A. Bozec) F90 : Free form and module
  14. !! 3.2 ! 10-08 (slaw, cbricaud): netcdf outputs and others
  15. !!----------------------------------------------------------------------
  16. #if defined key_floats || defined key_esopa
  17. !!----------------------------------------------------------------------
  18. !! 'key_floats' float trajectories
  19. !!----------------------------------------------------------------------
  20. !! * Modules used
  21. USE flo_oce ! ocean drifting floats
  22. USE oce ! ocean dynamics and tracers
  23. USE dom_oce ! ocean space and time domain
  24. USE lib_mpp ! distribued memory computing library
  25. USE in_out_manager ! I/O manager
  26. USE phycst ! physic constants
  27. USE dianam ! build name of file (routine)
  28. USE ioipsl
  29. USE iom ! I/O library
  30. IMPLICIT NONE
  31. PRIVATE
  32. PUBLIC flo_wri ! routine called by floats.F90
  33. PUBLIC flo_wri_alloc ! routine called by floats.F90
  34. INTEGER :: jfl ! number of floats
  35. CHARACTER (len=80) :: clname ! netcdf output filename
  36. ! Following are only workspace arrays but shape is not (jpi,jpj) and
  37. ! therefore make them module arrays rather than replacing with wrk_nemo
  38. ! member arrays.
  39. REAL(wp), ALLOCATABLE, DIMENSION(:) :: zlon , zlat, zdep ! 2D workspace
  40. REAL(wp), ALLOCATABLE, DIMENSION(:) :: ztem , zsal, zrho ! 2D workspace
  41. !! * Substitutions
  42. # include "domzgr_substitute.h90"
  43. !!----------------------------------------------------------------------
  44. !! NEMO/OPA 3.2 , LODYC-IPSL (2009)
  45. !! $Id$
  46. !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
  47. !!----------------------------------------------------------------------
  48. CONTAINS
  49. INTEGER FUNCTION flo_wri_alloc()
  50. !!-------------------------------------------------------------------
  51. !! *** FUNCTION flo_wri_alloc ***
  52. !!-------------------------------------------------------------------
  53. ALLOCATE( ztem(jpnfl) , zsal(jpnfl) , zrho(jpnfl) , &
  54. zlon(jpnfl) , zlat(jpnfl) , zdep(jpnfl) , STAT=flo_wri_alloc)
  55. !
  56. IF( lk_mpp ) CALL mpp_sum ( flo_wri_alloc )
  57. IF( flo_wri_alloc /= 0 ) CALL ctl_warn('flo_wri_alloc: failed to allocate arrays.')
  58. END FUNCTION flo_wri_alloc
  59. SUBROUTINE flo_wri( kt )
  60. !!---------------------------------------------------------------------
  61. !! *** ROUTINE flo_wri ***
  62. !!
  63. !! ** Purpose : Write position of floats in "trajec_float.nc",according
  64. !! to ARIANE TOOLS (http://stockage.univ-brest.fr/~grima/Ariane/ ) n
  65. !! nomenclature
  66. !!
  67. !!
  68. !! ** Method : The frequency of ??? is nwritefl
  69. !!
  70. !!----------------------------------------------------------------------
  71. !! * Arguments
  72. INTEGER :: kt ! time step
  73. !! * Local declarations
  74. INTEGER :: iafl , ibfl , icfl ! temporary integer
  75. INTEGER :: ia1fl, ib1fl, ic1fl ! "
  76. INTEGER :: iafloc,ibfloc,ia1floc,ib1floc ! "
  77. INTEGER :: irec, irecflo
  78. REAL(wp) :: zafl,zbfl,zcfl ! temporary real
  79. REAL(wp) :: ztime ! "
  80. INTEGER, DIMENSION(2) :: icount
  81. INTEGER, DIMENSION(2) :: istart
  82. INTEGER, DIMENSION(1) :: ish
  83. INTEGER, DIMENSION(2) :: ish2
  84. !!----------------------------------------------------------------------
  85. !-----------------------------------------------------
  86. ! I- Save positions, temperature, salinty and density
  87. !-----------------------------------------------------
  88. zlon(:)=0.0 ; zlat(:)=0.0 ; zdep(:)=0.0
  89. ztem(:)=0.0 ; zsal(:)=0.0 ; zrho(:)=0.0
  90. DO jfl = 1, jpnfl
  91. iafl = INT (tpifl(jfl)) ! I-index of the nearest point before
  92. ibfl = INT (tpjfl(jfl)) ! J-index of the nearest point before
  93. icfl = INT (tpkfl(jfl)) ! K-index of the nearest point before
  94. ia1fl = iafl + 1 ! I-index of the nearest point after
  95. ib1fl = ibfl + 1 ! J-index of the nearest point after
  96. ic1fl = icfl + 1 ! K-index of the nearest point after
  97. zafl = tpifl(jfl) - REAL(iafl,wp) ! distance ?????
  98. zbfl = tpjfl(jfl) - REAL(ibfl,wp) ! distance ?????
  99. zcfl = tpkfl(jfl) - REAL(icfl,wp) ! distance ?????
  100. IF( lk_mpp ) THEN
  101. iafloc = mi1( iafl )
  102. ibfloc = mj1( ibfl )
  103. IF( nldi <= iafloc .AND. iafloc <= nlei .AND. &
  104. & nldj <= ibfloc .AND. ibfloc <= nlej ) THEN
  105. !the float is inside of current proc's area
  106. ia1floc = iafloc + 1
  107. ib1floc = ibfloc + 1
  108. !save position of the float
  109. zlat(jfl) = (1.-zafl)*(1.-zbfl)*gphit(iafloc ,ibfloc ) + (1.-zafl) * zbfl * gphit(iafloc ,ib1floc) &
  110. + zafl *(1.-zbfl)*gphit(ia1floc,ibfloc ) + zafl * zbfl * gphit(ia1floc,ib1floc)
  111. zlon(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc) &
  112. + zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) + zafl * zbfl * glamt(ia1floc,ib1floc)
  113. zdep(jfl) = (1.-zcfl)*fsdepw(iafloc,ibfloc,icfl ) + zcfl * fsdepw(iafloc,ibfloc,ic1fl)
  114. !save temperature, salinity and density at this position
  115. ztem(jfl) = tsn(iafloc,ibfloc,icfl,jp_tem)
  116. zsal (jfl) = tsn(iafloc,ibfloc,icfl,jp_sal)
  117. zrho (jfl) = (rhd(iafloc,ibfloc,icfl)+1)*rau0
  118. ENDIF
  119. ELSE ! mono proc case
  120. iafloc = iafl
  121. ibfloc = ibfl
  122. ia1floc = iafloc + 1
  123. ib1floc = ibfloc + 1
  124. !save position of the float
  125. zlat(jfl) = (1.-zafl)*(1.-zbfl)*gphit(iafloc ,ibfloc ) + (1.-zafl) * zbfl * gphit(iafloc ,ib1floc) &
  126. + zafl *(1.-zbfl)*gphit(ia1floc,ibfloc ) + zafl * zbfl * gphit(ia1floc,ib1floc)
  127. zlon(jfl) = (1.-zafl)*(1.-zbfl)*glamt(iafloc ,ibfloc ) + (1.-zafl) * zbfl * glamt(iafloc ,ib1floc) &
  128. + zafl *(1.-zbfl)*glamt(ia1floc,ibfloc ) + zafl * zbfl * glamt(ia1floc,ib1floc)
  129. zdep(jfl) = (1.-zcfl)*fsdepw(iafloc,ibfloc,icfl ) + zcfl * fsdepw(iafloc,ibfloc,ic1fl)
  130. ztem(jfl) = tsn(iafloc,ibfloc,icfl,jp_tem)
  131. zsal(jfl) = tsn(iafloc,ibfloc,icfl,jp_sal)
  132. zrho(jfl) = (rhd(iafloc,ibfloc,icfl)+1)*rau0
  133. ENDIF
  134. END DO ! loop on float
  135. !Only proc 0 writes all positions : SUM of positions on all procs
  136. IF( lk_mpp ) THEN
  137. CALL mpp_sum( zlon, jpnfl ) ! sums over the global domain
  138. CALL mpp_sum( zlat, jpnfl ) ! sums over the global domain
  139. CALL mpp_sum( zdep, jpnfl ) ! sums over the global domain
  140. CALL mpp_sum( ztem, jpnfl ) ! sums over the global domain
  141. CALL mpp_sum( zsal, jpnfl ) ! sums over the global domain
  142. CALL mpp_sum( zrho, jpnfl ) ! sums over the global domain
  143. ENDIF
  144. !-------------------------------------!
  145. ! II- WRITE WRITE WRITE WRITE WRITE !
  146. !-------------------------------------!
  147. !--------------------------!
  148. ! II-1 Write in ascii file !
  149. !--------------------------!
  150. IF( ln_flo_ascii )THEN
  151. IF( ( kt == nn_it000 .OR. MOD( kt,nn_writefl)== 0 ) .AND. lwp )THEN
  152. !II-1-a Open ascii file
  153. !----------------------
  154. IF( kt == nn_it000 ) THEN
  155. CALL ctl_opn( numflo, 'trajec_float', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE. )
  156. irecflo = NINT( (nitend-nn_it000) / FLOAT(nn_writefl) )
  157. WRITE(numflo,*)cexper,no,irecflo,jpnfl,nn_writefl
  158. ENDIF
  159. !II-1-b Write in ascii file
  160. !-----------------------------
  161. WRITE(numflo,*) zlon,zlat,zdep,nisobfl,ngrpfl,ztem,zsal, FLOAT(ndastp)
  162. !II-1-c Close netcdf file
  163. !-------------------------
  164. IF( kt == nitend ) CLOSE( numflo )
  165. ENDIF
  166. !-----------------------------------------------------
  167. ! II-2 Write in netcdf file
  168. !-----------------------------------------------------
  169. ELSE
  170. !II-2-a Write with IOM
  171. !----------------------
  172. #if defined key_iomput
  173. CALL iom_put( "traj_lon" , zlon )
  174. CALL iom_put( "traj_lat" , zlat )
  175. CALL iom_put( "traj_dep" , zdep )
  176. CALL iom_put( "traj_temp" , ztem )
  177. CALL iom_put( "traj_salt" , zsal )
  178. CALL iom_put( "traj_dens" , zrho )
  179. CALL iom_put( "traj_group" , REAL(ngrpfl,wp) )
  180. #else
  181. !II-2-b Write with IOIPSL
  182. !------------------------
  183. IF( ( kt == nn_it000 .OR. MOD( kt,nn_writefl)== 0 ) .AND. lwp )THEN
  184. !II-2-b-1 Open netcdf file
  185. !-------------------------
  186. IF( kt==nn_it000 )THEN ! Create and open
  187. CALL dia_nam( clname, nn_writefl, 'trajec_float' )
  188. clname=TRIM(clname)//".nc"
  189. CALL fliocrfd( clname , (/ 'ntraj' , 't' /), (/ jpnfl , -1 /) , numflo )
  190. CALL fliodefv( numflo, 'traj_lon' , (/1,2/), v_t=flio_r8, long_name="Longitude" , units="degrees_east" )
  191. CALL fliodefv( numflo, 'traj_lat' , (/1,2/), v_t=flio_r8, long_name="Latitude" , units="degrees_north" )
  192. CALL fliodefv( numflo, 'traj_depth' , (/1,2/), v_t=flio_r8, long_name="Depth" , units="meters" )
  193. CALL fliodefv( numflo, 'time_counter', (/2/) , v_t=flio_r8, long_name="Time axis" &
  194. & , units="seconds since start of the run " )
  195. CALL fliodefv( numflo, 'traj_temp' , (/1,2/), v_t=flio_r8, long_name="Temperature" , units="C" )
  196. CALL fliodefv( numflo, 'traj_salt' , (/1,2/), v_t=flio_r8, long_name="Salinity" , units="PSU" )
  197. CALL fliodefv( numflo, 'traj_dens' , (/1,2/), v_t=flio_r8, long_name="Density" , units="kg/m3" )
  198. CALL fliodefv( numflo, 'traj_group' , (/1/) , v_t=flio_r8, long_name="number of the group" , units="no unit" )
  199. CALL flioputv( numflo , 'traj_group' , REAL(ngrpfl,wp) )
  200. ELSE ! Re-open
  201. CALL flioopfd( TRIM(clname), numflo , "WRITE" )
  202. ENDIF
  203. !II-2-b-2 Write in netcdf file
  204. !-------------------------------
  205. irec = INT( (kt-nn_it000+1)/nn_writefl ) +1
  206. ztime = ( kt-nn_it000 + 1 ) * rdt
  207. CALL flioputv( numflo , 'time_counter', ztime , start=(/irec/) )
  208. DO jfl = 1, jpnfl
  209. istart = (/jfl,irec/)
  210. icfl = INT( tpkfl(jfl) ) ! K-index of the nearest point before
  211. CALL flioputv( numflo , 'traj_lon' , zlon(jfl) , start=istart )
  212. CALL flioputv( numflo , 'traj_lat' , zlat(jfl) , start=istart )
  213. CALL flioputv( numflo , 'traj_depth' , zdep(jfl) , start=istart )
  214. CALL flioputv( numflo , 'traj_temp' , ztemp(icfl,jfl) , start=istart )
  215. CALL flioputv( numflo , 'traj_salt' , zsal(icfl,jfl) , start=istart )
  216. CALL flioputv( numflo , 'traj_dens' , zrho(icfl,jfl) , start=istart )
  217. ENDDO
  218. !II-2-b-3 Close netcdf file
  219. !---------------------------
  220. CALL flioclo( numflo )
  221. ENDIF
  222. #endif
  223. ENDIF ! netcdf writing
  224. END SUBROUTINE flo_wri
  225. # else
  226. !!----------------------------------------------------------------------
  227. !! Default option Empty module
  228. !!----------------------------------------------------------------------
  229. CONTAINS
  230. SUBROUTINE flo_wri ! Empty routine
  231. END SUBROUTINE flo_wri
  232. #endif
  233. !!=======================================================================
  234. END MODULE flowri