icbtrj.F90 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. MODULE icbtrj
  2. !!======================================================================
  3. !! *** MODULE icbtrj ***
  4. !! Ocean physics: trajectory I/O routines
  5. !!======================================================================
  6. !! History : 3.3.1 ! 2010-01 (Martin&Adcroft) Original code
  7. !! - ! 2011-03 (Madec) Part conversion to NEMO form
  8. !! - ! Removal of mapping from another grid
  9. !! - ! 2011-05 (Alderson) New module to handle trajectory output
  10. !!----------------------------------------------------------------------
  11. !!----------------------------------------------------------------------
  12. !! icb_trj_init :
  13. !!----------------------------------------------------------------------
  14. USE par_oce ! NEMO parameters
  15. USE dom_oce ! NEMO ocean domain
  16. USE phycst ! NEMO physical constants
  17. USE lib_mpp ! NEMO MPI library, lk_mpp in particular
  18. USE in_out_manager ! NEMO IO, numout in particular
  19. USE ioipsl, ONLY : ju2ymds ! for calendar
  20. USE netcdf
  21. !
  22. USE icb_oce ! define iceberg arrays
  23. USE icbutl ! iceberg utility routines
  24. IMPLICIT NONE
  25. PRIVATE
  26. PUBLIC icb_trj_init ! routine called in icbini.F90 module
  27. PUBLIC icb_trj_write ! routine called in icbstp.F90 module
  28. PUBLIC icb_trj_sync ! routine called in icbstp.F90 module
  29. PUBLIC icb_trj_end ! routine called in icbstp.F90 module
  30. INTEGER :: num_traj
  31. INTEGER :: n_dim, m_dim
  32. INTEGER :: ntrajid
  33. INTEGER :: numberid, nstepid, nscaling_id
  34. INTEGER :: nlonid, nlatid, nxid, nyid, nuvelid, nvvelid, nmassid
  35. INTEGER :: nuoid, nvoid, nuaid, nvaid, nuiid, nviid
  36. INTEGER :: nsshxid, nsshyid, nsstid, ncntid, nthkid
  37. INTEGER :: nthicknessid, nwidthid, nlengthid
  38. INTEGER :: nyearid, ndayid
  39. INTEGER :: nmass_of_bits_id, nheat_density_id
  40. !!----------------------------------------------------------------------
  41. !! NEMO/OPA 3.3 , NEMO Consortium (2011)
  42. !! $Id: icbtrj.F90 5424 2018-04-27 07:03:10Z ufla $
  43. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  44. !!----------------------------------------------------------------------
  45. CONTAINS
  46. !!-------------------------------------------------------------------------
  47. SUBROUTINE icb_trj_init( ktend )
  48. !!----------------------------------------------------------------------
  49. !! *** ROUTINE icb_trj_init ***
  50. !!
  51. !! ** Purpose : initialise iceberg trajectory output files
  52. !!----------------------------------------------------------------------
  53. INTEGER, INTENT( in ) :: ktend
  54. !
  55. INTEGER :: iret
  56. INTEGER :: iyear, imonth, iday
  57. REAL(wp) :: zfjulday, zsec
  58. CHARACTER(len=80) :: cl_filename
  59. TYPE(iceberg), POINTER :: this
  60. TYPE(point) , POINTER :: pt
  61. CHARACTER(LEN=20) :: cldate_ini, cldate_end
  62. !!----------------------------------------------------------------------
  63. ! compute initial time step date
  64. CALL ju2ymds( fjulday, iyear, imonth, iday, zsec )
  65. WRITE(cldate_ini, '(i4.4,2i2.2)') iyear, imonth, iday
  66. ! compute end time step date
  67. zfjulday = fjulday + rdttra(1) / rday * REAL( nitend - nit000 + 1 , wp)
  68. IF( ABS(zfjulday - REAL(NINT(zfjulday),wp)) < 0.1 / rday ) zfjulday = REAL(NINT(zfjulday),wp) ! avoid truncation error
  69. CALL ju2ymds( zfjulday, iyear, imonth, iday, zsec )
  70. WRITE(cldate_end, '(i4.4,2i2.2)') iyear, imonth, iday
  71. ! define trajectory output name
  72. IF( lk_mpp ) THEN
  73. WRITE(cl_filename,'("trajectory_icebergs_",A,"-",A,"_",I4.4,".nc")') &
  74. & TRIM(ADJUSTL(cldate_ini)), TRIM(ADJUSTL(cldate_end)), narea-1
  75. ELSE
  76. WRITE(cl_filename,'("trajectory_icebergs_",A,"-",A ,".nc")') &
  77. & TRIM(ADJUSTL(cldate_ini)), TRIM(ADJUSTL(cldate_end))
  78. ENDIF
  79. IF ( lwp .AND. nn_verbose_level >= 0) WRITE(numout,'(2a)') 'icebergs, icb_trj_init: creating ',TRIM(cl_filename)
  80. iret = NF90_CREATE(TRIM(cl_filename), NF90_CLOBBER, ntrajid)
  81. IF (iret .NE. NF90_NOERR) CALL ctl_stop('icebergs, icb_trj_init: nf_create failed')
  82. ! Dimensions
  83. iret = NF90_DEF_DIM(ntrajid, 'n', NF90_UNLIMITED, n_dim)
  84. IF (iret .NE. NF90_NOERR) CALL ctl_stop('icebergs, icb_trj_init: nf_def_dim n failed')
  85. iret = NF90_DEF_DIM(ntrajid, 'k', nkounts, m_dim)
  86. IF (iret .NE. NF90_NOERR) CALL ctl_stop('icebergs, icb_trj_init: nf_def_dim k failed')
  87. ! Variables
  88. iret = NF90_DEF_VAR(ntrajid, 'iceberg_number', NF90_INT, (/m_dim,n_dim/), numberid)
  89. iret = NF90_DEF_VAR(ntrajid, 'timestep', NF90_INT, n_dim, nstepid)
  90. iret = NF90_DEF_VAR(ntrajid, 'mass_scaling', NF90_DOUBLE, n_dim, nscaling_id)
  91. iret = NF90_DEF_VAR(ntrajid, 'lon', NF90_DOUBLE, n_dim, nlonid)
  92. iret = NF90_DEF_VAR(ntrajid, 'lat', NF90_DOUBLE, n_dim, nlatid)
  93. iret = NF90_DEF_VAR(ntrajid, 'xi', NF90_DOUBLE, n_dim, nxid)
  94. iret = NF90_DEF_VAR(ntrajid, 'yj', NF90_DOUBLE, n_dim, nyid)
  95. iret = NF90_DEF_VAR(ntrajid, 'uvel', NF90_DOUBLE, n_dim, nuvelid)
  96. iret = NF90_DEF_VAR(ntrajid, 'vvel', NF90_DOUBLE, n_dim, nvvelid)
  97. iret = NF90_DEF_VAR(ntrajid, 'uto', NF90_DOUBLE, n_dim, nuoid)
  98. iret = NF90_DEF_VAR(ntrajid, 'vto', NF90_DOUBLE, n_dim, nvoid)
  99. iret = NF90_DEF_VAR(ntrajid, 'uta', NF90_DOUBLE, n_dim, nuaid)
  100. iret = NF90_DEF_VAR(ntrajid, 'vta', NF90_DOUBLE, n_dim, nvaid)
  101. iret = NF90_DEF_VAR(ntrajid, 'uti', NF90_DOUBLE, n_dim, nuiid)
  102. iret = NF90_DEF_VAR(ntrajid, 'vti', NF90_DOUBLE, n_dim, nviid)
  103. iret = NF90_DEF_VAR(ntrajid, 'ssh_x', NF90_DOUBLE, n_dim, nsshxid)
  104. iret = NF90_DEF_VAR(ntrajid, 'ssh_y', NF90_DOUBLE, n_dim, nsshyid)
  105. iret = NF90_DEF_VAR(ntrajid, 'sst', NF90_DOUBLE, n_dim, nsstid)
  106. iret = NF90_DEF_VAR(ntrajid, 'icnt', NF90_DOUBLE, n_dim, ncntid)
  107. iret = NF90_DEF_VAR(ntrajid, 'ithk', NF90_DOUBLE, n_dim, nthkid)
  108. iret = NF90_DEF_VAR(ntrajid, 'mass', NF90_DOUBLE, n_dim, nmassid)
  109. iret = NF90_DEF_VAR(ntrajid, 'thickness', NF90_DOUBLE, n_dim, nthicknessid)
  110. iret = NF90_DEF_VAR(ntrajid, 'width', NF90_DOUBLE, n_dim, nwidthid)
  111. iret = NF90_DEF_VAR(ntrajid, 'length', NF90_DOUBLE, n_dim, nlengthid)
  112. iret = NF90_DEF_VAR(ntrajid, 'year', NF90_INT, n_dim, nyearid)
  113. iret = NF90_DEF_VAR(ntrajid, 'day', NF90_DOUBLE, n_dim, ndayid)
  114. iret = NF90_DEF_VAR(ntrajid, 'mass_of_bits', NF90_DOUBLE, n_dim, nmass_of_bits_id)
  115. iret = NF90_DEF_VAR(ntrajid, 'heat_density', NF90_DOUBLE, n_dim, nheat_density_id)
  116. ! Attributes
  117. iret = NF90_PUT_ATT(ntrajid, numberid, 'long_name', 'iceberg number on this processor')
  118. iret = NF90_PUT_ATT(ntrajid, numberid, 'units', 'count')
  119. iret = NF90_PUT_ATT(ntrajid, nstepid, 'long_name', 'timestep number kt')
  120. iret = NF90_PUT_ATT(ntrajid, nstepid, 'units', 'count')
  121. iret = NF90_PUT_ATT(ntrajid, nlonid, 'long_name', 'longitude')
  122. iret = NF90_PUT_ATT(ntrajid, nlonid, 'units', 'degrees_E')
  123. iret = NF90_PUT_ATT(ntrajid, nlatid, 'long_name', 'latitude')
  124. iret = NF90_PUT_ATT(ntrajid, nlatid, 'units', 'degrees_N')
  125. iret = NF90_PUT_ATT(ntrajid, nxid, 'long_name', 'x grid box position')
  126. iret = NF90_PUT_ATT(ntrajid, nxid, 'units', 'fractional')
  127. iret = NF90_PUT_ATT(ntrajid, nyid, 'long_name', 'y grid box position')
  128. iret = NF90_PUT_ATT(ntrajid, nyid, 'units', 'fractional')
  129. iret = NF90_PUT_ATT(ntrajid, nuvelid, 'long_name', 'zonal velocity')
  130. iret = NF90_PUT_ATT(ntrajid, nuvelid, 'units', 'm/s')
  131. iret = NF90_PUT_ATT(ntrajid, nvvelid, 'long_name', 'meridional velocity')
  132. iret = NF90_PUT_ATT(ntrajid, nvvelid, 'units', 'm/s')
  133. iret = NF90_PUT_ATT(ntrajid, nuoid, 'long_name', 'ocean u component')
  134. iret = NF90_PUT_ATT(ntrajid, nuoid, 'units', 'm/s')
  135. iret = NF90_PUT_ATT(ntrajid, nvoid, 'long_name', 'ocean v component')
  136. iret = NF90_PUT_ATT(ntrajid, nvoid, 'units', 'm/s')
  137. iret = NF90_PUT_ATT(ntrajid, nuaid, 'long_name', 'atmosphere u component')
  138. iret = NF90_PUT_ATT(ntrajid, nuaid, 'units', 'm/s')
  139. iret = NF90_PUT_ATT(ntrajid, nvaid, 'long_name', 'atmosphere v component')
  140. iret = NF90_PUT_ATT(ntrajid, nvaid, 'units', 'm/s')
  141. iret = NF90_PUT_ATT(ntrajid, nuiid, 'long_name', 'sea ice u component')
  142. iret = NF90_PUT_ATT(ntrajid, nuiid, 'units', 'm/s')
  143. iret = NF90_PUT_ATT(ntrajid, nviid, 'long_name', 'sea ice v component')
  144. iret = NF90_PUT_ATT(ntrajid, nviid, 'units', 'm/s')
  145. iret = NF90_PUT_ATT(ntrajid, nsshxid, 'long_name', 'sea surface height gradient from x points')
  146. iret = NF90_PUT_ATT(ntrajid, nsshxid, 'units', 'm/m')
  147. iret = NF90_PUT_ATT(ntrajid, nsshyid, 'long_name', 'sea surface height gradient from y points')
  148. iret = NF90_PUT_ATT(ntrajid, nsshyid, 'units', 'm/m')
  149. iret = NF90_PUT_ATT(ntrajid, nsstid, 'long_name', 'sea surface temperature')
  150. iret = NF90_PUT_ATT(ntrajid, nsstid, 'units', 'degC')
  151. iret = NF90_PUT_ATT(ntrajid, ncntid, 'long_name', 'sea ice concentration')
  152. iret = NF90_PUT_ATT(ntrajid, ncntid, 'units', 'degC')
  153. iret = NF90_PUT_ATT(ntrajid, nthkid, 'long_name', 'sea ice thickness')
  154. iret = NF90_PUT_ATT(ntrajid, nthkid, 'units', 'm')
  155. iret = NF90_PUT_ATT(ntrajid, nmassid, 'long_name', 'mass')
  156. iret = NF90_PUT_ATT(ntrajid, nmassid, 'units', 'kg')
  157. iret = NF90_PUT_ATT(ntrajid, nthicknessid, 'long_name', 'thickness')
  158. iret = NF90_PUT_ATT(ntrajid, nthicknessid, 'units', 'm')
  159. iret = NF90_PUT_ATT(ntrajid, nwidthid, 'long_name', 'width')
  160. iret = NF90_PUT_ATT(ntrajid, nwidthid, 'units', 'm')
  161. iret = NF90_PUT_ATT(ntrajid, nlengthid, 'long_name', 'length')
  162. iret = NF90_PUT_ATT(ntrajid, nlengthid, 'units', 'm')
  163. iret = NF90_PUT_ATT(ntrajid, nyearid, 'long_name', 'calendar year')
  164. iret = NF90_PUT_ATT(ntrajid, nyearid, 'units', 'years')
  165. iret = NF90_PUT_ATT(ntrajid, ndayid, 'long_name', 'day of year')
  166. iret = NF90_PUT_ATT(ntrajid, ndayid, 'units', 'days')
  167. iret = NF90_PUT_ATT(ntrajid, nscaling_id, 'long_name', 'scaling factor for mass of berg')
  168. iret = NF90_PUT_ATT(ntrajid, nscaling_id, 'units', 'none')
  169. iret = NF90_PUT_ATT(ntrajid, nmass_of_bits_id, 'long_name', 'mass of bergy bits')
  170. iret = NF90_PUT_ATT(ntrajid, nmass_of_bits_id, 'units', 'kg')
  171. iret = NF90_PUT_ATT(ntrajid, nheat_density_id, 'long_name', 'heat density')
  172. iret = NF90_PUT_ATT(ntrajid, nheat_density_id, 'units', 'J/kg')
  173. ! End define mode
  174. iret = NF90_ENDDEF(ntrajid)
  175. !
  176. END SUBROUTINE icb_trj_init
  177. SUBROUTINE icb_trj_write( kt )
  178. !!----------------------------------------------------------------------
  179. !! *** ROUTINE icb_trj_write ***
  180. !!
  181. !! ** Purpose : write out iceberg trajectories
  182. !!
  183. !! ** Method : - for the moment write out each snapshot of positions later
  184. !! can rewrite so that it is buffered and written out more efficiently
  185. !!----------------------------------------------------------------------
  186. INTEGER, INTENT( in ) :: kt
  187. !
  188. INTEGER :: iret, jn
  189. CHARACTER(len=80) :: cl_filename
  190. TYPE(iceberg), POINTER :: this
  191. TYPE(point) , POINTER :: pt
  192. !!----------------------------------------------------------------------
  193. ! Write variables
  194. ! sga - just write out the current point of the trajectory
  195. this => first_berg
  196. jn = num_traj
  197. DO WHILE (ASSOCIATED(this))
  198. pt => this%current_point
  199. jn=jn+1
  200. iret = NF90_PUT_VAR(ntrajid, numberid, this%number, (/1,jn/), (/nkounts,1/) )
  201. iret = NF90_PUT_VAR(ntrajid, nstepid, kt, (/ jn /) )
  202. iret = NF90_PUT_VAR(ntrajid, nscaling_id, this%mass_scaling, (/ jn /) )
  203. iret = NF90_PUT_VAR(ntrajid, nlonid, pt%lon, (/ jn /) )
  204. iret = NF90_PUT_VAR(ntrajid, nlatid, pt%lat, (/ jn /) )
  205. iret = NF90_PUT_VAR(ntrajid, nxid, pt%xi, (/ jn /) )
  206. iret = NF90_PUT_VAR(ntrajid, nyid, pt%yj, (/ jn /) )
  207. iret = NF90_PUT_VAR(ntrajid, nuvelid, pt%uvel, (/ jn /) )
  208. iret = NF90_PUT_VAR(ntrajid, nvvelid, pt%vvel, (/ jn /) )
  209. iret = NF90_PUT_VAR(ntrajid, nuoid, pt%uo, (/ jn /) )
  210. iret = NF90_PUT_VAR(ntrajid, nvoid, pt%vo, (/ jn /) )
  211. iret = NF90_PUT_VAR(ntrajid, nuaid, pt%ua, (/ jn /) )
  212. iret = NF90_PUT_VAR(ntrajid, nvaid, pt%va, (/ jn /) )
  213. iret = NF90_PUT_VAR(ntrajid, nuiid, pt%ui, (/ jn /) )
  214. iret = NF90_PUT_VAR(ntrajid, nviid, pt%vi, (/ jn /) )
  215. iret = NF90_PUT_VAR(ntrajid, nsshxid, pt%ssh_x, (/ jn /) )
  216. iret = NF90_PUT_VAR(ntrajid, nsshyid, pt%ssh_y, (/ jn /) )
  217. iret = NF90_PUT_VAR(ntrajid, nsstid, pt%sst, (/ jn /) )
  218. iret = NF90_PUT_VAR(ntrajid, ncntid, pt%cn, (/ jn /) )
  219. iret = NF90_PUT_VAR(ntrajid, nthkid, pt%hi, (/ jn /) )
  220. iret = NF90_PUT_VAR(ntrajid, nmassid, pt%mass, (/ jn /) )
  221. iret = NF90_PUT_VAR(ntrajid, nthicknessid, pt%thickness, (/ jn /) )
  222. iret = NF90_PUT_VAR(ntrajid, nwidthid, pt%width, (/ jn /) )
  223. iret = NF90_PUT_VAR(ntrajid, nlengthid, pt%length, (/ jn /) )
  224. iret = NF90_PUT_VAR(ntrajid, nyearid, pt%year, (/ jn /) )
  225. iret = NF90_PUT_VAR(ntrajid, ndayid, pt%day, (/ jn /) )
  226. iret = NF90_PUT_VAR(ntrajid, nmass_of_bits_id, pt%mass_of_bits, (/ jn /) )
  227. iret = NF90_PUT_VAR(ntrajid, nheat_density_id, pt%heat_density, (/ jn /) )
  228. this=>this%next
  229. END DO
  230. IF( lwp .and. nn_verbose_level > 0 ) WRITE(numout,*) 'trajectory write to frame ', jn
  231. num_traj = jn
  232. !
  233. END SUBROUTINE icb_trj_write
  234. !!-------------------------------------------------------------------------
  235. SUBROUTINE icb_trj_sync()
  236. !!----------------------------------------------------------------------
  237. !! *** ROUTINE icb_trj_sync ***
  238. !!
  239. !! ** Purpose :
  240. !!----------------------------------------------------------------------
  241. INTEGER :: iret
  242. !!----------------------------------------------------------------------
  243. ! flush to file
  244. iret = NF90_SYNC(ntrajid)
  245. IF(iret /= NF90_NOERR) CALL ctl_stop( 'icebergs, icb_trj_sync: nf_sync failed' )
  246. !
  247. END SUBROUTINE icb_trj_sync
  248. SUBROUTINE icb_trj_end()
  249. ! Local variables
  250. INTEGER :: iret
  251. !!----------------------------------------------------------------------
  252. ! Finish up
  253. iret = NF90_CLOSE(ntrajid)
  254. IF (iret /= NF90_NOERR) CALL ctl_stop( 'icebergs, icb_trj_end: nf_close failed' )
  255. !
  256. END SUBROUTINE icb_trj_end
  257. !!-------------------------------------------------------------------------
  258. END MODULE icbtrj