forked from geoschem/geos-chem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfullchem_mod.F90
2990 lines (2642 loc) · 122 KB
/
fullchem_mod.F90
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
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!------------------------------------------------------------------------------
! GEOS-Chem Global Chemical Transport Model !
!------------------------------------------------------------------------------
!BOP
!
! !MODULE: fullchem_mod.F90
!
! !DESCRIPTION: Contines arrays and routines for the GEOS_Chem "fullchem"
! mechanism, which is implemented in KPP-generated Fortran code.
!\\
!\\
! !INTERFACE:
!
MODULE FullChem_Mod
!
! !USES:
!
USE Precision_Mod
IMPLICIT NONE
PRIVATE
!
! !PUBLIC MEMBER FUNCTIONS:
!
PUBLIC :: Do_FullChem
PUBLIC :: Init_FullChem
PUBLIC :: Cleanup_FullChem
!
! !REVISION HISTORY:
! 14 Dec 2015 - M.S. Long - Initial version
! See https://github.com/geoschem/geos-chem for complete history
!EOP
!------------------------------------------------------------------------------
!BOC
!
! !PRIVATE TYPES:
!
! Species ID flags (and logicals to denote if species are present)
INTEGER :: id_OH, id_HO2, id_O3P, id_O1D, id_CH4
INTEGER :: id_PCO, id_LCH4, id_NH3, id_SO4
INTEGER :: id_SALAAL, id_SALCAL, id_SALC, id_SALA
INTEGER :: id_PSO4
#ifdef TOMAS
INTEGER :: id_NK05, id_NK08, id_NK10, id_NK20
#endif
#ifdef MODEL_GEOS
INTEGER :: id_O3
INTEGER :: id_A3O2, id_ATO2, id_B3O2, id_BRO2
INTEGER :: id_ETO2, id_LIMO2, id_MO2, id_PIO2, id_PO2
INTEGER :: id_PRN1, id_R4N1, id_R4O2, id_TRO2, id_XRO2
INTEGER :: id_IHOO1, id_IHOO4, id_IHCOO, id_ICHOO, id_IHPOO1
INTEGER :: id_IHPOO2, id_IHPOO3, id_IEPOXAOO, id_IEPOXBOO
INTEGER :: id_C4HVP1, id_C4HVP2, id_HPALD1OO, id_HPALD2OO
INTEGER :: id_ISOPNOO1, id_ISOPNOO2, id_INO2B, id_INO2D
INTEGER :: id_IDHNBOO, id_IDHNDOO1, id_IDHNDOO2
INTEGER :: id_IHPNBOO, id_IHPNDOO, id_ICNOO, id_IDNOO
#endif
#ifdef MODEL_CESM
INTEGER :: id_TSOA0, id_TSOA1, id_TSOA2, id_TSOA3
INTEGER :: id_ASOA1, id_ASOA2, id_ASOA3, id_ASOAN
INTEGER :: id_TSOG0, id_TSOG1, id_TSOG2, id_TSOG3
INTEGER :: id_ASOG1, id_ASOG2, id_ASOG3
INTEGER :: id_NIT, id_SO4s, id_NITs, id_HNO3
#endif
LOGICAL :: ok_OH, ok_HO2, ok_O1D, ok_O3P
LOGICAL :: Failed2x
! Diagnostic flags
LOGICAL :: Do_Diag_OH_HO2_O1D_O3P
#ifdef MODEL_GEOS
LOGICAL :: Archive_O3concAfterchem
LOGICAL :: Archive_RO2concAfterchem
#endif
! SAVEd scalars
INTEGER, SAVE :: PrevDay = -1
INTEGER, SAVE :: PrevMonth = -1
! Arrays
INTEGER, ALLOCATABLE :: PL_Kpp_ID (: )
REAL(f4), ALLOCATABLE :: JvCountDay(:,:,: )
REAL(f4), ALLOCATABLE :: JvCountMon(:,:,: )
REAL(f4), ALLOCATABLE :: JvSumDay (:,:,:,:)
REAL(f4), ALLOCATABLE :: JvSumMon (:,:,:,:)
CONTAINS
!EOC
!------------------------------------------------------------------------------
! GEOS-Chem Global Chemical Transport Model !
!------------------------------------------------------------------------------
!BOP
!
! !ROUTINE: do_fullchem
!
! !DESCRIPTION: Driver subroutine for the KPP fullchem mechanism.
!\\
!\\
! !INTERFACE:
!
SUBROUTINE Do_FullChem( Input_Opt, State_Chm, State_Diag, &
State_Grid, State_Met, RC )
!
! !USES:
!
USE ErrCode_Mod
USE ERROR_MOD
USE fullchem_AutoReduceFuncs, ONLY : fullchem_AR_KeepHalogensActive
USE fullchem_AutoReduceFuncs, ONLY : fullchem_AR_SetKeepActive
USE fullchem_AutoReduceFuncs, ONLY : fullchem_AR_UpdateKppDiags
USE fullchem_AutoReduceFuncs, ONLY : fullchem_AR_SetIntegratorOptions
USE fullchem_HetStateFuncs, ONLY : fullchem_SetStateHet
USE fullchem_SulfurChemFuncs, ONLY : fullchem_ConvertAlkToEquiv
USE fullchem_SulfurChemFuncs, ONLY : fullchem_ConvertEquivToAlk
USE fullchem_SulfurChemFuncs, ONLY : fullchem_HetDropChem
USE GcKpp_Monitor, ONLY : SPC_NAMES, FAM_NAMES, EQN_NAMES
USE GcKpp_Parameters
USE GcKpp_Integrator, ONLY : Integrate
USE GcKpp_Function
USE GcKpp_Global
USE GcKpp_Rates, ONLY : UPDATE_RCONST, RCONST
USE GcKpp_Util, ONLY : Get_OHreactivity
USE Input_Opt_Mod, ONLY : OptInput
USE Photolysis_Mod, ONLY : Do_Photolysis, PhotRate_Adj
USE PhysConstants, ONLY : AVO, AIRMW
USE PRESSURE_MOD
USE Species_Mod, ONLY : Species
USE State_Chm_Mod, ONLY : ChmState
USE State_Chm_Mod, ONLY : Ind_
USE State_Diag_Mod, ONLY : DgnState
USE State_Diag_Mod, ONLY : DgnMap
USE State_Grid_Mod, ONLY : GrdState
USE State_Met_Mod, ONLY : MetState
USE TIME_MOD, ONLY : GET_TS_CHEM
USE TIME_MOD, ONLY : Get_Day
USE TIME_MOD, ONLY : Get_Month
USE TIME_MOD, ONLY : Get_Year
USE Timers_Mod
USE UnitConv_Mod
USE UCX_MOD, ONLY : CALC_STRAT_AER
USE UCX_MOD, ONLY : SO4_PHOTFRAC
USE UCX_MOD, ONLY : UCX_NOX
USE UCX_MOD, ONLY : UCX_H2SO4PHOT
#ifdef TOMAS
USE TOMAS_MOD, ONLY : H2SO4_RATE
USE TOMAS_MOD, ONLY : PSO4AQ_RATE
#endif
!
! !INPUT PARAMETERS:
!
TYPE(OptInput), INTENT(IN) :: Input_Opt ! Input Options object
TYPE(GrdState), INTENT(IN) :: State_Grid ! Grid State object
!
! !INPUT/OUTPUT PARAMETERS:
!
TYPE(MetState), INTENT(INOUT) :: State_Met ! Meteorology State object
TYPE(ChmState), INTENT(INOUT) :: State_Chm ! Chemistry State object
TYPE(DgnState), INTENT(INOUT) :: State_Diag ! Diagnostics State object
!
! !OUTPUT PARAMETERS:
!
INTEGER, INTENT(OUT) :: RC ! Success or failure
!
! !REVISION HISTORY:
! 14 Dec 2015 - M.S. Long - Initial version
! See https://github.com/geoschem/geos-chem for complete history
!EOP
!------------------------------------------------------------------------------
!BOC
!
! !LOCAL VARIABLES:
!
! Scalars
LOGICAL :: IsLocNoon, Size_Res, Failed2x, doSuppress
INTEGER :: I, J, L, N
INTEGER :: NA, F, SpcID, KppID
INTEGER :: P, MONTH, YEAR, Day
INTEGER :: IERR, S, Thread
INTEGER :: errorCount, origUnit
REAL(fp) :: SO4_FRAC, T, TIN
REAL(fp) :: TOUT, SR, LWC
! Strings
CHARACTER(LEN=255) :: errMsg, thisLoc
! SAVEd scalars
LOGICAL, SAVE :: FIRSTCHEM = .TRUE.
INTEGER, SAVE :: CH4_YEAR = -1
! Forq
#ifdef MODEL_CLASSIC
#ifndef NO_OMP
INTEGER, EXTERNAL :: OMP_GET_THREAD_NUM
#endif
#endif
! Arrays
INTEGER :: ICNTRL (20)
INTEGER :: ISTATUS(20)
REAL(dp) :: RCNTRL (20)
REAL(dp) :: RSTATE (20)
REAL(dp) :: C_before_integrate(NSPEC)
REAL(fp) :: Before(State_Grid%NX, State_Grid%NY, &
State_Grid%NZ, State_Chm%nAdvect )
! For tagged CO saving
REAL(fp) :: LCH4, PCO_TOT, PCO_CH4, PCO_NMVOC
! Objects
TYPE(Species), POINTER :: SpcInfo
! OH reactivity and KPP reaction rate diagnostics
REAL(fp) :: OHreact
REAL(dp) :: Vloc(NVAR), Aout(NREACT)
#ifdef MODEL_GEOS
REAL(f4) :: NOxTau, NOxConc, NOx_weight, NOx_tau_weighted
REAL(f4) :: TROP_NOx_Tau
REAL(f4) :: TROPv_NOx_tau(State_Grid%NX,State_Grid%NY)
REAL(f4) :: TROPv_NOx_mass(State_Grid%NX,State_Grid%NY)
#endif
#if defined( MODEL_CESM )
! Sink rate for artificial UT/LS sink
REAL(dp) :: ScaleCESMLossRate
#endif
! Grid box integration time diagnostic
REAL(fp) :: TimeStart, TimeEnd
! Objects
TYPE(DgnMap), POINTER :: mapData => NULL()
!
! !DEFINED PARAMETERS
!
! Defines the slot in which the H-value from the KPP integrator is stored
! This should be the same as the value of Nhnew in gckpp_Integrator.F90
! (assuming Rosenbrock solver). Define this locally in order to break
! a compile-time dependency. -- Bob Yantosca (05 May 2022)
INTEGER, PARAMETER :: Nhnew = 3
! Suppress printing out KPP error messages after this many errors occur
INTEGER, PARAMETER :: INTEGRATE_FAIL_TOGGLE = 20
!========================================================================
! Do_FullChem begins here!
! NOTE: FlexChem timer is started in DO_CHEMISTRY (the calling routine)
!========================================================================
! Initialize
RC = GC_SUCCESS
ErrMsg = ''
ThisLoc = ' -> at Do_FullChem (in module GeosCore/FullChem_mod.F90)'
SpcInfo => NULL()
Day = Get_Day() ! Current day
Month = Get_Month() ! Current month
Year = Get_Year() ! Current year
Thread = 1
errorCount = 0
Failed2x = .FALSE.
doSuppress = .FALSE.
! Print information the first time that DO_FULLCHEM is called
CALL PrintFirstTimeInfo( Input_Opt, State_Chm, FirstChem )
! Zero diagnostic archival arrays to make sure that we don't have any
! leftover values from the last timestep near the top of the chemgrid
IF (State_Diag%Archive_Loss ) State_Diag%Loss = 0.0_f4
IF (State_Diag%Archive_Prod ) State_Diag%Prod = 0.0_f4
IF (State_Diag%Archive_Jval ) State_Diag%Jval = 0.0_f4
IF (State_Diag%Archive_JvalO3O1D ) State_Diag%JvalO3O1D = 0.0_f4
IF (State_Diag%Archive_JvalO3O3P ) State_Diag%JvalO3O3P = 0.0_f4
IF (State_Diag%Archive_JNoon ) State_Diag%JNoon = 0.0_f4
IF (State_Diag%Archive_ProdCOfromCH4 ) State_Diag%ProdCOfromCH4 = 0.0_f4
IF (State_Diag%Archive_ProdCOfromNMVOC) State_Diag%ProdCOfromNMVOC= 0.0_f4
IF (State_Diag%Archive_OHreactivity ) State_Diag%OHreactivity = 0.0_f4
IF (State_Diag%Archive_RxnRate ) State_Diag%RxnRate = 0.0_f4
IF (State_Diag%Archive_RxnConst ) State_Diag%RxnConst = 0.0_f4
IF (State_Diag%Archive_SatDiagnRxnRate) State_Diag%SatDiagnRxnRate= 0.0_f4
IF (State_Diag%Archive_KppDiags) THEN
IF (State_Diag%Archive_KppIntCounts) State_Diag%KppIntCounts = 0.0_f4
IF (State_Diag%Archive_KppJacCounts) State_Diag%KppJacCounts = 0.0_f4
IF (State_Diag%Archive_KppTotSteps ) State_Diag%KppTotSteps = 0.0_f4
IF (State_Diag%Archive_KppAccSteps ) State_Diag%KppAccSteps = 0.0_f4
IF (State_Diag%Archive_KppRejSteps ) State_Diag%KppRejSteps = 0.0_f4
IF (State_Diag%Archive_KppLuDecomps) State_Diag%KppLuDecomps = 0.0_f4
IF (State_Diag%Archive_KppSubsts ) State_Diag%KppSubsts = 0.0_f4
IF (State_Diag%Archive_KppSmDecomps) State_Diag%KppSmDecomps = 0.0_f4
IF (State_Diag%Archive_KppAutoReducerNVAR) &
State_Diag%KppAutoReducerNVAR = 0.0_f4
IF (State_Diag%Archive_KppcNONZERO) State_Diag%KppcNONZERO = 0.0_f4
IF (State_Diag%Archive_KppNegatives) State_Diag%KppNegatives = 0.0_f4
IF (State_Diag%Archive_KppNegatives0) State_Diag%KppNegatives0 = 0.0_f4
ENDIF
! Also zero satellite diagnostic archival arrays
IF ( State_Diag%Archive_SatDiagnLoss ) State_Diag%SatDiagnLoss = 0.0_f4
IF ( State_Diag%Archive_SatDiagnProd ) State_Diag%SatDiagnProd = 0.0_f4
IF ( State_Diag%Archive_SatDiagnJval ) THEN
State_Diag%SatDiagnJval = 0.0_f4
ENDIF
IF ( State_Diag%Archive_SatDiagnJvalO3O1D ) THEN
State_Diag%SatDiagnJvalO3O1D = 0.0_f4
ENDIF
IF ( State_Diag%Archive_SatDiagnJvalO3O3P ) THEN
State_Diag%SatDiagnJvalO3O3P = 0.0_f4
ENDIF
! Keep track of the boxes where it is local noon in the JNoonFrac
! diagnostic. When time-averaged, this will be the fraction of time
! that local noon occurred at a grid box. (bmy, 4/2/19)
IF ( State_Diag%Archive_JNoonFrac ) THEN
WHERE( State_Met%IsLocalNoon )
State_Diag%JNoonFrac = 1.0_f4
ELSEWHERE
State_Diag%JNoonFrac = 0.0_f4
ENDWHERE
ENDIF
#if defined( MODEL_GEOS )
IF ( State_Diag%Archive_NoxTau ) State_Diag%NoxTau(:,:,:) = 0.0_f4
IF ( State_Diag%Archive_TropNOxTau ) THEN
State_Diag%TropNOxTau(:,:) = 0.0_f4
TROPv_NOx_mass(:,:) = 0.0_f4
TROPv_NOx_tau(:,:) = 0.0_f4
ENDIF
#endif
!========================================================================
! Zero out certain species
!========================================================================
DO N = 1, State_Chm%nSpecies
! Get info about this species from the species database
SpcInfo => State_Chm%SpcData(N)%Info
! isoprene oxidation counter species
IF ( TRIM( SpcInfo%Name ) == 'LISOPOH' .or. &
TRIM( SpcInfo%Name ) == 'LISOPNO3' ) THEN
State_Chm%Species(N)%Conc(:,:,:) = 0.0_fp
ENDIF
! aromatic oxidation counter species
IF ( Input_Opt%LSOA .or. Input_Opt%LSVPOA ) THEN
SELECT CASE ( TRIM( SpcInfo%Name ) )
CASE ( 'LBRO2H', 'LBRO2N', 'LTRO2H', 'LTRO2N', &
'LXRO2H', 'LXRO2N', 'LNRO2H', 'LNRO2N' )
State_Chm%Species(N)%Conc(:,:,:) = 0.0_fp
END SELECT
ENDIF
! Sulfate gas/cloud prod diagnostic species
IF ( TRIM( SpcInfo%Name ) == 'PH2SO4' .or. &
TRIM( SpcInfo%Name ) == 'PSO4AQ' ) THEN
State_Chm%Species(N)%Conc(:,:,:) = 0.0_fp
ENDIF
! Free pointer
SpcInfo => NULL()
ENDDO
!========================================================================
! Convert species to [molec/cm3] (ewl, 8/16/16)
!========================================================================
CALL Convert_Spc_Units( &
Input_Opt = Input_Opt, &
State_Chm = State_Chm, &
State_Grid = State_Grid, &
State_Met = State_Met, &
outUnit = MOLECULES_SPECIES_PER_CM3, &
origUnit = origUnit, &
RC = RC )
IF ( RC /= GC_SUCCESS ) THEN
ErrMsg = 'Unit conversion error!'
CALL GC_Error( ErrMsg, RC, 'fullchem_mod.F90')
RETURN
ENDIF
!========================================================================
! Call photolysis routine to compute J-Values
!========================================================================
IF ( Input_Opt%useTimers ) THEN
CALL Timer_End ( "=> Gas-phase chem", RC )
CALL Timer_Start( "=> Photolysis", RC )
ENDIF
! Compute J-values
IF ( Input_Opt%Do_Photolysis ) THEN
CALL Do_Photolysis( Input_Opt, State_Chm, State_Diag, &
State_Grid, State_Met, RC )
IF ( RC /= GC_SUCCESS ) THEN
ErrMsg = 'Error encountered in "Do_Photolysis"!'
CALL GC_Error( ErrMsg, RC, ThisLoc )
RETURN
ENDIF
ENDIF
!### Debug
IF ( Input_Opt%Verbose ) THEN
CALL DEBUG_MSG( '### Do_FullChem: after computing J-values' )
ENDIF
IF ( Input_Opt%useTimers ) THEN
CALL Timer_End ( "=> Photolysis", RC )
CALL Timer_Start( "=> Gas-phase chem", RC ) ! ended in Do_Chemistry
ENDIF
#if defined( MODEL_GEOS ) || defined( MODEL_WRF ) || defined( MODEL_CESM )
! Init diagnostics
IF ( ASSOCIATED(State_Diag%KppError) ) THEN
State_Diag%KppError(:,:,:) = 0.0
ENDIF
#endif
!=======================================================================
! Archive concentrations before chemistry
!=======================================================================
IF ( State_Diag%Archive_ConcBeforeChem ) THEN
! Point to mapping obj specific to ConcBeforeChem diagnostic collection
mapData => State_Diag%Map_ConcBeforeChem
!$OMP PARALLEL DO &
!$OMP DEFAULT( SHARED ) &
!$OMP PRIVATE( N, S )
DO S = 1, mapData%nSlots
N = mapData%slot2id(S)
State_Diag%ConcBeforeChem(:,:,:,S) = State_Chm%Species(N)%Conc(:,:,:)
ENDDO
!$OMP END PARALLEL DO
! Free pointer
mapData => NULL()
ENDIF
!========================================================================
! Set up integration convergence conditions and timesteps
! (cf. M. J. Evans)
!
! NOTE: ATOL and RTOL are defined in gckpp_Global.F90 so they
! are probably only used as INTENT(IN). Therefore, it is
! probably safe to define them here outside the OpenMP loop.
! (bmy, 3/28/16)
!
! The ICNTRL vector specifies options for the solver. We can
! define ICNTRL outside of the "SOLVE CHEMISTRY" parallel loop
! below because it is passed to KPP as INTENT(IN).
! (bmy, 3/28/16)
!
! ICNTRL now needs to be updated within the TimeLoop for the AR solver
! (hplin, 4/13/22)
!========================================================================
!%%%%% TIMESTEPS %%%%%
! mje Set up conditions for the integration
! mje chemical timestep and convert it to seconds.
DT = GET_TS_CHEM() ! [s]
T = 0d0
TIN = T
TOUT = T + DT
!%%%%% CONVERGENCE CRITERIA %%%%%
! Absolute tolerance
ATOL = 1e-2_dp
! Relative tolerance
RTOL = 0.5e-2_dp
!=======================================================================
! %%%%% SOLVE CHEMISTRY -- This is the main KPP solver loop %%%%%
!=======================================================================
100 format('No. of function calls:', i6, /, &
'No. of jacobian calls:', i6, /, &
'No. of steps: ', i6, /, &
'No. of accepted steps:', i6, /, &
'No. of rejected steps ', i6, /, &
' (except at very beginning)', /, &
'No. of LU decompositions: ', i6, /, &
'No. of forward/backward substitutions:', i6, /, &
'No. of singular matrix decompositions:', i6, /, &
/, &
'Texit, the time corresponding to the ', /, &
' computed Y upon return: ', f11.4, /, &
'Hexit, last accepted step before exit: ', f11.4, /, &
'Hnew, last predicted step (not yet taken):', f11.4 )
!------------------------------------------------------------------------
! Always consider halogens as "fast" species for auto-reduce
!------------------------------------------------------------------------
IF ( FIRSTCHEM .and. Input_Opt%ITS_A_FULLCHEM_SIM ) THEN
IF ( Input_Opt%AutoReduce_Is_KeepActive ) THEN
CALL fullchem_AR_KeepHalogensActive( Input_Opt%amIRoot )
ENDIF
ENDIF
!========================================================================
! MAIN LOOP: Compute reaction rates and call chemical solver
!
! Variables not listed here are held THREADPRIVATE in gckpp_Global.F90
! !$OMP COLLAPSE(3) vectorizes the loop and !$OMP DYNAMIC(24) sends
! 24 boxes at a time to each core... then when that core is finished,
! it gets another chunk of 24 boxes. This should lead to better
! load balancing, and will spread the sunrise/sunset boxes across
! more cores.
!========================================================================
!$OMP PARALLEL DO &
!$OMP DEFAULT( SHARED )&
!$OMP PRIVATE( I, J, L, N )&
!$OMP PRIVATE( ICNTRL, C_before_integrate )&
!$OMP PRIVATE( SO4_FRAC, IERR, RCNTRL, ISTATUS, RSTATE )&
!$OMP PRIVATE( SpcID, KppID, F, P, Vloc )&
!$OMP PRIVATE( Aout, Thread, RC, S, LCH4 )&
!$OMP PRIVATE( OHreact, PCO_TOT, PCO_CH4, PCO_NMVOC, SR )&
!$OMP PRIVATE( SIZE_RES, LWC )&
#ifdef MODEL_GEOS
!$OMP PRIVATE( NOxTau, NOxConc, NOx_weight, NOx_tau_weighted )&
#endif
!$OMP COLLAPSE( 3 )&
!$OMP SCHEDULE( DYNAMIC, 24 )&
!$OMP REDUCTION( +:errorCount )
DO L = 1, State_Grid%NZ
DO J = 1, State_Grid%NY
DO I = 1, State_Grid%NX
! Skip to the end of the loop if we have failed integration twice
IF ( Failed2x ) CYCLE
!=====================================================================
! Initialize private loop variables for each (I,J,L)
! Other private variables will be assigned in Set_Kpp_GridBox_Values
!=====================================================================
IERR = 0 ! KPP success or failure flag
ISTATUS = 0.0_dp ! Rosenbrock output
ICNTRL = 0 ! Rosenbrock input (integer)
RCNTRL = 0.0_fp ! Rosenbrock input (real)
RSTATE = 0.0_dp ! Rosenbrock output
SO4_FRAC = 0.0_fp ! Frac of SO4 avail for photolysis
P = 0 ! GEOS-Chem photolyis species ID
LCH4 = 0.0_fp ! P/L diag: Methane loss rate
PCO_TOT = 0.0_fp ! P/L diag: Total P(CO)
PCO_CH4 = 0.0_fp ! P/L diag: P(CO) from CH4
PCO_NMVOC = 0.0_fp ! P/L diag: P(CO) from NMVOC
SR = 0.0_fp ! Enhancement to O2 catalysis rate
LWC = 0.0_fp ! Liquid water content
SIZE_RES = .FALSE. ! Size resolved calculation?
C = 0.0_dp ! KPP species conc's
RCONST = 0.0_dp ! KPP rate constants
PHOTOL = 0.0_dp ! Photolysis array for KPP
K_CLD = 0.0_dp ! Sulfur in-cloud rxn het rates
K_MT = 0.0_dp ! Sulfur sea salt rxn het rates
CFACTOR = 1.0_dp ! KPP conversion factor
SRO3 = 0.0_dp ! Enhanced sulfate production of
SRHOBr = 0.0_dp ! O3, HOBr, HCl in size-resolved
SRHOCl = 0.0_dp ! cloud droplets
#ifdef MODEL_CLASSIC
#ifndef NO_OMP
Thread = OMP_GET_THREAD_NUM() + 1 ! OpenMP thread number
#endif
#endif
! Per discussions for Lin et al., force keepActive throughout the
! atmosphere if keepActive option is enabled. (hplin, 2/9/22)
CALL fullchem_AR_SetKeepActive( option=.TRUE. )
! Start measuring KPP-related routine timing for this grid box
IF ( State_Diag%Archive_KppTime ) THEN
call cpu_time(TimeStart)
ENDIF
!=====================================================================
! Get photolysis rates (daytime only)
!
! NOTE: The ordering of the photolysis reactions here is
! the order in the Fast-J definition file FJX_j2j.dat.
! I've assumed that these are the same as in the text files
! but this may have been changed. This needs to be checked
! through more thoroughly -- M. Long (3/28/16)
!
! ALSO NOTE: We moved this section above the test to see if grid
! box (I,J,L) is in the chemistry grid. This will ensure that
! J-value diagnostics are defined for all levels in the column.
! This modification was validated by a geosfp_4x5_standard
! difference test. (bmy, 1/18/18)
!
! Update SUNCOSmid threshold from 0 to cos(98 degrees) since
! fast-jx allows for SZA down to 98 degrees. This is important in
! the stratosphere-mesosphere where sunlight still illuminates at
! high altitudes if the sun is below the horizon at the surface
! (update submitted by E. Fleming (NASA), 10/11/2018)
!=====================================================================
IF ( State_Met%SUNCOSmid(I,J) > -0.1391731e+0_fp ) THEN
! Only proceed if doing photolysis
IF ( Input_Opt%Do_Photolysis ) THEN
! Get the fraction of H2SO4 that is available for photolysis
! (this is only valid for UCX-enabled mechanisms)
SO4_FRAC = SO4_PHOTFRAC( I, J, L, State_Chm )
! Adjust certain photolysis rates:
! (1) H2SO4 + hv -> SO2 + OH + OH (UCX-based mechanisms)
! (2) O3 + hv -> O2 + O (UCX-based mechanisms)
! (2) O3 + hv -> OH + OH (trop-only mechanisms)
CALL PHOTRATE_ADJ( Input_Opt, State_Chm, State_Diag, State_Met,&
I, J, L, SO4_FRAC, &
IERR )
! Loop over the FAST-JX photolysis species
DO N = 1, State_Chm%Phot%nMaxPhotRxns
! Copy photolysis rate from FAST_JX into KPP PHOTOL array
PHOTOL(N) = State_Chm%Phot%ZPJ(L,N,I,J)
!============================================================
! HISTORY (aka netCDF diagnostics)
!
! Instantaneous photolysis rates [s-1] (aka J-values)
! and noontime photolysis rates [s-1]
!
! NOTE: Attach diagnostics here instead of in module
! fast_jx_mod.F90 so that we can get the adjusted photolysis
! rates (output from routne PHOTRATE_ADJ above).
!
! The mapping between the GEOS-Chem photolysis species and
! the FAST-JX photolysis species is contained in the lookup
! table in input file FJX_j2j.dat.
! Some GEOS-Chem photolysis species may have multiple
! branches for photolysis reactions. These will be
! represented by multiple entries in the FJX_j2j.dat
! lookup table.
!
! NOTE: For convenience, we have stored the GEOS-Chem
! photolysis species index (range: 1..State_Chm%nPhotol)
! for each of the FAST-JX photolysis species (range;
! 1..State_Chm%Phot%nMaxPhotRxns) in the GC_PHOTO_ID array
!============================================================
! GC photolysis species index
P = State_Chm%Phot%GC_Photo_Id(N)
! If this FAST_JX photolysis species maps to a valid
! GEOS-Chem photolysis species (for this simulation)...
IF ( P > 0 .and. P <= State_Chm%nPhotol ) THEN
! Archive the instantaneous photolysis rate
! (summing over all reaction branches)
IF ( State_Diag%Archive_Jval ) THEN
S = State_Diag%Map_Jval%id2slot(P)
IF ( S > 0 ) THEN
State_Diag%Jval(I,J,L,S) = &
State_Diag%Jval(I,J,L,S) + PHOTOL(N)
ENDIF
ENDIF
! Satellite diagnostics
! Archive the instantaneous photolysis rate
! (summing over all reaction branches)
IF ( State_Diag%Archive_SatDiagnJval ) THEN
S = State_Diag%Map_SatDiagnJval%id2slot(P)
IF ( S > 0 ) THEN
State_Diag%SatDiagnJval(I,J,L,S) = &
State_Diag%SatDiagnJval(I,J,L,S) + PHOTOL(N)
ENDIF
ENDIF
! Archive the noontime photolysis rate
! (summing over all reaction branches)
IF ( State_Met%IsLocalNoon(I,J) ) THEN
IF ( State_Diag%Archive_JNoon ) THEN
S = State_Diag%Map_JNoon%id2slot(P)
IF ( S > 0 ) THEN
State_Diag%JNoon(I,J,L,S) = &
State_Diag%JNoon(I,J,L,S) + PHOTOL(N)
ENDIF
ENDIF
ENDIF
ELSE IF ( P == State_Chm%nPhotol+1 ) THEN
! J(O3_O1D). This used to be stored as the nPhotol+1st
! diagnostic in Jval, but needed to be broken off
! to facilitate cleaner diagnostic indexing (bmy, 6/3/20)
IF ( State_Diag%Archive_JvalO3O1D ) THEN
State_Diag%JvalO3O1D(I,J,L) = &
State_Diag%JvalO3O1D(I,J,L) + PHOTOL(N)
ENDIF
! J(O3_O1D) for satellite diagnostics
IF ( State_Diag%Archive_SatDiagnJvalO3O1D ) THEN
State_Diag%SatDiagnJvalO3O1D(I,J,L) = &
State_Diag%SatDiagnJvalO3O1D(I,J,L) + PHOTOL(N)
ENDIF
ELSE IF ( P == State_Chm%nPhotol+2 ) THEN
! J(O3_O3P). This used to be stored as the nPhotol+2nd
! diagnostic in Jval, but needed to be broken off
! to facilitate cleaner diagnostic indexing (bmy, 6/3/20)
IF ( State_Diag%Archive_JvalO3O3P ) THEN
State_Diag%JvalO3O3P(I,J,L) = &
State_Diag%JvalO3O3P(I,J,L) + PHOTOL(N)
ENDIF
! J(O3_O3P) for satellite diagnostics
IF ( State_Diag%Archive_SatDiagnJvalO3O3P ) THEN
State_Diag%SatDiagnJvalO3O3P(I,J,L) = &
State_Diag%SatDiagnJvalO3O3P(I,J,L) + PHOTOL(N)
ENDIF
ENDIF
ENDDO
ENDIF
ENDIF
#if defined( MODEL_CESM )
!=====================================================================
! Unphysical fix: Photolyze soluble aerosol tracers
! This removes unphysical values of soluble tracers in the UT/LS due
! to decoupling of convection and wet scavenging in CESM dynamics.
!
! This process has to be done before InChemGrid as it is supposed to
! be active everywhere, especially the stratosphere.
! (hplin, 5/30/23)
!=====================================================================
IF ( Input_Opt%correctConvUTLS .and. L .ge. State_Met%PBL_TOP_L(I,J) ) THEN
! We operate directly on [molec/cm3] species concentrations in State_Chm,
! because they have not been copied to C() in KPP yet. But, we can use
! PHOTOL(11) which is J-NO2, and scale to create the artificial sink.
! This is a consistent handling based off the MOZART-TS1 mechanism
! in Emmons et al., 2020 JAMES.
ScaleCESMLossRate = MAX(0.0_dp, 1 - PHOTOL(11) * .0004_dp * DT)
State_Chm%Species(id_TSOA0)%Conc(I,J,L) = State_Chm%Species(id_TSOA0)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_TSOA1)%Conc(I,J,L) = State_Chm%Species(id_TSOA1)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_TSOA2)%Conc(I,J,L) = State_Chm%Species(id_TSOA2)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_TSOA3)%Conc(I,J,L) = State_Chm%Species(id_TSOA3)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_ASOA1)%Conc(I,J,L) = State_Chm%Species(id_ASOA1)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_ASOA2)%Conc(I,J,L) = State_Chm%Species(id_ASOA2)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_ASOA3)%Conc(I,J,L) = State_Chm%Species(id_ASOA3)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_ASOAN)%Conc(I,J,L) = State_Chm%Species(id_ASOAN)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_TSOG0)%Conc(I,J,L) = State_Chm%Species(id_TSOG0)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_TSOG1)%Conc(I,J,L) = State_Chm%Species(id_TSOG1)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_TSOG2)%Conc(I,J,L) = State_Chm%Species(id_TSOG2)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_TSOG3)%Conc(I,J,L) = State_Chm%Species(id_TSOG3)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_ASOG1)%Conc(I,J,L) = State_Chm%Species(id_ASOG1)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_ASOG2)%Conc(I,J,L) = State_Chm%Species(id_ASOG2)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_ASOG3)%Conc(I,J,L) = State_Chm%Species(id_ASOG3)%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_NIT )%Conc(I,J,L) = State_Chm%Species(id_NIT )%Conc(I,J,L) * ScaleCESMLossRate
State_Chm%Species(id_NITs )%Conc(I,J,L) = State_Chm%Species(id_NITs )%Conc(I,J,L) * ScaleCESMLossRate
! Don't apply this to sulfate as it is not applied in CAM-chem either and will affect the SO4 budget.
!State_Chm%Species(id_SO4 )%Conc(I,J,L) = State_Chm%Species(id_SO4 )%Conc(I,J,L) * ScaleCESMLossRate
!State_Chm%Species(id_SO4s )%Conc(I,J,L) = State_Chm%Species(id_SO4s )%Conc(I,J,L) * ScaleCESMLossRate
ENDIF
#endif
!=====================================================================
! Test if we need to do the chemistry for box (I,J,L),
! otherwise move onto the next box.
!=====================================================================
! If we are not in the troposphere don't do the chemistry!
IF ( .not. State_Met%InChemGrid(I,J,L) ) CYCLE
! Skipping buffer zone (lzh, 08/10/2014)
IF ( State_Grid%NestedGrid ) THEN
IF ( J <= State_Grid%SouthBuffer ) CYCLE
IF ( J > State_Grid%NY - State_Grid%NorthBuffer ) CYCLE
IF ( I <= State_Grid%EastBuffer ) CYCLE
IF ( I > State_Grid%NX - State_Grid%WestBuffer ) CYCLE
ENDIF
!=====================================================================
! Initialize the KPP "C" vector of species concentrations [molec/cm3]
!=====================================================================
DO N = 1, NSPEC
SpcID = State_Chm%Map_KppSpc(N)
C(N) = 0.0_dp
IF ( SpcId > 0 ) C(N) = State_Chm%Species(SpcID)%Conc(I,J,L)
ENDDO
!=====================================================================
! CHEMISTRY MECHANISM INITIALIZATION (#1)
!
! Populate KPP global variables and arrays in gckpp_global.F90
!
! NOTE: This has to be done before Set_Sulfur_Chem_Rates, so that
! the NUMDEN and SR_TEMP KPP variables will be populated first.
! Otherwise this can lead to differences in output that are evident
! when running with different numbers of OpenMP cores.
! See https://github.com/geoschem/geos-chem/issues/1157
! -- Bob Yantosca (08 Mar 2022)
!=====================================================================
! Copy values into the various KPP global variables
CALL Set_Kpp_GridBox_Values( I = I, &
J = J, &
L = L, &
Input_Opt = Input_Opt, &
State_Chm = State_Chm, &
State_Grid = State_Grid, &
State_Met = State_Met, &
RC = RC )
!=====================================================================
! CHEMISTRY MECHANISM INITIALIZATION (#2)
!
! Update reaction rates [1/s] for sulfur chemistry in cloud and on
! seasalt. These will be passed to the KPP chemical solver.
!
! NOTE: This has to be done before fullchem_SetStateHet so that
! State_Chm%HSO3_aq and State_Chm%SO3_aq will be populated first.
! These are copied into State_Het%HSO3_aq and State_Het%SO3_aq.
! See https://github.com/geoschem/geos-chem/issues/1157
! -- Bob Yantosca (08 Mar 2022)
!=====================================================================
! Compute sulfur chemistry reaction rates [1/s]
! If size_res = T, we'll call fullchem_HetDropChem below.
CALL Set_Sulfur_Chem_Rates( I = I, &
J = J, &
L = L, &
Input_Opt = Input_Opt, &
State_Chm = State_Chm, &
State_Diag = State_Diag, &
State_Grid = State_Grid, &
State_Met = State_Met, &
size_res = size_res, &
RC = RC )
!=====================================================================
! CHEMISTRY MECHANISM INITIALIZATION (#3)
!
! Populate the various fields of the State_Het object.
!
! NOTE: This has to be done after fullchem_SetStateHet so that
! State_Chm%HSO3_aq and State_Chm%SO3_aq will be populated first.
! These are copied into State_Het%HSO3_aq and State_Het%SO3_aq.
! See https://github.com/geoschem/geos-chem/issues/1157
! -- Bob Yantosca (08 Mar 2022)
!=====================================================================
! Populate fields of the State_Het object
CALL fullchem_SetStateHet( I = I, &
J = J, &
L = L, &
id_SALA = id_SALA, &
id_SALAAL = id_SALAAL, &
id_SALC = id_SALC, &
id_SALCAL = id_SALCAL, &
Input_Opt = Input_Opt, &
State_Chm = State_Chm, &
State_Met = State_Met, &
H = State_Het, &
RC = RC )
!=====================================================================
! CHEMISTRY MECHANISM INITIALIZATION (#5)
!
! Call Het_Drop_Chem (formerly located in sulfate_mod.F90) to
! estimate the in-cloud sulfate production rate in heterogeneous
! cloud droplets based on the Yuen et al., 1996 parameterization.
! Code by Becky Alexander (2011) with updates by Mike Long and Bob
! Yantosca (2021).
!
! We will only call Het_Drop_Chem if:
! (1) It is at least 0.01% cloudy
! (2) We are doing a size-resolved computation
! (3) The grid box is over water
! (4) The temperature is above -5C
! (5) Liquid water content is nonzero
!=====================================================================
IF ( State_Met%CLDF(I,J,L) > 1.0e-4_fp ) THEN
! Liquid water content (same formula from the old sulfate_mod.F90)
LWC = ( State_Met%QL(I,J,L) * State_Met%AIRDEN(I,J,L) &
* 1.0e-3_fp / State_Met%CLDF(I,J,L) )
! Eexecute fullchem_HetDropChem if criteria are satisfied
! NOTE: skip if LWC is very small, which will blow up equations!
IF ( ( size_res ) .and. &
( State_Met%IsWater(I,J) ) .and. &
( TEMP > 268.15_fp ) .and. &
( LWC > 1.0e-20_fp ) ) THEN
CALL fullchem_HetDropChem( I = I, &
J = J, &
L = L, &
Input_Opt = Input_Opt, &
State_Met = State_Met, &
State_Chm = State_Chm )
ENDIF
ENDIF
!=====================================================================
! Prepare arrays
!=====================================================================
! Zero out dummy species index in KPP
DO F = 1, NFAM
KppID = PL_Kpp_Id(F)
IF ( KppID > 0 ) C(KppID) = 0.0_dp
ENDDO
!=====================================================================
! Update reaction rates
!=====================================================================
! Update the array of rate constants
CALL Update_RCONST( )
!=====================================================================
! HISTORY (aka netCDF diagnostics)
!
! Archive KPP reaction rates [molec cm-3 s-1]
! See gckpp_Monitor.F90 for a list of chemical reactions
!
! NOTE: In KPP 2.5.0+, VAR and FIX are now private to the integrator
! and point to C. Therefore, pass C(1:NVAR) instead of VAR and
! C(NVAR+1:NSPEC) instead of FIX to routine FUN.
!=====================================================================
IF ( State_Diag%Archive_RxnRate .or. &
State_Diag%Archive_SatDiagnRxnRate ) THEN
! Get equation rates (Aout)
CALL Fun( V = C(1:NVAR), &
F = C(NVAR+1:NSPEC), &
RCT = RCONST, &
Vdot = Vloc, &
Aout = Aout )
! Archive the RxnRate diagnostic collection
IF ( State_Diag%Archive_RxnRate ) THEN
DO S = 1, State_Diag%Map_RxnRate%nSlots
N = State_Diag%Map_RxnRate%slot2Id(S)
State_Diag%RxnRate(I,J,L,S) = Aout(N)
ENDDO
ENDIF
! Archive the SatDiagnRxnRate diagnostic collection
IF ( State_Diag%Archive_SatDiagnRxnRate ) THEN
DO S = 1, State_Diag%Map_SatDiagnRxnRate%nSlots
N = State_Diag%Map_SatDiagnRxnRate%slot2Id(S)
State_Diag%SatDiagnRxnRate(I,J,L,S) = Aout(N)
ENDDO
ENDIF
ENDIF
! Archive KPP reaction rate constants (RCONST). The units vary.
! They are already updated in Update_RCONST, and do not require
! a call of Fun(). (hplin, 3/28/23)
IF ( State_Diag%Archive_RxnConst ) THEN
DO S = 1, State_Diag%Map_RxnConst%nSlots
N = State_Diag%Map_RxnConst%slot2Id(S)
State_Diag%RxnConst(I,J,L,S) = RCONST(N)
ENDDO
ENDIF
!=====================================================================
! Set options for the KPP integrator in vectors ICNTRL and RCNTRL
! This now needs to be done within the parallel loop
!=====================================================================
CALL fullchem_AR_SetIntegratorOptions( Input_Opt, State_Chm, &
State_Met, FirstChem, &
I, J, L, &
ICNTRL, RCNTRL )
!=====================================================================
! Integrate the box forwards
!=====================================================================
! Store concentrations before the call to "Integrate". This will
! let us reset concentrations before calling "Integrate" a 2nd time.
C_before_integrate = C
! Call the Rosenbrock integrator
! (with optional auto-reduce functionality)
CALL Integrate( TIN, TOUT, ICNTRL, &
RCNTRL, ISTATUS, RSTATE, IERR )
! Print grid box indices to screen if integrate failed
IF ( IERR < 0 ) THEN
! Turn off error output after a certain limit is reached
IF ( .not. doSuppress ) THEN
WRITE( 6, * ) '### INTEGRATE RETURNED ERROR AT: ', I, J, L
errorCount = errorCount + 1
IF ( errorCount > INTEGRATE_FAIL_TOGGLE ) THEN