ebischeme__dummy.F90 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. !#################################################################
  2. !
  3. ! Eulerian backward Iteration
  4. ! Chemistry solver for the CBM4 scheme
  5. !
  6. !### macro's #####################################################
  7. !
  8. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  9. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  10. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  11. !
  12. #include "tm5.inc"
  13. !
  14. !#################################################################
  15. module ebischeme
  16. !
  17. ! use GO, only : gol, goPr, goErr
  18. !
  19. ! implicit none
  20. !
  21. ! private
  22. !
  23. ! public :: ebi
  24. !
  25. !
  26. !contains
  27. !
  28. !
  29. ! subroutine ebi(region,level,rj,rr,y,ye)
  30. ! !
  31. ! ! perform Eulerian backwards chemistry at one model layer level in region
  32. ! ! input:
  33. ! ! region : region
  34. ! ! level: model layer...
  35. ! ! rj : array of photolysis rates
  36. ! ! rr : array of reaction rates
  37. ! ! y : vector of concentrations (to be returned...)
  38. ! !
  39. !#ifdef MPI
  40. ! use mpi_const,only : lmar,lmloc,myid
  41. !#endif
  42. ! use chem_param
  43. ! use dims, only: isr, ier, jsr,jer,im ,jm, nchem, tref, okdebug
  44. ! use global_data, only: region_dat
  45. ! use toolbox, only: dumpfield
  46. ! use dry_deposition, only: vd
  47. ! !type(emis_data),dimension(nregions,ntrace) :: vd
  48. !
  49. ! implicit none
  50. !
  51. ! ! input/output
  52. ! integer, intent(in) :: region,level
  53. ! real,dimension(im(region),jm(region),nreac),intent(in):: rr
  54. ! real,dimension(im(region),jm(region),nj ),intent(in):: rj
  55. ! real,dimension(im(region),jm(region),maxtrace) :: y
  56. ! real,dimension(im(region),jm(region),n_extra) :: ye
  57. !
  58. ! ! local
  59. ! integer,dimension(:,:),pointer :: zoomed
  60. ! real,dimension(:,:,:),allocatable :: cr2,cr3,cr4 !reaction budgets...
  61. ! real,dimension(:,:,:),allocatable :: y0
  62. !
  63. ! real :: dtime
  64. ! integer :: iterebi,i,j,ib,maxit,iter
  65. ! integer :: offsetl
  66. !
  67. ! real :: R57,R89,P1,R12,R21,XL1,P2,XL2,P3,XL3,X1,X2,X3
  68. ! real :: C1,C2,C3,Y2,XJT,R21T,R12T,R12TC,R21TC,XJTC,ACUB,BCUB,CCUB
  69. ! real :: CUBDET,DNO2,R56,R65,R75,P5,XL5,R66,X5,P6,XL6,X6,C6,XL7
  70. ! real :: Y1,C7,R98,P8,XL8,X4,C5,XL9,R1920,R1919,P19,XL19,R2019,XL20
  71. ! real :: XLHNO3,PH2O2,XLH2O2,PCH2O,PCO,PHNO3,XLCH2O,PCH3O2,XLCH3O2
  72. ! real :: PCH3O2H,XLCH3O2H,PALD2,XLALD2,PMGLY,XLMGLY,POLE,XLETH
  73. ! real :: XLOLE,XLISOP,PRXPAR,XLRXPAR,PPAR,XLPAR,PROR,XLROR,PXO2
  74. ! real :: XLXO2,PXO2N,XLXO2N,PROOH,XLROOH,PORGNTR,XLORGNTR,XLCO
  75. !
  76. ! real :: dt,dt2
  77. ! real :: qdms,pso2,qso2,qso2d,qnh3,pnh2,qnh2,qdms1,qdms2,pmsa,fnoy
  78. !
  79. ! integer :: io,sfstart,sfend
  80. !
  81. ! ! for vectorization/blocking ....
  82. ! ! npts can be varied to optimize cache memory management.
  83. ! integer,parameter :: npts=15
  84. ! integer,dimension(npts) :: ipts,jpts
  85. ! real,dimension(npts,nreac) :: rrv
  86. ! real,dimension(npts,nj ) :: rjv
  87. ! real,dimension(npts,ntrace) :: vdv ! deposition velocities
  88. ! real,dimension(npts) :: emino
  89. ! real,dimension(npts,maxtrace) :: yv,y0v
  90. ! integer :: iv,itrace,ivt,n
  91. !
  92. ! ! start
  93. !
  94. ! zoomed => region_dat(region)%zoomed
  95. !
  96. ! offsetl=0
  97. !#ifdef MPI
  98. ! if(myid>0) offsetl=sum(lmar(0:myid-1))
  99. !#endif
  100. ! dtime=nchem/(2*tref(region))
  101. ! !CMK iterebi=max(1,nint(dtime/2400)) !needed if nchem <2400
  102. ! iterebi=max(1,nint(dtime/1350)) !needed if nchem <2400
  103. ! dt=dtime/iterebi
  104. !
  105. ! if ( okdebug ) print *, 'EBI: called with:',region,offsetl+level, &
  106. ! 'with dt:',dt,iterebi
  107. !
  108. ! !cmkif(level==1) then
  109. ! !cmkio = sfstart('ebi.hdf',dfacc_create)
  110. ! !cmkcall io_write3d_32(io,im(region),'im',jm(region),'jm', &
  111. ! ! nreac,'nreac',rr,'rr')
  112. ! !cmkcall io_write3d_32(io,im(region),'im',jm(region),'jm', &
  113. ! ! nj ,'nj ',rj,'rj')
  114. ! !cmkcall io_write3d_32(io,im(region),'im',jm(region),'jm', &
  115. ! ! maxtrace,'maxtrace',y,'y')
  116. ! !cmkcall io_write3d_32(io,im(region),'im',jm(region),'jm', &
  117. ! ! n_extra,'n_extra',ye,'ye')
  118. ! !cmkio = sfend(io)
  119. ! !cmkend if
  120. !
  121. ! allocate(y0(im(region),jm(region),maxtrace))
  122. ! allocate(cr2(im(region),jm(region),nj ))
  123. ! allocate(cr3(im(region),jm(region),nreac))
  124. ! allocate(cr4(im(region),jm(region),nreacw))
  125. !
  126. ! !*** SCALING OF NOx, which has changed due to transport/deposition
  127. ! do j=jsr(region),jer(region)
  128. ! do i=isr(region),ier(region)
  129. ! if(zoomed(i,j)/=region) cycle
  130. ! y(i,j,ino) =max(1e-3,y(i,j,ino))
  131. ! y(i,j,ino2) =max(1e-3,y(i,j,ino2))
  132. ! y(i,j,ino3) =max(1e-3,y(i,j,ino3))
  133. ! y(i,j,in2o5)=max(1e-3,y(i,j,in2o5))
  134. ! y(i,j,ihno4)=max(1e-3,y(i,j,ihno4))
  135. ! fnoy=y(i,j,ino)+y(i,j,ino2)+y(i,j,ino3)+2.*y(i,j,in2o5)+y(i,j,ihno4)
  136. ! fnoy=y(i,j,inox)/fnoy
  137. ! y(i,j,ino) =fnoy*y(i,j,ino)
  138. ! y(i,j,ino2) =fnoy*y(i,j,ino2)
  139. ! y(i,j,ino3) =fnoy*y(i,j,ino3)
  140. ! y(i,j,in2o5)=fnoy*y(i,j,in2o5)
  141. ! y(i,j,ihno4)=fnoy*y(i,j,ihno4)
  142. ! end do
  143. ! end do
  144. ! !
  145. ! ! set budget accumulators to zero
  146. ! !
  147. ! cr2=0.
  148. ! cr3=0.
  149. ! cr4=0.
  150. ! !===========================================================
  151. ! ! ** Start iterating over CHEMISTRY
  152. ! !===========================================================
  153. ! do ib=1,iterebi
  154. ! maxit=8 !CMKTEMP
  155. ! if(offsetl+level<=3) maxit = maxit*2 ! lowest layers more iterations
  156. !
  157. ! y0 = y
  158. ! !-------------------------------
  159. ! ! wet sulphur/ammonia chemistry
  160. ! !------------------------------
  161. ! call wetS(region,level,y0,dt,y,ye,cr4)
  162. ! !-------------------------------------
  163. ! ! gasphase chemistry using EBI solver
  164. ! !-------------------------------------
  165. !
  166. ! !cmk NOTE this statement was there before but someone (me?) removed it.
  167. ! y0 = y
  168. !
  169. ! !cmk ______do EBI solver_______
  170. !
  171. ! !if (level == 19) then
  172. ! !call dumpfield(0,'dumpb.hdf',rr,'rr')
  173. ! !call dumpfield(1,'dumpb.hdf',rj,'rj')
  174. ! !call dumpfield(1,'dumpb.hdf',y,'y')
  175. ! !call dumpfield(1,'dumpb.hdf',ye,'ye')
  176. ! !end if
  177. !
  178. ! dt2 = dt*dt
  179. ! ! block the input for EBI for efficiency
  180. ! ! copy values with faster running index in inside loop
  181. ! iv = 0
  182. ! do j=jsr(region),jer(region)
  183. ! do i=isr(region),ier(region)
  184. ! if(zoomed(i,j)/=region) cycle
  185. ! iv = iv+1
  186. ! ipts(iv) = i
  187. ! jpts(iv) = j
  188. ! if(iv==npts) then
  189. ! ! copy reaction rates...
  190. ! do itrace=1,nreac
  191. ! do ivt=1,npts
  192. ! rrv(ivt,itrace) = rr(ipts(ivt),jpts(ivt),itrace)
  193. ! end do
  194. ! end do
  195. ! ! copy photolysis rates....
  196. ! do itrace=1,nj
  197. ! do ivt=1,npts
  198. ! rjv(ivt,itrace) = rj(ipts(ivt),jpts(ivt),itrace)
  199. ! end do
  200. ! end do
  201. ! ! copy tracer concentrations ....
  202. ! do itrace=1,maxtrace
  203. ! do ivt=1,npts
  204. ! yv(ivt,itrace) = y(ipts(ivt),jpts(ivt),itrace)
  205. ! y0v(ivt,itrace) = y0(ipts(ivt),jpts(ivt),itrace)
  206. ! end do
  207. ! end do
  208. ! ! deposition ....
  209. ! if(offsetl + level == 1) then
  210. ! do itrace=1,ntrace
  211. ! do ivt=1,npts
  212. ! vdv(ivt,itrace) = &
  213. ! vd(region,itrace)%surf(ipts(ivt),jpts(ivt)) &
  214. ! / ye(ipts(ivt),jpts(ivt),idz) !1/s
  215. ! end do
  216. ! end do
  217. ! else
  218. ! vdv(:,:) = 0.0
  219. ! end if
  220. ! ! copy nox emissions....
  221. ! do ivt=1,npts
  222. ! emino(ivt) = ye(ipts(ivt),jpts(ivt),ieno)
  223. ! end do
  224. ! ! do ebi solver....
  225. !
  226. ! call do_ebi(npts) !the actual EBI solver on vectorized arrays
  227. !
  228. ! do itrace=1,maxtrace
  229. ! do ivt=1,npts
  230. ! y(ipts(ivt),jpts(ivt),itrace)=yv(ivt,itrace)
  231. ! end do
  232. ! end do
  233. ! iv=0
  234. ! end if
  235. ! end do
  236. ! end do
  237. ! ! do the 'remaining' points...
  238. ! if(iv > 0) then
  239. ! do itrace=1,nreac
  240. ! do ivt=1,iv
  241. ! rrv(ivt,itrace) = rr(ipts(ivt),jpts(ivt),itrace)
  242. ! end do
  243. ! end do
  244. ! do itrace=1,nj
  245. ! do ivt=1,iv
  246. ! rjv(ivt,itrace) = rj(ipts(ivt),jpts(ivt),itrace)
  247. ! end do
  248. ! end do
  249. ! do itrace=1,maxtrace
  250. ! do ivt=1,iv
  251. ! yv(ivt,itrace) = y(ipts(ivt),jpts(ivt),itrace)
  252. ! y0v(ivt,itrace) = y0(ipts(ivt),jpts(ivt),itrace)
  253. ! end do
  254. ! end do
  255. ! ! deposition ....
  256. ! if(offsetl + level == 1) then
  257. ! do itrace=1,ntrace
  258. ! do ivt=1,iv
  259. ! vdv(ivt,itrace) = &
  260. ! vd(region,itrace)%surf(ipts(ivt),jpts(ivt)) &
  261. ! / ye(ipts(ivt),jpts(ivt),idz) !1/s
  262. ! end do
  263. ! end do
  264. ! else
  265. ! vdv(:,:) = 0.0
  266. ! end if
  267. ! do ivt=1,iv
  268. ! emino(ivt) = ye(ipts(ivt),jpts(ivt),ieno)
  269. ! end do
  270. !
  271. ! call do_ebi(iv) !the actual EBI solver on remaining cells
  272. !
  273. ! do itrace=1,maxtrace
  274. ! do ivt=1,iv
  275. ! y(ipts(ivt),jpts(ivt),itrace)=yv(ivt,itrace)
  276. ! end do
  277. ! end do
  278. ! end if
  279. !
  280. ! call NOymass
  281. !
  282. ! !-------------------------------------
  283. ! ! marked tracers
  284. ! ! apply after correction of nitrogen components
  285. ! !----------------------------------------------
  286. !
  287. ! call mark_trac(region,level,y,rr,rj,dt,ye)
  288. !
  289. ! !------------------------------------------------------------
  290. ! ! increase budget accumulators cr2 and cr3 (cr4 is done in wetS)
  291. ! !------------------------------------------------------------
  292. !
  293. ! call incc2c3
  294. ! !===========================================================
  295. ! ! ** END iterating over CHEMISTRY
  296. ! !===========================================================
  297. ! end do !iterebi
  298. !
  299. ! call reacbud !add budgets for this timestep
  300. !
  301. ! deallocate(y0)
  302. ! deallocate(cr2)
  303. ! deallocate(cr3)
  304. ! deallocate(cr4)
  305. !
  306. ! nullify(zoomed)
  307. !
  308. ! contains
  309. !
  310. ! subroutine do_ebi(lvec)
  311. !
  312. ! integer, intent(in) :: lvec
  313. ! integer :: ivec
  314. !
  315. ! do ITER=1,MAXIT
  316. !
  317. !
  318. ! do ivec=1,lvec
  319. ! ! --- Short living compounds & groups
  320. ! ! --- First group: NO NO2 O3
  321. ! P1=rjv(ivec,jbno3)*yv(ivec,ino3)+emino(ivec)
  322. ! R12=0.
  323. ! R21=rrv(ivec,kho2no)*yv(ivec,iho2)+rrv(ivec,kmo2no)*yv(ivec,ich3o2)&
  324. ! +rrv(ivec,kc79)*yv(ivec,ixo2)+rrv(ivec,kc46)*yv(ivec,ic2o3)
  325. ! XL1=rrv(ivec,knono3)*yv(ivec,ino3)+rrv(ivec,kc81)*yv(ivec,ixo2n)
  326. ! XL1 = XL1 + vdv(ivec,ino)
  327. ! P2=rjv(ivec,jhno3)*yv(ivec,ihno3)+rjv(ivec,jn2o5)*yv(ivec,in2o5)&
  328. ! +rrv(ivec,kn2o5)*yv(ivec,in2o5)+rjv(ivec,jano3)*yv(ivec,ino3)&
  329. ! +yv(ivec,ihno4)*(rjv(ivec,jhno4)+rrv(ivec,khno4m)+rrv(ivec,khno4oh)&
  330. ! *yv(ivec,ioh))+2.*rrv(ivec,knono3)*yv(ivec,ino3)*yv(ivec,ino)&
  331. ! +rrv(ivec,kc48)*yv(ivec,ipan)+rrv(ivec,kc59)*yv(ivec,iole)*yv(ivec,ino3)&
  332. ! +rrv(ivec,kc84)*yv(ivec,iorgntr)*yv(ivec,ioh)+rjv(ivec,jorgn)&
  333. ! *yv(ivec,iorgntr)+rjv(ivec,jpan)*yv(ivec,ipan)+0.1*rrv(ivec,kc78) *yv(ivec,iisop)*yv(ivec,ino3)
  334. ! XL2=rrv(ivec,kno2oh)*yv(ivec,ioh)+rrv(ivec,kno2no3)*yv(ivec,ino3)&
  335. ! +rrv(ivec,kno2ho2)*yv(ivec,iho2)+rrv(ivec,kno2o3)*yv(ivec,io3)+rrv(ivec,kc47)*yv(ivec,ic2o3)
  336. ! XL2 = XL2 + vdv(ivec,ino2)
  337. ! P3=rjv(ivec,jano3)*yv(ivec,ino3)
  338. ! XL3=rrv(ivec,ko3ho2)*yv(ivec,iho2)+rrv(ivec,ko3oh)*yv(ivec,ioh)+rrv(ivec,kno2o3)&
  339. ! *yv(ivec,ino2)+rjv(ivec,jo3d)+rrv(ivec,kc58)*yv(ivec,iole)&
  340. ! +rrv(ivec,kc62)*yv(ivec,ieth)+rrv(ivec,kc77)*yv(ivec,iisop)
  341. ! XL3 = XL3 + vdv(ivec,io3)
  342. !
  343. ! X1=y0v(ivec,ino)+P1*DT
  344. ! X2=y0v(ivec,ino2)+P2*DT
  345. ! X3=y0v(ivec,io3)+P3*DT
  346. ! C1=1.+XL1*DT
  347. ! C2=1.+XL2*DT
  348. ! C3=1.+XL3*DT
  349. ! Y1=rrv(ivec,knoo3)*DT
  350. ! R21T=R21*DT
  351. ! R12T=R12*DT
  352. ! XJT=rjv(ivec,jno2)*DT
  353. ! ! --- Oplossen onbekende x
  354. ! ACUB=-2.*Y1*(C2+R12T+C2*R21T/C1)
  355. ! BCUB=2.*C1*C2*C3+2.*C1*C3*(R12T+XJT)+2.*C2*C3*R21T+&
  356. ! 2.*Y1*(R12T*(X1-X2)+2.*C2*R21T*X1/C1+C2*(X1+X3))
  357. ! CCUB=2.*C1*C3*X2*(R12T+XJT)-2.*C2*C3*X1*R21T+2.*Y1*X1*&
  358. ! (X2*R12T-C2*X3-C2*R21T*X1/C1)
  359. ! CUBDET=BCUB*BCUB-4.*ACUB*CCUB
  360. ! DNO2=(-1.*BCUB+SQRT(CUBDET))/(2.*ACUB)
  361. ! dno2=min(x1,dno2)
  362. ! yv(ivec,ino2)=(X2+DNO2)/C2
  363. ! yv(ivec,ino)=(X1-DNO2)/C1
  364. ! yv(ivec,io3)=(X3+XJT*yv(ivec,ino2))/(C3+Y1*yv(ivec,ino))
  365. ! ! --- Second group: yv(ivec,iho2) yv(ivec,ioh) yv(ivec,ihno4)
  366. ! R57=rjv(ivec,jhno4)+rrv(ivec,khno4m)
  367. ! R56=rrv(ivec,kcooh)*yv(ivec,ico)+rrv(ivec,ko3oh)*yv(ivec,io3)+rrv(ivec,khpoh)&
  368. ! *yv(ivec,ih2o2)+rrv(ivec,kfrmoh)*yv(ivec,ich2o)+rrv(ivec,kh2oh)
  369. ! P5=2.*rjv(ivec,jbch2o)*yv(ivec,ich2o)+rrv(ivec,kc46)*yv(ivec,ic2o3)*yv(ivec,ino)&
  370. ! +rrv(ivec,kmo2no)*yv(ivec,ich3o2)*yv(ivec,ino)+0.66*rrv(ivec,kmo2mo2)&
  371. ! *yv(ivec,ich3o2)*yv(ivec,ich3o2)+rjv(ivec,jmepe)*yv(ivec,ich3o2h)&
  372. ! +2.*rrv(ivec,kc49)*yv(ivec,ic2o3)*yv(ivec,ic2o3)+2.*rjv(ivec,j45)&
  373. ! *yv(ivec,iald2)+rjv(ivec,j74)*yv(ivec,imgly)+0.11*rrv(ivec,kc52)*yv(ivec,ipar)&
  374. ! *yv(ivec,ioh)+0.94*rrv(ivec,kc53)*yv(ivec,iror)+rrv(ivec,kc54)*yv(ivec,iror)&
  375. ! +rrv(ivec,kc57)*yv(ivec,iole)*yv(ivec,ioh)+0.25*rrv(ivec,kc58)*yv(ivec,io3)&
  376. ! *yv(ivec,iole)+rrv(ivec,kc61)*yv(ivec,ieth)*yv(ivec,ioh)+0.26*rrv(ivec,kc62)&
  377. ! *yv(ivec,ieth)*yv(ivec,io3)+0.85*rrv(ivec,kc76)*yv(ivec,iisop)*yv(ivec,ioh)&
  378. ! +0.3*rrv(ivec,kc77)*yv(ivec,iisop)*yv(ivec,io3)+rrv(ivec,kc41)*yv(ivec,ich2o)&
  379. ! *yv(ivec,ino3)+rjv(ivec,jorgn)*yv(ivec,iorgntr)+0.9*rrv(ivec,kc78)*yv(ivec,iisop)*yv(ivec,ino3)
  380. ! XL5=rrv(ivec,kho2no)*yv(ivec,ino)+rrv(ivec,kno2ho2)*yv(ivec,ino2)&
  381. ! +rrv(ivec,ko3ho2)*yv(ivec,io3)+rrv(ivec,kmo2ho2)*yv(ivec,ich3o2)&
  382. ! +rrv(ivec,kho2oh)*yv(ivec,ioh)+rrv(ivec,kc82)*yv(ivec,ixo2)+rrv(ivec,kc85)*yv(ivec,ixo2n)
  383. ! R66=2.*rrv(ivec,kho2ho2)
  384. ! X5=y0v(ivec,iho2)+P5*DT
  385. ! R65=rrv(ivec,kho2no)*yv(ivec,ino)+rrv(ivec,ko3ho2)*yv(ivec,io3)
  386. ! P6=rjv(ivec,jhno3)*yv(ivec,ihno3)+2.*rjv(ivec,jo3d)*yv(ivec,io3)&
  387. ! +2.*rjv(ivec,jh2o2)*yv(ivec,ih2o2)+rjv(ivec,jmepe)*yv(ivec,ich3o2h)&
  388. ! +0.79*rrv(ivec,kc50)*yv(ivec,ic2o3)*yv(ivec,iho2)+0.4*rrv(ivec,kc58)&
  389. ! *yv(ivec,io3)*yv(ivec,iole)+0.28*rrv(ivec,kc77)*yv(ivec,iisop)*yv(ivec,io3)&
  390. ! +rjv(ivec,jrooh)*yv(ivec,irooh)+0.12*rrv(ivec,kc62)*yv(ivec,ieth)*yv(ivec,io3)
  391. ! XL6=rrv(ivec,khno4oh)*yv(ivec,ihno4)+rrv(ivec,kho2oh)*yv(ivec,iho2)&
  392. ! +rrv(ivec,kno2oh)*yv(ivec,ino2)+rrv(ivec,kohhno3)*yv(ivec,ihno3)&
  393. ! +rrv(ivec,kcooh)*yv(ivec,ico)+rrv(ivec,ko3oh)*yv(ivec,io3)+rrv(ivec,khpoh)&
  394. ! *yv(ivec,ih2o2)+rrv(ivec,kfrmoh)*yv(ivec,ich2o)+rrv(ivec,kch4oh)&
  395. ! *yv(ivec,ich4)+0.7*rrv(ivec,kohmper)*yv(ivec,ich3o2h)+rrv(ivec,kc43)&
  396. ! *yv(ivec,iald2)+rrv(ivec,kc73)*yv(ivec,imgly)+rrv(ivec,kc52)&
  397. ! *yv(ivec,ipar)+rrv(ivec,kc57)*yv(ivec,iole)+rrv(ivec,kc61)*yv(ivec,ieth)&
  398. ! +rrv(ivec,kc76)*yv(ivec,iisop)+0.7*rrv(ivec,kohrooh)*yv(ivec,irooh)&
  399. ! +rrv(ivec,kc84)*yv(ivec,iorgntr)+rrv(ivec,kh2oh)&
  400. ! +(rrv(ivec,kdmsoha)+rrv(ivec,kdmsohb)) *yv(ivec,idms) +rrv(ivec,knh3oh)*yv(ivec,inh3) !sulfur
  401. !
  402. ! X6=y0v(ivec,ioh)+P6*DT
  403. ! C6=1.+XL6*DT
  404. ! R75=rrv(ivec,kno2ho2)*yv(ivec,ino2)
  405. ! XL7=rjv(ivec,jhno4)+rrv(ivec,khno4oh)*yv(ivec,ioh)+rrv(ivec,khno4m)
  406. ! XL7 = XL7 + vdv(ivec,ihno4)
  407. ! C7=1.+XL7*DT
  408. ! Y1=R57/C7
  409. ! Y2=R56/C6
  410. ! ACUB=R66*DT
  411. ! BCUB=1.+XL5*DT-DT2*(Y1*R75+Y2*R65)
  412. ! CCUB=-1.*X5-DT*(Y1*y0v(ivec,ihno4)+Y2*X6)
  413. ! CUBDET=BCUB*BCUB-4.*ACUB*CCUB
  414. ! CUBDET=MAX(CUBDET,1.E-20)
  415. ! yv(ivec,iho2)=max(0.1,(-1.*BCUB+SQRT(CUBDET))/(2.*ACUB))
  416. ! yv(ivec,ioh)=(X6+R65*yv(ivec,iho2)*DT)/C6
  417. ! yv(ivec,ihno4)=(y0v(ivec,ihno4)+R75*DT*yv(ivec,iho2))/C7
  418. ! ! --- Third group: NO3 N2O5
  419. ! R89=rjv(ivec,jn2o5)+rrv(ivec,kn2o5)
  420. ! P8=rrv(ivec,kohhno3)*yv(ivec,ihno3)*yv(ivec,ioh)+rrv(ivec,kno2o3)*yv(ivec,ino2)*yv(ivec,io3)
  421. ! XL8=rjv(ivec,jbno3)+rjv(ivec,jano3)+rrv(ivec,knono3)*yv(ivec,ino)&
  422. ! +rrv(ivec,kno2no3)*yv(ivec,ino2)+rrv(ivec,kc44)*yv(ivec,iald2)+rrv(ivec,kc59)&
  423. ! *yv(ivec,iole)+rrv(ivec,kc78)*yv(ivec,iisop)+rrv(ivec,kc41)*yv(ivec,ich2o)+rrv(ivec,kdmsno3)*yv(ivec,idms)
  424. ! XL8 = XL8 + vdv(ivec,ino3)
  425. ! X4=y0v(ivec,ino3)+P8*DT
  426. ! C5=1.+XL8*DT
  427. ! R98=rrv(ivec,kno2no3)*yv(ivec,ino2)
  428. ! XL9=rjv(ivec,jn2o5)+rrv(ivec,kn2o5)+rrv(ivec,kn2o5aq)+rrv(ivec,kn2o5l) !cmk rates now idependent from y
  429. ! XL9 = XL9 + vdv(ivec,in2o5)
  430. ! C6=1.+XL9*DT
  431. ! C7=(C5*C6-R89*R98*DT2)
  432. ! yv(ivec,in2o5)=(C5*y0v(ivec,in2o5)+R98*DT*X4)/C7
  433. ! yv(ivec,ino3)=(C6*X4+R89*DT*y0v(ivec,in2o5))/C7
  434. ! ! --- Fourth group: C2O3 PAN
  435. ! R1920=rrv(ivec,kc48)+rjv(ivec,jpan)
  436. ! R1919=rrv(ivec,kc49)
  437. ! P19=rrv(ivec,kc43)*yv(ivec,iald2)*yv(ivec,ioh)+rrv(ivec,kc44)*yv(ivec,iald2)&
  438. ! *yv(ivec,ino3)+rrv(ivec,kc73)*yv(ivec,imgly)*yv(ivec,ioh)+rjv(ivec,j74)&
  439. ! *yv(ivec,imgly)+0.15*rrv(ivec,kc77)*yv(ivec,iisop)*yv(ivec,io3)
  440. ! XL19=rrv(ivec,kc46)*yv(ivec,ino)+rrv(ivec,kc50)*yv(ivec,iho2)+rrv(ivec,kc47)*yv(ivec,ino2)
  441. ! XL19 = XL19 + vdv(ivec,ic2o3)
  442. ! R2019=rrv(ivec,kc47)*yv(ivec,ino2)
  443. ! XL20=rrv(ivec,kc48)+rjv(ivec,jpan)
  444. ! XL20 = XL20 + vdv(ivec,ipan)
  445. ! ACUB=2*R1919*DT*(1+XL20*DT)
  446. ! BCUB=(1+XL20*DT)*(1+XL19*DT)-R1920*DT*R2019*DT
  447. ! CCUB=(1+XL20*DT)*(y0v(ivec,ic2o3)+P19*DT)+R1920*DT*y0v(ivec,ipan)
  448. ! CUBDET=BCUB*BCUB+4.*ACUB*CCUB
  449. ! yv(ivec,ic2o3)=max(1e-8,(-1.*BCUB+SQRT(CUBDET))/(2.*ACUB)) !cmk put max here....
  450. ! yv(ivec,ipan)=(y0v(ivec,ipan)+R2019*yv(ivec,ic2o3)*DT)/(1.+XL20*DT)
  451. ! ! --- CH4 chemistry (short living radicals)
  452. ! PCH3O2=rrv(ivec,kch4oh)*yv(ivec,ich4)*yv(ivec,ioh)+0.7*rrv(ivec,kohmper)*yv(ivec,ioh)*yv(ivec,ich3o2h)
  453. ! XLCH3O2=rrv(ivec,kmo2no)*yv(ivec,ino)+rrv(ivec,kmo2ho2)*yv(ivec,iho2)&
  454. ! +2*rrv(ivec,kmo2mo2)*yv(ivec,ich3o2)
  455. ! yv(ivec,ich3o2)=(y0v(ivec,ich3o2)+PCH3O2*DT)/(1.+XLCH3O2*DT)
  456. ! ! --- CBM4 chem.(short living compounds & operators)
  457. ! PRXPAR=0.11*rrv(ivec,kc52)*yv(ivec,ioh)*yv(ivec,ipar)+2.1*rrv(ivec,kc53)&
  458. ! *yv(ivec,iror)+rrv(ivec,kc57)*yv(ivec,iole)*yv(ivec,ioh)+0.9*rrv(ivec,kc58)&
  459. ! *yv(ivec,io3)*yv(ivec,iole)+rrv(ivec,kc59)*yv(ivec,iole)*yv(ivec,ino3)
  460. ! XLRXPAR=rrv(ivec,kc83)*yv(ivec,ipar)
  461. ! yv(ivec,irxpar)=(y0v(ivec,irxpar)+PRXPAR*DT)/(1.+XLRXPAR*DT)
  462. ! XLISOP=rrv(ivec,kc76)*yv(ivec,ioh)+rrv(ivec,kc77)*yv(ivec,io3)+rrv(ivec,kc78)*yv(ivec,ino3)
  463. ! yv(ivec,iisop)=y0v(ivec,iisop)/(1.+XLISOP*DT)
  464. ! PROR=0.76*rrv(ivec,kc52)*yv(ivec,ipar)*yv(ivec,ioh)+0.02*rrv(ivec,kc53)*yv(ivec,iror)
  465. ! XLROR=rrv(ivec,kc53)+rrv(ivec,kc54)
  466. ! yv(ivec,iror)=(y0v(ivec,iror)+PROR*DT)/(1.+XLROR*DT)
  467. ! PXO2=rrv(ivec,kc46)*yv(ivec,ic2o3)*yv(ivec,ino)+2.*rrv(ivec,kc49)&
  468. ! *yv(ivec,ic2o3)*yv(ivec,ic2o3)+rrv(ivec,kc50)*yv(ivec,ic2o3)&
  469. ! *yv(ivec,iho2)+rjv(ivec,j45)*yv(ivec,iald2)+rrv(ivec,kc73)&
  470. ! *yv(ivec,imgly)*yv(ivec,ioh)+0.87*rrv(ivec,kc52)*yv(ivec,ipar)*yv(ivec,ioh)&
  471. ! +0.96*rrv(ivec,kc53)*yv(ivec,iror)+rrv(ivec,kc57)*yv(ivec,iole)*yv(ivec,ioh)&
  472. ! +0.29*rrv(ivec,kc58)*yv(ivec,io3)*yv(ivec,iole)+0.91*rrv(ivec,kc59)&
  473. ! *yv(ivec,iole)*yv(ivec,ino3)+rrv(ivec,kc61)*yv(ivec,ieth)*yv(ivec,ioh)&
  474. ! +0.85*rrv(ivec,kc76)*yv(ivec,iisop)*yv(ivec,ioh)+0.7*rrv(ivec,kohrooh)&
  475. ! *yv(ivec,irooh)*yv(ivec,ioh)+rrv(ivec,kc84)*yv(ivec,ioh)*yv(ivec,iorgntr)&
  476. ! +0.18*rrv(ivec,kc77)*yv(ivec,iisop)*yv(ivec,io3)
  477. ! XLXO2=rrv(ivec,kc79)*yv(ivec,ino)+2.*rrv(ivec,kc80)*yv(ivec,ixo2)+rrv(ivec,kc82)*yv(ivec,iho2)
  478. ! yv(ivec,ixo2)=(y0v(ivec,ixo2)+PXO2*DT)/(1.+XLXO2*DT)
  479. ! PXO2N=0.13*rrv(ivec,kc52)*yv(ivec,ipar)*yv(ivec,ioh)+0.04*rrv(ivec,kc53)&
  480. ! *yv(ivec,iror)+0.09*rrv(ivec,kc59)*yv(ivec,iole)*yv(ivec,ino3)+0.15*rrv(ivec,kc76)*yv(ivec,iisop)*yv(ivec,ioh)
  481. ! XLXO2N=rrv(ivec,kc81)*yv(ivec,ino)+rrv(ivec,kc85)*yv(ivec,iho2)
  482. ! yv(ivec,ixo2n)=(y0v(ivec,ixo2n)+PXO2N*DT)/(1.+XLXO2N*DT)
  483. ! end do !ivec
  484. !
  485. ! if ( mod(iter,2) == 0 ) then
  486. !
  487. ! do ivec=1,lvec
  488. ! ! --- Species with intermediate lifetimes
  489. ! ! --- Inorganic compounds (HNO3 H2O2)
  490. ! !
  491. ! PHNO3=rrv(ivec,kno2oh)*yv(ivec,ino2)*yv(ivec,ioh)+2.*(rrv(ivec,kn2o5aq)+rrv(ivec,kn2o5l))&
  492. ! *yv(ivec,in2o5)+rrv(ivec,kc44)*yv(ivec,iald2)*yv(ivec,ino3)+rrv(ivec,kc41)*yv(ivec,ich2o)*yv(ivec,ino3)
  493. ! XLHNO3=rjv(ivec,jhno3)+rrv(ivec,kohhno3)*yv(ivec,ioh)
  494. ! XLHNO3=XLHNO3 + vdv(ivec,ihno3)
  495. ! yv(ivec,ihno3)=(y0v(ivec,ihno3)+PHNO3*DT)/(1.+XLHNO3*DT)
  496. ! PH2O2=rrv(ivec,kho2ho2)*yv(ivec,iho2)*yv(ivec,iho2)
  497. ! XLH2O2=rjv(ivec,jh2o2)+rrv(ivec,khpoh)*yv(ivec,ioh)
  498. ! XLH2O2=XLH2O2 + vdv(ivec,ih2o2)
  499. ! yv(ivec,ih2o2)=(y0v(ivec,ih2o2)+PH2O2*DT)/(1.+XLH2O2*DT)
  500. ! ! --- CH4-chemistry (methyl peroxide formaldehyde)
  501. ! PCH3O2H=rrv(ivec,kmo2ho2)*yv(ivec,ich3o2)*yv(ivec,iho2)
  502. ! XLCH3O2H=rrv(ivec,kohmper)*yv(ivec,ioh)+rjv(ivec,jmepe)
  503. ! XLCH3O2H=XLCH3O2H + vdv(ivec,ich3o2h)
  504. ! yv(ivec,ich3o2h)=(y0v(ivec,ich3o2h)+PCH3O2H*DT)/(1.+XLCH3O2H*DT)
  505. ! PCH2O=rrv(ivec,kc46)*yv(ivec,ic2o3)*yv(ivec,ino)+0.3*rrv(ivec,kohmper)&
  506. ! *yv(ivec,ich3o2h)*yv(ivec,ioh)+rrv(ivec,kmo2no)*yv(ivec,ich3o2)*yv(ivec,ino)&
  507. ! +1.33*rrv(ivec,kmo2mo2)*yv(ivec,ich3o2)*yv(ivec,ich3o2)+rjv(ivec,jmepe)&
  508. ! *yv(ivec,ich3o2h)+2.*rrv(ivec,kc49)*yv(ivec,ic2o3)*yv(ivec,ic2o3)&
  509. ! +rrv(ivec,kc50)*yv(ivec,ic2o3)*yv(ivec,iho2)+rjv(ivec,j45)*yv(ivec,iald2)&
  510. ! +rrv(ivec,kc57)*yv(ivec,iole)*yv(ivec,ioh)+0.64*rrv(ivec,kc58)*yv(ivec,iole)&
  511. ! *yv(ivec,io3)+rrv(ivec,kc59)*yv(ivec,iole)*yv(ivec,ino3)+1.56*rrv(ivec,kc61)&
  512. ! *yv(ivec,ieth)*yv(ivec,ioh)+rrv(ivec,kc62)*yv(ivec,ieth)*yv(ivec,io3)&
  513. ! +0.61*rrv(ivec,kc76)*yv(ivec,iisop)*yv(ivec,ioh)+0.9*rrv(ivec,kc77)&
  514. ! *yv(ivec,iisop)*yv(ivec,io3)+0.03*rrv(ivec,kc78)*yv(ivec,iisop)*yv(ivec,ino3)
  515. ! XLCH2O=rjv(ivec,jach2o)+rjv(ivec,jbch2o)+yv(ivec,ioh)*rrv(ivec,kfrmoh)+rrv(ivec,kc41)*yv(ivec,ino3)
  516. ! XLCH2O=XLCH2O + vdv(ivec,ich2o)
  517. ! yv(ivec,ich2o)=(y0v(ivec,ich2o)+PCH2O*DT)/(1.+XLCH2O*DT)
  518. ! ! --- CBIV-elements for higher HC-chemistry: ALD2 MGLY
  519. ! ! --- ETH OLE ISOP ROOH ORGNTR
  520. ! PALD2=0.11*rrv(ivec,kc52)*yv(ivec,ipar)*yv(ivec,ioh)+1.1*rrv(ivec,kc53)&
  521. ! *yv(ivec,iror)+rrv(ivec,kc57)*yv(ivec,iole)*yv(ivec,ioh)+0.44*rrv(ivec,kc58)&
  522. ! *yv(ivec,iole)*yv(ivec,io3)+rrv(ivec,kc59)*yv(ivec,iole)*yv(ivec,ino3)&
  523. ! +0.22*rrv(ivec,kc61)*yv(ivec,ieth)*yv(ivec,ioh)+0.12*rrv(ivec,kc78)*yv(ivec,iisop)*yv(ivec,ino3)
  524. ! XLALD2=rrv(ivec,kc43)*yv(ivec,ioh)+rrv(ivec,kc44)*yv(ivec,ino3)+rjv(ivec,j45)
  525. ! XLALD2=XLALD2 + vdv(ivec,iald2)
  526. ! yv(ivec,iald2)=(y0v(ivec,iald2)+PALD2*DT)/(1.+XLALD2*DT)
  527. ! PMGLY=0.03*rrv(ivec,kc76)*yv(ivec,iisop)*yv(ivec,ioh)+0.03*rrv(ivec,kc77)&
  528. ! *yv(ivec,iisop)*yv(ivec,io3)+0.08*rrv(ivec,kc78)*yv(ivec,iisop)*yv(ivec,ino3)
  529. ! XLMGLY=rrv(ivec,kc73)*yv(ivec,ioh)+rjv(ivec,j74)
  530. ! yv(ivec,imgly)=(y0v(ivec,imgly)+PMGLY*DT)/(1.+XLMGLY*DT)
  531. ! XLETH=rrv(ivec,kc61)*yv(ivec,ioh)+rrv(ivec,kc62)*yv(ivec,io3)
  532. ! yv(ivec,ieth)=y0v(ivec,ieth)/(1.+XLETH*DT)
  533. ! POLE=0.58*rrv(ivec,kc76)*yv(ivec,iisop)*yv(ivec,ioh)+0.55*rrv(ivec,kc77)&
  534. ! *yv(ivec,iisop)*yv(ivec,io3)+0.45*rrv(ivec,kc78)*yv(ivec,iisop) *yv(ivec,ino3)
  535. ! XLOLE=rrv(ivec,kc57)*yv(ivec,ioh)+rrv(ivec,kc58)*yv(ivec,io3)+rrv(ivec,kc59)*yv(ivec,ino3)
  536. ! yv(ivec,iole)=(y0v(ivec,iole)+POLE*DT)/(1.+XLOLE*DT)
  537. ! PROOH=rrv(ivec,kc82)*yv(ivec,ixo2)*yv(ivec,iho2)+0.21*rrv(ivec,kc50)&
  538. ! *yv(ivec,ic2o3)*yv(ivec,iho2)+rrv(ivec,kc85)*yv(ivec,iho2)*yv(ivec,ixo2n)
  539. ! XLROOH=rjv(ivec,jrooh)+rrv(ivec,kohrooh)*yv(ivec,ioh)
  540. ! XLROOH = XLROOH + vdv(ivec,irooh)
  541. ! yv(ivec,irooh)=(y0v(ivec,irooh)+PROOH*DT)/(1.+XLROOH*DT)
  542. !
  543. ! PORGNTR=rrv(ivec,kc81)*yv(ivec,ino)*yv(ivec,ixo2n)+0.9*rrv(ivec,kc78)*yv(ivec,iisop)*yv(ivec,ino3)
  544. ! XLORGNTR=rrv(ivec,kc84)*yv(ivec,ioh)+rjv(ivec,jorgn)
  545. ! XLORGNTR=XLORGNTR+vdv(ivec,iorgntr)
  546. !
  547. ! yv(ivec,iorgntr)=(y0v(ivec,iorgntr)+PORGNTR*DT)/(1.+XLORGNTR*DT)
  548. !
  549. ! ! gas phase sulfur & ammonia
  550. !
  551. ! qdms1=rrv(ivec,kdmsoha)*yv(ivec,ioh)+rrv(ivec,kdmsno3)*yv(ivec,ino3)
  552. ! qdms2=rrv(ivec,kdmsohb)*yv(ivec,ioh)
  553. ! qdms=qdms1+qdms2
  554. ! yv(ivec,idms)=y0v(ivec,idms)/(1.+qdms*DT)
  555. ! pso2=yv(ivec,idms)*(qdms1+0.75*qdms2)
  556. ! pmsa=yv(ivec,idms)*0.25*qdms2
  557. ! qso2=rrv(ivec,kso2oh)*yv(ivec,ioh)
  558. ! qso2d=qso2 + vdv(ivec,iso2)
  559. ! yv(ivec,iso2)=(y0v(ivec,iso2)+pso2*DT) /(1.+qso2d*DT) !qso2d includes deposition
  560. ! yv(ivec,imsa)=(y0v(ivec,imsa)+pmsa*DT) /(1.+vdv(ivec,imsa)*DT)
  561. ! yv(ivec,iso4)=(y0v(ivec,iso4)+qso2*yv(ivec,iso2)*DT) /(1. + vdv(ivec,iso4)*DT) !corredted CMK qso2/qso2d
  562. ! yv(ivec,iacid)=(y0v(ivec,iacid)+(pmsa+2.*qso2*yv(ivec,iso2))*DT)/&
  563. ! (1.+rrv(ivec,knh3SO4)*yv(ivec,inh3)*DT)
  564. ! yv(ivec,inh4)=(y0v(ivec,inh4)+yv(ivec,iacid)*rrv(ivec,knh3SO4)*yv(ivec,inh3)*DT)/(1.+vdv(ivec,inh4)*DT)
  565. ! pnh2=yv(ivec,ioh)*rrv(ivec,knh3oh)
  566. ! qnh3=yv(ivec,iacid)*rrv(ivec,knh3SO4)+pnh2
  567. ! qnh3 = qnh3 + vdv(ivec,inh3)
  568. ! yv(ivec,inh3)=y0v(ivec,inh3)/(1.+qnh3*DT)
  569. ! qnh2= rrv(ivec,knh2no)*yv(ivec,ino)+rrv(ivec,knh2no2)*yv(ivec,ino2)&
  570. ! +rrv(ivec,knh2ho2)*yv(ivec,iho2) +rrv(ivec,knh2o2)+rrv(ivec,knh2o3)*yv(ivec,io3)
  571. ! yv(ivec,inh2)=(y0v(ivec,inh2)+yv(ivec,inh3)*pnh2*dt)/(1.+qnh2*dt)
  572. ! end do !ivec
  573. !
  574. ! end if
  575. !
  576. ! if ( mod(iter,maxit) == 0 ) then
  577. !
  578. ! ! --- Long living compounds
  579. ! do ivec=1,lvec
  580. ! yv(ivec,ich4)=y0v(ivec,ich4)/(1.+rrv(ivec,kch4oh)*yv(ivec,ioh)*DT)
  581. ! PCO=yv(ivec,ich2o)*(rjv(ivec,jach2o)+rjv(ivec,jbch2o)+yv(ivec,ioh)&
  582. ! *rrv(ivec,kfrmoh))+rjv(ivec,j45)*yv(ivec,iald2)+rjv(ivec,j74)*yv(ivec,imgly)&
  583. ! +0.37*rrv(ivec,kc58)*yv(ivec,iole)*yv(ivec,io3)+0.43*rrv(ivec,kc62)&
  584. ! *yv(ivec,ieth)*yv(ivec,io3)+0.36*rrv(ivec,kc77)*yv(ivec,iisop)*yv(ivec,io3)&
  585. ! +rrv(ivec,kc41)*yv(ivec,ich2o)*yv(ivec,ino3)
  586. ! XLCO = rrv(ivec,kcooh)*yv(ivec,ioh)
  587. ! XLCO = XLCO + vdv(ivec,ico)
  588. ! yv(ivec,ico)=(y0v(ivec,ico)+PCO*DT)/(1.+XLCO*DT)
  589. ! PPAR=0.63*rrv(ivec,kc77)*yv(ivec,iisop)*yv(ivec,io3)+0.63*rrv(ivec,kc76)*yv(ivec,iisop)*yv(ivec,ioh)
  590. ! XLPAR=rrv(ivec,kc52)*yv(ivec,ioh)+rrv(ivec,kc83)*yv(ivec,irxpar)
  591. ! yv(ivec,ipar)=(y0v(ivec,ipar)+PPAR*DT)/(1.+XLPAR*DT)
  592. ! !cmk ____added rn222 chemistry in EBI language
  593. ! yv(ivec,irn222) = y0v(ivec,irn222)/(1.+rrv(ivec,krn222)*dt)
  594. ! yv(ivec,ipb210) = y0v(ivec,ipb210)+y0v(ivec,irn222)-yv(ivec,irn222)
  595. ! !if(yv(ivec,ipb210) < 0.0 .or. yv(ivec,irn222) < 0.0) then
  596. ! ! print *, 'Negatives .....rn222, pb210', y0v(ivec,irn222), yv(ivec,irn222) , y0v(ivec,ipb210), yv(ivec,ipb210)
  597. ! !end if
  598. ! end do !ivec
  599. !
  600. ! end if
  601. !
  602. ! end do !ITER
  603. !
  604. ! end subroutine do_ebi
  605. !
  606. !
  607. ! subroutine NOYmass
  608. !#ifdef MPI
  609. ! use mpi_comm,only: stopmpi
  610. !#endif
  611. ! implicit none
  612. ! integer i,j,imax, offsetl
  613. ! real :: ncormax,ncorav,totn,totn0,fnoy,fnoy1
  614. ! real :: ncorr,ncorr1,ncorr2,ncorr3, totdep
  615. ! logical :: nerr
  616. !
  617. ! offsetl=0
  618. !#ifdef MPI
  619. ! if(myid>0) offsetl=sum(lmar(0:myid-1))
  620. !#endif
  621. !
  622. ! ncormax=0.
  623. ! ncorav=0.
  624. ! nerr=.false.
  625. ! imax = 0
  626. ! do j=jsr(region),jer(region)
  627. ! do i=isr(region),ier(region)
  628. ! if(zoomed(i,j)/=region) cycle
  629. ! imax = imax + 1
  630. ! !
  631. ! !** Guarantee exact mass conservation of NOY
  632. ! ! (this may matter a few percent)
  633. ! !
  634. ! fnoy=y(i,j,ino)+y(i,j,ino2)+y(i,j,ino3)+2.*y(i,j,in2o5)+y(i,j,ihno4)
  635. ! if (level+offsetl == 1) then
  636. ! totdep = (y(i,j,ino) *vd(region,ino )%surf(i,j) + &
  637. ! y(i,j,ino2)*vd(region,ino2)%surf(i,j) + &
  638. ! y(i,j,ino3)*vd(region,ino3)%surf(i,j) + &
  639. ! y(i,j,ihno3)*vd(region,ihno3)%surf(i,j) + &
  640. ! y(i,j,ipan)*vd(region,ipan)%surf(i,j) + &
  641. ! y(i,j,iorgntr)*vd(region,iorgntr)%surf(i,j) + &
  642. ! 2*y(i,j,in2o5)*vd(region,in2o5)%surf(i,j) + &
  643. ! y(i,j,ihno4)*vd(region,ihno4)%surf(i,j) )*dt/ye(i,j,idz)
  644. ! else
  645. ! totdep = 0.0
  646. ! end if
  647. ! totn0=y0(i,j,inox)+y0(i,j,ihno3)+y0(i,j,ipan)+ &
  648. ! y0(i,j,iorgntr) + ye(i,j,ieno)*dt - totdep
  649. ! ! note that emino is added here and the total deposition is subtracted
  650. ! !
  651. ! ! totn0 contains all nitrogen at beginning of timestep + nox emissions
  652. ! !
  653. ! !
  654. ! ! totn contains all nitrogen at end of timestep
  655. ! !
  656. ! totn=fnoy+y(i,j,ihno3)+y(i,j,ipan)+y(i,j,iorgntr)
  657. ! ! correction factor for all nitrogen compounds
  658. ! ncorr=totn-totn0
  659. !
  660. ! if ( totn < tiny(totn) ) cycle
  661. !
  662. ! if ( (abs(ncorr)/totn) > 0.05 ) then !CMK changed from 0.1 to 0.05
  663. !
  664. ! nerr=.true.
  665. ! print *,'NOYmass: N-error....',region,offsetl+level,i,j,totn0,totn
  666. ! print *,'NOYmass: emino ',ye(i,j,ieno)*dt/y0(i,j,iair)*1e9
  667. ! print *,'NOYmass: NO(0) ', &
  668. ! y0(i,j,ino)/y0(i,j,iair)*1e9,y(i,j,ino)/y(i,j,iair)*1e9
  669. ! print *,'NOYmass: NO2(0) ', &
  670. ! y0(i,j,ino2)/y0(i,j,iair)*1e9,y(i,j,ino2)/y(i,j,iair)*1e9
  671. ! print *,'NOYmass: O3(0) ', &
  672. ! y0(i,j,io3)/y0(i,j,iair)*1e9,y(i,j,io3)/y(i,j,iair)*1e9
  673. ! print *,'NOYmass: NO3(0) ', &
  674. ! y0(i,j,ino3)/y0(i,j,iair)*1e9,y(i,j,ino3)/y(i,j,iair)*1e9
  675. ! print *,'NOYmass: N2O5(0) ', &
  676. ! y0(i,j,in2o5)/y0(i,j,iair)*1e9,y(i,j,in2o5)/y(i,j,iair)*1e9
  677. ! print *,'NOYmass: HNO4(0) ', &
  678. ! y0(i,j,ihno4)/y0(i,j,iair)*1e9,y(i,j,ihno4)/y(i,j,iair)*1e9
  679. ! print *,'NOYmass: HNO3(0) ', &
  680. ! y0(i,j,ihno3)/y0(i,j,iair)*1e9,y(i,j,ihno3)/y(i,j,iair)*1e9
  681. ! print *,'NOYmass: PAN(0) ', &
  682. ! y0(i,j,ipan)/y0(i,j,iair)*1e9,y(i,j,ipan)/y(i,j,iair)*1e9
  683. ! print *,'NOYmass: ORGNT(0) ', &
  684. ! y0(i,j,iorgntr)/y0(i,j,iair)*1e9,y(i,j,iorgntr)/y(i,j,iair)*1e9
  685. ! print *,'NOYmass: NOx(0) ', &
  686. ! y0(i,j,inox)/y0(i,j,iair)*1e9,y(i,j,inox)/y(i,j,iair)*1e9
  687. ! print *,'NOYmass: ',rj(i,j,jhno3),rr(i,j,kohhno3)*y(i,j,ioh), &
  688. ! y(i,j,ioh)/y(i,j,iair)*1e9
  689. !
  690. ! end if
  691. ! ! maximum and average correction factor in this loop
  692. ! ncormax=max(abs(ncormax),abs(ncorr/totn))
  693. ! ncorav=ncorav+abs(ncorr/totn)
  694. ! !
  695. ! ! first correct hno3, pan and organic nitrates
  696. ! ! (as a group of reservoir tracers)
  697. ! !
  698. ! totn=y(i,j,ihno3)+y(i,j,ipan)+y(i,j,iorgntr)
  699. ! if ( totn < tiny(totn) ) cycle
  700. ! ncorr1=y(i,j,ihno3) *(1.-ncorr/totn)
  701. ! ncorr2=y(i,j,ipan) *(1.-ncorr/totn)
  702. ! ncorr3=y(i,j,iorgntr)*(1.-ncorr/totn)
  703. ! y(i,j,ihno3) =max(0.,ncorr1)
  704. ! y(i,j,ipan) =max(0.,ncorr2)
  705. ! y(i,j,iorgntr)=max(0.,ncorr3)
  706. ! ncorr=ncorr1+ncorr2+ncorr3-y(i,j,ihno3)-y(i,j,ipan)- y(i,j,iorgntr)
  707. ! !
  708. ! ! the remainder is used to scale the noy components
  709. ! !
  710. ! fnoy1=(fnoy+ncorr)/fnoy
  711. ! y(i,j,ino) =fnoy1*y(i,j,ino)
  712. ! y(i,j,ino2) =fnoy1*y(i,j,ino2)
  713. ! y(i,j,ino3) =fnoy1*y(i,j,ino3)
  714. ! y(i,j,in2o5)=fnoy1*y(i,j,in2o5)
  715. ! y(i,j,ihno4)=fnoy1*y(i,j,ihno4)
  716. ! y(i,j,inox)=y(i,j,ino)+y(i,j,ino2)+y(i,j,ino3)+ &
  717. ! 2.*y(i,j,in2o5)+y(i,j,ihno4)
  718. !
  719. ! end do
  720. !
  721. ! end do
  722. !
  723. ! if ( nerr ) print*,'NOYmass: N-mass balance error, ncorr>5% ',&
  724. ! 'Maximum correction:', ncormax,&
  725. ! 'Average correction in this loop:', ncorav/imax, imax, '(imax)'
  726. !
  727. ! end subroutine NOYmass
  728. !
  729. !
  730. !
  731. ! subroutine incc2c3
  732. ! !
  733. ! use budget_global,only : buddep_dat, sum_deposition, sum_chemistry
  734. ! use budget_fine,only: depdry
  735. ! implicit none
  736. ! integer :: i1,n1,n2,jl,i,j,offsetl
  737. ! ! nrj and nrr used for reaction budget calculations
  738. ! integer,dimension(nj ),parameter :: nrj=(/io3,ino2,ih2o2,ihno3,ihno4,in2o5,ich2o,ich2o, &
  739. ! ich3o2h,ino3,ino3,ipan,iorgntr,iald2,imgly,irooh/)
  740. ! integer,dimension(nreac,2),parameter :: nrr = reshape((/ &
  741. ! ino,iho2,ich3o2,ino2,ioh,ino2,ino,ino2,in2o5,ihno4,&
  742. ! ino2,ihno4,iair,ih2o,io3,ico,io3,ih2o2,ich2o,ich4, &
  743. ! ioh,ioh,ich3o2, ich3o2, iho2,iho2,in2o5,in2o5,ioh,ich2o,&
  744. ! iald2,iald2,ic2o3,ic2o3,ipan,ic2o3,ic2o3,ipar,iror,iror,&
  745. ! ioh,io3,ino3,ioh,io3,ioh,ioh,io3,ino3,ixo2,&
  746. ! ixo2,ixo2n,ixo2,irxpar,iorgntr,ixo2n,idms,idms,idms,iso2,&
  747. ! inh3,inh3,inh2,inh2,inh2,inh2,inh2,irn222, &
  748. ! !second reaction partner (if monmolecular = 0)
  749. ! io3,ino,ino,ioh,ihno3,io3,ino3,ino3, 0, ioh, &
  750. ! iho2,0,0,0,iho2,ioh,ioh,ioh,ioh,ioh, &
  751. ! ich3o2h,irooh,iho2, ich3o2, ioh,iho2,0,0,0,ino3,&
  752. ! ioh,ino3,ino,ino2,0,ic2o3,iho2,ioh, 0, 0,&
  753. ! iole,iole,iole,ieth,ieth,imgly,iisop,iisop,iisop,ino,&
  754. ! ixo2,ino,iho2,ipar,ioh,iho2,ioh,ioh,ino3,ioh,&
  755. ! iacid,ioh,ino,ino2,iho2,0,io3,0/),(/nreac,2/))
  756. !
  757. ! real :: c1,xdep
  758. !
  759. ! c1=dt*1000./xmair !conversion to moles...
  760. !
  761. ! offsetl=0
  762. !#ifdef MPI
  763. ! if(myid>0) offsetl=sum(lmar(0:myid-1))
  764. !#endif
  765. !
  766. ! ! reaction budgets
  767. !
  768. ! do i1=1,nj !photolysis rates
  769. ! n1=nrj(i1)
  770. ! do j=jsr(region),jer(region)
  771. ! do i=isr(region),ier(region)
  772. ! if(zoomed(i,j)/=region) cycle
  773. ! if(n1 > 0) cr2(i,j,i1)=cr2(i,j,i1)+rj(i,j,i1)*y(i,j,n1)
  774. ! end do
  775. ! end do
  776. ! end do!i1=1,nj
  777. ! !
  778. ! do i1=1,nreac !reactions
  779. ! n1=nrr(i1,1) !make sure n1 > 0
  780. ! n2=nrr(i1,2)
  781. ! if (n2 > 0.) then
  782. ! do j=jsr(region),jer(region)
  783. ! do i=isr(region),ier(region)
  784. ! if(zoomed(i,j)/=region) cycle
  785. ! cr3(i,j,i1)= cr3(i,j,i1)+y(i,j,n1)*y(i,j,n2)*rr(i,j,i1)
  786. ! end do
  787. ! end do
  788. ! else
  789. ! do j=jsr(region),jer(region)
  790. ! do i=isr(region),ier(region)
  791. ! if(zoomed(i,j)/=region) cycle
  792. ! cr3(i,j,i1)= cr3(i,j,i1)+y(i,j,n1)*rr(i,j,i1)
  793. ! end do
  794. ! end do
  795. ! end if
  796. ! end do !i1=1,nreac
  797. !
  798. ! if ( offsetl + level == 1 ) then ! deposition budget
  799. !
  800. ! do i1=1,ntrace
  801. ! do j=jsr(region),jer(region)
  802. ! do i=isr(region),ier(region)
  803. ! if(zoomed(i,j)/=region) cycle
  804. ! xdep = y(i,j,i1)*vd(region,i1)%surf(i,j)/ye(i,j,idz)* &
  805. ! c1*ye(i,j,iairm)/y(i,j,iair) !from updated concentrations
  806. ! buddep_dat(region)%dry(i,j,i1) = &
  807. ! buddep_dat(region)%dry(i,j,i1) + xdep
  808. ! if ( region == nregions ) then
  809. ! depdry(i,j,i1) = depdry(i,j,i1) + xdep !in mole
  810. ! end if
  811. ! if ( i1 == 1 ) then !seperate deposition from 'other' chemistry
  812. ! sum_deposition(region) = sum_deposition(region) - &
  813. ! xdep*ra(1)*1e-3 ! in kg
  814. ! sum_chemistry(region) = sum_chemistry(region) + &
  815. ! (y(i,j,1)-y0(i,j,1))/y(i,j,iair)* &
  816. ! ye(i,j,iairm)/xmair*ra(1) + xdep*ra(1)*1e-3
  817. ! end if
  818. ! end do
  819. ! end do
  820. ! end do !i1
  821. ! else ! other layers
  822. ! do j=jsr(region),jer(region)
  823. ! do i=isr(region),ier(region)
  824. ! if(zoomed(i,j)/=region) cycle
  825. ! sum_chemistry(region) = sum_chemistry(region) + &
  826. ! (y(i,j,1)-y0(i,j,1))/y(i,j,iair)*ye(i,j,iairm)/xmair*ra(1)
  827. ! end do
  828. ! end do
  829. ! end if !level ==1
  830. ! end subroutine incc2c3
  831. !
  832. !
  833. !
  834. ! subroutine reacbud
  835. ! !------------------------------------------------------------------------
  836. ! !
  837. ! ! REACBUD increase reaction budgets for each reaction
  838. ! ! arrays nrr and nrj determine which species are
  839. ! ! involved in a reaction
  840. ! !
  841. ! !
  842. ! !------------------------------------------------------------------------
  843. ! use budget_global,only : budrjg,budrrg,budrwg,budg_dat,nzon_vg
  844. ! use budget_fine,only: budrj,budrr,budrw,nzon,nzon_v
  845. ! implicit none
  846. ! integer :: i1,i,j,nzone,nzone_v
  847. ! real :: c1
  848. ! !
  849. ! ! attribute to regions
  850. ! !
  851. ! c1=dt*1000./xmair !conversion to moles...
  852. ! do j=jsr(region),jer(region)
  853. ! do i=isr(region),ier(region)
  854. ! if(zoomed(i,j)/=region) cycle
  855. ! if(region==nregions) then !finest region budget....
  856. ! nzone=nzon(i,j)
  857. ! nzone_v=nzon_v(offsetl+level) !level is passed to ebi...
  858. ! do i1=1,nj
  859. ! budrj(nzone,nzone_v,i1)=budrj(nzone,nzone_v,i1)+ &
  860. ! cr2(i,j,i1)*c1*ye(i,j,iairm)/y(i,j,iair) !units mole
  861. ! end do !nj
  862. ! do i1=1,nreac
  863. ! budrr(nzone,nzone_v,i1)=budrr(nzone,nzone_v,i1)+ &
  864. ! cr3(i,j,i1)*c1*ye(i,j,iairm)/y(i,j,iair) !units mole
  865. ! end do
  866. ! do i1=1,nreacw
  867. ! budrw(nzone,nzone_v,i1)=budrw(nzone,nzone_v,i1)- &
  868. ! cr4(i,j,i1)*(1000./xmair)*ye(i,j,iairm)/y(i,j,iair)
  869. ! !note: changed sign to get 'positive' budget, just a
  870. ! ! matter of definition, !CMK
  871. ! end do
  872. ! end if
  873. ! nzone=budg_dat(region)%nzong(i,j) !global budget
  874. ! nzone_v=nzon_vg(offsetl+level) !level is passed to ebi...
  875. ! do i1=1,nj
  876. ! budrjg(nzone,nzone_v,i1)=budrjg(nzone,nzone_v,i1)+ &
  877. ! cr2(i,j,i1)*c1*ye(i,j,iairm)/y(i,j,iair) !units mole
  878. ! end do !nj
  879. ! do i1=1,nreac
  880. ! budrrg(nzone,nzone_v,i1)=budrrg(nzone,nzone_v,i1)+ &
  881. ! cr3(i,j,i1)*c1*ye(i,j,iairm)/y(i,j,iair) !units mole
  882. ! end do
  883. ! do i1=1,nreacw
  884. ! budrwg(nzone,nzone_v,i1)=budrwg(nzone,nzone_v,i1)- &
  885. ! cr4(i,j,i1)*(1000./xmair)*ye(i,j,iairm)/y(i,j,iair) ! mole
  886. ! !note: changed sign to get 'positive' budget, just a
  887. ! ! matter of definition, !CMK
  888. ! end do
  889. ! end do
  890. ! end do
  891. !
  892. ! end subroutine REACBUD
  893. !
  894. !
  895. ! end subroutine ebi
  896. !
  897. !
  898. !
  899. ! subroutine wetS(region,level,y0,dt,y,ye,c4)
  900. ! !**********************************************************************
  901. ! !
  902. ! !wetS - aqueous phase chemistry of sulfur (and other)
  903. ! !programmed by Ad Jeuken (KNMI) and Frank Dentener (IMAU)
  904. ! !adapted for TM5 by Maarten Krol (IMAU) 1-2002
  905. ! !
  906. ! !purpose
  907. ! !-------
  908. ! !oxidation of SO2 and uptake of other gases in the aqueous phase
  909. ! !
  910. ! !interface
  911. ! !---------
  912. ! !call wetS(region,level,zoomed,y0,dt,y,ye,c4)
  913. ! !region region under operation (provides im,jm,lm via chemistry.mod)
  914. ! !level vertical level
  915. ! !zoomed which cells to skip (chemistrty is done by child)
  916. ! !y0 initial concentration
  917. ! !dt chemistry timestep
  918. ! !yt concentrations at time is t
  919. ! !ye extra fields (temperature, clouds, ....)
  920. ! !c4 budget accumulatior
  921. ! !
  922. ! !method
  923. ! !------
  924. ! !implicit solution of oxidation of SO2
  925. ! !
  926. ! !external
  927. ! !--------
  928. ! !none
  929. ! !
  930. ! !reference
  931. ! !---------
  932. ! !-
  933. ! !**********************************************************************
  934. !
  935. ! use global_data, only: region_dat
  936. ! use reaction_data,only: nreacw,ntlow,kso2hp,kso2o3
  937. ! use chem_param
  938. ! use budget_global, only: sum_wetchem
  939. ! use dims, only: isr, jsr, ier,jer, im, jm
  940. ! use Binas, only: Avog
  941. !
  942. ! ! use toolbox, only: dumpfield, escape_tm
  943. ! ! use dims, only: lm
  944. ! implicit none
  945. !
  946. ! ! input/output
  947. !
  948. ! integer,intent(in) :: region
  949. ! integer,intent(in) :: level
  950. ! real,intent(in),dimension(im(region),jm(region),maxtrace) :: y0
  951. ! real,intent(in) :: dt
  952. ! real,intent(out),dimension(im(region),jm(region),maxtrace):: y
  953. ! real,dimension(im(region),jm(region),n_extra) :: ye !extra fields (temp, cc, pH)
  954. ! real,dimension(im(region),jm(region),nreacw),intent(inout):: c4
  955. !
  956. ! ! local
  957. !
  958. ! integer,dimension(:,:),pointer :: zoomed
  959. ! integer n,i,j,l,itemp,iter
  960. ! real x1,x2,x3,b1,b2,so2x,dh2o2,dso2,disc,dnh3,dn2o5,xso2o3a,xso2o3b
  961. ! real,parameter :: co2=3.20e-4,rg=0.08314
  962. ! real,dimension(:,:),allocatable :: hkso2 ! Henry's constant for sulfur dioxide
  963. ! real,dimension(:,:),allocatable :: hkh2o2 ! Henry's constant for hydroperoxide
  964. ! real,dimension(:,:),allocatable :: hko3 ! Henry's constant for ozone
  965. ! real,dimension(:,:),allocatable :: dkso2 ! Dissociation constant for SO2
  966. ! real,dimension(:,:),allocatable :: dkhso3 ! Dissociation constant for HSO3-
  967. ! real,dimension(:,:),allocatable :: dkh2o ! dissociation constant water
  968. ! real,dimension(:,:),allocatable :: dknh3 ! dissociation constant ammonia
  969. ! real,dimension(:,:),allocatable :: hknh3 ! Henry's constant ammonia
  970. ! real,dimension(:,:),allocatable :: hkco2 ! Henry's constant CO2
  971. ! real,dimension(:,:),allocatable :: dkco2 ! Dissociation constant CO2
  972. ! real phs4 ! effective dissolvation of S(IV)
  973. ! real phso2 ! effective dissolvation of SO2
  974. ! real phh2o2 ! effective dissolvation of H2O2
  975. ! real phozone ! effective dissolvation of O3
  976. ! real,dimension(:,:),allocatable :: hplus !concentration h+
  977. ! real a1,a2,a,b,c,z ! help variables
  978. ! real xcov,xliq,xl,temp,rt,ztr,h2o,air,press ! meteo
  979. ! real,dimension(:,:,:),allocatable :: rw ! reaction rates
  980. ! logical,dimension(:,:),allocatable :: cloudy
  981. ! ! character(len=2) :: levelc
  982. !
  983. ! ! start
  984. !
  985. ! zoomed => region_dat(region)%zoomed
  986. !
  987. ! allocate(hkso2 (im(region),jm(region)))
  988. ! allocate(hkh2o2 (im(region),jm(region)))
  989. ! allocate(hko3 (im(region),jm(region)))
  990. ! allocate(dkso2 (im(region),jm(region)))
  991. ! allocate(dkhso3 (im(region),jm(region)))
  992. ! allocate(dkh2o (im(region),jm(region)))
  993. ! allocate(dknh3 (im(region),jm(region)))
  994. ! allocate(hknh3 (im(region),jm(region)))
  995. ! allocate(hkco2 (im(region),jm(region)))
  996. ! allocate(dkco2 (im(region),jm(region)))
  997. ! allocate(hplus (im(region),jm(region)))
  998. ! allocate(rw (im(region),jm(region),nreacw))
  999. ! allocate(cloudy (im(region),jm(region)))
  1000. !
  1001. ! !-----------------------------
  1002. ! ! wet phase reactions
  1003. ! !-----------------------------
  1004. ! rw =0.0
  1005. ! hplus=0.0
  1006. !
  1007. ! do j=jsr(region),jer(region)
  1008. ! do i=isr(region),ier(region)
  1009. ! if(zoomed(i,j)/=region) cycle
  1010. ! cloudy(i,j)=.false.
  1011. !
  1012. ! ! lwc is dimensionless
  1013. ! if ((ye(i,j,ilwc) > 1e-10).and.(ye(i,j,icc) > 0.01)) then
  1014. ! cloudy(i,j)=.true.
  1015. ! TEMP=ye(i,j,i_temp)
  1016. ! ZTR=(1./TEMP-1./298)
  1017. ! RT=TEMP*rg
  1018. ! ITEMP=nint(TEMP-float(ntlow))
  1019. ! !
  1020. ! ! Henry and dissociation equilibria
  1021. ! !
  1022. ! dkh2o(i,j) =1.01e-14*exp(-6706.0 *ztr) !h2o<=>hplus+so3--
  1023. ! hkco2(i,j) =3.4e-2*(2420.*ztr) ! is already dimensionless
  1024. ! dkco2(i,j) =4.5E-7*exp(-1000.*ztr) !co2aq<=>hco3- + hplus
  1025. ! hkso2(i,j) =henry(iso2,itemp)*rt !dimensionless
  1026. ! dknh3(i,j) =1.8e-5*exp(-450.*ztr) !nh3<=>nh4+ + OH-
  1027. ! hknh3(i,j) =henry(inh3,itemp)*rt !dimensionless
  1028. ! hkh2o2(i,j)=henry(ih2o2,itemp)*rt !dimensionless
  1029. ! hko3(i,j) =henry(io3,itemp)*rt !dimensionless
  1030. ! dkso2(i,j) =1.7e-2*exp(2090.*ztr) !so2<=>hso3m+hplus
  1031. ! dkhso3(i,j)=6.6e-8*exp(1510.*ztr) !hso3m<=>so3-- + hplus
  1032. ! !
  1033. ! ! calculate H+ from initial sulfate, ammonium, hno3, and nh3
  1034. ! ! if solution is strongly acidic no further calculations are performed
  1035. ! !
  1036. !
  1037. ! xl=ye(i,j,ilwc)*Avog*1e-3/ye(i,j,icc)
  1038. ! !x1 is initial strong acidity from SO4 and NO3
  1039. ! !
  1040. ! !acidity from strong acids alone
  1041. ! !
  1042. ! hplus(i,j)=(2.*y0(i,j,iso4)+y0(i,j,imsa)-y0(i,j,inh4)+ &
  1043. ! y0(i,j,ihno3)+y0(i,j,ino3_a))/xl
  1044. ! end if
  1045. ! end do
  1046. ! end do
  1047. ! do iter=1,10
  1048. ! do j=jsr(region),jer(region)
  1049. ! do i=isr(region),ier(region)
  1050. ! if ( zoomed(i,j) /= region ) cycle
  1051. ! ! only if solution pH>4.5
  1052. ! if ( cloudy(i,j) .and. hplus(i,j) < 3e-5 ) then
  1053. ! xl=ye(i,j,ilwc)*Avog*1e-3/ye(i,j,icc)
  1054. ! x1=(2.*y0(i,j,iso4)+y0(i,j,imsa)+y0(i,j,ihno3)+ &
  1055. ! y0(i,j,ino3_a))/xl
  1056. ! !x2 is initial total NHx
  1057. ! x2=(y0(i,j,inh3)+y0(i,j,inh4))/xl
  1058. ! !x3 is combined dissolution and solubility const for CO2
  1059. ! x3=dkco2(i,j)*hkco2(i,j)*co2
  1060. ! a1=dkh2o(i,j)/dknh3(i,j)*(1.+1./hknh3(i,j)) ! integration constant
  1061. ! a2=y0(i,j,iso2)/xl !initial SO2
  1062. ! z=a2/(hplus(i,j)/dkso2(i,j)*(1.+1./hkso2(i,j))+ &
  1063. ! dkhso3(i,j)/hplus(i,j)+1.)
  1064. ! a=1.+x2/(a1+hplus(i,j))
  1065. ! b=-x1-z
  1066. ! c=-x3-2.*dkhso3(i,j)*z
  1067. ! z=max(0.,(b*b-4.*a*c))
  1068. ! hplus(i,j)=max(1.e-10,(-b+sqrt(z))/(2.*a))
  1069. ! end if
  1070. ! end do !
  1071. ! end do ! i,j loop
  1072. ! end do !iter
  1073. ! do j=jsr(region),jer(region)
  1074. ! do i=isr(region),ier(region)
  1075. ! if(zoomed(i,j)/=region) cycle
  1076. ! if (cloudy(i,j)) then
  1077. ! temp=ye(i,j,i_temp)
  1078. ! ZTR=(1./TEMP-1./298)
  1079. ! xliq=ye(i,j,ilwc)/ye(i,j,icc)
  1080. ! xl=ye(i,j,ilwc)*Avog*1e-3/ye(i,j,icc)
  1081. ! ye(i,j,iph)=-log10(hplus(i,j)) ! pH for diagnostics
  1082. !
  1083. ! ! phase factor ratio of aqueous phase to gas phase concentration
  1084. !
  1085. ! phs4 =hkso2(i,j) *(1.+dkso2(i,j)/hplus(i,j)+ &
  1086. ! dkhso3(i,j)/hplus(i,j)/hplus(i,j))*xliq
  1087. ! phso2 =hkso2(i,j) *xliq
  1088. ! phh2o2 =hkh2o2(i,j)*xliq
  1089. ! phozone=hko3(i,j) *xliq
  1090. !
  1091. ! ! the original rate equations could be partly in look-up table
  1092. !
  1093. ! rw(i,j,KSO2HP) =8e4*exp(-3560.*ztr)/(0.1+hplus(i,j))
  1094. ! XSO2O3A=4.39e11*exp(-4131./temp)+2.56e3*exp(-966./temp) !S(IV)
  1095. ! XSO2O3B=2.56e3*exp(-966./temp)/hplus(i,j)
  1096. ! !divide by [H+]!S(IV)
  1097. !
  1098. ! ! make rate constants dimensionless by multiplying
  1099. ! ! by (1./xliq/avo=6e20)
  1100. ! ! multiply with the fractions of concentrations residing
  1101. ! ! in the aqueous phase
  1102. !
  1103. ! rw(i,j,KSO2HP)=rw(i,j,KSO2HP)/xl*phso2/(1.+phs4)*phh2o2/(1.+phh2o2)
  1104. ! rw(i,j,KSO2O3)=(XSO2O3A+XSO2O3B)/xl*phs4/(1.+phs4)*phozone/ &
  1105. ! (1.+phozone)
  1106. ! end if !cloudy
  1107. ! end do !
  1108. ! end do ! I,J, LOOP
  1109. !! write(levelc,'(i2.2)') level
  1110. !! if(level == 1) then
  1111. !! call dumpfield(0,'rw.hdf',im(region),jm(region),nreacw,1,rw,'rw'//levelc)
  1112. !! call dumpfield(1,'rw.hdf',im(region),jm(region),n_extra,1,ye,'ye'//levelc)
  1113. !! else
  1114. !! call dumpfield(1,'rw.hdf',im(region),jm(region),nreacw,1,rw,'rw'//levelc)
  1115. !! call dumpfield(1,'rw.hdf',im(region),jm(region),n_extra,1,ye,'ye'//levelc)
  1116. !! end if
  1117. !! if(level == lm(1) ) call escape_tm(' forced stop ')
  1118. !
  1119. ! ! Start main loop
  1120. ! do j=jsr(region),jer(region)
  1121. ! do i=isr(region),ier(region)
  1122. ! if(zoomed(i,j)/=region) cycle
  1123. ! !
  1124. ! ! only cloud chemistry if substantial amount of clouds are present
  1125. ! !
  1126. ! if (cloudy(i,j)) then
  1127. ! !
  1128. ! ! oxidation of S(IV) by O3
  1129. ! !
  1130. ! so2x=y0(i,j,iso2)
  1131. ! xcov=ye(i,j,icc)
  1132. ! x1=min(100.,rw(i,j,kso2o3)*y0(i,j,io3)*dt)
  1133. ! dso2=y0(i,j,iso2)*xcov*(exp(-x1)-1.)
  1134. ! !only applied to xcov part of cloud
  1135. ! !CMK print *, i,j, xcov, x1, y0(i,j,iso2), dso2
  1136. ! dso2=max(-y0(i,j,io3)*xcov,dso2)! limit to o3 availability
  1137. ! y(i,j,iso2)=y0(i,j,iso2)+dso2
  1138. ! !NOTE CMK: paralel MPI should take care here!
  1139. ! y(i,j,iso4)=y0(i,j,iso4)-dso2
  1140. ! y(i,j,io3)=y0(i,j,io3)+dso2
  1141. ! if ( io3 == 1 ) sum_wetchem(region) = sum_wetchem(region)- &
  1142. ! dso2 *ye(i,j,iairm)/ (fscale(1)*y(i,j,iair))
  1143. ! if ( iso2 == 1 ) sum_wetchem(region) = sum_wetchem(region)+ &
  1144. ! dso2 *ye(i,j,iairm)/ (fscale(1)*y(i,j,iair))
  1145. ! if ( iso4 == 1 ) sum_wetchem(region) = sum_wetchem(region)- &
  1146. ! dso2 *ye(i,j,iairm)/ (fscale(1)*y(i,j,iair))
  1147. ! c4(i,j,1)=c4(i,j,1)+dso2
  1148. ! xliq=ye(i,j,ilwc)/ye(i,j,icc)
  1149. ! !
  1150. ! ! oxidation of S(IV) by H2O2
  1151. ! !
  1152. ! !*** here we explicitly solve the dv:
  1153. ! ! y'=P-Q*y-R*y*y (P and Q are 0=>b3=0.)
  1154. ! !
  1155. ! so2x=y(i,j,iso2)
  1156. ! if ( so2x > tiny(so2x) ) then
  1157. ! b1=rw(i,j,kso2hp)
  1158. ! b2=b1*(y0(i,j,ih2o2)-so2x)
  1159. ! disc=min(100.,sqrt(b2*b2)) ! disc is b2 for b3=0.0
  1160. ! x1=(b2-disc)/(-2.*b1) ! in this case x1 =0.
  1161. ! x2=(b2+disc)/(-2.*b1)
  1162. ! x3=(so2x-x1)/(so2x-x2)*exp(-disc*dt)
  1163. ! so2x=(x1-x2*x3)/(1.-x3)
  1164. ! dso2=(so2x-y(i,j,iso2))*xcov
  1165. ! dso2=max(dso2,-y0(i,j,ih2o2)*xcov)
  1166. ! y(i,j,iso2) =y(i,j,iso2)+dso2 ! dso2 is loss of SO2 and H2O2
  1167. ! y(i,j,iso4)=y(i,j,iso4)-dso2
  1168. ! y(i,j,ih2o2) =y0(i,j,ih2o2)+dso2
  1169. ! if ( ih2o2 == 1 ) sum_wetchem(region) = sum_wetchem(region)- &
  1170. ! dso2 *ye(i,j,iairm)/ (fscale(1)*y(i,j,iair))
  1171. ! if ( iso2 == 1 ) sum_wetchem(region) = sum_wetchem(region)- &
  1172. ! dso2 *ye(i,j,iairm)/ (fscale(1)*y(i,j,iair))
  1173. ! if ( iso4 == 1 ) sum_wetchem(region) = sum_wetchem(region)+ &
  1174. ! dso2 *ye(i,j,iairm)/ (fscale(1)*y(i,j,iair))
  1175. ! c4(i,j,2)=c4(i,j,2)+dso2
  1176. ! end if
  1177. !
  1178. ! !
  1179. ! ! NH3 uptake in cloud droplets is limited by H2SO4 availability
  1180. ! ! no HNO3 is considered at this point
  1181. ! ! assume instantaneous uptake of NH3 incloud only in cloudy part
  1182. ! !
  1183. ! dnh3=max((2.*y(i,j,iso4)+y0(i,j,imsa)-y0(i,j,inh4))*xcov,0.)
  1184. ! dnh3=max(-y0(i,j,inh3)*xcov,-dnh3)
  1185. ! y(i,j,inh3)=y0(i,j,inh3)+dnh3 ! dnh3 is loss of NH3
  1186. ! y(i,j,inh4)=y0(i,j,inh4)-dnh3
  1187. ! if ( inh3 == 1 ) sum_wetchem(region) = sum_wetchem(region) - &
  1188. ! dnh3*ye(i,j,iairm)/ (fscale(1)*y(i,j,iair))
  1189. ! if ( inh4 == 1 ) sum_wetchem(region) = sum_wetchem(region) + &
  1190. ! dnh3*ye(i,j,iairm)/ (fscale(1)*y(i,j,iair))
  1191. ! c4(i,j,3)=c4(i,j,3)+dnh3
  1192. ! end if !cloudy
  1193. ! end do ! i,j,loop
  1194. ! end do !
  1195. !
  1196. ! !free memory
  1197. ! deallocate(hkso2 )
  1198. ! deallocate(hkh2o2 )
  1199. ! deallocate(hko3 )
  1200. ! deallocate(dkso2 )
  1201. ! deallocate(dkhso3 )
  1202. ! deallocate(dkh2o )
  1203. ! deallocate(dknh3 )
  1204. ! deallocate(hknh3 )
  1205. ! deallocate(hkco2 )
  1206. ! deallocate(dkco2 )
  1207. ! deallocate(hplus )
  1208. ! deallocate(rw )
  1209. ! deallocate(cloudy )
  1210. !
  1211. ! nullify(zoomed)
  1212. !
  1213. ! ! write(levelc, '(i2.2)') level
  1214. ! ! call dumpfield(1,'wetS.hdf', im(region), jm(region), maxtrace, 1, y0, 'y0'//levelc)
  1215. ! ! call dumpfield(1,'wetS.hdf', im(region), jm(region), n_extra , 1, ye, 'ye'//levelc)
  1216. ! ! call dumpfield(1,'wetS.hdf', ntracet, ntemp, 1 , 1, henry, 'henry'//levelc)
  1217. ! ! call dumpfield(1,'wetS.hdf', im(region), jm(region), maxtrace, 1, y, 'y'//levelc)
  1218. !
  1219. ! end subroutine wets
  1220. !
  1221. !
  1222. !
  1223. ! subroutine mark_trac(region,level,y,rr,rj,dt,ye)
  1224. ! ! ---------
  1225. ! ! call subroutine mark_trac(region,level,zoomed,y,rr,rj,dt,ye)
  1226. ! ! region,level :: where and which cells
  1227. ! ! zoomed :: which cells are done by child?
  1228. ! ! y :: concentrations in layer
  1229. ! ! rr :: reaction rates
  1230. ! ! rj :: photolysis rates
  1231. ! ! dt :: time step
  1232. ! ! ye :: help fields ( air masses )
  1233. ! !
  1234. ! ! method
  1235. ! ! ------
  1236. ! ! calculate nox/pan/orgn/hno3 analogous to ebi scheme
  1237. ! ! ozone production from marked nox
  1238. ! ! simple nhx chemistry, scaled to real nhx
  1239. ! !
  1240. ! ! fjd Mon Aug 10 16:55:35 MET 1998/Fri Jan 1 17:08:37 MET 1999
  1241. ! ! mk adapted for TM5 jan/2002
  1242. ! !-------------------------------------------------------------
  1243. ! use global_data, only : region_dat
  1244. ! use budget_global, only : budmarkg,budg_dat,nzon_vg
  1245. ! use budget_fine, only : budmark,nzon,nzon_v
  1246. ! use chem_param
  1247. ! use dims, only: isr, ier, jsr, jer, at, bt, im, jm
  1248. !
  1249. ! implicit none
  1250. !
  1251. ! ! input/output
  1252. ! integer, intent(in) :: region,level
  1253. ! real,dimension(im(region),jm(region),maxtrace) :: y
  1254. ! real,dimension(im(region),jm(region),nreac),intent(in):: rr
  1255. ! real,dimension(im(region),jm(region),nj ),intent(in):: rj
  1256. ! real :: dt
  1257. ! real, dimension(im(region),jm(region),n_extra) :: ye
  1258. !
  1259. ! ! local
  1260. ! integer, dimension(:,:),pointer :: zoomed
  1261. !
  1262. ! ! start
  1263. !
  1264. ! zoomed => region_dat(region)%zoomed
  1265. !
  1266. ! call mark_o3s
  1267. ! !
  1268. ! ! more marked tracers possible here
  1269. ! !
  1270. ! nullify(zoomed)
  1271. !
  1272. ! contains
  1273. !
  1274. !
  1275. ! subroutine mark_o3s
  1276. ! !---------------------------------------------------
  1277. ! ! marked tracer O3S stratospheric ozone
  1278. ! !---------------------------------------------------
  1279. !
  1280. !#ifdef MPI
  1281. ! use mpi_const,only: myid,lmar
  1282. !#endif
  1283. ! use dry_deposition, only: vd
  1284. ! implicit none
  1285. ! integer :: i,j,nzone,nzone_v
  1286. ! real :: p3,xl3,o3old
  1287. ! integer :: offsetl
  1288. !
  1289. ! offsetl=0
  1290. !#ifdef MPI
  1291. ! if(myid>0) offsetl=sum(lmar(0:myid-1))
  1292. !#endif
  1293. !
  1294. ! do j=jsr(region),jer(region)
  1295. ! do i=isr(region),ier(region)
  1296. ! if(zoomed(i,j)/=region) cycle
  1297. ! if (at(offsetl+level+1)+bt(offsetl+level+1)*1e5<= 14000) then !
  1298. ! ! well, you want to count all layers below 140 hPa
  1299. ! ! (given surface pressure of 1e5 Pa)
  1300. ! ! in the current model setup (25 layers) this means
  1301. ! ! 12077 + 1e5*0.00181 = 12258 Pa and above...
  1302. !
  1303. ! ! p3: production of o3 in stratosphere
  1304. ! P3 = rj(i,j,jano3)*y(i,j,ino3)+ &
  1305. ! rj(i,j,jno2)*y(i,j,ino2)
  1306. ! XL3= rr(i,j,ko3ho2)*y(i,j,iho2)+&
  1307. ! rr(i,j,ko3oh)*y(i,j,ioh)+ &
  1308. ! rr(i,j,kno2o3)*y(i,j,ino2)+&
  1309. ! rj(i,j,jo3d)+&
  1310. ! rr(i,j,knoo3)*y(i,j,ino)+&
  1311. ! rr(i,j,kc62)*y(i,j,ieth)+&
  1312. ! rr(i,j,kc58)*y(i,j,iole)+&
  1313. ! rr(i,j,kc77)*y(i,j,iisop)
  1314. ! else
  1315. ! !
  1316. ! ! these are only the net destruction reactions
  1317. ! !
  1318. ! P3 = 0.
  1319. ! XL3= rr(i,j,ko3ho2)*y(i,j,iho2)+&
  1320. ! rr(i,j,ko3oh)*y(i,j,ioh)+&
  1321. ! rj(i,j,jo3d)+&
  1322. ! rr(i,j,kc62)*y(i,j,ieth)+&
  1323. ! rr(i,j,kc58)*y(i,j,iole)+&
  1324. ! rr(i,j,kc77)*y(i,j,iisop)
  1325. ! ! add up deposition....
  1326. ! if ( offsetl + level == 1 ) &
  1327. ! XL3 = XL3 + vd(region,io3)%surf(i,j)/ye(i,j,idz)
  1328. ! end if
  1329. ! o3old=y(i,j,io3s)
  1330. ! y(i,j,io3s)=(o3old+p3*dt)/(1.+xl3*dt)
  1331. ! if ( region == nregions ) then
  1332. ! nzone=nzon(i,j)
  1333. ! nzone_v=nzon_v(level+offsetl)
  1334. ! ! budget in mole
  1335. ! budmark(nzone,nzone_v,1)=budmark(nzone,nzone_v,1)+ &
  1336. ! (y(i,j,io3s)-o3old)*ye(i,j,iairm)*1000./xmair/y(i,j,iair)
  1337. ! end if
  1338. ! nzone=budg_dat(region)%nzong(i,j) ! global budget
  1339. ! nzone_v=nzon_vg(level+offsetl)
  1340. ! budmarkg(nzone,nzone_v,1)=budmarkg(nzone,nzone_v,1)+ &
  1341. ! (y(i,j,io3s)-o3old)*ye(i,j,iairm)*1000./xmair/y(i,j,iair)
  1342. ! end do
  1343. !
  1344. ! end do !i,j, l
  1345. !
  1346. ! end subroutine mark_o3s
  1347. !
  1348. ! end subroutine mark_trac
  1349. !
  1350. !
  1351. !
  1352. end module ebischeme