emission_nh3.F90 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. !
  2. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  3. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  4. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  5. !
  6. #include "tm5.inc"
  7. !
  8. !-----------------------------------------------------------------------------
  9. ! TM5 !
  10. !-----------------------------------------------------------------------------
  11. !BOP
  12. !
  13. ! !MODULE: EMISSION_NH3
  14. !
  15. ! !DESCRIPTION: Perform NH3 emissions needed for TM5 CBM4 version.
  16. !\\
  17. !\\
  18. ! !INTERFACE:
  19. !
  20. MODULE EMISSION_NH3
  21. !
  22. ! !USES:
  23. !
  24. use GO, only : gol, goErr, goPr
  25. use tm5_distgrid, only : dgrid, get_distgrid, scatter, gather
  26. use dims, only : nregions, idate, okdebug
  27. use global_types, only : emis_data, d3_data
  28. use emission_read, only : used_providers, has_emis
  29. implicit none
  30. private
  31. !
  32. ! !PUBLIC MEMBER FUNCTIONS:
  33. !
  34. public :: Emission_NH3_init ! allocate
  35. public :: Emission_nh3_declare ! read monthly input
  36. public :: Emission_nh3_apply ! distribute & add emissions to tracer array
  37. public :: Emission_nh3_done ! deallocate
  38. !
  39. ! !PRIVATE DATA MEMBERS:
  40. !
  41. character(len=*), parameter :: mname = 'emission_nh3'
  42. type(emis_data), dimension(:,:), allocatable :: nh3_emis_2d
  43. type(d3_data), dimension(:,:), allocatable :: nh3_emis_3d
  44. integer :: nh3_3dsec, nh3_2dsec
  45. logical, allocatable :: has_data_3d(:), has_data_2d(:)
  46. !
  47. ! !REVISION HISTORY:
  48. ! 1 Oct 2010 - Achim Strunk - overhaul for AR5
  49. ! 1 Dec 2011 - Narcisa Banda - added EDGAR 4
  50. ! 25 Jun 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  51. !
  52. ! !REMARKS:
  53. !
  54. !EOP
  55. !------------------------------------------------------------------------
  56. CONTAINS
  57. !--------------------------------------------------------------------------
  58. ! TM5 !
  59. !--------------------------------------------------------------------------
  60. !BOP
  61. !
  62. ! !IROUTINE: EMISSION_NH3_INIT
  63. !
  64. ! !DESCRIPTION: Allocate space needed to handle the emissions
  65. !\\
  66. !\\
  67. ! !INTERFACE:
  68. !
  69. SUBROUTINE EMISSION_NH3_INIT( status )
  70. !
  71. ! !USES:
  72. !
  73. use dims, only : lm
  74. use emission_read, only : providers_def, numb_providers, ed42_nsect_nh3
  75. use emission_data, only : LAR5BMB
  76. use emission_read, only : n_ar5_ant_sec, n_ar5_shp_sec, n_ar5_air_sec, n_ar5_bmb_sec
  77. use emission_read, only : ar5_cat_ant, ar5_cat_shp, ar5_cat_air, ar5_cat_bmb
  78. !
  79. ! !OUTPUT PARAMETERS:
  80. !
  81. integer, intent(out) :: status
  82. !
  83. ! !REVISION HISTORY:
  84. ! 1 Oct 2010 - Achim Strunk - v0
  85. ! 25 Jun 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  86. !
  87. !EOP
  88. !------------------------------------------------------------------------
  89. !BOC
  90. character(len=*), parameter :: rname = mname//'/Emission_NH3_Init'
  91. integer :: region
  92. integer :: lmr, lsec, lprov, i1, i2, j1, j2
  93. ! --- begin --------------------------------------
  94. status = 0
  95. if(.not. has_emis) return
  96. ! nb of sectors
  97. nh3_2dsec = 0
  98. nh3_3dsec = 0
  99. do lprov = 1, numb_providers
  100. if (count(used_providers.eq.providers_def(lprov)%name)/=0) then
  101. if (trim(providers_def(lprov)%name) .eq. 'AR5') then
  102. ! nb of available sectors in AR5 depends on category
  103. nh3_2dsec = nh3_2dsec + n_ar5_ant_sec*count('NH3'.eq.ar5_cat_ant) + &
  104. n_ar5_shp_sec*count('NH3'.eq.ar5_cat_shp)
  105. if (LAR5BMB) nh3_2dsec = nh3_2dsec + n_ar5_bmb_sec*count('NH3'.eq.ar5_cat_bmb)
  106. nh3_3dsec = nh3_3dsec + n_ar5_air_sec*count('NH3'.eq.ar5_cat_air)
  107. elseif (trim(providers_def(lprov)%name) .eq. 'ED42') then
  108. nh3_2dsec = nh3_2dsec + ed42_nsect_nh3
  109. ! no 3d sectors in EDGAR 4.2
  110. else
  111. nh3_2dsec = nh3_2dsec + providers_def(lprov)%nsect2d
  112. nh3_3dsec = nh3_3dsec + providers_def(lprov)%nsect3d
  113. endif
  114. endif
  115. enddo
  116. ! basic check
  117. if (nh3_2dsec == 0) then
  118. write(gol,*) "WARNING - there is no 2D sectors for NH3 !"; call goPr
  119. end if
  120. if (nh3_3dsec == 0) then
  121. write(gol,*) "WARNING - there is no 3D sectors for NH3 !"; call goPr
  122. end if
  123. allocate( nh3_emis_2d( nregions, nh3_2dsec ) )
  124. allocate( nh3_emis_3d( nregions, nh3_3dsec ) )
  125. allocate( has_data_2d(nh3_2dsec)) ; has_data_2d=.false.
  126. allocate( has_data_3d(nh3_3dsec)) ; has_data_3d=.false.
  127. ! allocate information arrays (2d and 3d)
  128. do region=1,nregions
  129. CALL GET_DISTGRID( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  130. lmr = lm(region)
  131. do lsec=1,nh3_2dsec
  132. allocate( nh3_emis_2d(region,lsec)%surf(i1:i2,j1:j2) )
  133. end do
  134. do lsec=1,nh3_3dsec
  135. allocate( nh3_emis_3d(region,lsec)%d3(i1:i2,j1:j2,lmr) )
  136. end do
  137. enddo
  138. ! ok
  139. status = 0
  140. END SUBROUTINE EMISSION_NH3_INIT
  141. !EOC
  142. !--------------------------------------------------------------------------
  143. ! TM5 !
  144. !--------------------------------------------------------------------------
  145. !BOP
  146. !
  147. ! !IROUTINE: EMISSION_NH3_DONE
  148. !
  149. ! !DESCRIPTION: Free space after handling of the emissions
  150. !\\
  151. !\\
  152. ! !INTERFACE:
  153. !
  154. SUBROUTINE EMISSION_NH3_DONE( status )
  155. !
  156. ! !OUTPUT PARAMETERS:
  157. !
  158. integer, intent(out) :: status
  159. !
  160. ! !REVISION HISTORY:
  161. ! 1 Oct 2010 - Achim Strunk - v0
  162. !
  163. !EOP
  164. !------------------------------------------------------------------------
  165. !BOC
  166. character(len=*), parameter :: rname = mname//'/Emission_NH3_Done'
  167. integer :: region, lsec
  168. ! --- begin ---------------------------------
  169. status = 0
  170. if(.not. has_emis) return
  171. do region = 1, nregions
  172. do lsec=1,nh3_2dsec
  173. deallocate( nh3_emis_2d(region,lsec)%surf )
  174. end do
  175. do lsec=1,nh3_3dsec
  176. deallocate( nh3_emis_3d(region,lsec)%d3 )
  177. end do
  178. end do
  179. deallocate( nh3_emis_2d, nh3_emis_3d )
  180. deallocate( has_data_2d, has_data_3d )
  181. status = 0
  182. END SUBROUTINE EMISSION_NH3_DONE
  183. !EOC
  184. !--------------------------------------------------------------------------
  185. ! TM5 !
  186. !--------------------------------------------------------------------------
  187. !BOP
  188. !
  189. ! !IROUTINE: EMISSION_NH3_DECLARE
  190. !
  191. ! !DESCRIPTION: Opens, reads and evaluates input files (per month).
  192. ! Provides emissions on 2d/3d-arrays which are then added
  193. ! to tracers in routine *apply.
  194. !\\
  195. !\\
  196. ! !INTERFACE:
  197. !
  198. SUBROUTINE EMISSION_NH3_DECLARE( status )
  199. !
  200. ! !USES:
  201. !
  202. use toolbox, only : coarsen_emission
  203. use partools, only : isRoot, par_broadcast
  204. use dims, only : im, jm, lm, idate, sec_month, nlon360, nlat180, iglbsfc
  205. use chem_param, only : xmnh3
  206. use emission_data, only : msg_emis, LAR5BMB
  207. ! ---------------- AR5 - EDGAR 4 - ETC. --------------------
  208. use emission_data, only : emis_input_year
  209. use emission_data, only : emis_input_dir_mac
  210. use emission_data, only : emis_input_dir_retro
  211. use emission_data, only : emis_input_dir_gfed
  212. use emission_data, only : emis_input_dir_ed4
  213. use emission_read, only : emission_ar5_regrid_aircraft
  214. use emission_read, only : emission_ar5_ReadSector
  215. use emission_read, only : emission_macc_ReadSector
  216. use emission_read, only : emission_ed4_ReadSector
  217. use emission_read, only : emission_gfed_ReadSector
  218. use emission_read, only : emission_retro_ReadSector
  219. use emission_read, only : sectors_def, numb_sectors
  220. use emission_read, only : ar5_dim_3ddata
  221. use emission_read, only : ed42_nh3_sectors
  222. !
  223. ! !OUTPUT PARAMETERS:
  224. !
  225. integer, intent(out) :: status
  226. !
  227. ! !REVISION HISTORY:
  228. ! 1 Oct 2010 - Achim Strunk - adapted for AR5
  229. ! 1 Dec 2011 - Narcisa Banda - added EDGAR 4
  230. ! 25 Jun 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  231. !
  232. !EOP
  233. !------------------------------------------------------------------------
  234. !BOC
  235. character(len=*), parameter :: rname = mname//'/emission_nh3_declare'
  236. integer :: region, hasData
  237. integer,parameter :: add_field=0
  238. integer,parameter :: amonth=2
  239. integer :: imr, jmr, lmr, lsec
  240. ! AR5
  241. real,dimension(:,:,:), allocatable :: field3d, field3d2
  242. type(d3_data) :: emis3d, work(nregions)
  243. type(emis_data) :: wrk2D(nregions)
  244. integer :: seccount2d, seccount3d
  245. ! --- begin -----------------------------------------
  246. status = 0
  247. if(.not. has_emis) return
  248. write(gol,'(" EMISS-INFO ------------- read NH3 emissions -------------")'); call goPr
  249. ! reset arrays
  250. do region = 1, nregions
  251. do lsec=1,nh3_2dsec
  252. nh3_emis_2d(region,lsec)%surf = 0.0
  253. end do
  254. do lsec=1,nh3_3dsec
  255. nh3_emis_3d(region,lsec)%d3 = 0.0
  256. end do
  257. end do
  258. ! global arrays for coarsening
  259. do region = 1, nregions
  260. if (isRoot)then
  261. allocate(work(region)%d3(im(region),jm(region),lm(region)))
  262. else
  263. allocate(work(region)%d3(1,1,1))
  264. end if
  265. enddo
  266. do region = 1, nregions
  267. wrk2D(region)%surf => work(region)%d3(:,:,1)
  268. end do
  269. ! --------------------------------
  270. ! do a loop over available sectors
  271. ! --------------------------------
  272. ! count 2d and 3d sectors
  273. seccount2d = 0
  274. seccount3d = 0
  275. ! always allocate here 3d data set (for 2d sectors it will be filled in first layer only)
  276. if (isRoot) then
  277. allocate( field3d( nlon360, nlat180, ar5_dim_3ddata ) ) ; field3d = 0.0
  278. else
  279. allocate( field3d( 1, 1, 1 ) )
  280. end if
  281. sec : do lsec = 1, numb_sectors
  282. if (count(used_providers.eq.sectors_def(lsec)%prov).eq.0) cycle
  283. if ((trim(sectors_def(lsec)%prov).eq.'ED42') .and. (count(ed42_nh3_sectors.eq.sectors_def(lsec)%name) .eq. 0)) cycle
  284. if (associated(sectors_def(lsec)%species)) then ! AR5 checks
  285. if (count('NH3'.eq.sectors_def(lsec)%species).eq.0) cycle
  286. if ((trim(sectors_def(lsec)%catname) .eq. 'biomassburning').and.(.not.LAR5BMB)) cycle
  287. endif
  288. field3d = 0.0
  289. if( sectors_def(lsec)%f3d ) then
  290. seccount3d = seccount3d + 1
  291. else
  292. seccount2d = seccount2d + 1
  293. end if
  294. if (isRoot) then ! READ
  295. select case( trim(sectors_def(lsec)%prov) )
  296. case( 'AR5' )
  297. ! Screen out solvent, waste and shipping sectors for NH3,
  298. ! because they are zero in the RCPs
  299. ! and not present in the historical files.
  300. if (trim(sectors_def(lsec)%name) .ne. 'emiss_slv' .and. &
  301. trim(sectors_def(lsec)%name) .ne. 'emiss_wst' .and. &
  302. trim(sectors_def(lsec)%name) .ne. 'emiss_shp') then
  303. call emission_ar5_ReadSector( 'NH3', emis_input_year, idate(2), lsec, field3d, status )
  304. IF_NOTOK_RETURN(status=1)
  305. endif
  306. case( 'MACC' )
  307. ! screen out 'nat', 'bio', 'air' sectors
  308. if ( ( .not. (trim(sectors_def(lsec)%name) .eq. 'emiss_nat')) .and. &
  309. ( .not. (trim(sectors_def(lsec)%name) .eq. 'emiss_bio')) .and. &
  310. ( .not. (trim(sectors_def(lsec)%name) .eq. 'emiss_air')) ) then
  311. call emission_macc_ReadSector( emis_input_dir_mac, 'NH3', emis_input_year, idate(2), &
  312. '0.5x0.5_kg.nc', sectors_def(lsec)%name, 'kg / s', field3d, status )
  313. IF_NOTOK_RETURN(status=1)
  314. endif
  315. case( 'ED41' )
  316. select case(trim(sectors_def(lsec)%name))
  317. case ('1A3b_c_e')
  318. call emission_ed4_ReadSector( emis_input_dir_ed4, 'NH3', 'nh3', 2005, idate(2), &
  319. lsec, trim(sectors_def(lsec)%prov), 'kg / s', field3d, status )
  320. IF_NOTOK_RETURN(status=1)
  321. end select
  322. case( 'ED42' )
  323. ! biomass burning (GFED/RETRO/AR5BMB) and transport (ED41) are excluded through ED42_NH3_SECTORS definition
  324. call emission_ed4_ReadSector( emis_input_dir_ed4, 'NH3', 'nh3', emis_input_year, idate(2), &
  325. lsec, trim(sectors_def(lsec)%prov), 'kg / s', field3d, status )
  326. IF_NOTOK_RETURN(status=1)
  327. case('GFEDv3')
  328. call emission_gfed_ReadSector( emis_input_dir_gfed, 'nh3', emis_input_year, idate(2), &
  329. sectors_def(lsec)%name, 'kg / s', field3d(:,:,1), status )
  330. IF_NOTOK_RETURN(status=1)
  331. case('RETRO')
  332. call emission_retro_ReadSector( emis_input_dir_retro, 'NH3', emis_input_year, idate(2), &
  333. sectors_def(lsec)%name, 'kg / s', field3d(:,:,1), status )
  334. IF_NOTOK_RETURN(status=1)
  335. case('MEGAN')
  336. !
  337. ! No biogenic NH3 emissions available in MEGAN
  338. !
  339. case('DUMMY')
  340. case default
  341. write(gol,*) "Error in buidling list of providers USED_PROVIDERS"; call goErr
  342. status=1; TRACEBACK; return
  343. end select
  344. ! nothing found???
  345. if( sum(field3d) < 100.*TINY(1.0) ) then
  346. if (okdebug) then
  347. write(gol,'("EMISS-INFO - no NH3 emissions found for ",a," ",a," for month ",i2 )') &
  348. trim(sectors_def(lsec)%prov), trim(sectors_def(lsec)%name), idate(2) ; call goPr
  349. endif
  350. hasData=0
  351. else
  352. if (okdebug) then
  353. write(gol,'("EMISS-INFO - found NH3 emissions for ",a," ",a," for month ",i2 )') &
  354. trim(sectors_def(lsec)%prov), trim(sectors_def(lsec)%name), idate(2) ; call goPr
  355. endif
  356. ! scale from kg/s to kg/month
  357. field3d = field3d * sec_month ! kg / month
  358. hasData=1
  359. end if
  360. end if
  361. call Par_broadcast(hasData, status)
  362. IF_NOTOK_RETURN(status=1)
  363. if (hasData == 0) then
  364. cycle sec
  365. else
  366. if ( sectors_def(lsec)%f3d ) then
  367. has_data_3d(seccount3d)=.true.
  368. else
  369. has_data_2d(seccount2d)=.true.
  370. end if
  371. end if
  372. ! Distinguish 2d/3d sectors
  373. if( sectors_def(lsec)%f3d ) then
  374. write(gol,'("EMISS-ERROR - Unexpected 3D data: Uncomment code below ")'); call goErr
  375. status=1; TRACEBACK; return
  376. ! ---------------------------
  377. ! 3d data (AIRCRAFT)
  378. ! ---------------------------
  379. ! if (isRoot) then ! REGRID
  380. ! ! helper array for regridding
  381. ! allocate( field3d2( nlon360,nlat180,lm(1) ) ) ; field3d2 = 0.0
  382. ! ! aircraft data: regrid vertically to model layers
  383. ! call emission_ar5_regrid_aircraft( iglbsfc, field3d, nlon360, nlat180, ar5_dim_3ddata, lm(1), field3d2, status )
  384. ! IF_NOTOK_RETURN(status=1;deallocate(field3d,field3d2))
  385. ! ! write some numbers
  386. ! call msg_emis( amonth, trim(sectors_def(lsec)%prov),sectors_def(lsec)%name, 'NH3', xmnh3, sum(field3d2) )
  387. ! IF_NOTOK_RETURN(status=1;deallocate(field3d,field3d2))
  388. ! ! distribute to nh3_emis in regions
  389. ! call Coarsen_Emission( 'NH3 '//trim(sectors_def(lsec)%name), nlon360, nlat180, lm(1), &
  390. ! field3d2, work, add_field, status )
  391. ! IF_NOTOK_RETURN(status=1;deallocate(field3d,field3d2))
  392. ! deallocate( field3d2 )
  393. ! end if
  394. ! do region = 1, nregions
  395. ! call scatter(dgrid(region), nh3_emis_3d(region,seccount3d)%d3, work(region)%d3, 0, status)
  396. ! IF_NOTOK_RETURN(status=1)
  397. ! end do
  398. else ! ar5_sector is 2d
  399. ! ---------------------------
  400. ! 2d data (Anthropogenic, Ships, Biomassburning)
  401. ! ---------------------------
  402. if (isRoot) then ! print total & regrid
  403. call msg_emis( amonth, trim(sectors_def(lsec)%prov), sectors_def(lsec)%name, 'NH3', xmnh3, sum(field3d(:,:,1)) )
  404. IF_NOTOK_RETURN(status=1)
  405. call coarsen_emission( 'NH3 '//sectors_def(lsec)%name, nlon360, nlat180, field3d(:,:,1), wrk2D, add_field, status)
  406. IF_NOTOK_RETURN(status=1)
  407. end if
  408. do region = 1, nregions
  409. call scatter(dgrid(region), nh3_emis_2d(region,seccount2d)%surf, work(region)%d3(:,:,1), 0, status)
  410. IF_NOTOK_RETURN(status=1)
  411. end do
  412. end if
  413. end do sec ! sectors
  414. deallocate( field3d )
  415. do region = 1, nregions
  416. if (associated(wrk2D(region)%surf)) nullify(wrk2D(region)%surf)
  417. deallocate( work(region)%d3 )
  418. end do
  419. ! check sectors found
  420. if( seccount2d /= nh3_2dsec ) then
  421. write(gol,'(80("-"))') ; call goPr
  422. write(gol,'("ERROR: 2d sectors do not equal total number:",i4," /= ",i4," !")') seccount2d, nh3_2dsec ; call goErr
  423. write(gol,'(80("-"))') ; call goPr
  424. status=1; return
  425. end if
  426. if( seccount3d /= nh3_3dsec ) then
  427. write(gol,'(80("-"))') ; call goPr
  428. write(gol,'("ERROR: 3d sectors do not equal total number:",i4," /= ",i4," !")') seccount3d, nh3_3dsec ; call goErr
  429. write(gol,'(80("-"))') ; call goPr
  430. status=1; return
  431. end if
  432. status = 0
  433. END SUBROUTINE EMISSION_NH3_DECLARE
  434. !EOC
  435. !--------------------------------------------------------------------------
  436. ! TM5 !
  437. !--------------------------------------------------------------------------
  438. !BOP
  439. !
  440. ! !IROUTINE: EMISSION_NH3_APPLY
  441. !
  442. ! !DESCRIPTION: Take monthly emissions, and
  443. ! - split them vertically
  444. ! - apply time splitting factors
  445. ! - add them up (add_3d)
  446. !\\
  447. !\\
  448. ! !INTERFACE:
  449. !
  450. SUBROUTINE EMISSION_NH3_APPLY( region, status )
  451. !
  452. ! !USES:
  453. !
  454. use dims, only : itaur, nsrce, tref
  455. use dims, only : im, jm, lm
  456. use datetime, only : tau2date
  457. use emission_data, only : emission_vdist_by_sector, LAR5BMB
  458. use emission_data, only : do_add_3d, do_add_3d_cycle, bb_cycle
  459. use emission_data, only : emis_bb_trop_cycle
  460. use chem_param, only : inh3, xmnh3, xmn
  461. use emission_read, only : sectors_def, numb_sectors
  462. use emission_read, only : ed42_nh3_sectors
  463. !
  464. ! !INPUT PARAMETERS:
  465. !
  466. integer, intent(in) :: region
  467. !
  468. ! !OUTPUT PARAMETERS:
  469. !
  470. integer, intent(out) :: status
  471. !
  472. ! !REVISION HISTORY:
  473. ! 1 Oct 2010 - Achim Strunk - adapted for new vertical distribution
  474. ! 25 Jun 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  475. !
  476. !EOP
  477. !------------------------------------------------------------------------
  478. !BOC
  479. character(len=*), parameter :: rname = mname//'/emission_nh3_apply'
  480. integer, dimension(6) :: idater
  481. real :: dtime, fraction
  482. integer :: imr, jmr, lmr, lsec, i1, i2, j1, j2
  483. integer :: seccount2d, seccount3d
  484. type(d3_data) :: emis3d
  485. ! --- begin -----------------------------------------
  486. status = 0
  487. if(.not. has_emis) return
  488. if( okdebug ) then
  489. write(gol,*) 'start of emission_nh3_apply'; call goPr
  490. end if
  491. call tau2date(itaur(region),idater)
  492. dtime=float(nsrce)/(2*tref(region)) !emissions are added in two steps...XYZECCEZYX.
  493. if(okdebug) then
  494. write(gol,*) 'emission_nh3_apply in region ',region,' at date: ',idater, ' with time step:', dtime ; call goPr
  495. endif
  496. ! get a working structure for 3d emissions
  497. call get_distgrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  498. allocate( emis3d%d3(i1:i2,j1:j2,lm(region)) ) ; emis3d%d3 = 0.0
  499. ! count 2d and 3d sectors
  500. seccount2d = 0
  501. seccount3d = 0
  502. ! cycle over sectors
  503. do lsec = 1, numb_sectors
  504. if (count(used_providers.eq.sectors_def(lsec)%prov).eq.0) cycle
  505. if ((trim(sectors_def(lsec)%prov).eq.'ED42') .and. (count(ed42_nh3_sectors.eq.sectors_def(lsec)%name) .eq. 0)) cycle
  506. if (associated(sectors_def(lsec)%species)) then ! AR5 check
  507. if (count('NH3'.eq.sectors_def(lsec)%species).eq.0) cycle
  508. if ((trim(sectors_def(lsec)%catname) .eq. 'biomassburning').and.(.not.LAR5BMB)) cycle
  509. endif
  510. ! default: no additional splitting
  511. fraction = 1.0
  512. ! ----------------------------------------------------------------------------------------
  513. ! distinguish here between sectors and whether they should have additional splitting
  514. ! if( sectors_def(lsec)%catname == 'biomassburning' ) fraction = fraction * bb_frac etc...
  515. ! ----------------------------------------------------------------------------------------
  516. ! distinguish between 2d/3d sectors
  517. if( sectors_def(lsec)%f3d ) then
  518. seccount3d = seccount3d + 1
  519. if (.not.has_data_3d(seccount3d)) cycle
  520. emis3d%d3 = nh3_emis_3d(region,seccount3d)%d3
  521. else
  522. seccount2d = seccount2d + 1
  523. if (.not.has_data_2d(seccount2d)) cycle
  524. emis3d%d3 = 0.0
  525. ! vertically distribute according to sector
  526. call emission_vdist_by_sector( sectors_def(lsec)%vdisttype, 'NH3', region, nh3_emis_2d(region,seccount2d), emis3d, status)
  527. IF_NOTOK_RETURN(status=1;deallocate(emis3d%d3))
  528. end if
  529. ! add dataset according to sector and category
  530. if( emis_bb_trop_cycle .and. trim(sectors_def(lsec)%catname) == "biomassburning" ) then
  531. call do_add_3d_cycle( region, inh3, i1, j1, emis3d%d3, bb_cycle(region)%scalef, xmnh3, xmnh3, status, fraction )
  532. IF_NOTOK_RETURN(status=1)
  533. else
  534. call do_add_3d( region, inh3, i1, j1, emis3d%d3, xmnh3, xmnh3, status, fraction )
  535. IF_NOTOK_RETURN(status=1)
  536. end if
  537. end do
  538. deallocate( emis3d%d3 )
  539. if(okdebug) then
  540. write(gol,*) 'end of emission_nh3_apply'; call goPr
  541. endif
  542. ! OK
  543. status = 0
  544. end subroutine emission_nh3_apply
  545. !EOC
  546. END MODULE EMISSION_NH3