ecearth_optics.F90 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  2. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  3. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  4. !
  5. #include "tm5.inc"
  6. !
  7. !-----------------------------------------------------------------------------
  8. ! TM5 !
  9. !-----------------------------------------------------------------------------
  10. !BOP
  11. !
  12. ! !MODULE: ECEARTH_OPTICS
  13. !
  14. ! !DESCRIPTION: Optics module to calculate optical depth from m7 output, based
  15. ! on the AOP_Package of Michael Kahnert.
  16. !\\
  17. !\\
  18. ! !INTERFACE:
  19. !
  20. MODULE ECEARTH_OPTICS
  21. !
  22. ! !USES:
  23. !
  24. use GO, only : gol, goErr, goPr
  25. use global_types, only : d3_data
  26. use optics, only : wavelendep ! wavelength type
  27. use tm5_distgrid, only : dgrid, Get_DistGrid
  28. IMPLICIT NONE
  29. PRIVATE
  30. !
  31. ! !PUBLIC MEMBER FUNCTIONS:
  32. !
  33. public :: ECEarth_Optics_Init, ECEarth_Optics_Done, ECEarth_Optics_Step
  34. !
  35. ! !PUBLIC TYPES:
  36. !
  37. type, public :: optics_data
  38. real, dimension(:,:,:,:), pointer :: Ext, a, g
  39. end type optics_data
  40. !
  41. ! !PUBLIC DATA MEMBERS:
  42. !
  43. integer, public, parameter :: nregions_optics = 1 ! number of regions for which optical properties are calculated for EC-Earth
  44. type(optics_data), public, dimension(nregions_optics), target :: optics_dat ! optical properties container
  45. !
  46. ! !PRIVATE DATA MEMBERS:
  47. !
  48. !integer, parameter :: nwl = 6 ! number of wavelengths for EC-Earth v2
  49. integer, parameter :: nwl = 14 ! number of wavelengths for McRad (EC-Earth v3 and later)
  50. type(wavelendep), dimension(nwl) :: ecearth_wvl
  51. !
  52. character(len=*), parameter :: mname = 'ECEarth_Optics'
  53. !
  54. ! !REVISION HISTORY:
  55. ! Mar 2009 - Maarten Krol - Implemented
  56. ! Apr 2009 - Twan van Noije - Adapted
  57. ! 5 Sep 2013 - Ph. Le Sager - adapted for TM5v4
  58. ! 19 Sep 2013 - Ph. Le Sager - adapted for lon-Lat MPI decomposition
  59. !
  60. ! !REMARKS:
  61. !
  62. !EOP
  63. !------------------------------------------------------------------------
  64. CONTAINS
  65. !--------------------------------------------------------------------------
  66. ! TM5 !
  67. !--------------------------------------------------------------------------
  68. !BOP
  69. !
  70. ! !IROUTINE: ECEarth_Optics_Init
  71. !
  72. ! !DESCRIPTION: Read lookup table, initialize wavelengths and their
  73. ! parameters. Allocate work arrays. Called from initexit/start.
  74. !\\
  75. !\\
  76. ! !INTERFACE:
  77. !
  78. SUBROUTINE ECEarth_Optics_Init( status )
  79. !
  80. ! !USES:
  81. !
  82. use dims, only : lm
  83. use optics, only : optics_init
  84. !
  85. ! !OUTPUT PARAMETERS:
  86. !
  87. integer, intent(out) :: status
  88. !
  89. ! !REVISION HISTORY:
  90. ! 5 Sep 2013 - Ph. Le Sager - TM5v4 version
  91. ! 19 Sep 2013 - Ph. Le Sager - adapted for lon-Lat MPI decomposition
  92. !
  93. ! !REMARKS:
  94. !
  95. !EOP
  96. !------------------------------------------------------------------------
  97. !BOC
  98. integer :: region, i1, i2, j1, j2, lmr
  99. character(len=*), parameter :: rname = mname//'/ECEarth_Optics_Init'
  100. ! --- begin --------------------------------
  101. write (gol,'("Initializing M7 aerosol optical properties for EC-Earth (ancillary fields) ...")'); call goPr
  102. ! ------------------------------------------
  103. ! ecearth optics wavelengths
  104. ! for 6-band SW radiative code in IFS
  105. ! 0.185-0.25-0.44-0.69-1.19-2.38-4.00 micron
  106. ! ------------------------------------------
  107. ! ecearth_wvl( 1)%wl = 0.2175
  108. ! ecearth_wvl( 2)%wl = 0.345
  109. ! ecearth_wvl( 3)%wl = 0.565
  110. ! ecearth_wvl( 4)%wl = 0.94
  111. ! ecearth_wvl( 5)%wl = 1.785
  112. ! ecearth_wvl( 6)%wl = 3.19
  113. ! -------------------------------------
  114. ! ecearth optics wavelengths
  115. ! for "McRad" radiative code in IFS,
  116. ! adapted to account for solar spectrum
  117. ! as done in IFS, e.g. for MACv2-SP.
  118. ! -------------------------------------
  119. !ecearth_wvl( 1)%wl = 0.2316
  120. !ecearth_wvl( 2)%wl = 0.3040
  121. !ecearth_wvl( 3)%wl = 0.3932
  122. !ecearth_wvl( 4)%wl = 0.5332
  123. !ecearth_wvl( 5)%wl = 0.7016
  124. !ecearth_wvl( 6)%wl = 1.0101
  125. !ecearth_wvl( 7)%wl = 1.2705
  126. !ecearth_wvl( 8)%wl = 1.4625
  127. !ecearth_wvl( 9)%wl = 1.7840
  128. !ecearth_wvl(10)%wl = 2.0460
  129. !ecearth_wvl(11)%wl = 2.3250
  130. !ecearth_wvl(12)%wl = 2.7885
  131. !ecearth_wvl(13)%wl = 3.4615
  132. !ecearth_wvl(14)%wl = 8.0205
  133. ecearth_wvl( 1)%wl = 0.257
  134. ecearth_wvl( 2)%wl = 0.313
  135. ecearth_wvl( 3)%wl = 0.398
  136. ecearth_wvl( 4)%wl = 0.530
  137. ecearth_wvl( 5)%wl = 0.697
  138. ecearth_wvl( 6)%wl = 0.973
  139. ecearth_wvl( 7)%wl = 1.269
  140. ecearth_wvl( 8)%wl = 1.447
  141. ecearth_wvl( 9)%wl = 1.767
  142. ecearth_wvl(10)%wl = 2.040
  143. ecearth_wvl(11)%wl = 2.308
  144. ecearth_wvl(12)%wl = 2.752
  145. ecearth_wvl(13)%wl = 3.407
  146. ecearth_wvl(14)%wl = 5.254
  147. ecearth_wvl%split = .false.
  148. ecearth_wvl%insitu = .false.
  149. ! ------------------------------------------
  150. ! initialise the optics
  151. ! ------------------------------------------
  152. ! read lookup table, initialize wavelength dependent parameters
  153. call optics_init( nwl, ecearth_wvl, status )
  154. IF_NOTOK_RETURN(status=1)
  155. ! ------------------------------------------
  156. ! allocate optical properties arrays.
  157. ! ------------------------------------------
  158. do region = 1, nregions_optics
  159. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  160. lmr = lm(region)
  161. allocate ( optics_dat(region)%Ext(i1:i2,j1:j2,lmr,nwl)); optics_dat(region)%Ext = 0.
  162. allocate ( optics_dat(region)%a (i1:i2,j1:j2,lmr,nwl)); optics_dat(region)%a = 0.
  163. allocate ( optics_dat(region)%g (i1:i2,j1:j2,lmr,nwl)); optics_dat(region)%g = 0.
  164. end do
  165. ! ok
  166. status = 0
  167. END SUBROUTINE ECEarth_Optics_Init
  168. !EOC
  169. !--------------------------------------------------------------------------
  170. ! TM5 !
  171. !--------------------------------------------------------------------------
  172. !BOP
  173. !
  174. ! !IROUTINE: ECEARTH_OPTICS_STEP
  175. !
  176. ! !DESCRIPTION:
  177. !\\
  178. !\\
  179. ! !INTERFACE:
  180. !
  181. subroutine ECEarth_Optics_Step( status )
  182. !
  183. ! !USES:
  184. !
  185. use optics, only : optics_aop_get
  186. use dims, only : lm
  187. use tm5_prism, only : ifs_cpl_nlev, ifs_cpl_nlev_cutoff, refine_levels
  188. !
  189. ! !OUTPUT PARAMETERS:
  190. !
  191. integer, intent(out) :: status
  192. !
  193. ! !REVISION HISTORY:
  194. ! 5 Sep 2013 - Ph. Le Sager - TM5v4
  195. ! 19 Sep 2013 - Ph. Le Sager - adapted for lon-Lat MPI decomposition
  196. !
  197. ! !REMARKS:
  198. !
  199. !EOP
  200. !------------------------------------------------------------------------
  201. !BOC
  202. integer :: region, i1, i2, j1, j2, lmr
  203. integer :: lwl, lvec
  204. real, dimension(:,:,:), allocatable :: aop_out_ext
  205. real, dimension(:,:), allocatable :: aop_out_a, aop_out_g
  206. logical, parameter :: new_units=.false.
  207. ! --- const ------------------------------
  208. character(len=*), parameter :: rname = mname//'/ECEarth_Optics_Step'
  209. ! --- begin --------------------------------
  210. REG: do region = 1, nregions_optics
  211. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  212. if (ifs_cpl_nlev_cutoff /= ifs_cpl_nlev) then
  213. if (.NOT. refine_levels) then
  214. ! Limit optics calculations at IFS wavelengths to ifs_cpl_nlev_cutoff.
  215. ! The values at higher levels are not sent to IFS
  216. ! and can therefore be left zero.
  217. lmr = ifs_cpl_nlev_cutoff
  218. else
  219. write(gol,'("WARNING: EC-Earth optics called for the whole atmosphere,")'); call goPr
  220. write(gol,'("WARNING: but not all levels are sent to IFS")'); call goPr
  221. lmr = lm(region)
  222. endif
  223. else
  224. lmr = lm(region)
  225. endif
  226. lvec = (i2-i1+1)*(j2-j1+1)*lmr
  227. ! allocate AOP fields
  228. allocate( aop_out_ext(lvec, nwl, 1 ) ) ! extinction
  229. allocate( aop_out_a (lvec, nwl ) ) ! single scattering albedo (extinction due to absorption if new_units)
  230. allocate( aop_out_g (lvec, nwl ) ) ! asymmetry factor (times extinction due to scattering if new_units)
  231. ! Compute AOP (ie fill aop_out_* arrays)
  232. call optics_aop_get( lvec, region, nwl, ecearth_wvl, 1, new_units, &
  233. aop_out_ext, aop_out_a, aop_out_g, status )
  234. IF_NOTOK_RETURN(status=1)
  235. ! ---------------------------------
  236. ! unpack results from aop computation
  237. ! ---------------------------------
  238. do lwl = 1, nwl
  239. optics_dat(region)%ext(:,:,1:lmr,lwl) = reshape( aop_out_ext(:,lwl,1), (/(i2-i1+1),(j2-j1+1),lmr/) )
  240. optics_dat(region)%a (:,:,1:lmr,lwl) = reshape( aop_out_a (:,lwl), (/(i2-i1+1),(j2-j1+1),lmr/) )
  241. optics_dat(region)%g (:,:,1:lmr,lwl) = reshape( aop_out_g (:,lwl), (/(i2-i1+1),(j2-j1+1),lmr/) )
  242. end do
  243. ! free temporary arrays for results from calculate_aop
  244. deallocate( aop_out_ext, aop_out_a, aop_out_g )
  245. end do REG
  246. status = 0
  247. END SUBROUTINE ECEARTH_OPTICS_STEP
  248. !EOC
  249. !--------------------------------------------------------------------------
  250. ! TM5 !
  251. !--------------------------------------------------------------------------
  252. !BOP
  253. !
  254. ! !IROUTINE: ECEARTH_OPTICS_DONE
  255. !
  256. ! !DESCRIPTION: Deallocate optical properties arrays. Called from initexit/exitus.
  257. !\\
  258. !\\
  259. ! !INTERFACE:
  260. !
  261. SUBROUTINE ECEarth_Optics_Done( status )
  262. !
  263. ! !OUTPUT PARAMETERS:
  264. !
  265. integer, intent(out) :: status
  266. !
  267. ! !REVISION HISTORY:
  268. ! 5 Sep 2013 - Ph. Le Sager -
  269. !
  270. ! !REMARKS:
  271. !
  272. !EOP
  273. !------------------------------------------------------------------------
  274. !BOC
  275. character(len=*), parameter :: rname = mname//'/ECEarth_Optics_Done'
  276. integer :: region
  277. ! --- begin --------------------------------
  278. do region = 1, nregions_optics
  279. deallocate ( optics_dat(region)%Ext )
  280. deallocate ( optics_dat(region)%a )
  281. deallocate ( optics_dat(region)%g )
  282. enddo
  283. ! ok
  284. status = 0
  285. END SUBROUTINE ECEarth_Optics_Done
  286. !EOC
  287. END MODULE ECEARTH_OPTICS