chemistry.F90 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  1. #define TRACEBACK write (gol,'("in ",a," (",a,i6,")")') 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. #include "output.inc"
  7. !
  8. !-----------------------------------------------------------------------------
  9. ! TM5 !
  10. !-----------------------------------------------------------------------------
  11. !BOP
  12. !
  13. ! !MODULE: CHEMISTRY
  14. !
  15. ! !DESCRIPTION: perform CB05 chemistry simulation in TM5 + M7
  16. !\\
  17. !\\
  18. ! !INTERFACE:
  19. !
  20. MODULE CHEMISTRY
  21. !
  22. ! !USES:
  23. !
  24. use GO, only : gol, goErr, goPr, goBug
  25. use tm5_distgrid, only : dgrid, Get_DistGrid, gather
  26. use dims, only : nregions
  27. #ifdef with_budgets
  28. use budget_global, only : nbudg, nbud_vg
  29. use chem_param, only : ntrace, ntracet
  30. #endif
  31. IMPLICIT NONE
  32. PRIVATE
  33. !
  34. ! !PUBLIC MEMBER FUNCTIONS:
  35. !
  36. public :: Chemistry_Init, Chemistry_Done
  37. public :: Chemie
  38. !
  39. ! !PRIVATE DATA MEMBERS:
  40. !
  41. #ifdef with_budgets
  42. real, dimension(:,:,:), allocatable :: budchem
  43. real, Dimension(:,:,:), Allocatable :: budeqsam
  44. real :: eminox
  45. #ifdef with_m7
  46. real, dimension(:,:,:), allocatable :: budm7proc
  47. real, dimension(:,:,:), allocatable :: budm7
  48. real, dimension(:,:,:),allocatable,public::d_nucle, growth1_2, coag_sink_nuc, cond1_soa, cond1_su, m_nucle_su
  49. real, dimension(:,:,:),allocatable,public::cond2_soa, cond3_soa, cond4_soa, cond5_soa, m_nucle_soa
  50. #endif
  51. #endif
  52. character(len=*), parameter :: mname = 'chemistry'
  53. !
  54. ! minimal concentration required to apply scaling for slopes
  55. ! (to avoid floating point overflows):
  56. real, parameter :: eps = 1.0e-20
  57. !
  58. ! !REVISION HISTORY:
  59. ! 2005 - Elisabetta Vignati - changed for coupling with M7
  60. ! 22 Mar 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  61. !
  62. ! !REMARKS:
  63. !
  64. !EOP
  65. !------------------------------------------------------------------------
  66. CONTAINS
  67. !--------------------------------------------------------------------------
  68. ! TM5 !
  69. !--------------------------------------------------------------------------
  70. !BOP
  71. !
  72. ! !IROUTINE: CHEMISTRY_INIT
  73. !
  74. ! !DESCRIPTION: allocate and initialize budget arrays. Init M7 if needed.
  75. !\\
  76. !\\
  77. ! !INTERFACE:
  78. !
  79. SUBROUTINE CHEMISTRY_INIT( status )
  80. !
  81. ! !USES:
  82. !
  83. use Dims , only : nregions, im, jm, lm
  84. #ifdef with_budgets
  85. use Chem_param, only : ntrace, ntracet
  86. use ebischeme , only : sum_deposition, sum_wetchem, sum_chemistry
  87. use ebischeme , only : buddep_dat, budrrg, budrjg, budrwg,diag_prod,AC_diag_prod,AC_O3_lp,AC_loss,nprod,nprod_AC,nprod_AC_o3,n_loss
  88. !PLS use chem_param, only : ch4oh, so4pg, so4pa, o3p, o3l
  89. use chem_param, only : o3p, o3l
  90. #ifdef with_m7
  91. use m7_data, only : nm7procs
  92. #endif
  93. #endif
  94. #ifdef with_m7
  95. use mo_aero_m7, only : m7_initialize
  96. use m7_data, only : init_m7_data
  97. #endif
  98. use meteoData , only : Set
  99. use MeteoData , only : phlb_dat, m_dat, temper_dat, humid_dat, gph_dat
  100. use MeteoData , only : lwc_dat, iwc_dat, cc_dat
  101. !
  102. ! !OUTPUT PARAMETERS:
  103. !
  104. integer, intent(out) :: status
  105. !
  106. ! !REVISION HISTORY:
  107. ! 22 Mar 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  108. !
  109. !EOP
  110. !------------------------------------------------------------------------
  111. !BOC
  112. integer :: region, i1, i2, j1, j2
  113. character(len=*), parameter :: rname = mname//'/Chemistry_Init'
  114. ! --- begin --------------------------------
  115. ! select meteo to be used:
  116. do region = 1, nregions
  117. call Set( phlb_dat(region), status, used=.true. )
  118. call Set( m_dat(region), status, used=.true. )
  119. call Set( temper_dat(region), status, used=.true. )
  120. call Set( humid_dat(region), status, used=.true. )
  121. call Set( gph_dat(region), status, used=.true. )
  122. call Set( lwc_dat(region), status, used=.true. )
  123. call Set( iwc_dat(region), status, used=.true. )
  124. call Set( cc_dat(region), status, used=.true. )
  125. enddo
  126. #ifdef with_budgets
  127. do region = 1, nregions
  128. sum_chemistry (region) = 0.0
  129. sum_deposition(region) = 0.0
  130. sum_wetchem (region) = 0.0
  131. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  132. allocate(buddep_dat(region)%dry(i1:i2, j1:j2, ntrace))
  133. buddep_dat(region)%dry = 0.0
  134. !nprod=4
  135. #ifdef with_m7
  136. allocate(diag_prod (region)%prod(i1:i2, j1:j2, lm(region), nprod))
  137. allocate(AC_diag_prod(region)%prod(i1:i2, j1:j2, lm(region), nprod_AC))
  138. allocate(AC_O3_lp (region)%prod(i1:i2, j1:j2, lm(region), nprod_AC_o3))
  139. allocate(AC_loss (region)%prod(i1:i2, j1:j2, lm(region), n_loss))
  140. diag_prod(region)%prod = 0.0
  141. AC_diag_prod(region)%prod = 0.0
  142. AC_O3_lp(region)%prod = 0.0
  143. AC_loss(region)%prod = 0.0
  144. allocate(d_nucle(i1:i2,j1:j2,lm(region)))
  145. allocate(m_nucle_su(i1:i2,j1:j2,lm(region)))
  146. allocate(m_nucle_soa(i1:i2,j1:j2,lm(region)))
  147. allocate(growth1_2(i1:i2,j1:j2,lm(region)))
  148. allocate(coag_sink_nuc(i1:i2,j1:j2,lm(region)))
  149. allocate(cond1_soa(i1:i2,j1:j2,lm(region)))
  150. allocate(cond2_soa(i1:i2,j1:j2,lm(region)))
  151. allocate(cond3_soa(i1:i2,j1:j2,lm(region)))
  152. allocate(cond4_soa(i1:i2,j1:j2,lm(region)))
  153. allocate(cond5_soa(i1:i2,j1:j2,lm(region)))
  154. allocate(cond1_su(i1:i2,j1:j2,lm(region)))
  155. d_nucle=0.0
  156. m_nucle_soa=0.0
  157. m_nucle_su=0.0
  158. growth1_2=0.0
  159. coag_sink_nuc=0.0
  160. cond1_soa=0.0
  161. cond2_soa=0.0
  162. cond3_soa=0.0
  163. cond4_soa=0.0
  164. cond5_soa=0.0
  165. cond1_su=0.0
  166. #endif
  167. allocate(o3p(region)%d3(i1:i2, j1:j2, lm(region))); o3p(region)%d3 = 0.0
  168. allocate(o3l(region)%d3(i1:i2, j1:j2, lm(region))); o3l(region)%d3 = 0.0
  169. ! >>>
  170. ! TvN: still in sources_sinks.F90
  171. ! allocate(ch4oh(region)%d3(i1:i2, j1:j2, lm(region))); ch4oh(region)%d3 = 0.0
  172. ! allocate(so4pg(region)%d3(i1:i2, j1:j2, lm(region))); so4pg(region)%d3 = 0.0
  173. ! allocate(so4pa(region)%d3(i1:i2, j1:j2, lm(region))); so4pa(region)%d3 = 0.0
  174. ! <<<
  175. enddo
  176. budrrg = 0.0
  177. budrjg = 0.0
  178. budrwg = 0.0
  179. Allocate(budchem(nbudg,nbud_vg,ntrace))
  180. budchem = 0.0
  181. ! Two acid-base reactions
  182. Allocate(budeqsam(nbudg,nbud_vg,2))
  183. budeqsam = 0.0
  184. #ifdef with_m7
  185. ! M7 Bugets
  186. Allocate(budm7proc(nbudg,nbud_vg,nm7procs))
  187. Allocate(budm7(nbudg,nbud_vg,ntracet))
  188. budm7proc = 0.0
  189. budm7 = 0.0
  190. #endif
  191. ! global lightning NOx
  192. eminox = 0.
  193. #endif /* BUDGETS */
  194. #ifdef with_m7
  195. CALL M7_INITIALIZE
  196. CALL INIT_M7_DATA( status ) ! declare M7 output data structure
  197. IF_NOTOK_RETURN(status=1)
  198. #endif
  199. ! ok
  200. status = 0
  201. END SUBROUTINE CHEMISTRY_INIT
  202. !EOC
  203. !--------------------------------------------------------------------------
  204. ! TM5 !
  205. !--------------------------------------------------------------------------
  206. !BOP
  207. !
  208. ! !IROUTINE: CHEMISTRY_DONE
  209. !
  210. ! !DESCRIPTION: gather and write budgets
  211. !\\
  212. !\\
  213. ! !INTERFACE:
  214. !
  215. SUBROUTINE CHEMISTRY_DONE( status )
  216. !
  217. ! !USES:
  218. !
  219. use dims, only : nregions, im, jm, lm
  220. #ifdef with_budgets
  221. use dims, only : region_name
  222. #ifdef with_hdf4
  223. use file_hdf, only : Init, Done, WriteAttribute, WriteData, SetDim, THdfFile, TSds
  224. #endif
  225. use budget_global, only : budget_file_global, budg_dat, NHAB
  226. #ifndef without_boundary
  227. use boundary, only : budstratg
  228. #endif
  229. #ifndef without_emission
  230. use emission, only : budemig_all
  231. #endif
  232. use partools, only : isRoot, par_reduce_element, par_reduce
  233. use ebischeme, only : sum_deposition, sum_wetchem, sum_chemistry
  234. use ebischeme, only : buddep_dat, budrrg, budrjg, budrwg, budmarkg, diag_prod, AC_diag_prod, AC_O3_lp, AC_loss
  235. !PLS use chem_param, only : ch4oh, so4pg, so4pa, o3p, o3l, marknam, nmark
  236. use chem_param, only : o3p, o3l, marknam, nmark
  237. use chem_param, only : marknam, ntrace
  238. use chem_param, only : inox
  239. use reaction_data, only : nreac, ratnam, nreacw, rwnam
  240. use photolysis_data, only : nj, jnam
  241. #ifdef with_cariolle
  242. use chem_param, only : ncar, carnam
  243. use chemistry_cariolle, only : budcarg
  244. #endif
  245. #ifdef with_m7
  246. use m7_data, only : nm7procs
  247. #endif
  248. #endif /* BUDGETS */
  249. #ifdef with_m7
  250. use m7_data, only : free_m7_data
  251. #endif
  252. !
  253. ! !OUTPUT PARAMETERS:
  254. !
  255. integer, intent(out) :: status
  256. !
  257. ! !REVISION HISTORY:
  258. ! 22 Mar 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  259. !
  260. ! !REMARKS:
  261. !
  262. !EOP
  263. !------------------------------------------------------------------------
  264. !BOC
  265. character(len=*), parameter :: rname = mname//'/Chemistry_Done'
  266. integer :: region
  267. #ifdef with_budgets
  268. #ifdef with_hdf4
  269. type(THdfFile) :: io
  270. type(TSds) :: sds
  271. #endif
  272. real, dimension(:,:,:), allocatable :: collectb
  273. real,dimension(nbudg,nbud_vg,ntrace) :: buddry
  274. real,dimension(nbudg,nbud_vg,ntrace) :: budchem_result
  275. integer :: i, j, l, nzone, n, nsend, i1, i2, j1, j2
  276. ! for buggy MPI (see comment in budget_global.F90 for details)
  277. real, dimension(nregions) :: sum_chemistry_all, sum_wetchem_all, sum_deposition_all
  278. real, dimension(nbudg,nbud_vg,nreac) :: budrrg_all
  279. real, dimension(nbudg,nbud_vg,nj) :: budrjg_all
  280. real, dimension(nbudg,nbud_vg,nreacw) :: budrwg_all
  281. real, dimension(nbudg,nbud_vg,nmark) :: budmarkg_all
  282. real, dimension(nbudg,nbud_vg,ntrace) :: buddry_all
  283. real, dimension(nbudg,nbud_vg,ntrace) :: budchem_all
  284. real, dimension(nbudg,nbud_vg,2) :: budeqsam_all
  285. real :: eminox_all
  286. #ifndef without_boundary
  287. real, dimension(nbudg,nbud_vg,ntracet) :: budstratg_all
  288. #endif
  289. #ifdef with_cariolle
  290. real, dimension(nbudg,nbud_vg,ncar) :: budcarg_all
  291. #endif
  292. #ifdef with_m7
  293. real, dimension(nbudg,nbud_vg,ntracet) :: budm7_all
  294. real, dimension(nbudg,nbud_vg,nm7procs) :: budm7proc_all
  295. #endif
  296. #ifdef with_m7
  297. ! Do not change this order. And if you do, look through the M7 code to pprocess (parameter process) where it is written with a fixed paramter. You can, however, change this order if it is made dynamic.
  298. Character(len=8), Dimension(nm7procs), Parameter :: m7procnames = (/'NucN ','NucSU ','Coag11N ','Coag12N ','Coag12SU',&
  299. 'Coag13N ','Coag13SU','Coag14N ','Coag14SU','Coag15N ','Coag15SU','Coag16N ','Coag16SU','Coag17N ','Coag17SU',&
  300. 'Coag22N ','Coag23N ','Coag23SU','Coag23BC','Coag23OC','Coag24N ','Coag24SU','Coag24BC','Coag24OC','Coag25N ',&
  301. 'Coag25BC','Coag25OC','Coag26N ','Coag26SU','Coag26BC','Coag26OC','Coag27N ','Coag27SU','Coag27BC','Coag27OC',&
  302. 'Coag33N ','Coag35N ','Coag35BC','Coag35OC','Coag55N ','Cond1SU ','Cond2SU ','Cond3SU ','Cond4SU ','Cond5SU ',&
  303. 'Cond6SU ','Cond7SU ','Age5N ','Age5BC ','Age5OC ','Age6N ','Age6DU ','Age7N ','Age7DU ','Grow1N ',&
  304. 'Grow1SU ','Grow2N ','Grow2SU ','Grow2BC ','Grow2OC ','Grow3N ','Grow3SU ','Grow3BC ','Grow3OC ','Grow3SS ',&
  305. 'Grow3DU ','Coa12SOA','Coa13SOA','Coa14SOA','Coa15SOA','Coa16SOA','Coa17SOA','Coa23SOA','Coa24SOA','Coa25SOA',&
  306. 'Coa26SOA','Coa27SOA','Coa35SOA','Cond1SOA','Cond2SOA','Cond3SOA','Cond4SOA','Cond5SOA','Age5SOA ','Grow1SOA',&
  307. 'Grow2SOA','Grow3SOA','NucSOA '/)
  308. ! Array for left hand sides, static attribute for the M7 process budget data set.
  309. Character(len=8), Dimension(nm7procs), Parameter :: m7proclhs = (/'void ','H2SO4 ','NUS_N ','NUS_N ','SO4NUS ',&
  310. 'NUS_N ','SO4NUS ','NUS_N ','SO4NUS ','NUS_N ','SO4NUS ','NUS_N ','SO4NUS ','NUS_N ','SO4NUS ',&
  311. 'AIS_N ','AIS_N ','SO4AIS ','BCAIS ','POMAIS ','AIS_N ','SO4AIS ','BCAIS ','POMAIS ','AII_N ',&
  312. 'BCAII ','POMAII ','AIS_N ','SO4AIS ','BCAIS ','POMAIS ','AIS_N ','SO4AIS ','BCAIS ','POMAIS ',&
  313. 'ACS_N ','AII_N ','BCAII ','POMAII ','AII_N ','H2SO4 ','H2SO4 ','H2SO4 ','H2SO4 ','H2SO4 ',&
  314. 'H2SO4 ','H2SO4 ','AII_N ','BCAII ','POMAII ','ACI_N ','DUACI ','COI_N ','DUCOI ','NUS_N ',&
  315. 'SO4NUS ','AIS_N ','SO4AIS ','BCAIS ','POMAIS ','ACS_N ','SO4ACS ','BCACS ','POMACS ','SSACS ',&
  316. 'DUACS ','SOANUS ','SOANUS ','SOANUS ','SOANUS ','SOANUS ','SOANUS ','SOAAIS ','SOAAIS ','SOAAII ',&
  317. 'SOAAIS ','SOAAIS ','SOAAII ','EL+SVOC ','EL+SVOC ','EL+SVOC ','EL+SVOC ','EL+SVOC ','SOAAII ','SOANUS ',&
  318. 'SOAAIS ','SOAACS ','ELVOC '/)
  319. ! Array for right hand sides, static attribute for the M7 process budget data set.
  320. Character(len=8), Dimension(nm7procs), Parameter :: m7procrhs = (/'NUS_N ','SO4NUS ','void ','void ','SO4AIS ',&
  321. 'void ','SO4ACS ','void ','SO4COS ','void ','SO4AIS ','void ','SO4ACS ','void ','SO4COS ',&
  322. 'void ','void ','SO4ACS ','BCACS ','POMACS ','void ','SO4COS ','BCCOS ','POMCOS ','void ',&
  323. 'BCAIS ','POMAIS ','void ','SO4ACS ','BCACS ','POMACS ','void ','SO4COS ','BCCOS ','POMCOS ',&
  324. 'void ','void ','BCACS ','POMACS ','void ','SO4NUS ','SO4AIS ','SO4ACS ','SO4COS ','SO4AIS ',&
  325. 'SO4ACS ','SO4COS ','AIS_N ','BCAIS ','POMAIS ','ACS_N ','DUACS ','COS_N ','DUCOS ','AIS_N ',&
  326. 'SO4AIS ','ACS_N ','SO4ACS ','BCACS ','POMACS ','COS_N ','SO4COS ','BCCOS ','POMCOS ','SSCOS ',&
  327. 'DUCOS ','SOAAIS ','SOAACS ','SOACOS ','SOAAIS ','SOAACS ','SOACOS ','SOAACS ','SOAACS ','SOAAIS ',&
  328. 'SOAACS ','SOACOS ','SOAACS ','SOANUS ','SOAAIS ','SOAACS ','SOACOS ','SOAAII ','SOAAIS ','SOAAIS ',&
  329. 'SOAACS ','SOACOS ','SOANUS '/)
  330. #endif
  331. #endif /* BUDGETS */
  332. ! --- begin --------------------------------
  333. #ifdef with_budgets
  334. eminox_all=0.0
  335. ! Sum up contribution from each proc into root array
  336. call PAR_REDUCE_ELEMENT(budrrg, 'SUM', budrrg_all, status )
  337. do region = 1, nregions
  338. CALL PAR_REDUCE(sum_chemistry(region), 'SUM', sum_chemistry_all(region), status)
  339. IF_NOTOK_RETURN(status=1)
  340. CALL PAR_REDUCE(sum_deposition(region), 'SUM', sum_deposition_all(region), status)
  341. IF_NOTOK_RETURN(status=1)
  342. CALL PAR_REDUCE(sum_wetchem(region), 'SUM', sum_wetchem_all(region), status)
  343. IF_NOTOK_RETURN(status=1)
  344. end do
  345. ! Sum up contribution from each proc into root array for "total LiNOx"
  346. call PAR_REDUCE( eminox, 'SUM', eminox_all, status )
  347. eminox_all = eminox_all*1.e-9 ! kg -> Tg
  348. #ifdef with_hdf4
  349. if ( isRoot ) then
  350. call Init(io, budget_file_global, 'write', status)
  351. IF_NOTOK_RETURN(status=1)
  352. call WriteAttribute(io, 'sum_chemistry' , sum_chemistry_all, status)
  353. IF_NOTOK_RETURN(status=1)
  354. call WriteAttribute(io, 'sum_wetchem' , sum_wetchem_all, status)
  355. IF_NOTOK_RETURN(status=1)
  356. call WriteAttribute(io, 'sum_deposition' , sum_deposition_all, status)
  357. IF_NOTOK_RETURN(status=1)
  358. call WriteAttribute(io, 'total_lightning_nox_emissions_Tg_N' , eminox_all, status)
  359. IF_NOTOK_RETURN(status=1)
  360. call Init(Sds, io, 'budrr', (/nbudg,nbud_vg,nreac/), 'real(8)', status)
  361. IF_NOTOK_RETURN(status=1)
  362. call WriteAttribute(Sds, 'ratnam', ratnam, status)
  363. IF_NOTOK_RETURN(status=1)
  364. call SetDim(Sds, 0, 'nbudg', 'horizontal region', (/(j, j=1,nbudg)/), status)
  365. call SetDim(Sds, 1, 'nbud_vg','vertical layer', (/(j, j=1,nbud_vg)/), status)
  366. call SetDim(Sds, 2, 'nreac', 'reaction number', (/(j, j=1,nreac)/), status)
  367. IF_NOTOK_RETURN(status=1)
  368. call WriteData(Sds, BUDRRG_all, status)
  369. IF_NOTOK_RETURN(status=1)
  370. call Done(Sds, status)
  371. IF_NOTOK_RETURN(status=1)
  372. end if
  373. #endif
  374. ! Sum up contribution from each proc into root array
  375. call PAR_REDUCE_ELEMENT(budrjg, 'SUM', budrjg_all, status )
  376. #ifdef with_hdf4
  377. if ( isRoot ) then
  378. call Init(Sds,io, 'budrj',(/nbudg,nbud_vg,nj/), 'real(8)', status)
  379. IF_NOTOK_RETURN(status=1)
  380. call WriteAttribute(Sds, 'jnam', jnam, status)
  381. IF_NOTOK_RETURN(status=1)
  382. call SetDim(Sds, 0, 'nbudg','horizontal region', (/(j, j=1,nbudg)/), status)
  383. call SetDim(Sds, 1, 'nbud_vg','vertical layer', (/(j, j=1,nbud_vg)/), status)
  384. call SetDim(Sds, 2, 'nj','reaction number', (/(j, j=1,nj)/), status)
  385. IF_NOTOK_RETURN(status=1)
  386. call WriteData(Sds, BUDRJG_all, status)
  387. IF_NOTOK_RETURN(status=1)
  388. call Done(Sds, status)
  389. IF_NOTOK_RETURN(status=1)
  390. end if
  391. #endif
  392. ! Lets us write down the WET CHEMISTRY
  393. call PAR_REDUCE_ELEMENT(budrwg, 'SUM', budrwg_all, status )
  394. #ifdef with_hdf4
  395. if ( isRoot ) then
  396. call Init(Sds,io, 'budrw',(/nbudg,nbud_vg,nreacw/), 'real(8)', status)
  397. IF_NOTOK_RETURN(status=1)
  398. call WriteAttribute(Sds, 'rwnam', rwnam, status)
  399. IF_NOTOK_RETURN(status=1)
  400. call SetDim(Sds, 0, 'nbudg','horizontal region', (/(j, j=1,nbudg)/), status)
  401. call SetDim(Sds, 1, 'nbud_vg','vertical layer', (/(j, j=1,nbud_vg)/), status)
  402. call SetDim(Sds, 2, 'nreacw','wet reaction number', (/(j, j=1,nreacw)/), status)
  403. IF_NOTOK_RETURN(status=1)
  404. call WriteData(Sds, BUDRWG_all, status)
  405. IF_NOTOK_RETURN(status=1)
  406. call Done(Sds, status)
  407. IF_NOTOK_RETURN(status=1)
  408. end if
  409. #endif
  410. ! Sum up contribution from each proc into root array
  411. call PAR_REDUCE_ELEMENT(budmarkg, 'SUM', budmarkg_all, status )
  412. #ifdef with_hdf4
  413. if ( isRoot ) then
  414. call Init(Sds,io, 'budmark',(/nbudg,nbud_vg,nmark/), 'real(8)', status)
  415. IF_NOTOK_RETURN(status=1)
  416. call WriteAttribute(Sds, 'marknam', marknam, status)
  417. IF_NOTOK_RETURN(status=1)
  418. call SetDim(Sds, 0, 'nbudg','horizontal region', (/(j, j=1,nbudg)/), status)
  419. call SetDim(Sds, 1, 'nbud_vg','vertical layer', (/(j, j=1,nbud_vg)/), status)
  420. call SetDim(Sds, 2, 'nmark','marked tracer number', (/(j, j=1,nmark)/), status)
  421. IF_NOTOK_RETURN(status=1)
  422. call WriteData(Sds, BUDMARKG_all, status)
  423. IF_NOTOK_RETURN(status=1)
  424. call Done(Sds, status)
  425. IF_NOTOK_RETURN(status=1)
  426. end if
  427. #endif
  428. ! DRYDEP budget
  429. buddry = 0.0
  430. do region=1,nregions
  431. ! aggregates horizontally budget
  432. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  433. do n=1,ntrace
  434. do j=j1,j2
  435. do i=i1,i2
  436. nzone = budg_dat(region)%nzong(i,j)
  437. buddry(nzone,1,n) = buddry(nzone,1,n) + buddep_dat(region)%dry(i,j,n)
  438. end do
  439. end do
  440. end do
  441. call PAR_REDUCE_ELEMENT(buddry, 'SUM', buddry_all, status ) ! contribution from all procs
  442. ! gather and write Non-Horizontally-Aggregated-Budgets
  443. if (NHAB) then
  444. if ( isRoot ) then
  445. allocate( collectb(im(region),jm(region),ntrace ))
  446. else
  447. allocate( collectb(1,1,1))
  448. end if
  449. call GATHER( dgrid(region), buddep_dat(region)%dry, collectb, 0, status)
  450. #ifdef with_hdf4
  451. if(isRoot) then
  452. call Init(Sds,io, 'buddep_dat_dry_'//region_name(region),(/im(region),jm(region),ntrace/), 'real(4)', status)
  453. call SetDim(Sds, 0, 'im_'//region_name(region),'longitude', (/(j, j=1,im(region))/), status)
  454. call SetDim(Sds, 1, 'jm_'//region_name(region),'latitude', (/(j, j=1,jm(region))/), status)
  455. call SetDim(Sds, 2, 'ntrace','tracer index', (/(j, j=1,ntrace)/), status)
  456. IF_NOTOK_RETURN(status=1)
  457. call WriteData(Sds, collectb, status)
  458. IF_NOTOK_RETURN(status=1)
  459. call Done(Sds, status)
  460. IF_NOTOK_RETURN(status=1)
  461. endif
  462. #endif
  463. deallocate(collectb)
  464. endif ! NHAB
  465. enddo ! regions
  466. !-- write more aggregated budgets
  467. call PAR_REDUCE_ELEMENT(budchem, 'SUM', budchem_all, status )
  468. call PAR_REDUCE_ELEMENT(budeqsam, 'SUM', budeqsam_all, status )
  469. #ifndef without_boundary
  470. call PAR_REDUCE_ELEMENT(budstratg,'SUM', budstratg_all, status )
  471. #endif
  472. #ifdef with_m7
  473. call PAR_REDUCE_ELEMENT(budm7, 'SUM', budm7_all, status )
  474. call PAR_REDUCE_ELEMENT(budm7proc,'SUM', budm7proc_all, status )
  475. #endif
  476. if(isRoot) then
  477. #ifdef with_hdf4
  478. call Init(Sds,io, 'buddry',(/nbudg,nbud_vg,ntrace/), 'real(8)', status)
  479. IF_NOTOK_RETURN(status=1)
  480. call SetDim(Sds, 0, 'nbudg','horizontal region', (/(j, j=1,nbudg)/), status)
  481. call SetDim(Sds, 1, 'nbud_vg','vertical layer', (/(j, j=1,nbud_vg)/), status)
  482. call SetDim(Sds, 2, 'ntrace','tracer index', (/(j, j=1,ntrace)/), status)
  483. IF_NOTOK_RETURN(status=1)
  484. call WriteData(Sds,buddry_all,status)
  485. IF_NOTOK_RETURN(status=1)
  486. call Done(Sds, status)
  487. IF_NOTOK_RETURN(status=1)
  488. Call Init(Sds,io,"budchem",(/nbudg,nbud_vg,ntrace/),'real(8)',status)
  489. call SetDim(Sds, 0, 'nbudg','horizontal budget', (/(j, j=1,nbudg)/), status)
  490. call SetDim(Sds, 1, 'nbud_vg','vertical budget', (/(j, j=1,nbud_vg)/), status)
  491. call SetDim(Sds, 2, 'ntrace','tracer number', (/(j, j=1,ntrace)/), status)
  492. IF_NOTOK_RETURN(status=1)
  493. call WriteAttribute(Sds, 'comment', 'EBI budget stuffed together. Hopefully it does not explode', status)
  494. #endif
  495. ! correct chemistry budget
  496. budchem_result = budchem_all+buddry_all
  497. #ifndef without_emission
  498. budchem_result(:,:,inox) = budchem_result(:,:,inox) - budemig_all(:,:,inox)
  499. #endif
  500. #ifdef with_hdf4
  501. call WriteData(Sds,budchem_result,status)
  502. IF_NOTOK_RETURN(status=1)
  503. call Done(Sds, status)
  504. IF_NOTOK_RETURN(status=1)
  505. Call Init(Sds,io,"budeqsam",(/nbudg,nbud_vg,2/),'real(8)',status)
  506. call SetDim(Sds, 0, 'nbudg','horizontal budget', (/(j, j=1,nbudg)/), status)
  507. call SetDim(Sds, 1, 'nbud_vg','vertical budget', (/(j, j=1,nbud_vg)/), status)
  508. call SetDim(Sds, 2, 'AB_reac','Acid-base reaction number', (/(j, j=1,2)/), status)
  509. IF_NOTOK_RETURN(status=1)
  510. call WriteAttribute(Sds, 'comment', 'EQSAM evil acid base reaction. Positive forms aerosol material.', status)
  511. call WriteData(Sds,budeqsam_all,status)
  512. IF_NOTOK_RETURN(status=1)
  513. call Done(Sds, status)
  514. IF_NOTOK_RETURN(status=1)
  515. #ifndef without_boundary
  516. Call Init(Sds,io,"budstrat",(/nbudg,nbud_vg,ntracet/),'real(8)',status)
  517. call SetDim(Sds, 0, 'nbudg','horizontal budget', (/(j, j=1,nbudg)/), status)
  518. call SetDim(Sds, 1, 'nbud_vg','vertical budget', (/(j, j=1,nbud_vg)/), status)
  519. call SetDim(Sds, 2, 'ntracet','tracer number', (/(j, j=1,ntracet)/), status)
  520. IF_NOTOK_RETURN(status=1)
  521. call WriteAttribute(Sds, 'comment', 'Stratosphere (from boundary.F90)', status)
  522. call WriteData(Sds,budstratg_all,status)
  523. IF_NOTOK_RETURN(status=1)
  524. call Done(Sds, status)
  525. IF_NOTOK_RETURN(status=1)
  526. #endif
  527. #endif
  528. endif
  529. #ifdef with_cariolle
  530. call PAR_REDUCE_ELEMENT(budcarg, 'SUM', budcarg_all, status )
  531. #ifdef with_hdf4
  532. if ( isRoot ) then
  533. call Init(Sds,io, 'budcar',(/nbudg,nbud_vg,ncar/), 'real(8)', status)
  534. IF_NOTOK_RETURN(status=1)
  535. call WriteAttribute(Sds, 'carnam', carnam, status)
  536. IF_NOTOK_RETURN(status=1)
  537. call SetDim(Sds, 0, 'nbudg','horizontal region', (/(j, j=1,nbudg)/), status)
  538. call SetDim(Sds, 1, 'nbud_vg','vertical layer', (/(j, j=1,nbud_vg)/), status)
  539. call SetDim(Sds, 2, 'ncar','Cariolle tracer number', (/(j, j=1,ncar)/), status)
  540. IF_NOTOK_RETURN(status=1)
  541. call WriteData(Sds,budcarg_all,status)
  542. IF_NOTOK_RETURN(status=1)
  543. call Done(Sds, status)
  544. IF_NOTOK_RETURN(status=1)
  545. end if
  546. #endif
  547. #endif
  548. #ifdef with_m7
  549. #ifdef with_hdf4
  550. if ( isRoot ) then
  551. ! M7 process budget
  552. Call Init(Sds,io,"budm7proc",(/nbudg,nbud_vg,nm7procs/),'real(8)',status)
  553. call SetDim(Sds, 0, 'nbudg','horizontal budget', (/(j, j=1,nbudg)/), status)
  554. call SetDim(Sds, 1, 'nbud_vg','vertical budget', (/(j, j=1,nbud_vg)/), status)
  555. call SetDim(Sds, 2, 'nm7proc','M7 process number', (/(j, j=1,nm7procs)/), status)
  556. IF_NOTOK_RETURN(status=1)
  557. call WriteAttribute(Sds, 'procnames',m7procnames, status)
  558. call WriteAttribute(Sds, 'lefthandsides',m7proclhs, status)
  559. call WriteAttribute(Sds, 'righthandsides',m7procrhs, status)
  560. call WriteData(Sds,budm7proc_all,status)
  561. IF_NOTOK_RETURN(status=1)
  562. call Done(Sds, status)
  563. IF_NOTOK_RETURN(status=1)
  564. ! M7 budget
  565. Call Init(Sds,io,"budm7",(/nbudg,nbud_vg,ntracet/),'real(8)',status)
  566. call SetDim(Sds, 0, 'nbudg','horizontal budget', (/(j, j=1,nbudg)/), status)
  567. call SetDim(Sds, 1, 'nbud_vg','vertical budget', (/(j, j=1,nbud_vg)/), status)
  568. call SetDim(Sds, 2, 'ntracet','tracer number', (/(j, j=1,ntracet)/), status)
  569. IF_NOTOK_RETURN(status=1)
  570. call WriteAttribute(Sds, 'comment', 'M7 budget stuffed together. Hopefully the M7 tracers have now correct budgets', status)
  571. call WriteData(Sds,budm7_all,status)
  572. IF_NOTOK_RETURN(status=1)
  573. call Done(Sds, status)
  574. IF_NOTOK_RETURN(status=1)
  575. endif
  576. if ( isRoot ) then
  577. call Done(io, status)
  578. IF_NOTOK_RETURN(status=1)
  579. endif
  580. #endif
  581. #endif
  582. do region = 1, nregions
  583. #ifdef with_m7
  584. deallocate(diag_prod (region)%prod)
  585. deallocate(AC_diag_prod(region)%prod)
  586. deallocate(AC_O3_lp (region)%prod)
  587. deallocate(AC_loss (region)%prod)
  588. #endif
  589. deallocate(buddep_dat(region)%dry)
  590. deallocate(o3p(region)%d3)
  591. deallocate(o3l(region)%d3)
  592. enddo
  593. deallocate(budchem)
  594. deallocate(budeqsam)
  595. #ifdef with_m7
  596. deallocate(budm7proc)
  597. deallocate(budm7)
  598. deallocate(d_nucle)
  599. deallocate(m_nucle_su)
  600. deallocate(m_nucle_soa)
  601. deallocate(growth1_2)
  602. deallocate(coag_sink_nuc)
  603. deallocate(cond1_soa)
  604. deallocate(cond2_soa)
  605. deallocate(cond3_soa)
  606. deallocate(cond4_soa)
  607. deallocate(cond5_soa)
  608. deallocate(cond1_su)
  609. #endif
  610. #endif /* BUDGETS */
  611. #ifdef with_m7
  612. call free_m7_data
  613. #endif
  614. ! ok
  615. status = 0
  616. END SUBROUTINE CHEMISTRY_DONE
  617. !EOC
  618. !--------------------------------------------------------------------------
  619. ! TM5 !
  620. !--------------------------------------------------------------------------
  621. !BOP
  622. !
  623. ! !IROUTINE: CHEMIE
  624. !
  625. ! !DESCRIPTION: performs chemistry transformations of the tracers
  626. !\\
  627. !\\
  628. ! !INTERFACE:
  629. !
  630. SUBROUTINE CHEMIE( region, tr, status )
  631. !
  632. ! !USES:
  633. !
  634. use GO, only : TDate
  635. use binas, only : Avog, pi, xmair, Rgas_air
  636. use dims, only : itaur, nchem, tref, sec_month, revert, okdebug
  637. use dims, only : dx, xref, dy, yref, im, jm, lm
  638. use dims, only : nregions, ndyn, ndyn_max
  639. use dims, only : xbeg, ybeg, adv_scheme, mlen
  640. use chem_param, only : xmbc, xmpom, xmnacl, xmdust !EV
  641. use chem_param, only : maxtrace, n_extra, iso4, ino3_a, inh4, ih2opart
  642. use chem_param, only : irinc, ino, xmn, inox, ieno, iairm, iairn, ntrace
  643. use chem_param, only : ntracet, fscale, imsa, iacid, iair, ih2o, io2, ih2on
  644. use chem_param, only : iairm,i_temp, i_pres, inh3, ihno3, xmh2o, names, iterp, xmelvoc, xmsvoc
  645. #ifdef with_m7
  646. use chem_param, only : iso4nus, iso4ais, iso4acs, iso4cos, ibcais, ibcacs, ibccos, ibcaii, isoanus, ipomais, ipomacs
  647. use chem_param, only : ipomcos, ipomaii, issacs, isscos, iduacs, iducos, iduaci,iducoi
  648. use chem_param, only : isoaais, isoaacs, isoacos, isoaaii
  649. use chem_param, only : inus_n, xmnumb, iais_n, iacs_n, icos_n, iaii_n, iaci_n, icoi_n
  650. use chem_param, only : nh4no3_factor, nh4no3_density, msa_density
  651. use mo_aero_m7, only : cmr2ram, ram2cmr
  652. use binas, only : rol
  653. use chem_param, only : ielvoc, isvoc
  654. #endif
  655. use chem_param, only : idz
  656. use meteodata, only : m_dat, gph_dat
  657. use reaction_data, only : nreac, aerdens
  658. use chem_rates, only : calrates
  659. use eqsam_param, only : eqsam_v03d
  660. use toolbox, only : dumpfield
  661. use datetime, only : tau2date, get_day
  662. use global_data, only : region_dat, mass_dat, chem_dat
  663. #ifndef without_photolysis
  664. #ifdef with_optics
  665. use photolysis, only : aerosol_info_m7
  666. #else
  667. use photolysis, only : aerosol_info
  668. #endif
  669. use photolysis, only : daysim, get_sza, photo_flux
  670. use photolysis_data
  671. #endif
  672. use ebischeme, only : ebi
  673. #ifdef with_budgets
  674. #ifdef with_m7
  675. use ebischeme, only :diag_prod,nprod,AC_diag_prod,iprod_soa3dmon,iprod_soa2dhour
  676. #endif
  677. #endif
  678. #ifndef without_emission
  679. use dims, only : at, bt
  680. use emission_nox, only : eminox_lightning, nox_emis_3d
  681. use emission_nox, only : nox_emis_3d_bb_app, emission_nox_bb_daily_cycle
  682. #endif
  683. #ifdef with_budgets
  684. use emission_data, only : budemi_dat, sum_emission
  685. use budget_global, only : budg_dat, nzon_vg
  686. #endif
  687. #ifndef without_sedimentation
  688. use sedimentation, only : rh
  689. #endif
  690. #ifdef with_cariolle
  691. use chem_param, only : io3
  692. use chemistry_cariolle, only : l_cariolle, with_trop_force
  693. #endif
  694. ! use tracer_data, only : tracer_print ! for debugging
  695. #ifdef with_m7
  696. use mo_aero, only : nsoa !RM
  697. use mo_aero_m7, only : naermod, nmod, nsol
  698. use m7_data, only : rw_mode, rwd_mode, dens_mode, h2o_mode
  699. !use emission_data, only : oc2pom !factor for conversion of OC mass to POM
  700. #ifdef with_budgets
  701. Use m7_data, only : nm7procs
  702. #endif
  703. !#ifdef with_optics
  704. ! Use Optics, only : nwl, aod_count, AOD, calculate_aop
  705. ! Use chem_param, only : xmso4, xmno3
  706. !#endif
  707. external :: m7
  708. #endif /* M7 */
  709. !
  710. ! !INPUT PARAMETERS:
  711. !
  712. integer, intent(in) :: region
  713. type(TDate), intent(in) :: tr(2)
  714. !
  715. ! !OUTPUT PARAMETERS:
  716. !
  717. integer, intent(out) :: status
  718. !
  719. ! !REVISION HISTORY:
  720. ! 22 Mar 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  721. !
  722. !EOP
  723. !------------------------------------------------------------------------
  724. !BOC
  725. character(len=*), parameter :: rname = mname//'/chemie'
  726. ! --- local ------------------------------
  727. real,dimension(:,:,:),pointer :: m
  728. real,dimension(:,:,:,:),pointer :: rm
  729. #ifdef slopes
  730. real,dimension(:,:,:,:),pointer :: rxm, rym, rzm
  731. #ifdef secmom
  732. real,dimension(:,:,:,:),pointer :: rxxm, rxym, rxzm, ryym, ryzm, rzzm
  733. #endif
  734. #endif
  735. real,dimension(:,:,:,:),pointer :: rmc
  736. real,dimension(:,:,:),pointer :: r_cloud
  737. ! store per level actinic fluxes, photolysis rates, and reaction rates
  738. #ifndef without_photolysis
  739. real,dimension(:,:,:),allocatable :: fact
  740. #endif
  741. real,dimension(:,:,:),allocatable :: rj, rr
  742. ! new photolysis array
  743. real,dimension(:,:,:,:),allocatable :: rj_new
  744. ! store concentrations for chemistry ....
  745. real,dimension(:,:,:),allocatable :: y, y0, yhelp
  746. ! store information that is transferred
  747. ! between chemistry modules
  748. real,dimension(:,:,:),allocatable :: ye
  749. real,dimension(:,:), allocatable :: th, tha, sza, mu, reff
  750. real :: starttime,deltat
  751. ! eqsam:
  752. real,dimension(:,:), allocatable :: yi, yo
  753. ! sad:
  754. real,dimension(:,:,:), allocatable :: sad_aer_out, sad_cld_out, sad_ice_out
  755. #ifdef with_m7
  756. ! m7:
  757. real, dimension(:), pointer :: dxyp
  758. real, dimension(:,:), allocatable :: presm7, rhm7, tempm7, dryairm7 ! meteo parameters
  759. real, dimension(:,:), allocatable :: h2so4m7 ! h2so4 gas phase
  760. real, dimension(:,:,:), allocatable :: aemassm7 ! aerosol mass
  761. real, dimension(:,:,:), allocatable :: aenumm7 ! aerosol number
  762. real, dimension(:,:), allocatable :: elvocm7, svocm7 ! ELVOC & SVOC gas phase !RM
  763. !#ifdef with_optics
  764. ! Integer :: iband
  765. ! real,dimension(:,:,:),allocatable :: Ext ! extinction coefficient [1/m]
  766. ! real,dimension(:,:,:),allocatable :: a ! single-scattering albedo [unitless]
  767. ! real,dimension(:,:,:),allocatable :: g ! asymmetry parameter [unitless]
  768. !#endif
  769. real, dimension(:,:,:), allocatable :: aedensm7 ! aerosol density
  770. real, dimension(:,:,:), allocatable :: aewatm7 ! aerosol water content
  771. real, dimension(:,:,:), allocatable :: aeradm7 ! aerosol radius in equilibrium with water
  772. real, dimension(:,:,:), allocatable :: aeradrm7 ! aerosol dry radius
  773. !
  774. ! To convert units from M7 to TM5 units
  775. real, parameter :: convnumb = 1.e3/xmnumb*Avog ! This value is needed directly
  776. real, parameter :: convsu = 1. ! Nothing happens for sulfate.
  777. real, parameter :: convbc = 1e-12/xmbc*Avog ! BC
  778. !>>> TvN
  779. ! I have the impression that OC in M7 actually refers to POM.
  780. ! doc seems to be the density of POM not OC, and is equal to the density of BC (dbc).
  781. ! Compare with GLOMAP, where the densities of POM and BC are the same (Mann et al., GMD, 2010).
  782. ! This would imply that also the mass of POM and not OC should be used in M7,
  783. ! and that "OC" in the paper by Vignati et al. (JGR, 2004) is actually referring to POM,
  784. ! consistent with the terminology used by Stier et al. (ACP, 2005).
  785. !real, parameter :: convoc = 1e-12/xmpom*Avog*oc2pom ! OC (M7) POM (TM5)
  786. real, parameter :: convoc = 1e-12/xmpom*Avog ! POM (in both M7 and TM5)
  787. !<<< TvN
  788. !RM
  789. real, parameter :: convelvoc = 1e-12/xmelvoc*Avog ! ELVOC
  790. real, parameter :: convsvoc = 1e-12/xmsvoc*Avog ! S/LVOC
  791. real, parameter :: convss = 1e-12/xmnacl*Avog ! SS
  792. real, parameter :: convdu = 1e-12/xmdust*Avog ! DU
  793. #ifdef with_budgets
  794. real,dimension(:,:,:), allocatable :: processm7 ! M7 processes in M7 units.
  795. ! Array that convertts M7 processes from M7 to TM5 units.
  796. real, dimension(nm7procs), parameter :: processm7totm5 = (/ &
  797. ! 1 2 3 4 5 6 7 8 9 10
  798. convnumb,convsu ,convnumb,convnumb,convsu ,convnumb,convsu ,convnumb,convsu,convnumb,& ! 0?
  799. convsu ,convnumb,convsu ,convnumb,convsu ,convnumb,convnumb,convsu ,convbc,convoc ,& ! 1?
  800. convnumb,convsu ,convbc ,convoc ,convnumb,convbc ,convoc ,convnumb,convsu,convbc ,& ! 2?
  801. convoc ,convnumb,convsu ,convbc ,convoc ,convnumb,convnumb,convbc ,convoc,convnumb,& ! 3?
  802. convsu ,convsu ,convsu ,convsu ,convsu ,convsu ,convsu ,convnumb,convbc,convoc ,& ! 4?
  803. convnumb,convdu ,convnumb,convdu ,convnumb,convsu ,convnumb,convsu ,convbc,convoc ,& ! 5?
  804. convnumb,convsu ,convbc ,convoc ,convss ,convdu ,convoc ,convoc ,convoc,convoc ,& ! 6?
  805. convoc ,convoc ,convoc ,convoc ,convoc ,convoc ,convoc ,convoc ,convoc,convoc ,& ! 7?
  806. convoc ,convoc ,convoc ,convoc ,convoc ,convoc ,convoc ,convoc/) ! 8?
  807. #endif
  808. real :: dryvol_m7, vol_nh4no3, vol_msa, vol_h2o
  809. real :: number_conc
  810. integer :: imode
  811. #endif /* M7 */
  812. real :: dtime, gmt, dxx, dyy, lat, lon
  813. real :: px, skf, x, month2dt
  814. integer :: day, level, nzone, nzone_v
  815. integer,dimension(6) :: idater, idate_temp
  816. integer :: i, j, l, n
  817. integer :: ispec
  818. integer :: imax, nca, nco, iloop
  819. integer :: eqsam_option
  820. real :: dry_aerosol_mass, dry_aerosol_volume
  821. real :: water_aerosol_mass, water_aerosol_volume, ccs, s
  822. integer :: i1, i2, j1, j2, lmr, is3, ie3, klm
  823. ! --- begin ---------------------------------
  824. if ( okdebug ) write (*,*) 'start of chemistry'
  825. m => m_dat (region)%data
  826. rmc => chem_dat(region)%rm
  827. rm => mass_dat(region)%rm
  828. #ifdef slopes
  829. rxm => mass_dat(region)%rxm
  830. rym => mass_dat(region)%rym
  831. rzm => mass_dat(region)%rzm
  832. #ifdef secmom
  833. rxxm => mass_dat(region)%rxxm
  834. rxym => mass_dat(region)%rxym
  835. rxzm => mass_dat(region)%rxzm
  836. ryym => mass_dat(region)%ryym
  837. ryzm => mass_dat(region)%ryzm
  838. rzzm => mass_dat(region)%rzzm
  839. #endif
  840. #endif
  841. #ifdef with_m7
  842. dxyp => region_dat(region)%dxyp
  843. #endif
  844. r_cloud => phot_dat(region)%cloud_reff
  845. ! ------- Time stuff
  846. call tau2date(itaur(region), idater) ! current time
  847. dtime = nchem/(2*tref(region)) ! time step
  848. month2dt = dtime/sec_month ! conversion to emission per timestep
  849. call tau2date(itaur(region)+revert*nint(dtime*0.5),idate_temp) ! get date @ halfway interval.
  850. gmt = idate_temp(4) + idate_temp(5)/60.0 + idate_temp(6)/3600.0 ! GMT in hours
  851. day = get_day(idate_temp(2),idate_temp(3),mlen)
  852. if ( okdebug ) then
  853. write(gol,*)'chemistry: region ',region, ' at date: ',idater,' with time step ',dtime
  854. call goPr
  855. write(gol,*)'chemistry: day, gmt, date@halfway interval ', day, gmt, idate_temp
  856. call goPr
  857. end if
  858. ! ------- Resolution and bounds
  859. dxx = dx/xref(region) ! gridsize at current region
  860. dyy = dy/yref(region) ! gridsize at current region
  861. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  862. lmr = lm(region)
  863. is3=(i1-1)*3+1 ! to cover three times oversampled
  864. ie3=i2*3
  865. ! allocate(tha (is3:ie3,j1:j2))
  866. allocate(tha (im(region)*3,j1:j2))
  867. allocate(sza (i1:i2, j1:j2 ))
  868. allocate(mu (i1:i2, j1:j2 ))
  869. allocate(reff (i1:i2, j1:j2 ))
  870. allocate(fact (i1:i2, j1:j2, nbands_trop ))
  871. allocate(rj (i1:i2, j1:j2, nj ))
  872. allocate(rr (i1:i2, j1:j2, nreac ))
  873. allocate(rj_new(i1:i2, j1:j2, lmr, nj ))
  874. allocate(y (i1:i2, j1:j2, maxtrace ))
  875. allocate(y0 (i1:i2, j1:j2, maxtrace ))
  876. allocate(yhelp (i1:i2, j1:j2, ntrace ))
  877. allocate(ye (i1:i2, j1:j2, n_extra )) ! Eqsam
  878. allocate(sad_cld_out(i1:i2, j1:j2, lmr )) ; sad_cld_out = 0.
  879. allocate(sad_ice_out(i1:i2, j1:j2, lmr )) ; sad_ice_out = 0.
  880. allocate(sad_aer_out(i1:i2, j1:j2, lmr )) ; sad_aer_out = 0.
  881. imax = (i2-i1+1)*(j2-j1+1) !nb of grid box per layer (was im(region)*jm(region))
  882. nca = 11
  883. nco = 37 ! was 36, JadB added one for the water associated with just the nitrate.
  884. allocate(yi(imax,nca)) ; yi = 0.0
  885. allocate(yo(imax,nco)) ; yo = 0.0
  886. #ifdef with_m7
  887. allocate( presm7 (imax, 1 ))
  888. allocate( rhm7 (imax, 1 ))
  889. allocate( tempm7 (imax, 1 ))
  890. allocate( dryairm7(imax, 1 ))
  891. allocate( h2so4m7 (imax, 1 ))
  892. allocate( aemassm7(imax, 1, naermod))
  893. allocate( aenumm7 (imax, 1, nmod ))
  894. allocate( aedensm7(imax, 1, nmod ))
  895. allocate( aewatm7 (imax, 1, nmod ))
  896. allocate( aeradm7 (imax, 1, nmod ))
  897. allocate( aeradrm7(imax, 1, nsol ))
  898. allocate( elvocm7 (imax, 1 ))
  899. allocate( svocm7 (imax, 1 ))
  900. presm7 =0.
  901. rhm7 =0.
  902. tempm7 =0.
  903. dryairm7=0.
  904. h2so4m7 =0.
  905. aemassm7=0.
  906. aenumm7 =0.
  907. aedensm7=0.
  908. aewatm7 =0.
  909. aeradm7 =0.
  910. aeradrm7=0.
  911. elvocm7 =0.
  912. svocm7 =0.
  913. #ifdef with_budgets
  914. allocate(processm7(imax,1,nm7procs))
  915. #endif
  916. #endif
  917. tha = 0.0
  918. sza = 0.0
  919. mu = 0.0
  920. fact = 0.0
  921. rj = 0.0
  922. rr = 0.0
  923. rj_new = 0.0
  924. y = 0.0
  925. y0 = 0.0
  926. ye = 0.0
  927. ! alternative calculation of zenith angle with higher sampling (time and space).
  928. ! yields factor of two lower angles in the tropics!
  929. ! Difference is resolution dependent. The coarser the larger the differences
  930. starttime = real(idate_temp(4)) + real(idate_temp(5))/60.0 + real(idate_temp(6))/3600.
  931. deltat = nchem/3600.0
  932. call daysim(region, day, is3, i1,i2,j1, j2, tha)
  933. call get_sza(region, i1, j1, i2, j2, starttime, deltat, tha, sza)
  934. ! ascribe mu
  935. do j=j1,j2
  936. do i=i1,i2
  937. mu(i,j)=max(1.e-5,COS(sza(i,j)*pi/180.))
  938. enddo
  939. enddo
  940. #ifdef with_optics
  941. call aerosol_info_m7(region, status)
  942. IF_NOTOK_RETURN(status=1)
  943. #else
  944. call aerosol_info(region)
  945. #endif
  946. ! calculate actinic flux outside level loop for online fluxes
  947. call photo_flux(region, i1, j1, sza, rj_new)
  948. ! scale NOx BMB if needed
  949. #ifndef without_emission
  950. call emission_nox_bb_daily_cycle(status)
  951. IF_NOTOK_RETURN(status=1)
  952. #endif
  953. ! compute global LiNox budget
  954. #ifdef with_budgets
  955. #ifndef without_emission
  956. #ifndef without_convection
  957. eminox=eminox+sum(eminox_lightning(region)%d3)*month2dt ! kg [N] month-1 * dt /(sec_month) = kg [N]
  958. #endif
  959. #endif
  960. #endif
  961. LEVS: do level = 1, lmr
  962. rj(:,:,:) = rj_new (:,:,level,:)
  963. reff(:,:) = r_cloud(:,:,level)
  964. #ifdef with_budgets
  965. nzone_v=nzon_vg(level)
  966. #endif
  967. ! get/calculate all the fields needed in chemistry
  968. call GET_EXTRA( region, level, ye, i1, j1)
  969. ! calculate the rinc: relative radius growth of aerosols due to water
  970. ! Eqsam wants to calculate aerosol radii
  971. ! irinc is used by chem_rates in calchet2
  972. ! calchet2 is used by no one
  973. ! So, this part is not so important
  974. ! -----------------------------------
  975. ! To get this code back, take a stone-age copy of chemistry.F90
  976. ! But, to prevent even more errors.
  977. ! -----------------------------------
  978. ye(:,:,irinc) = 1.0
  979. call CALRATES(region, level, i1, j1, rj, rr, reff, ye, dtime, &
  980. sad_cld_out(:,:,level), sad_ice_out(:,:,level), sad_aer_out(:,:,level), status) ! also returns rh in ye
  981. IF_ERROR_RETURN(status=1)
  982. ! CALCULATE NOX EMISSIONS
  983. ! ---------------------------
  984. do j=j1,j2
  985. do i=i1,i2
  986. ! nox emis in this cell; init to zero:
  987. x = 0.0 ! kg(N)/month
  988. #ifndef without_emission
  989. ! add total 3d emissions if any
  990. if(associated(nox_emis_3d(region)%d3)) then
  991. x = x + nox_emis_3d(region)%d3(i,j,level)
  992. end if
  993. if(associated(nox_emis_3d_bb_app(region)%d3)) then
  994. x = x + nox_emis_3d_bb_app(region)%d3(i,j,level)
  995. end if
  996. #ifndef without_convection
  997. ! add lightning emissions:
  998. x = x + eminox_lightning(region)%d3(i,j,level)
  999. #endif
  1000. #endif /* EMISS */
  1001. ! emission budget (since nox emissions are added in chemistry)
  1002. #ifdef with_budgets
  1003. #ifndef without_emission
  1004. budemi_dat(region)%emi(i,j,nzone_v,inox) = &
  1005. budemi_dat(region)%emi(i,j,nzone_v,inox) + x/xmn*month2dt*1e3 ! g
  1006. if (inox == 1) sum_emission(region) = sum_emission(region) + x*month2dt ! kg N
  1007. #endif
  1008. #endif
  1009. ! put emissions in the units #/s/cm3 used in chemistry
  1010. ye(i,j,ieno) = x/ye(i,j,iairm)*ye(i,j,iairn)* &
  1011. (xmair/xmn)/sec_month !kg N/month ----> #(NO)/cm3/s
  1012. end do
  1013. end do
  1014. ! INITIAL CONCENTRATIONS
  1015. ! ---------------------------
  1016. do n=1,ntracet
  1017. do j=j1,j2
  1018. do i=i1,i2
  1019. y(i,j,n) = rm(i,j,level,n)/ye(i,j,iairm)*ye(i,j,iairn)* fscale(n) !kg ----> #/cm3
  1020. end do
  1021. end do
  1022. end do
  1023. do n=ntracet+1,ntrace
  1024. do j=j1,j2
  1025. do i=i1,i2
  1026. ! remember nontransported tracers are in rmc
  1027. y(i,j,n) =rmc(i,j,level,n)/ye(i,j,iairm)*ye(i,j,iairn)* fscale(n) !kg ----> #/cm3
  1028. end do
  1029. end do
  1030. end do
  1031. ! FILL EXTRA SPECIES : (from ntrace+1 to maxtrace)
  1032. ! ---------------------------
  1033. do j=j1,j2
  1034. do i=i1,i2
  1035. ! these are in #/cm3 and used in budget....should be in y....
  1036. y(i,j,iair) = ye(i,j,iairn)
  1037. y(i,j,ih2o) = ye(i,j,ih2on)
  1038. ! introduced to calculate correct budget for JO2
  1039. y(i,j,io2) = 1.
  1040. #ifdef with_m7
  1041. !RM
  1042. y(i,j,ielvoc)=0.
  1043. y(i,j,isvoc)=0.
  1044. #endif
  1045. end do
  1046. end do
  1047. ! BACKUP INIT CONCENTRATIONS
  1048. ! ---------------------------
  1049. y0 = y
  1050. do klm=1,ntrace
  1051. yhelp(:,:,klm) = y(:,:,klm)*ye(:,:,iairm)*1000./xmair/y(:,:,iair)
  1052. end do
  1053. ! EBI
  1054. ! ---------------------------
  1055. CALL EBI( region, level, i1, j1, rj, rr, y, ye, status)
  1056. IF_ERROR_RETURN(status=1)
  1057. ! EBI scheme budgets
  1058. #ifdef with_budgets
  1059. do j=j1,j2
  1060. do i=i1,i2
  1061. nzone=budg_dat(region)%nzong(i,j) ! global budget zone
  1062. budchem(nzone,nzone_v,1:ntrace) = budchem(nzone,nzone_v,1:ntrace) + &
  1063. y(i,j,1:ntrace)*ye(i,j,iairm)*1000./xmair/y(i,j,iair)-yhelp(i,j,:)
  1064. !production data
  1065. !d_gas_prod_so4=1
  1066. !d_liq_prod_so4=2
  1067. !d_prod_elvoc=3
  1068. !d_prod_svoc=4
  1069. ! cannot be done here, or would have also the existing so4-> ebischeme
  1070. !diag_prod(region)%prod(i,j,1)=y(i,j,iso4)
  1071. !diag_prod(region)%prod(i,j,1)=y(i,j,ielvoc)
  1072. !=y(i,j,n)/y(i,j,iair)*ye(i,j,iairm)/fscale(n)
  1073. ! y in #cm-3
  1074. ! y -> #cm-3s-1 : /y(air)-> #/#(air) : *y(airm)/xmair*xmelvoc -> kg(elvoc)
  1075. #ifdef with_m7
  1076. diag_prod(region)%prod(i,j,level,3)=diag_prod(region)%prod(i,j,level,3)+y(i,j,ielvoc)/y(i,j,iair)*ye(i,j,iairm)/xmair*xmelvoc
  1077. diag_prod(region)%prod(i,j,level,4)=diag_prod(region)%prod(i,j,level,4)+y(i,j,isvoc)/y(i,j,iair)*ye(i,j,iairm)/xmair*xmsvoc
  1078. !AERCHEMMIP
  1079. AC_diag_prod(region)%prod(i,j,level,iprod_soa3dmon)=AC_diag_prod(region)%prod(i,j,level,iprod_soa3dmon)+y(i,j,ielvoc)/y(i,j,iair)*ye(i,j,iairm)/xmair*xmelvoc+y(i,j,isvoc)/y(i,j,iair)*ye(i,j,iairm)/xmair*xmsvoc
  1080. !instantaneous 2d hour/6hour, make it hourly mean
  1081. AC_diag_prod(region)%prod(i,j,level,iprod_soa2dhour)=AC_diag_prod(region)%prod(i,j,level,iprod_soa2dhour)+y(i,j,ielvoc)/y(i,j,iair)*ye(i,j,iairm)/xmair*xmelvoc+y(i,j,isvoc)/y(i,j,iair)*ye(i,j,iairm)/xmair*xmsvoc
  1082. #endif
  1083. end do
  1084. end do
  1085. #endif
  1086. !--- Begin of M7: ------------------------------------------------------
  1087. #ifdef with_m7
  1088. ! M7
  1089. iloop = 0
  1090. do j=j1,j2
  1091. do i=i1,i2
  1092. #ifdef with_budgets
  1093. ! For the M7 budgets, we first subtract the old concentrations.
  1094. nzone=budg_dat(region)%nzong(i,j) ! global budget zone
  1095. budm7(nzone,nzone_v,:)=budm7(nzone,nzone_v,:)-y(i,j,1:ntracet)*ye(i,j,iairm)*1000./xmair/y(i,j,iair)
  1096. #endif
  1097. iloop = iloop + 1
  1098. ! meteo parameters
  1099. presm7 (iloop,1) = ye(i,j,i_pres) ! Pa
  1100. rhm7 (iloop,1) = rh(region)%d3(i,j,level) ! fraction, in cloud free part!
  1101. tempm7 (iloop,1) = ye(i,j,i_temp) ! K
  1102. dryairm7(iloop,1) = presm7(iloop,1)/(Rgas_air*tempm7(iloop,1)) ! density of dry air
  1103. ! H2SO4 gas concentrations molecule/cm3
  1104. h2so4m7(iloop,1) = y(i,j,iso4)/convsu
  1105. ! molecule/cm3 ----> molecules/cm3
  1106. if (nsoa==2) then
  1107. !RM ELVOC+SVOC
  1108. elvocm7(iloop,1) = y(i,j,ielvoc)/convelvoc
  1109. svocm7(iloop,1) = y(i,j,isvoc)/convsvoc
  1110. end if
  1111. ! sulphate mass in the 4 soluble modes molecule/cm3
  1112. aemassm7(iloop,1,1) = y(i,j,iso4nus)/convsu
  1113. aemassm7(iloop,1,2) = y(i,j,iso4ais)/convsu
  1114. aemassm7(iloop,1,3) = y(i,j,iso4acs)/convsu
  1115. aemassm7(iloop,1,4) = y(i,j,iso4cos)/convsu
  1116. ! molecule/cm3 ----> molecules/cm3
  1117. ! BC mass in the 3 soluble modes and 1 insoluble
  1118. aemassm7(iloop,1,5) = y(i,j,ibcais)/convbc
  1119. aemassm7(iloop,1,6) = y(i,j,ibcacs)/convbc
  1120. aemassm7(iloop,1,7) = y(i,j,ibccos)/convbc
  1121. aemassm7(iloop,1,8) = y(i,j,ibcaii)/convbc
  1122. ! molecule/cm3 -----> ug/m3
  1123. ! was: POM (tm5) OC (m7) mass in the 3 soluble modes and 1 insoluble
  1124. ! POM mass in the 3 soluble modes and 1 insoluble
  1125. aemassm7(iloop,1,9) = y(i,j,ipomais)/convoc
  1126. aemassm7(iloop,1,10) = y(i,j,ipomacs)/convoc
  1127. aemassm7(iloop,1,11) = y(i,j,ipomcos)/convoc
  1128. aemassm7(iloop,1,12) = y(i,j,ipomaii)/convoc
  1129. ! molecule/cm3 -----> ug/m3
  1130. ! SOA mass in the 3 soluble modes and 1 insoluble
  1131. aemassm7(iloop,1,19) = y(i,j,isoanus)/convoc
  1132. aemassm7(iloop,1,20) = y(i,j,isoaais)/convoc
  1133. aemassm7(iloop,1,21) = y(i,j,isoaacs)/convoc
  1134. aemassm7(iloop,1,22) = y(i,j,isoacos)/convoc
  1135. aemassm7(iloop,1,23) = y(i,j,isoaaii)/convoc
  1136. ! molecule/cm3 -----> ug/m3
  1137. ! SS mass in the 2 soluble modes
  1138. aemassm7(iloop,1,13) = y(i,j,issacs)/convss
  1139. aemassm7(iloop,1,14) = y(i,j,isscos)/convss
  1140. ! molecule/cm3 -----> ug/m3
  1141. ! DUST mass in the 2 soluble modes and 2 insoluble
  1142. aemassm7(iloop,1,15) = y(i,j,iduacs)/convdu
  1143. aemassm7(iloop,1,16) = y(i,j,iducos)/convdu
  1144. aemassm7(iloop,1,17) = y(i,j,iduaci)/convdu
  1145. aemassm7(iloop,1,18) = y(i,j,iducoi)/convdu
  1146. ! molecule/cm3 -----> ug/m3
  1147. ! number concentrations of the 7 modes
  1148. aenumm7(iloop,1,1) = y(i,j,inus_n)/convnumb
  1149. aenumm7(iloop,1,2) = y(i,j,iais_n)/convnumb
  1150. aenumm7(iloop,1,3) = y(i,j,iacs_n)/convnumb
  1151. aenumm7(iloop,1,4) = y(i,j,icos_n)/convnumb
  1152. aenumm7(iloop,1,5) = y(i,j,iaii_n)/convnumb
  1153. aenumm7(iloop,1,6) = y(i,j,iaci_n)/convnumb
  1154. aenumm7(iloop,1,7) = y(i,j,icoi_n)/convnumb
  1155. !
  1156. ! molecule/cm3 -----> particle/cm3:
  1157. ! 1 # air
  1158. !rm in total aerosol number (#aer) ----> #aer * ------ * ------ is y
  1159. ! kg(air) cm-3
  1160. !#aer # air 1
  1161. !---- * ------- ----> 1 kg(air) = 10^3 g air = 10^3 * ----- * Avog
  1162. !cm-3 kg(air) xmair
  1163. !
  1164. end do
  1165. end do
  1166. ! The M7 processes will be calculated when budgets are used. The extra
  1167. ! argument will appear when the compiler flag with_budgets is set.
  1168. #ifdef with_budgets
  1169. call M7(iloop, imax, 1, & ! TM5 indices
  1170. presm7, rhm7, tempm7, & ! " thermodynamics
  1171. h2so4m7, elvocm7, svocm7, aemassm7, aenumm7, & ! M7 tracers
  1172. aedensm7, aewatm7, aeradm7, aeradrm7, dtime, & ! M7 aerosol propertis
  1173. processm7) ! The extra argument, in which the rates of each process is stored in M7 units.
  1174. #else
  1175. call M7(iloop, imax, 1, & ! TM5 indices
  1176. presm7, rhm7, tempm7, & ! " thermodynamics
  1177. h2so4m7, elvocm7, svocm7, aemassm7, aenumm7, & ! M7 tracers
  1178. aedensm7, aewatm7, aeradm7, aeradrm7, dtime) ! M7 aerosol propertis
  1179. #endif
  1180. iloop = 0
  1181. do j=j1,j2
  1182. do i=i1,i2
  1183. iloop = iloop + 1
  1184. ! H2SO4 gas concentrations in molecule/cm3
  1185. y(i,j,iso4) = h2so4m7(iloop,1)*convsu
  1186. ! molecule/cm3 ----> molecule/cm3
  1187. if (nsoa==2)then
  1188. !RM ELVOC+SVOC
  1189. y(i,j,ielvoc) = elvocm7(iloop,1)*convelvoc
  1190. y(i,j,isvoc) = svocm7(iloop,1)*convsvoc
  1191. end if
  1192. ! sulphate mass in the 4 soluble modes
  1193. y(i,j,iso4nus) = aemassm7(iloop,1,1)*convsu
  1194. y(i,j,iso4ais) = aemassm7(iloop,1,2)*convsu
  1195. y(i,j,iso4acs) = aemassm7(iloop,1,3)*convsu
  1196. y(i,j,iso4cos) = aemassm7(iloop,1,4)*convsu
  1197. ! molecule/cm3 ----> molecule/cm3
  1198. ! BC mass in the 3 soluble modes and 1 insoluble
  1199. y(i,j,ibcais) = aemassm7(iloop,1,5)*convbc
  1200. y(i,j,ibcacs) = aemassm7(iloop,1,6)*convbc
  1201. y(i,j,ibccos) = aemassm7(iloop,1,7)*convbc
  1202. y(i,j,ibcaii) = aemassm7(iloop,1,8)*convbc
  1203. ! ug/m3 ----> molecule/cm3
  1204. ! was: POM (tm5) OC (m7) mass in the 3 soluble modes and 1 insoluble
  1205. ! POM mass in the 3 soluble modes and 1 insoluble
  1206. y(i,j,ipomais) = aemassm7(iloop,1,9)*convoc
  1207. y(i,j,ipomacs) = aemassm7(iloop,1,10)*convoc
  1208. y(i,j,ipomcos) = aemassm7(iloop,1,11)*convoc
  1209. y(i,j,ipomaii) = aemassm7(iloop,1,12)*convoc
  1210. ! ug/m3 ----> molecule/cm3
  1211. ! POM mass in the 3 soluble modes and 1 insoluble
  1212. y(i,j,isoanus) = aemassm7(iloop,1,19)*convoc
  1213. y(i,j,isoaais) = aemassm7(iloop,1,20)*convoc
  1214. y(i,j,isoaacs) = aemassm7(iloop,1,21)*convoc
  1215. y(i,j,isoacos) = aemassm7(iloop,1,22)*convoc
  1216. y(i,j,isoaaii) = aemassm7(iloop,1,23)*convoc
  1217. ! ug/m3 ----> molecule/cm3
  1218. ! SS mass in the 2 soluble modes
  1219. y(i,j,issacs) = aemassm7(iloop,1,13)*convss
  1220. y(i,j,isscos) = aemassm7(iloop,1,14)*convss
  1221. ! ug/m3 ----> molecule/cm3
  1222. ! DUST mass in the 2 soluble modes and 2 insoluble
  1223. y(i,j,iduacs) = aemassm7(iloop,1,15)*convdu
  1224. y(i,j,iducos) = aemassm7(iloop,1,16)*convdu
  1225. y(i,j,iduaci) = aemassm7(iloop,1,17)*convdu
  1226. y(i,j,iducoi) = aemassm7(iloop,1,18)*convdu
  1227. ! ug/m3 ----> molecule/cm3
  1228. ! number concentrations of the 7 modes
  1229. y(i,j,inus_n) = aenumm7(iloop,1,1)*convnumb
  1230. y(i,j,iais_n) = aenumm7(iloop,1,2)*convnumb
  1231. y(i,j,iacs_n) = aenumm7(iloop,1,3)*convnumb
  1232. y(i,j,icos_n) = aenumm7(iloop,1,4)*convnumb
  1233. y(i,j,iaii_n) = aenumm7(iloop,1,5)*convnumb
  1234. y(i,j,iaci_n) = aenumm7(iloop,1,6)*convnumb
  1235. y(i,j,icoi_n) = aenumm7(iloop,1,7)*convnumb
  1236. !number of particles/cm3 ----> molecule/cm3 (see comment above)
  1237. #ifdef with_budgets
  1238. ! For the M7 budgets, we now add the new concentrations.
  1239. nzone=budg_dat(region)%nzong(i,j) ! global budget zone
  1240. budm7(nzone,nzone_v,:)=budm7(nzone,nzone_v,:)+y(i,j,1:ntracet)*ye(i,j,iairm)*1000./xmair/y(i,j,iair)
  1241. budm7proc(nzone,nzone_v,:)=budm7proc(nzone,nzone_v,:)+processm7(iloop,1,:)*processm7totm5*ye(i,j,iairm)*&
  1242. 1000./xmair/y(i,j,iair) ! processm7totm5 is a 88-element array with unit conversion factors.
  1243. !nucleation in processm7 is saved as #/cm3 within one timestep
  1244. d_nucle(i,j,level)= d_nucle(i,j,level)+processm7(iloop,1,1)
  1245. m_nucle_su(i,j,level)= m_nucle_su(i,j,level)+processm7(iloop,1,2)
  1246. m_nucle_soa(i,j,level)= m_nucle_soa(i,j,level)+processm7(iloop,1,88)
  1247. growth1_2(i,j,level)= growth1_2(i,j,level)+processm7(iloop,1,55)
  1248. coag_sink_nuc(i,j,level)=coag_sink_nuc(i,j,level)+(processm7(iloop,1,3)+processm7(iloop,1,4)+processm7(iloop,1,6)&
  1249. +processm7(iloop,1,8)+processm7(iloop,1,10)+processm7(iloop,1,12)&
  1250. +processm7(iloop,1,14))
  1251. cond1_soa(i,j,level)= cond1_soa(i,j,level)+processm7(iloop,1,79)
  1252. cond2_soa(i,j,level)= cond2_soa(i,j,level)+processm7(iloop,1,80)
  1253. cond3_soa(i,j,level)= cond3_soa(i,j,level)+processm7(iloop,1,81)
  1254. cond4_soa(i,j,level)= cond4_soa(i,j,level)+processm7(iloop,1,82)
  1255. cond5_soa(i,j,level)= cond5_soa(i,j,level)+processm7(iloop,1,83)
  1256. cond1_su(i,j,level)= cond1_su(i,j,level)+processm7(iloop,1,41)
  1257. !1000./xmair/y(i,j,iair)
  1258. #endif
  1259. ! output m7
  1260. ! kgH2O/m3 ---> kg water per gridbox
  1261. do imode=1,nsol
  1262. h2o_mode(region,imode)%d3(i,j,level) = aewatm7(iloop,1,imode) *dxyp(j)*ye(i,j,idz)
  1263. rwd_mode (region,imode)%d3(i,j,level) = aeradrm7(iloop,1,imode)*1e-2 ! from cm to meter
  1264. end Do
  1265. do imode=1,nmod
  1266. dens_mode(region,imode)%d3(i,j,level) = aedensm7(iloop,1,imode)*1e3 ! from g/cm^3 --> kg/m^3
  1267. rw_mode (region,imode)%d3(i,j,level) = aeradm7(iloop,1,imode)*1e-2 ! from cm to meter
  1268. end do
  1269. end do
  1270. end do
  1271. #endif /* M7 */
  1272. ! ====================== EQSAM ! Using HNO3 / NO3_A, NH4 / NH2 and SO4.
  1273. yi = 0.0
  1274. yo = 0.0
  1275. iloop = 0
  1276. do j=j1,j2
  1277. do i=i1,i2
  1278. iloop = iloop + 1
  1279. yi(iloop,1)=ye(i,j,i_temp) ! K
  1280. #ifndef without_sedimentation
  1281. #ifdef with_m7
  1282. s = rh(region)%d3(i,j,level) ! in cloud free part!
  1283. #else
  1284. s = 0.0
  1285. #endif
  1286. #else
  1287. s = 0.0
  1288. #endif
  1289. yi(iloop,2)=max(0.001,min(0.95,s))
  1290. yi(iloop,11)=ye(i,j,i_pres)/100. ! Pa -> hPa
  1291. ! yi(iloop,6)= c(nv2,ina)/Avog*1.e12
  1292. yi(iloop,6)=0.
  1293. #ifdef with_m7
  1294. yi(iloop,4)=(y(i,j,iso4)+y(i,j,iso4nus)+y(i,j,iso4ais)+y(i,j,iso4acs)+y(i,j,iso4cos))/Avog*1.e12 ! molec/cm3 -> umol/m3
  1295. #else
  1296. yi(iloop,4)=(y(i,j,iso4))/Avog*1.e12 ! molec/cm3 -> umol/m3
  1297. #endif
  1298. yi(iloop,3)=(y(i,j,inh3)+y(i,j,inh4))/Avog*1.e12
  1299. yi(iloop,5)=(y(i,j,ihno3)+y(i,j,ino3_a))/Avog*1.e12
  1300. !yi(iloop,7)=(c(nv2,ihcl)+c(nv2,icl))/Avog*1.e12
  1301. yi(iloop,7)=0.
  1302. !yi(iloop,8)=c(nv2,ik)/Avog*1.e12
  1303. yi(iloop,8)=0.
  1304. !yi(iloop,9)=c(nv2,ica)/Avog*1.e12
  1305. yi(iloop,9)=0.
  1306. !yi(iloop,10)=c(nv2,img)/Avog*1.e12
  1307. yi(iloop,10)=0.
  1308. end do
  1309. end do
  1310. eqsam_option = 1
  1311. call EQSAM_V03D( yi, yo, nca, nco, eqsam_option, iloop, imax, 0, (/0,0,0,0,0,0/))
  1312. iloop = 0
  1313. do j=j1,j2
  1314. do i=i1,i2
  1315. iloop = iloop + 1
  1316. #ifdef with_budgets
  1317. nzone=budg_dat(region)%nzong(i,j) ! global budget zone
  1318. budeqsam(nzone,nzone_v,1) = budeqsam(nzone,nzone_v,1) + &
  1319. (yo(iloop,19)*Avog*1.e-12-y(i,j,inh4)) *ye(i,j,iairm)*1000./xmair/y(i,j,iair) ! Ammonium
  1320. budeqsam(nzone,nzone_v,2) = budeqsam(nzone,nzone_v,2) + &
  1321. (yo(iloop,20)*Avog*1.e-12-y(i,j,ino3_a))*ye(i,j,iairm)*1000./xmair/y(i,j,iair) ! Nitrate
  1322. #endif
  1323. y(i,j,ihno3) = yo(iloop, 9)*Avog*1.e-12 ! umol/m3 -> molec/cm3
  1324. y(i,j,inh3) = yo(iloop,10)*Avog*1.e-12 ! umol/m3 -> molec/cm3
  1325. y(i,j,inh4) = yo(iloop,19)*Avog*1.e-12 ! umol/m3 -> molec/cm3
  1326. y(i,j,ino3_a) = yo(iloop,20)*Avog*1.e-12 ! umol/m3 -> molec/cm3
  1327. ! Sulfuric acid is unchanged:
  1328. ! y(i,j,iso4) = yo(iloop,21)*Avog*1.e-12
  1329. ! The NO3_A should also get some water. M7 takes the water for the
  1330. ! anoins: SO4-- and Cl- (Sea Salt). Cations are neglected.
  1331. ! Just the NO3- water is used apart from the M7 water.
  1332. ! Ignore the direct eqsam water
  1333. ! ug/m3 -> molec/cm3
  1334. ! y(i,j,ih2opart) = yo(iloop,12)*Avog*1.e-12/xmh2o
  1335. #ifdef with_m7
  1336. ! The water associated with nitrate aerosol is put into
  1337. ! the soluble accumulation mode.
  1338. h2o_mode(region,3)%d3(i,j,level) = h2o_mode(region,3)%d3(i,j,level) + yo(iloop,37)*dxyp(j)*ye(i,j,idz)*1.e-9
  1339. ! from ug/m^3 (according to eqsam), then take the M7 conversion (from kg/m^3) times 1.e-9.
  1340. ! This EQSAM water is added to the optics water at the call of optics.
  1341. #endif
  1342. end do
  1343. end do
  1344. ! END EQSAM
  1345. ! Check for negative concentrations.
  1346. do n=1,ntrace
  1347. do j=j1,j2
  1348. do i=i1,i2
  1349. if ( y(i,j,n) < 0. ) then
  1350. !print *,' chemistry: negatives appeared in chemie'
  1351. !write(6,*)i,j,level,idater
  1352. !write(6,907)(y0(i,j,ispec),ispec=1,ntrace)
  1353. !write(6,907)(y(i,j,ispec),ispec=1,ntrace)
  1354. if ( n > ntracet ) then
  1355. do ispec=ntracet+1,ntrace
  1356. y(i,j,ispec)=max(0.,y(i,j,ispec))
  1357. end do
  1358. else
  1359. write (gol,'(a,a8,a,4i4,e12.4)') &
  1360. 'chemistry: negatives for species:',names(n), ' at ', i,j,level,region, &
  1361. y(i,j,n)/y(i,j,iair); call goPr
  1362. y(i,j,n)=max(0.,y(i,j,n))
  1363. end if
  1364. end if
  1365. end do !i
  1366. end do !j
  1367. end do !n
  1368. ! Write the tracers back to the mass_dat (rm)
  1369. do n=1,ntrace
  1370. #ifdef with_cariolle
  1371. if ( (n==io3) .and. ( (level.ge.l_cariolle(region)) .or. with_trop_force ) ) then
  1372. ! O3 is changed by Cariolle chemistry
  1373. else
  1374. #endif
  1375. do j=j1,j2
  1376. do i=i1,i2
  1377. if ( n <= ntracet ) then
  1378. rm(i,j,level,n)=y(i,j,n)/y(i,j,iair)*ye(i,j,iairm)/fscale(n)
  1379. else
  1380. rmc(i,j,level,n)=y(i,j,n)/y(i,j,iair)*ye(i,j,iairm)/fscale(n)
  1381. end if
  1382. #ifdef slopes
  1383. if ( n <= ntracet ) then
  1384. skf=0.
  1385. if ( y(i,j,n) > eps .and. y0(i,j,n) > eps ) skf=y(i,j,n)/y0(i,j,n)
  1386. rxm(i,j,level,n)=rxm(i,j,level,n)*skf
  1387. rym(i,j,level,n)=rym(i,j,level,n)*skf
  1388. rzm(i,j,level,n)=rzm(i,j,level,n)*skf
  1389. #ifdef secmom
  1390. rxxm(i,j,level,n)=rxxm(i,j,level,n)*skf
  1391. rxym(i,j,level,n)=rxym(i,j,level,n)*skf
  1392. rxzm(i,j,level,n)=rxzm(i,j,level,n)*skf
  1393. ryym(i,j,level,n)=ryym(i,j,level,n)*skf
  1394. ryzm(i,j,level,n)=ryzm(i,j,level,n)*skf
  1395. rzzm(i,j,level,n)=rzzm(i,j,level,n)*skf
  1396. #endif
  1397. endif
  1398. #endif
  1399. end do
  1400. end do !j,i
  1401. #ifdef with_cariolle
  1402. endif
  1403. #endif
  1404. end do !n
  1405. ! For the optics calculations,
  1406. ! it is assumed that nitrate aerosol is formed
  1407. ! by condensation onto existing particles
  1408. ! in the soluble accumulation mode (Adams et al., JGR, 2001).
  1409. ! Therefore, the presence of nitrate does not increase
  1410. ! the number of particles, nor does it have an impact
  1411. ! on the processes described by M7.
  1412. ! Above, the water associated with nitrate aerosol
  1413. ! is added to the total aerosol water (h2o_mode) in the accumulation mode.
  1414. ! However, this only affects the calculation of the refractive index,
  1415. ! which also accounts for the nitrate mass itself.
  1416. ! In order to properly account for the additional ammonium nitrate
  1417. ! and the associated water in the optics routine,
  1418. ! the corresponding dry and wet particle radii have to be increased as well;
  1419. ! the aerosol density (dens_mode) can be left unchanged,
  1420. ! because it is not used in the optics routine.
  1421. ! We use the same refractive index for ammonium nitrate as for sulfate.
  1422. ! This is a reasonable approximation, since,
  1423. ! according to Tang (JGR, 1997), for sulfate and nitrate aerosols
  1424. ! the effect of chemical composition on light scattering
  1425. ! is outweighted by the size effect of the particles.
  1426. ! Lowenthal et al. (Atmos. Environ., 2000)
  1427. ! give a refractive index of 1.44 for sulfuric acid
  1428. ! and 1.55 for ammonium nitrate.
  1429. ! If desired, the refractive index of ammonium nitrate
  1430. ! could be estimated at different wavelengths
  1431. ! by scaling the OPAC data for sulfate,
  1432. ! based on these values.
  1433. ! In M7 and in the optics calculations,
  1434. ! sulfate aerosols are assumed to be pure sulfuric acid,
  1435. ! and we do not try to account for the presence of ammonium (bi)sulfate.
  1436. ! The reason is that the presence of ammonium (bi)sulfate
  1437. ! has competing effects on scattering,
  1438. ! which cannot be easily accounted for in a model based on M7.
  1439. ! Sulfuric acid particles are extremely hygroscopic
  1440. ! and will draw significant water mass into the aerosol phase
  1441. ! at any relative humidity (RH).
  1442. ! If these particles are partially or completely neutralized
  1443. ! by drawing ammonia from the gas phase,
  1444. ! there will be an increase in particle mass due to the added ammonium
  1445. ! but a decrease in particle hygroscopicity at low to moderate RH,
  1446. ! and thus a decrease in particulate water mass.
  1447. ! On the other hand, ammonium bisulfate and ammonium sulfate both
  1448. ! have a higher refractive index than sulfuric acid (see e.g. Boucher and Anderson, 1995).
  1449. ! The net result of these competing factors is that
  1450. ! one mole of sulfuric acid scatters about 25% more sunlight
  1451. ! than one mole of ammonium bisulfate at 80% relative humidity.
  1452. ! Ammonium sulfate is intermediate between the two.
  1453. ! For more information see Boucher and Anderson (1995) and Boucher et al. (JGR, 1998).
  1454. ! An excellent discussion of the optical properties of ammonium (bi)sulfate
  1455. ! versus sulfuric acid is also given by Adams et al. (JGR, 2001).
  1456. !
  1457. ! In remote regions, especially outside the tropics,
  1458. ! the contribution of methane sulfonate (MSA-) aerosol
  1459. ! to the total particulate sulfure burden
  1460. ! cannot be neglected.
  1461. ! Like nitrate, MSA- aerosols are mainly formed by
  1462. ! condensation onto exisiting particles,
  1463. ! in the soluble accumulation and coarse modes
  1464. ! (Saltzmann et al., JGR, 1983; Pzenny et al., J. Atmos. Chem., 1992).
  1465. ! For simplicity, we assume in the model
  1466. ! that MSA- is formed only in the accumulation mode.
  1467. ! Moreover, it seems reasonable to use the refractive index of
  1468. ! sulfuric acid (H2SO4) for MSA, as is done by Kinne et al. (2003).
  1469. ! The similarity between the refractive index for MSA and H2SO4
  1470. ! is also discussed by Myhre et al. (Applied Optics, 2004).
  1471. !
  1472. #ifdef with_m7
  1473. do j=j1,j2
  1474. do i=i1,i2
  1475. ! prevent division for zero for extremely low aerosol concentrations
  1476. ! calculate corresponding number concentration in #/cm3
  1477. ! and test if this is larger than 1.e-10
  1478. ! the same criterion is applied in m7_equil
  1479. number_conc = rm(i,j,level,iacs_n) / ( 1.e6 * dxyp(j) * ye(i,j,idz) )
  1480. if ( number_conc > 1.e-10 ) then
  1481. dryvol_m7=((rwd_mode(region,3)%d3(i,j,level)*cmr2ram(3))**3.0)*pi/0.75 ! dry particle volume [m3]
  1482. ! in the accumulation mode from M7
  1483. vol_nh4no3=rm(i,j,level,ino3_a)*nh4no3_factor/ &
  1484. (rm(i,j,level,iacs_n)*nh4no3_density) ! ammonium-nitrate aerosol volume per particle [m3]
  1485. vol_msa=rm(i,j,level,imsa)/(rm(i,j,level,iacs_n)*msa_density) ! MSA- aerosol volume per particle [m3]
  1486. vol_h2o=h2o_mode(region,3)%d3(i,j,level)/(rm(i,j,level,iacs_n)*rol) ! total aerosol water per particle [m3]
  1487. rw_mode(region,3)%d3(i,j,level) = ((dryvol_m7+vol_nh4no3+vol_msa+vol_h2o)*0.75/pi)**(1./3.)*ram2cmr(3)
  1488. rwd_mode(region,3)%d3(i,j,level) = ((dryvol_m7+vol_nh4no3+vol_msa)*0.75/pi)**(1./3.)*ram2cmr(3)
  1489. else
  1490. ! don't change rwd_mode and set rw_mode equal to rwd_mode
  1491. rw_mode(region,3)%d3(i,j,level) = rwd_mode(region,3)%d3(i,j,level)
  1492. endif
  1493. enddo
  1494. enddo
  1495. #endif
  1496. end do LEVS ! loop over vertical levels...
  1497. ! SAD
  1498. phot_dat(region)%sad_cld=sad_cld_out
  1499. phot_dat(region)%sad_ice=sad_ice_out
  1500. phot_dat(region)%sad_aer=sad_aer_out
  1501. ! perform averaging...
  1502. phot_dat(region)%nsad_av = phot_dat(region)%nsad_av + float(ndyn)/float(ndyn_max)
  1503. phot_dat(region)%sad_cld_av = phot_dat(region)%sad_cld_av + (float(ndyn)/float(ndyn_max))*phot_dat(region)%sad_cld
  1504. phot_dat(region)%sad_ice_av = phot_dat(region)%sad_ice_av + (float(ndyn)/float(ndyn_max))*phot_dat(region)%sad_ice
  1505. phot_dat(region)%sad_aer_av = phot_dat(region)%sad_aer_av + (float(ndyn)/float(ndyn_max))*phot_dat(region)%sad_aer
  1506. ! cleanup
  1507. deallocate(tha)
  1508. deallocate(mu)
  1509. deallocate(sza)
  1510. deallocate(reff)
  1511. deallocate(fact)
  1512. deallocate(rj)
  1513. deallocate(rj_new)
  1514. deallocate(rr)
  1515. deallocate(y)
  1516. deallocate(y0)
  1517. deallocate(ye, yhelp)
  1518. ! eqsam
  1519. deallocate(yo)
  1520. deallocate(yi)
  1521. ! sad
  1522. deallocate(sad_cld_out,sad_ice_out,sad_aer_out)
  1523. #ifdef with_m7
  1524. deallocate(presm7)
  1525. deallocate(rhm7)
  1526. deallocate(tempm7)
  1527. deallocate(dryairm7)
  1528. deallocate(h2so4m7)
  1529. deallocate(aemassm7)
  1530. deallocate(aenumm7)
  1531. deallocate(aedensm7)
  1532. deallocate(aewatm7)
  1533. deallocate(aeradm7)
  1534. deallocate(aeradrm7)
  1535. deallocate(elvocm7)
  1536. deallocate(svocm7 )
  1537. #ifdef with_budgets
  1538. deallocate(processm7)
  1539. #endif
  1540. nullify(dxyp)
  1541. #endif
  1542. nullify(m)
  1543. nullify(rm)
  1544. nullify(rmc)
  1545. #ifdef slopes
  1546. nullify(rxm)
  1547. nullify(rym)
  1548. nullify(rzm)
  1549. #ifdef secmom
  1550. nullify(rxxm)
  1551. nullify(rxym)
  1552. nullify(rxzm)
  1553. nullify(ryym)
  1554. nullify(ryzm)
  1555. nullify(rzzm)
  1556. #endif
  1557. #endif
  1558. nullify(r_cloud)
  1559. if ( okdebug ) write (*,*) 'end of chemistry'
  1560. ! ok
  1561. status = 0
  1562. END SUBROUTINE CHEMIE
  1563. !EOC
  1564. !--------------------------------------------------------------------------
  1565. ! TM5 !
  1566. !--------------------------------------------------------------------------
  1567. !BOP
  1568. !
  1569. ! !IROUTINE: GET_EXTRA
  1570. !
  1571. ! !DESCRIPTION:
  1572. ! calculate / get 2D fields needed in the chemistry routines...
  1573. ! some fields (like pH) are calculated later on...
  1574. !\\
  1575. !\\
  1576. ! !INTERFACE:
  1577. !
  1578. SUBROUTINE GET_EXTRA( region, level, ye, is, js)
  1579. !
  1580. ! !USES:
  1581. !
  1582. use Binas, only : Avog, grav
  1583. use dims, only : im, jm, lm
  1584. use Dims, only : CheckShape
  1585. use global_data, only : region_dat, mass_dat
  1586. use meteodata, only : phlb_dat, m_dat, temper_dat, humid_dat, gph_dat, cc_dat, iwc_dat, lwc_dat
  1587. use chem_param, only : n_extra, i_pres, i_temp, iairn, ih2on
  1588. use chem_param, only : xmair, xmh2o, iairm, ilwc, iiwc, icc, iph, idz,iciwc,iclwc
  1589. !
  1590. ! !INPUT PARAMETERS:
  1591. !
  1592. integer, intent(in) :: region ! region #
  1593. integer, intent(in) :: level, is, js ! level and start indices
  1594. !
  1595. ! !OUTPUT PARAMETERS:
  1596. !
  1597. real, intent(out) :: ye(is:,js:,:)
  1598. !
  1599. ! !REVISION HISTORY:
  1600. ! 22 Mar 2012 - P. Le Sager - adapted for lon-lat MPI domain decomposition
  1601. !
  1602. ! !REMARKS:
  1603. !
  1604. !EOP
  1605. !------------------------------------------------------------------------
  1606. !BOC
  1607. real,dimension(:,:,:),pointer :: phlb,m,gph,t,q,lwc,iwc,cc
  1608. integer :: i,j,l
  1609. real :: px,x1,x2,xice,xliq,aird
  1610. integer :: imr, jmr, lmr, i1, i2, j1, j2, status
  1611. ! --- begin --------------------------------
  1612. call Get_DistGrid( dgrid(region), I_STRT=i1, I_STOP=i2, J_STRT=j1, J_STOP=j2 )
  1613. ! check arguments ...
  1614. call CheckShape( (/i2-i1+1, j2-j1+1, n_extra/), shape(ye ), status )
  1615. lmr = lm(region)
  1616. phlb => phlb_dat(region)%data
  1617. m => m_dat(region)%data
  1618. t => temper_dat(region)%data
  1619. q => humid_dat(region)%data
  1620. gph => gph_dat(region)%data ! (:,:,1:lm(region)+1)
  1621. lwc => lwc_dat(region)%data
  1622. iwc => iwc_dat(region)%data
  1623. cc => cc_dat(region)%data
  1624. do j=j1,j2
  1625. do i=i1,i2
  1626. px = 0.5*(phlb(i,j,level)+phlb(i,j,level+1))
  1627. ye(i,j,i_pres) = px
  1628. ye(i,j,i_temp) = t(i,j,level)
  1629. ye(i,j,iairn ) = 7.24e16*px/t(i,j,level)
  1630. ye(i,j,ih2on ) = q(i,j,level)*ye(i,j,iairn)*xmair/xmh2o
  1631. ye(i,j,iairm ) = m(i,j,level)
  1632. ye(i,j,iclwc ) = lwc(i,j,level)
  1633. ye(i,j,iciwc ) = iwc(i,j,level)
  1634. ! x1: kg water to m3 water (m3 water/ kg air)
  1635. x1=lwc(i,j,level)*1.e-3
  1636. aird = ye(i,j,iairn)
  1637. x2=xmair*1e3*aird/Avog ! kg/m3 (air)
  1638. xliq = x1/x2 ! dimensionless number (m^3/m^3)
  1639. ! avoid negatives and artificial values(1e-10 is about 0.0001 g/m3)
  1640. if ( xliq < 1e-10 ) xliq=0.
  1641. ye(i,j,ilwc) = xliq
  1642. x1=iwc(i,j,level)*1.e-3 ! kg ice to m3 ice
  1643. xice=x1/x2
  1644. ! avoid negatives and artificial values)
  1645. if ( xice < 1e-10 ) xice=0.
  1646. ye(i,j,iiwc) = xice
  1647. ye(i,j,icc) = cc(i,j,level)
  1648. ye(i,j,iph) = 0.0 ! only set in wetS when cloudy!!!
  1649. ye(i,j,idz) = gph(i,j,level+1)-gph(i,j,level) !dz
  1650. end do
  1651. end do
  1652. nullify(phlb)
  1653. nullify(m)
  1654. nullify(gph)
  1655. nullify(t)
  1656. nullify(q)
  1657. nullify(lwc)
  1658. nullify(iwc)
  1659. nullify(cc)
  1660. END SUBROUTINE GET_EXTRA
  1661. !EOC
  1662. END MODULE CHEMISTRY