-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchemdriv.f
780 lines (768 loc) · 29.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
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,Jnuc)
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'
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)
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)
c
integer ii,jj,kk
integer nsect,isp
c integer ispc,naero
integer order(nspec)
integer iflag
integer isund !check underbar
real massum
real massum2
real frctn, nmbr
real dsulfdt !sulfuric acid production rate
double precision fndt(2) !nucleation diagnostic
real Jnuc(ncol,nrow,nlay,2) !Common Nucleation Diagnostic
real,allocatable,save :: Jnucsav(:,:,:,:) !local saved copy of nucleation rates
integer inuc
logical,save :: frstcall=.true. ! flag for first call to the routine
c
c-----Entry point
c
cdbg write(*,*)'At the beginning of chemdriv'
call flush(6)
cdbg write(*,*)'after flush(6) in chemdriv'
call flush(iout)
c
cdbg write(*,*)'In chemdriv, after flushing before time printing.' !dbg
!need to allocate the size of Jnucsav. The size can not be given in the variable definition
!since one can not use dummy arguments (ncol etc.) together with the save attribute
!Notice that this will only work as long as ncol, nrow and nlay are the same each call,
!so if the grid size is changing within a run something else needs to be done to fix the nucleation
!rate printing
if (.not.allocated(Jnucsav)) allocate(Jnucsav(ncol,nrow,nlay,2))
!initialize Jnucsav to zeroes if this is the first time chemdriv is called
if (frstcall) then
Jnucsav=0.0
frstcall=.false.
end if
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) 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
cdbg write(*,*)'In chemdriv, after time printing before ordering.'
c
c For setting the order of conversion from con to conc by jgj 12/6/06
c The order(kk) has a number of gas concentration first.
c Then it saves mass concentrations at the first size bin.
c Thereafter it saves number concentration at the size bin.
c The order(kk) saves the order of species as the same way
c as increasing the order of size bins.
c
nsect = 43
naero = 14
c
do kk=1,ngas
order(kk) = kk
enddo
kk=ngas
do ii=1,nsect
do jj=1,naero
kk=kk+1
if (jj.eq.naero) then
order(kk) = ngas + (naero-1)*nsect + ii
else
order(kk) = ngas + (jj-1)*nsect + ii
endif
enddo
enddo
c
igrdchm = igrd
do 91 k = 1,nlay
write(*,*) 'Layer=',k
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
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
cjgj con(is) = amax1(bdnl(is),con(is)) ! for conserving M/N ratios
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
ctrns = cldtrns(i,j,k)
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)
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)
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)
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)
call aerochem(water(i,j,k),tcell,pcell,cwc(i,j,k),con,
& convfac,dtchem,ldoipr,ipa_idx)
elseif (idmech.eq.5) then
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)
elseif (idmech.eq.6) then
if (ldark(i,j)) then
nflag=0.0d0
else
nflag=1.0d0
endif
cdbg if ((ichm.eq.31).and.(jchm.eq.2).and.(kchm.eq.1)) then!dbg
cdbg print*,'before trap'
cdbg print*,'coordinate of (31,2,1)' !dbg
cdbg print*,'tempk,pressure,dsulfdt=',tempk(i,j,k)
cdbg & ,pressure,dsulfdt !dbg
cdbg endif !dbg
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,dsulfdt) ! to get sulfuric acid production rate
cjgj & lirr)
cdbg if ((i.eq.65).and.(j.eq.51).and.(k.eq.1)) then
cdbg if (k.eq.1) then
cdbg call mnratios(conc,ncol,nrow,nlay,nspec,31)
cdbg if ((ichm.eq.31).and.(jchm.eq.2).and.(kchm.eq.1)) then!dbg
cdbg print*,'after trap and before fullaero'
cdbg print*,'coordinate of (31,2,1)' !dbg
cdbg print*,'tempk,pressure,dsulfdt=',tempk,pressure
cdbg & ,dsulfdt !dbg
cdbg endif !dbg
if ( laero_upd ) then
call fullaero(water(i,j,k),tcell,pcell,cwc(i,j,k),
& MXSPEC,MXRADCL,NSPEC,NGAS,
& con,crad,convfac,time,aero_dt(igrd),
& ichm,jchm,kchm,height,dsulfdt,fndt)
do inuc = 1,2
Jnucsav(i,j,k,inuc) = real(fndt(inuc))
enddo
endif
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),fndt)
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
enddo
c
c In case a con is less than bdnl, the fraction of difference
c between con and bdnl to the total mass at the size bin will be
c multiplied by the number concentration at the bin, then it will
c be added to the number concentration. This is to avoid setting
c very tiny values to con so that we do not have M/N ratio
c problem in TOMAS.
c 12/6/06 jgj
c
c added by LA
do is=1,nspec
if(con(is).lt.1.0e-37) then
con(is)=1.0e-37
endif
enddo
c end LA
if (ngas.lt.nspec) then
ispc=ngas
do ii=1,nsect
isp = ispc
massum = 0 ! old mass sum
massum2 = 0 ! new mass sum
do jj=1,naero
ispc = ispc + 1
is = order(ispc)
if (jj.le.naero-1) then
! To avoid number conc.
isund=INDEX(spname(is),'_')
if (spname(is)(1:isund-1).ne.'PH2O') then ! To avoid H2O
massum = massum + con(is)
cdbg if ((time.gt.0.).and.(time.lt.30.))then
cdbg if ((i.eq.36).and.(j.eq.29).and.(k.eq.1))then
cdbg write(*,*)'Coord=',i,j,k
cdbg write(*,*)'species=',spname(is)
cdbg write(*,*)'con',con(is)
cdbg endif
cdbg endif
endif
endif
enddo
ispc = isp
inum = order(ispc+naero)
nmbr = con(inum)
frctn = 0.
do jj=1,naero
ispc = ispc + 1
is = order(ispc)
if (con(is).lt.bdnl(is)) then
cdbg if ((time.gt.0.).and.(time.lt.30.))then
cdbg if ((i.eq.36).and.(j.eq.29).and.(k.eq.1))then
cdbg write(*,*)'Coord=',i,j,k
cdbg write(*,*)'species=',spname(is)
cdbg write(*,*)'con is less than bdnl.'
cdbg write(*,*)'con',con(is)
cdbg write(*,*)'bdnl=',bdnl(is)
cdbg write(*,*)'con(inum)=',con(inum)
cdbg iflag=1
cdbg endif
cdbg endif
con(is)=bdnl(is)
endif
if (jj.le.naero-1) then
! To avoid number conc.
isund=INDEX(spname(is),'_')
if (spname(is)(1:isund-1).ne.'PH2O') then ! To avoid H2O
massum2 = massum2 + con(is)
endif
endif
enddo
frctn=massum2/massum
con(inum)=nmbr*frctn
cdbg if (iflag.eq.1) then
cdbg write(*,*)'con(inum)=',con(inum)
cdbg write(*,*)'massum=',massum
cdbg write(*,*)'massum2=',massum2
cdbg write(*,*)'frctn=',frctn
cdbg iflag = 0
cdbg endif
enddo
do is=ngas+1,nspec
cjgj conc(i,j,k,is) = amax1(con(is),bdnl(is))
conc(i,j,k,is) = con(is)
enddo
endif
c
89 continue
90 continue
c
91 continue
c
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
c added by LA
c write(*,*)'end of chemdriv; conc(2,2,1,:) =',conc(2,2,1,:)
c end LA
c
! assign Jnuc the values in Jnucsav, which is either from the call to fullaero on this timestep
! or a saved one from when fullaero was last called
Jnuc=Jnucsav
return
end