-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchemdriv.f
886 lines (842 loc) · 32.2 KB
/
chemdriv.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
subroutine chemdriv(igrd,ncol,nrow,nlay,dt,itzon,idfin,fcloud,
& cldtrns,water,tempk,press,height,cwc,conc,
& cncrad,cellat,cellon,ldark,l3davg,
& iptr2d,iptrsa,ipa_cel, masschem,masspart, !<- BNM 6/2/09
& dxmass, dymass, dzmass ) !<-BNM 6/30/09
c
c-----CAMx v4.02 030709
c
c CHEMDRIV performs chemistry on the current grid for one time step.
c It calls one of two ODE solvers: TRAP or IEHSOLV.
c TRAP is the driver routine for the CMC fast solver.
c IEHSOLV is the driver for an IEH solver
c
c Mechanism specific subroutines are passed to the driver routines.
c
c Local array element con(nspec+1) is used to store the concentrations
c of non-used species, i.e., species that are in the chem solver but
c not on the species list for this run
c
c
c Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
c ENVIRON International Corporation
c
c Modifications:
c 1/9/02 A minor bug fix related to fast aero routine
c (units conversion)
c 1/15/02 Added code to handle RTRAC
c 01/30/02 Added code for RTRAC probing tool
c 10/18/02 Added CWC for aqueous PM chemistry
c 4/2/03 Removed option for UAM-V type cloud adjustment
c 03/21/03 Removed the OSAT technology type OPPAT
c
c Input arguments:
c igrd grid index
c ncol number of columns
c nrow number of rows
c nlay number of layers
c dt timestep (s)
c itzon time zone
c idfin map of nested grids in this grid
c fcloud cloud coverage (fraction)
c cldtrns energy transmission coefficient (fraction)
c water water vapor (ppm)
c tempk temperature (K)
c press pressure (mb)
c height layer interface height (m)
c cwc cloud water content (g/m3)
c conc species concentration (umol/m3)
c cncrad radical concentration (ppm)
c cellat cell centroid latitude (deg)
c cellon cell centroid longitude (deg)
c ldark darkness flag (T=dark)
c l3davg save 3-D average concentrations
c iptr2d pointers into vectors for 2-D fields
c iptrsa pointers into vectors for tracer conc
c ipa_cel gridded array to identify if cell is
c in a IPRM sub-domain
c
c Output arguments:
c conc species concentration (umol/m3)
c
c Routines called:
c KTHERM
c GETZNTH
c KPHOTO
c TRAP
c AEROCHEM
c IEHSOLV
c
c Called by:
c CHEMRXN
c
include 'camx.prm'
include 'camx.com'
include 'bndary.com'
include 'chmstry.com'
include 'filunit.com'
include 'ahomap.com'
include 'App.com' !Added by Kristina 08/23/07
c
c======================== Process Analysis Begin =======================
c
include 'procan.com'
c
c======================== Process Analysis End =========================
c
c
c======================== Source Apportion Begin =======================
c
include "tracer.com"
c
c-----------------------------------------------------------------------
c Local variables:
c-----------------------------------------------------------------------
c
integer ispc
real delo3, delno, delno2, delvoc, delh22, delhn3
real modo3, modnox, modvoc, o3old, o3new
real cold(MXTRSP), cnew(MXTRSP), dtchem
C BNM VARIABLES FOR SUMMING MASSES
real dconcchem(ncol,nrow,nlay,nspec), dconcpart(ncol,nrow,nlay,nspec)
real conca(nspec), concb(nspec)
real masschem(nspec), masspart(nspec)
real dxmass(nrow), dymass, dzmass(ncol,nrow,nlay)
real concbnmNO2 !debugging
integer s, nx, ny, nz
c
c========================= Source Apportion End ========================
c
c
c======================== DDM Begin =======================
c
real sddm(MXFDDM*MXSPEC)
c
c======================== DDM End =======================
c
c======================== Process Analysis Begin =======================
c
integer ipa_cel(ncol,nrow,nlay)
logical ldoirr, ldoipr
real rrxn_irr(MXRXN), patmp(MXTRSP)
real titrt
c
c======================== Process Analysis End =========================
c
c-----subroutine names to be called by TRAP and IEHSOLV
c
external rxnrate1,radslvr1,ratejac1,rateslo1,ddmjac1
external rxnrate2,radslvr2,ratejac2,rateslo2,ddmjac2
external rxnrate3,radslvr3,ratejac3,rateslo3,ddmjac3
external rxnrate4,radslvr4,ratejac4,rateslo4,ddmjac4
external rxnrate5,radslvr5,ratejac5,rateslo5,ddmjac5
external rxnrate6,radslvr6,ratejac6,rateslo6,ddmjac6
external ierxn1, ierate1, iejac1, ieslow1
external ierxn2, ierate2, iejac2, ieslow2
external ierxn3, ierate3, iejac3, ieslow3
external ierxn4, ierate4, iejac4, ieslow4
external ierxn5, ierate5, iejac5, ieslow5
external ierxn6, ierate6, iejac6, ieslow6
c
logical l3davg,ldark(ncol,nrow),laero_upd
real con(MXSPEC+1),crad(MXRADCL),avgrad(MXRADCL)
real fcloud(ncol,nrow,nlay),cldtrns(ncol,nrow,nlay),
& water(ncol,nrow,nlay),tempk(ncol,nrow,nlay),
& press(ncol,nrow,nlay),height(ncol,nrow,nlay),
& cwc(ncol,nrow,nlay),conc(ncol,nrow,nlay,nspec),
& cellat(ncol,nrow),cellon(ncol,nrow),
& cncrad(ncol,nrow,nlay,MXRADCL)
integer idfin(ncol,nrow)
real orig(MXSPEC),final(MXSPEC) !Added by Kristina
real changes(40) !Added by Kristina
logical lApp !Added by Kristina
c
c-----Entry point
c
lApp = .TRUE. !Added by Kristina
c
call flush(6)
call flush(iout)
c
dtchem = dt/3600.
con(nspec+1) = 0.
c
c aero_tchk: current time (=time; HHMM)
c grd_time : time to call aerosol routine (HHMM)
c date_aer : simulation date (YYJJJ)
c dtaero : adjusted time interval between aerosol routines (min)
c aero_dt : actual time interval for each grid (hr) (accumulated dtchem)
aero_tchk = time
aero_dt(igrd) = aero_dt(igrd) + dtchem
laero_upd = .false.
if (idmech.eq.6.or.idmech.eq.5) then ! bkoo_dbg
write(*,*) 'aerotchk,grdtime: ',aero_tchk,grd_time(igrd)
if ( (aero_tchk-grd_time(igrd)) .ge. -0.01 .and.
& (date .eq. date_aer(igrd)) ) then
laero_upd = .true.
write(*,*) 'Calling fullaero ... time: ',time,dtchem
& ,aero_dt(igrd)
endif
endif ! bkoo_dbg
c
CDEBUGBNM PRINT BSOG Concentration
c concbnmNO2 = 0.0
c concbnmNO = 0.0
c do k2 = 1,nlay
c do i2 = 1,ncol
c do j2 = 1,nrow
c concbnmNO2 = concbnmNO2 + conc(i2,j2,k2,KCBS1)
c concbnmNO = concbnmNO + conc(i2,j2,k2,KCBS2)
c enddo
c enddo
c enddo
c print *,'CHEMDRIV: Ccbs1(Before chem)=',concbnmNO2
c print *,'CHEMDRIV: Ccbs2(Before chem)=',concbnmNO
igrdchm = igrd
do 91 k = 1,nlay
c
c$omp parallel default(shared)
c$omp& private(i,j,l,is,ispc,i1,i2,con,
c$omp& crad,ij,iozon,ihaze,ialb,hght,iabov,ctrns,fcld,
c$omp& zenith,ldark,delo3,modo3,delno,delno2,modnox,delh22,
c$omp& delhn3,delvoc,modvoc,tcell,pcell,atm,O2,H2,CH4,sddm,
c$omp& ldoipr,ldoirr,ipa_idx,titrt,irxn,rrxn_irr,convfac,
c$omp& patmp,idx,nn,cold,cnew,o3old,o3new,avgrad,irt_cel)
c$omp& copyin(/ijkgrd/)
c
c$omp do schedule(dynamic)
c
do 90 j = 2,nrow-1
i1 = 2
i2 = ncol-1
if (igrd.eq.1) then
if (ibeg(j).eq.-999) goto 90
i1=ibeg(j)
i2=iend(j)
endif
do 89 i = i1,i2
ichm = i
jchm = j
kchm = k
c
c-----skip chemistry if fine grid exists in this cell
c
if (idfin(i,j).gt.igrd) goto 89
c
c-----For the gas phase species (numbered 1 to ngas)
c Pass concentration to CON, converting from umol/m3 to ppm
cbk Now SOA condensible gasses (CG) are in umol/m3 like other gases
c
tcell = tempk(i,j,k)
pcell = press(i,j,k)
convfac = densfac*(273./tcell)*(pcell/1013.)
cbk if (kcg1.ne.nspec+1) then
cbk conc(i,j,k,kcg1) = conc(i,j,k,kcg1)*convfac
cbk conc(i,j,k,kcg2) = conc(i,j,k,kcg2)*convfac
cbk conc(i,j,k,kcg3) = conc(i,j,k,kcg3)*convfac
cbk conc(i,j,k,kcg4) = conc(i,j,k,kcg4)*convfac
cbk endif
do is = 1,ngas
con(is) = conc(i,j,k,is)/convfac !umol/m3->ppm
if (con(is).lt.0.) then
write(iout,'(//,a)') 'ERROR in CHEMDRIV:'
write(iout,*) 'Negative concentration before chem'
write(iout,*) 'igrd, i, j, k = ', igrd,i,j,k
do l = 1,nspec
write(iout,'(i3,2x,a7,e10.3)') l,spname(l),con(l)
enddo
call camxerr()
endif
con(is) = amax1(bdnl(is),con(is))
enddo
c
c-----Load any aerosols
c
if (ngas.lt.nspec) then
do is=ngas+1,nspec
con(is) = conc(i,j,k,is)
if (con(is).lt.0.) then
write(iout,'(//,a)') 'ERROR in CHEMDRIV:'
write(iout,*) 'Negative concentration before chem'
write(iout,*) 'igrd, i, j, k = ', igrd,i,j,k
do l = 1,nspec
write(iout,'(i3,2x,a7,e10.3)') l,spname(l),con(l)
enddo
call camxerr()
endif
con(is) = amax1(bdnl(is),con(is))
enddo
endif
c
c-----Load radicals from last time step to use as initial guess
c
do l=1,nrad
crad(l) = cncrad(i,j,k,l)
enddo
c
c-----Determine thermal rate constants
c
call ktherm(tcell,pcell)
c
c-----Load local values of ozone, haze, albedo and zenith angle
c
ij = i + (j-1)*ncol
iozon = icdozn(iptr2d-1+ij)
ihaze = icdhaz(iptr2d-1+ij)
ialb = icdalb(iptr2d-1+ij)
hght = height(i,j,k)/2000.
if (k.gt.1)
& hght = (height(i,j,k) + height(i,j,k-1))/2000.
if (cldtrns(i,j,k).ne.1.) then
iabov = 0
ctrns = cldtrns(i,j,k)
fcld = fcloud(i,j,k)
else
iabov = 1
ctrns = cldtrns(i,j,1)
fcld = fcloud(i,j,1)
endif
call getznth(cellat(i,j),cellon(i,j),time,date,itzon,
& zenith,ldark(i,j))
c
c-----Determine photolysis rates through interpolation of look-up table
c
call kphoto(iozon,ialb,ihaze,hght,zenith,fcld,
& ctrns,ldark(i,j),iabov)
c
c======================== Source Apportion Begin =======================
c
c --- store the current value of the species needed for tracer "chemistry" ----
c
if( ltrace )then
if( tectyp .EQ. RTRAC ) then
do ispc=1,ngas
cold(ispc) = con(ispc)
enddo
o3old = con(ko3)
else
delo3 = -con(ko3)*convfac
modo3 = con(ko3)*convfac
delno = -con(kno)*convfac
delno2 = -con(kno2)*convfac
modnox = con(kno)*convfac + con(kno2)*convfac
delh22 = -con(kh2o2)*convfac
delhn3 = -con(khno3)*convfac
delvoc = 0.
modvoc = 0.
do 10 ispc=1,ngas
if( lvocsp(ispc) ) then
delvoc = delvoc - con(ispc) * crbnum(ispc) *
& convfac
modvoc = modvoc + con(ispc) * crbnum(ispc) *
& convfac
endif
10 continue
c
c --- call routine to recalibrate so that tracer species stays
c on track with model species: needed because the numerics
c cause tracer species to drift
c
call recalib(ncol,nrow,nlay,ntotsp,ptconc(iptrsa),
& i,j,k,modo3,modnox,modvoc)
endif
endif
c
c========================= Source Apportion End ========================
c
c
c======================== DDM Begin ====================================
c
c ---- load the sensitivities for this cell into 2-D array ---
c
if (lddm) then
call loaddm(.FALSE.,ncol,nrow,nlay,ntotsp,ptconc(iptrsa),
& i,j,k,nddmsp,ngas,sddm,convfac)
endif
c
c
c======================== DDM End =======================================
c
c
c
c-----Chemistry integration, pass subroutines for mechanism used
c
atm = 1.e6
O2 = 2.095e5
CH4 = 1.75
H2 = 0.50
c
c======================== Process Analysis Begin =======================
c
ldoipr = .FALSE.
ldoirr = .FALSE.
if( lproca ) then
if( lipr .AND. ipa_cel(i,j,k) .GT. 0 ) then
ipa_idx = ipa_cel(i,j,k)
ldoipr = .TRUE.
endif
if( lirr ) then
if( ipa_cel(i,j,k) .GT. 0 ) then
ipa_idx = ipa_cel(i,j,k)
ldoirr = .TRUE.
endif
titrt = 0.0
do irxn=1,MXRXN
rrxn_irr(irxn) = 0.0
enddo
endif
endif
c
c======================== Process Analysis End =========================
c
if ( idsolv .EQ. IDCMC ) then
if (idmech.eq.1) then
call trap(rxnrate1,radslvr1,ratejac1,rateslo1,dtchem,
& ldark(i,j),water(i,j,k),atm,O2,CH4,H2,con,crad,
& avgrad,tcell,
& sddm,nddmsp,ngas,ddmjac2,lddm,nirrrxn,titrt,rrxn_irr,
& lirr,i,j,k) !Kristina added i,j,k,changes on 06/21/07
elseif (idmech.eq.2) then
call trap(rxnrate2,radslvr2,ratejac2,rateslo2,dtchem,
& ldark(i,j),water(i,j,k),atm,O2,CH4,H2,con,crad,
& avgrad,tcell,
& sddm,nddmsp,ngas,ddmjac2,lddm,nirrrxn,titrt,rrxn_irr,
& lirr,i,j,k) !Kristina added i,j,k,changes on 06/21/07
elseif (idmech.eq.3) then
call trap(rxnrate3,radslvr3,ratejac3,rateslo3,dtchem,
& ldark(i,j),water(i,j,k),atm,O2,CH4,H2,con,crad,
& avgrad,tcell,
& sddm,nddmsp,ngas,ddmjac3,lddm,nirrrxn,titrt,rrxn_irr,
& lirr,i,j,k) !Kristina added i,j,k,changes on 06/21/07
elseif (idmech.eq.4) then
call trap(rxnrate4,radslvr4,ratejac4,rateslo4,dtchem,
& ldark(i,j),water(i,j,k),atm,O2,CH4,H2,con,crad,
& avgrad,tcell,
& sddm,nddmsp,ngas,ddmjac4,lddm,nirrrxn,titrt,rrxn_irr,
& lirr,i,j,k) !Kristina added i,j,k,changes on 06/21/07
call aerochem(water(i,j,k),tcell,pcell,cwc(i,j,k),con,
& convfac,dtchem,ldoipr,ipa_idx)
elseif (idmech.eq.5) then !Used for SAPRC/VBS Version
if (ldark(i,j)) then
nflag=1.0d0
else
nflag=1.0d0
endif
C BNM Split Budget Contributions from Chemistry and Partitioning
CDEBUG
c print *
c print *,'CHEMDRIV: dtchem=',dtchem
do ispc = 1,nspec
conca(ispc) = conc(i,j,k,ispc)
enddo
C END <- BNM
c
CDEBUGBNM PRINT OPOG Concentration
c concbnmNO2 = 0.0
c concbnmNO = 0.0
c do k2 = 1,nlay
c do i2 = 1,ncol
c do j2 = 1,nrow
c concbnmNO2 = concbnmNO2 + conc(i2,j2,k2,KCBS1)
c concbnmNO = concbnmNO + conc(i2,j2,k2,KCBS2)
c enddo
c enddo
c enddo
c print *,'CHEMDRIV: Ccbs1(Before chem)=',concbnmNO2
c print *,'CHEMDRIV: Ccbs2(Before chem)=',concbnmNO
c print *,'CHEMDRIV: Con(cbs1,Before chem)=',con(KCBS1)
c loc = 73+97*(6-1)+90*97*(1-1)+97*90*14*(14-1)+97*90*14*490*(1-1)
c print *,'Chemdriv: Appconc(73,6,1,PAN2)=',
c & (Appconc(loc+97*90*14*490*(is-1)),is=1,4)
c print *,'Starting from trap'
call trap(rxnrate5,radslvr5,ratejac5,rateslo5,dtchem,
& ldark(i,j),water(i,j,k),atm,O2,CH4,H2,con,crad,
& avgrad,tcell,
& sddm,nddmsp,ngas,ddmjac5,lddm,nirrrxn,titrt,rrxn_irr,
& lirr,i,j,k,convfac) !Kristina added i,j,k,changes on 06/21/07
c print *,'Back from trap'
C END <- BNM
C BNM Account for just contribution from chemistry
CDEBUGBNM PRINT OPOG Concentration
c concbnmNO2 = 0.0
c concbnmNO = 0.0
c do k2 = 1,nlay
c do i2 = 1,ncol
c do j2 = 1,nrow
c concbnmNO2 = concbnmNO2 + conc(i2,j2,k2,KCBS1)
c concbnmNO = concbnmNO + conc(i2,j2,k2,KCBS2)
c enddo
c enddo
c enddo
c print *,'CHEMDRIV: Ccbs1(After chem)=',concbnmNO2
c print *,'CHEMDRIV: Ccbs2(After chem)=',concbnmNO
c print *,'CHEMDRIV: Con(cbs1,After chem)=',con(KCbs1)
do ispc = 1,ngas
dconcchem(i,j,k,ispc) = amax1(bdnl(ispc),con(ispc))*convfac
& - conca(ispc)
concb(ispc) = amax1(bdnl(ispc),con(ispc))*convfac
enddo
if (ngas.lt.nspec) then
do ispc = ngas+1,nspec
dconcchem(i,j,k,ispc) = amax1(con(ispc),bdnl(ispc))
& - conca(ispc)
concb(ispc) = amax1(bdnl(ispc),con(ispc))
enddo
endif
CDEBUG
c print *,'CHEMDRIV: dtchem before aero=',dtchem
dtchem1 = dtchem
C END <- BNM
if ( laero_upd )then !Kristina added "then" on 05/11/07
c
c------------------Added by Kristina 05/11/07------------------------
c
if(lApp) then
do ispc = 1,MXSPEC
if (ispc.le.ngas) then
orig(ispc) = con(ispc)*convfac
else
if (Appmaprev(Appmap(ispc)).eq.ispc) then
orig(Appmaprev(Appmap(ispc))) = con(ispc)
else
orig(Appmaprev(Appmap(ispc))) =
& orig(Appmaprev(Appmap(ispc))) + con(ispc)
endif
endif
enddo
endif
c
c-------------------End added 05/11/07--------------------------------
c
call fullaero(water(i,j,k),tcell,pcell,cwc(i,j,k),
& MXSPEC,MXRADCL,NSPEC,NGAS,
& con,crad,convfac,time,aero_dt(igrd),
& i,j,k,height)
c
c------------------Added by Kristina 05/11/07------------------------
c
if(lApp) then
do ispc = 1,MXSPEC
if (ispc.le.ngas) then
final(ispc) = con(ispc)*convfac
if (final(ispc).eq.0.0) then
final(ispc) = bdnl(ispc)*convfac
endif
else
if (Appmaprev(Appmap(ispc)).eq.ispc) then
final(Appmaprev(Appmap(ispc))) = con(ispc)
else
final(Appmaprev(Appmap(ispc))) =
& final(Appmaprev(Appmap(ispc))) + con(ispc)
endif
if (final(ispc).eq.0.0) then
final(ispc) = bdnl(ispc)
endif
endif
enddo
c print *,'Calling Appaero\n'
call Appaero(orig,final,i,j,k,convfac)
c print *,'Done with Appaero i=',i,' j=',j,'\n'
endif
if (i.eq.7.and.j.eq.78) then
!print *,'Chemdriv: i=',i,' j=',j,' k=',k
!ispc=17
!print *,' orig(57)=',orig(57),' final(57)=',final(57)
endif
c
c-------------------End added 05/11/07--------------------------------
c
endif !Added by Kristina on 05/11/07
C END <- BNM
CDEBUGBNM PRINT OPOG Concentration
c concbnmNO2 = 0.0
c concbnmNO = 0.0
c do k2 = 1,nlay
c do i2 = 1,ncol
c do j2 = 1,nrow
c concbnmNO2 = concbnmNO2 + conc(i2,j2,k2,KCBS1)
c concbnmNO = concbnmNO + conc(i2,j2,k2,KCBS2)
c enddo
c enddo
c enddo
c print *,'CHEMDRIV: Ccbs1(After aero)=',concbnmNO2
c print *,'CHEMDRIV: Ccbs2(After aero)=',concbnmNO
c print *,'CHEMDRIV: Con(cbs1,After aero)=',con(KCBS1)
c print *
C BNM Account for just contribution from partitioning
CDEBUG
c print *,'CHEMDRIV: after aero dtchem=',dtchem
c print *,'CHEMDRIV: after aero dtchem1=',dtchem1
dtchem = dtchem1
do ispc = 1,ngas
dconcpart(i,j,k,ispc) = amax1(bdnl(ispc),con(ispc))*convfac
& - concb(ispc)
enddo
if (ngas.lt.nspec) then
do ispc = ngas+1,nspec
dconcpart(i,j,k,ispc) = amax1(con(ispc),bdnl(ispc))
& - concb(ispc)
enddo
endif
C END <- BNM
elseif (idmech.eq.6) then
if (ldark(i,j)) then
nflag=1.0d0
else
nflag=1.0d0
endif
call trap(rxnrate6,radslvr6,ratejac6,rateslo6,dtchem,
& ldark(i,j),water(i,j,k),atm,O2,CH4,H2,con,crad,
& avgrad,tcell,
& sddm,nddmsp,ngas,ddmjac6,lddm,nirrrxn,titrt,rrxn_irr,
& lirr)
if ( laero_upd )
& call fullaero(water(i,j,k),tcell,pcell,cwc(i,j,k),
& MXSPEC,MXRADCL,NSPEC,NGAS,
& con,crad,convfac,time,aero_dt(igrd),
& i,j,k,height)
endif
c
elseif ( idsolv .EQ. IDIEH ) then
if (idmech.eq.1) then
call iehsolv(ierxn1,ierate1,iejac1,ieslow1,
& dtchem,water(i,j,k),atm,O2,CH4,H2,con,crad,
& ldark(i,j),tcell,nirrrxn,rrxn_irr,lirr)
elseif (idmech.eq.2) then
call iehsolv(ierxn2,ierate2,iejac2,ieslow2,
& dtchem,water(i,j,k),atm,O2,CH4,H2,con,crad,
& ldark(i,j),tcell,nirrrxn,rrxn_irr,lirr)
elseif (idmech.eq.3) then
call iehsolv(ierxn3,ierate3,iejac3,ieslow3,
& dtchem,water(i,j,k),atm,O2,CH4,H2,con,crad,
& ldark(i,j),tcell,nirrrxn,rrxn_irr,lirr)
elseif (idmech.eq.4) then
call iehsolv(ierxn4,ierate4,iejac4,ieslow4,
& dtchem,water(i,j,k),atm,O2,CH4,H2,con,crad,
& ldark(i,j),tcell,nirrrxn,rrxn_irr,lirr)
call aerochem(water(i,j,k),tcell,pcell,cwc(i,j,k),
& con,convfac,dtchem,ldoipr,
& ipa_idx)
elseif (idmech.eq.5) then
call iehsolv(ierxn5,ierate5,iejac5,ieslow5,
& dtchem,water(i,j,k),atm,O2,CH4,H2,con,crad,
& ldark(i,j),tcell,nirrrxn,rrxn_irr,lirr)
elseif (idmech.eq.6) then
call iehsolv(ierxn6,ierate6,iejac6,ieslow6,
& dtchem,water(i,j,k),atm,O2,CH4,H2,con,crad,
& ldark(i,j),tcell,nirrrxn,rrxn_irr,lirr)
if ( laero_upd )
& call fullaero(water(i,j,k),tcell,pcell,cwc(i,j,k),
& MXSPEC,MXRADCL,NSPEC,NGAS,
& con,crad,convfac,time,aero_dt(igrd))
endif
c
endif
c
do l=1,nrad
cncrad(i,j,k,l) = amax1(crad(l),bdlrad)
enddo
c
c======================== Source Apportion Begin =======================
c
c --- subtract the current values of the species from the before values
c to get the delta values ---
c
if( ltrace ) then
delo3 = delo3 + AMAX1(bdnl(ko3),con(ko3)) * convfac
delno = delno + AMAX1(bdnl(kno),con(kno)) * convfac
delno2 = delno2 + AMAX1(bdnl(kno2),con(kno2)) * convfac
delh22 = delh22 + AMAX1(bdnl(kh2o2),con(kh2o2)) * convfac
delhn3 = delhn3 + AMAX1(bdnl(khno3),con(khno3)) * convfac
do 20 ispc=1,ngas
if( lvocsp(ispc) ) then
delvoc = delvoc + amax1(bdnl(ispc),con(ispc)) *
& crbnum(ispc) * convfac
endif
cnew(ispc) = con(ispc)
20 continue
o3new = AMAX1(bdnl(ko3),con(ko3))
c
c --- call routine to do the tracer species "chemistry", just makes
c adjustments for production or decay of the regular model species ----
c
if( tectyp .EQ. OSAT ) then
call osatsa(ldark(i,j),igrd,i,j,k,
& delo3,delno,delno2,delvoc,delh22,delhn3,dtchem)
else if( tectyp .EQ. GOAT ) then
call goatsa(ldark(i,j),igrd,i,j,k,
& delo3,delno,delno2,delvoc,dtchem)
else if( tectyp .EQ. APCA ) then
call apcasa(ldark(i,j),igrd,i,j,k,
& delo3,delno,delno2,delvoc,delh22,delhn3,dtchem)
else if( tectyp .EQ. RTRAC ) then
if( ipa_cel(i,j,k) .GT. 0 ) then
irt_cel = ipa_cel(i,j,k)
else
irt_cel = -9
endif
call chemrt(igrd,i,j,k,pcell,tcell,cold,cnew,
& avgrad(koh),(o3old+o3new)/2,avgrad(kno3),dtchem,
& convfac,irt_cel)
endif
endif
c
c========================= Source Apportion End ========================
c
c
c========================= DDM Begin ===================================
c
c --- put the changed values back into the gridded array ---
c
if (lddm) then
call loaddm(.TRUE.,ncol,nrow,nlay,ntotsp,ptconc(iptrsa),
& i,j,k,nddmsp,ngas,sddm,convfac)
endif
c
c========================= DDM End =====================================
c
c
c======================= Process Analysis Begin ========================
c
if( ldoipr ) then
c
c --- Chemistry change in umol/m3 units ----
c
do is=1,ngas
cipr(IPR_CHEM, ipa_idx, is) =
& cipr(IPR_CHEM, ipa_idx, is) +
& con(is)*convfac-conc(i,j,k,is)
enddo
endif
c
c --- Chemical reaction tracking in ppm units
c Account for titration reaction in TRAP at night ---
c
if( ldoirr ) then
do irxn=1,nirrrxn
cirr(ipa_idx, irxn) =
& cirr(ipa_idx, irxn) + rrxn_irr(irxn)
enddo
if ( titrt .GT. 0.0 ) then
if ( idmech.EQ.5) then
cirr(ipa_idx, 5) =
& cirr(ipa_idx, 5) + titrt
else
cirr(ipa_idx, 3) =
& cirr(ipa_idx, 3) + titrt
endif
endif
endif
c
c --- calculate the gridded chemical mechanism data ---
c
if( lirr .AND. (l3davg .OR. k .EQ. 1) ) then
if(idmech .EQ. 3) then
call cpamech3(rrxn_irr,MXRXN,patmp,ntotsp,nn)
elseif(idmech .EQ. 5) then
call cpamech5(rrxn_irr,MXRXN,patmp,ntotsp,nn)
endif
c
c --- save radical concentrations ---
c
if( .NOT. lcpacum)
& call cparad(crad, nrad, patmp, ntotsp, nn, dtchem)
c
c --- add CPA values to gridded array in native units ---
c
do l=1,ntotsp
idx = i + ncol*(j-1) + ncol*nrow*(k-1) +
& ncol*nrow*nlay*(l-1)
ptconc(iptrsa-1+idx) = ptconc(iptrsa-1+idx) + patmp(l)
enddo
endif
c
c======================== Process Analysis End =========================
c
c-----Pass CON back to concentration, convert gases from ppm to umol/m3
cbk Now SOA condensible gasses (CG) are in umol/m3 like other gases
c
cbk if (kcg1.ne.nspec+1) then
cbk con(kcg1) = con(kcg1)/convfac
cbk con(kcg2) = con(kcg2)/convfac
cbk con(kcg3) = con(kcg3)/convfac
cbk con(kcg4) = con(kcg4)/convfac
cbk endif
do is=1,ngas
con(is) = amax1(bdnl(is),con(is)) ! bkoo (03/12/03)
conc(i,j,k,is) = con(is)*convfac ! ppm->umol/m3
enddo
if (ngas.lt.nspec) then
do is=ngas+1,nspec
conc(i,j,k,is) = amax1(con(is),bdnl(is))
enddo
endif
89 continue !col
90 continue !row
c BNM
print *,'Layer: ',k
c BNM
c
c$omp end parallel
c
91 continue !Layer
c
C BNM ADD UP MASS CONTRIBUTIONS OF CHEMISTRY AND PARTITIONOING FROM
C ALL ROWS, COLUMNS, AND LAYERS
do ispc = 1,nspec
do k = 1,nlay
do j = 2,nrow-1
do i = ibeg(j),iend(j)
masschem(ispc) = masschem(ispc)
& + dconcchem(i,j,k,ispc)*dxmass(j)*dymass*dzmass(i,j,k)
masspart(ispc) = masspart(ispc)
& + dconcpart(i,j,k,ispc)*dxmass(j)*dymass*dzmass(i,j,k)
enddo
enddo
enddo
enddo
C END <- BNM
c BNM cccc ------------- Write Radicals Murphy -------------- cccc
c Write these radicals once every time step instead of within the
c Trap.f subroutine (1 write statement vs 90*97*14 write statements
c-----------------write OH Tsimpidi------------------------
c call get_param(igrdchm,ichm,jchm,kchm,iout,idiag)
do irads = 1,nrads
do k = 1,MXLAY1
if (l3davg.or.k.eq.1) then
c print *, 'l3davg = ',l3davg
c print *,'Trap Time: ',dtchem
c print *,'Time Time: ',time
c print *,'Grid cell: i=',ichm,' j=',jchm,' k=',kchm
c print *,'iavg = ',iavg
write(iavg+(k-1)*(1+nrads)+irads) time,
& ((bnmradcnc(irads,i,j,k),i=1,MXCOL1),j=1,MXROW1)
c print *,'bnmradcnc(OH,Pit) = ', bnmradcnc(1,55,61,k)
c print *,'bnmradcnc(NO3,Pit) = ', bnmradcnc(2,55,61,k)
c print *,'bnmradcnc(HO2,Pit) = ', bnmradcnc(3,55,61,k)
c print *, 'Writing to file unit: ',iavg+(k-1)*(1+nrads)+irads, ' for radical ',crads(irads)
endif
enddo
enddo
c----------------------------------------------------------
c BNM cccc -------------------------------------------------
c if fullaero was called
c - reset aero_dt
c - increase grd_time (& date_aer) by dtaero (or multiple of dtaero)
if (laero_upd) then
aero_dt(igrd) = 0.0
call uptime(grd_time(igrd),date_aer(igrd),60.*dtaero)
gtime = grd_time(igrd)
idate = date_aer(igrd)
92 call uptime(gtime,idate,60.*dtaero)
if ( gtime .le. time .and. idate .eq. date ) then
grd_time(igrd) = gtime
date_aer(igrd) = idate
else
goto 93
endif
goto 92
endif
93 continue
return
end