-
Notifications
You must be signed in to change notification settings - Fork 0
/
FUTURE_ISOFWD.f90
18710 lines (14342 loc) · 596 KB
/
FUTURE_ISOFWD.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
!=======================================================================
! *** ISORROPIA CODE
! *** SUBROUTINE ISRP1F
! *** THIS SUBROUTINE IS THE DRIVER ROUTINE FOR THE FOREWARD PROBLEM OF
! AN AMMONIUM-SULFATE AEROSOL SYSTEM.
! THE COMPOSITION REGIME IS DETERMINED BY THE SULFATE RATIO AND BY
! THE AMBIENT RELATIVE HUMIDITY.
! *** COPYRIGHT 1996-2006, UNIVERSITY OF MIAMI, CARNEGIE MELLON UNIVERSITY,
! *** GEORGIA INSTITUTE OF TECHNOLOGY
! *** WRITTEN BY ATHANASIOS NENES
! *** UPDATED BY CHRISTOS FOUNTOUKIS
!=======================================================================
SUBROUTINE ISRP1F (WI, RHI, TEMPI)
INCLUDE 'isrpia.inc'
DIMENSION WI(NCOMP)
! *** INITIALIZE ALL VARIABLES IN COMMON BLOCK **************************
CALL INIT1 (WI, RHI, TEMPI)
! *** CALCULATE SULFATE RATIO *******************************************
SULRAT = W(3)/W(2)
! *** FIND CALCULATION REGIME FROM (SULRAT,RH) **************************
! *** SULFATE POOR
IF (2.0 <= SULRAT) THEN
DC = W(3) - 2.001D0*W(2) ! For numerical stability
W(3) = W(3) + MAX(-DC, ZERO)
IF(METSTBL == 1) THEN
SCASE = 'A2'
CALL CALCA2 ! Only liquid (metastable)
ELSE
IF (RH < DRNH42S4) THEN
SCASE = 'A1'
CALL CALCA1 ! NH42SO4 ; case A1
ELSEIF (DRNH42S4 <= RH) THEN
SCASE = 'A2'
CALL CALCA2 ! Only liquid ; case A2
ENDIF
ENDIF
! *** SULFATE RICH (NO ACID)
ELSEIF (1.0 <= SULRAT .AND. SULRAT < 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'B4'
CALL CALCB4 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4HS4) THEN
SCASE = 'B1'
CALL CALCB1 ! NH4HSO4,LC,NH42SO4 ; case B1
ELSEIF (DRNH4HS4 <= RH .AND. RH < DRLC) THEN
SCASE = 'B2'
CALL CALCB2 ! LC,NH42S4 ; case B2
ELSEIF (DRLC <= RH .AND. RH < DRNH42S4) THEN
SCASE = 'B3'
CALL CALCB3 ! NH42S4 ; case B3
ELSEIF (DRNH42S4 <= RH) THEN
SCASE = 'B4'
CALL CALCB4 ! Only liquid ; case B4
ENDIF
ENDIF
CALL CALCNH3
! *** SULFATE RICH (FREE ACID)
ELSEIF (SULRAT < 1.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'C2'
CALL CALCC2 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4HS4) THEN
SCASE = 'C1'
CALL CALCC1 ! NH4HSO4 ; case C1
ELSEIF (DRNH4HS4 <= RH) THEN
SCASE = 'C2'
CALL CALCC2 ! Only liquid ; case C2
ENDIF
ENDIF
CALL CALCNH3
ENDIF
! *** RETURN POINT
RETURN
! *** END OF SUBROUTINE ISRP1F *****************************************
END SUBROUTINE ISRP1F
!=======================================================================
! *** ISORROPIA CODE
! *** SUBROUTINE ISRP2F
! *** THIS SUBROUTINE IS THE DRIVER ROUTINE FOR THE FOREWARD PROBLEM OF
! AN AMMONIUM-SULFATE-NITRATE AEROSOL SYSTEM.
! THE COMPOSITION REGIME IS DETERMINED BY THE SULFATE RATIO AND BY
! THE AMBIENT RELATIVE HUMIDITY.
! *** COPYRIGHT 1996-2006, UNIVERSITY OF MIAMI, CARNEGIE MELLON UNIVERSITY,
! *** GEORGIA INSTITUTE OF TECHNOLOGY
! *** WRITTEN BY ATHANASIOS NENES
! *** UPDATED BY CHRISTOS FOUNTOUKIS
!=======================================================================
SUBROUTINE ISRP2F (WI, RHI, TEMPI)
INCLUDE 'isrpia.inc'
DIMENSION WI(NCOMP)
! *** INITIALIZE ALL VARIABLES IN COMMON BLOCK **************************
CALL INIT2 (WI, RHI, TEMPI)
! *** CALCULATE SULFATE RATIO *******************************************
SULRAT = W(3)/W(2)
! *** FIND CALCULATION REGIME FROM (SULRAT,RH) **************************
! *** SULFATE POOR
IF (2.0 <= SULRAT) THEN
IF(METSTBL == 1) THEN
SCASE = 'D3'
CALL CALCD3 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4NO3) THEN
SCASE = 'D1'
CALL CALCD1 ! NH42SO4,NH4NO3 ; case D1
ELSEIF (DRNH4NO3 <= RH .AND. RH < DRNH42S4) THEN
SCASE = 'D2'
CALL CALCD2 ! NH42S4 ; case D2
ELSEIF (DRNH42S4 <= RH) THEN
SCASE = 'D3'
CALL CALCD3 ! Only liquid ; case D3
ENDIF
ENDIF
! *** SULFATE RICH (NO ACID)
! FOR SOLVING THIS CASE, NITRIC ACID IS ASSUMED A MINOR SPECIES,
! THAT DOES NOT SIGNIFICANTLY PERTURB THE HSO4-SO4 EQUILIBRIUM.
! SUBROUTINES CALCB? ARE CALLED, AND THEN THE NITRIC ACID IS DISSOLVED
! FROM THE HNO3(G) -> (H+) + (NO3-) EQUILIBRIUM.
ELSEIF (1.0 <= SULRAT .AND. SULRAT < 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'B4'
CALL CALCB4 ! Only liquid (metastable)
SCASE = 'E4'
ELSE
IF (RH < DRNH4HS4) THEN
SCASE = 'B1'
CALL CALCB1 ! NH4HSO4,LC,NH42SO4 ; case E1
SCASE = 'E1'
ELSEIF (DRNH4HS4 <= RH .AND. RH < DRLC) THEN
SCASE = 'B2'
CALL CALCB2 ! LC,NH42S4 ; case E2
SCASE = 'E2'
ELSEIF (DRLC <= RH .AND. RH < DRNH42S4) THEN
SCASE = 'B3'
CALL CALCB3 ! NH42S4 ; case E3
SCASE = 'E3'
ELSEIF (DRNH42S4 <= RH) THEN
SCASE = 'B4'
CALL CALCB4 ! Only liquid ; case E4
SCASE = 'E4'
ENDIF
ENDIF
CALL CALCNA ! HNO3(g) DISSOLUTION
! *** SULFATE RICH (FREE ACID)
! FOR SOLVING THIS CASE, NITRIC ACID IS ASSUMED A MINOR SPECIES,
! THAT DOES NOT SIGNIFICANTLY PERTURB THE HSO4-SO4 EQUILIBRIUM
! SUBROUTINE CALCC? IS CALLED, AND THEN THE NITRIC ACID IS DISSOLVED
! FROM THE HNO3(G) -> (H+) + (NO3-) EQUILIBRIUM.
ELSEIF (SULRAT < 1.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'C2'
CALL CALCC2 ! Only liquid (metastable)
SCASE = 'F2'
ELSE
IF (RH < DRNH4HS4) THEN
SCASE = 'C1'
CALL CALCC1 ! NH4HSO4 ; case F1
SCASE = 'F1'
ELSEIF (DRNH4HS4 <= RH) THEN
SCASE = 'C2'
CALL CALCC2 ! Only liquid ; case F2
SCASE = 'F2'
ENDIF
ENDIF
CALL CALCNA ! HNO3(g) DISSOLUTION
ENDIF
! *** RETURN POINT
RETURN
! *** END OF SUBROUTINE ISRP2F *****************************************
END SUBROUTINE ISRP2F
!=======================================================================
! *** ISORROPIA CODE
! *** SUBROUTINE ISRP3F
! *** THIS SUBROUTINE IS THE DRIVER ROUTINE FOR THE FORWARD PROBLEM OF
! AN AMMONIUM-SULFATE-NITRATE-CHLORIDE-SODIUM AEROSOL SYSTEM.
! THE COMPOSITION REGIME IS DETERMINED BY THE SULFATE & SODIUM
! RATIOS AND BY THE AMBIENT RELATIVE HUMIDITY.
! *** COPYRIGHT 1996-2006, UNIVERSITY OF MIAMI, CARNEGIE MELLON UNIVERSITY,
! *** GEORGIA INSTITUTE OF TECHNOLOGY
! *** WRITTEN BY ATHANASIOS NENES
! *** UPDATED BY CHRISTOS FOUNTOUKIS
!=======================================================================
SUBROUTINE ISRP3F (WI, RHI, TEMPI)
INCLUDE 'isrpia.inc'
DIMENSION WI(NCOMP)
! *** ADJUST FOR TOO LITTLE AMMONIUM AND CHLORIDE ***********************
WI(3) = MAX (WI(3), 1.D-10) ! NH4+ : 1e-4 umoles/m3
WI(5) = MAX (WI(5), 1.D-10) ! Cl- : 1e-4 umoles/m3
! *** ADJUST FOR TOO LITTLE SODIUM, SULFATE AND NITRATE COMBINED ********
IF (WI(1)+WI(2)+WI(4) <= 1d-10) THEN
WI(1) = 1.D-10 ! Na+ : 1e-4 umoles/m3
WI(2) = 1.D-10 ! SO4- : 1e-4 umoles/m3
ENDIF
! *** INITIALIZE ALL VARIABLES IN COMMON BLOCK **************************
CALL ISOINIT3 (WI, RHI, TEMPI)
! *** CHECK IF TOO MUCH SODIUM ; ADJUST AND ISSUE ERROR MESSAGE *********
REST = 2.D0*W(2) + W(4) + W(5)
IF (W(1) > REST) THEN ! NA > 2*SO4+CL+NO3 ?
W(1) = (ONE-1D-6)*REST ! Adjust Na amount
CALL PUSHERR (0050, 'ISRP3F') ! Warning error: Na adjusted
ENDIF
! *** CALCULATE SULFATE & SODIUM RATIOS *********************************
SULRAT = (W(1)+W(3))/W(2)
SODRAT = W(1)/W(2)
! *** FIND CALCULATION REGIME FROM (SULRAT,RH) **************************
! *** SULFATE POOR ; SODIUM POOR
IF (2.0 <= SULRAT .AND. SODRAT < 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'G5'
CALL CALCG5 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4NO3) THEN
SCASE = 'G1'
CALL CALCG1 ! NH42SO4,NH4NO3,NH4CL,NA2SO4
ELSEIF (DRNH4NO3 <= RH .AND. RH < DRNH4CL) THEN
SCASE = 'G2'
CALL CALCG2 ! NH42SO4,NH4CL,NA2SO4
ELSEIF (DRNH4CL <= RH .AND. RH < DRNH42S4) THEN
SCASE = 'G3'
CALL CALCG3 ! NH42SO4,NA2SO4
ELSEIF (DRNH42S4 <= RH .AND. RH < DRNA2SO4) THEN
SCASE = 'G4'
CALL CALCG4 ! NA2SO4
ELSEIF (DRNA2SO4 <= RH) THEN
SCASE = 'G5'
CALL CALCG5 ! Only liquid
ENDIF
ENDIF
! *** SULFATE POOR ; SODIUM RICH
ELSE IF (SULRAT >= 2.0 .AND. SODRAT >= 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'H6'
CALL CALCH6 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4NO3) THEN
SCASE = 'H1'
CALL CALCH1 ! NH4NO3,NH4CL,NA2SO4,NACL,NANO3
ELSEIF (DRNH4NO3 <= RH .AND. RH < DRNANO3) THEN
SCASE = 'H2'
CALL CALCH2 ! NH4CL,NA2SO4,NACL,NANO3
ELSEIF (DRNANO3 <= RH .AND. RH < DRNACL) THEN
SCASE = 'H3'
CALL CALCH3 ! NH4CL,NA2SO4,NACL
ELSEIF (DRNACL <= RH .AND. RH < DRNH4Cl) THEN
SCASE = 'H4'
CALL CALCH4 ! NH4CL,NA2SO4
ELSEIF (DRNH4Cl <= RH .AND. RH < DRNA2SO4) THEN
SCASE = 'H5'
CALL CALCH5 ! NA2SO4
ELSEIF (DRNA2SO4 <= RH) THEN
SCASE = 'H6'
CALL CALCH6 ! NO SOLID
ENDIF
ENDIF
! *** SULFATE RICH (NO ACID)
ELSEIF (1.0 <= SULRAT .AND. SULRAT < 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'I6'
CALL CALCI6 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4HS4) THEN
SCASE = 'I1'
CALL CALCI1 ! NA2SO4,(NH4)2SO4,NAHSO4,NH4HSO4,LC
ELSEIF (DRNH4HS4 <= RH .AND. RH < DRNAHSO4) THEN
SCASE = 'I2'
CALL CALCI2 ! NA2SO4,(NH4)2SO4,NAHSO4,LC
ELSEIF (DRNAHSO4 <= RH .AND. RH < DRLC) THEN
SCASE = 'I3'
CALL CALCI3 ! NA2SO4,(NH4)2SO4,LC
ELSEIF (DRLC <= RH .AND. RH < DRNH42S4) THEN
SCASE = 'I4'
CALL CALCI4 ! NA2SO4,(NH4)2SO4
ELSEIF (DRNH42S4 <= RH .AND. RH < DRNA2SO4) THEN
SCASE = 'I5'
CALL CALCI5 ! NA2SO4
ELSEIF (DRNA2SO4 <= RH) THEN
SCASE = 'I6'
CALL CALCI6 ! NO SOLIDS
ENDIF
ENDIF
CALL CALCNHA ! MINOR SPECIES: HNO3, HCl
CALL CALCNH3 ! NH3
! *** SULFATE RICH (FREE ACID)
ELSEIF (SULRAT < 1.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'J3'
CALL CALCJ3 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4HS4) THEN
SCASE = 'J1'
CALL CALCJ1 ! NH4HSO4,NAHSO4
ELSEIF (DRNH4HS4 <= RH .AND. RH < DRNAHSO4) THEN
SCASE = 'J2'
CALL CALCJ2 ! NAHSO4
ELSEIF (DRNAHSO4 <= RH) THEN
SCASE = 'J3'
CALL CALCJ3
ENDIF
ENDIF
CALL CALCNHA ! MINOR SPECIES: HNO3, HCl
CALL CALCNH3 ! NH3
ENDIF
! *** RETURN POINT
RETURN
! *** END OF SUBROUTINE ISRP3F *****************************************
END SUBROUTINE ISRP3F
!=======================================================================
! *** ISORROPIA CODE II
! *** SUBROUTINE ISRP4F
! *** THIS SUBROUTINE IS THE DRIVER ROUTINE FOR THE FORWARD PROBLEM OF
! AN AMMONIUM-SULFATE-NITRATE-CHLORIDE-SODIUM-CALCIUM-POTASSIUM-MAGNESIUM
! AEROSOL SYSTEM.
! THE COMPOSITION REGIME IS DETERMINED BY THE SULFATE & SODIUM
! RATIOS AND BY THE AMBIENT RELATIVE HUMIDITY.
! *** COPYRIGHT 1996-2006, UNIVERSITY OF MIAMI, CARNEGIE MELLON UNIVERSITY
! *** GEORGIA INSTITUTE OF TECHNOLOGY
! *** WRITTEN BY CHRISTOS FOUNTOUKIS AND ATHANASIOS NENES
!=======================================================================
SUBROUTINE ISRP4F (WI, RHI, TEMPI)
INCLUDE 'isrpia.inc'
DIMENSION WI(NCOMP)
real :: NAFRI, NO3FRI
! *** ADJUST FOR TOO LITTLE AMMONIUM AND CHLORIDE ***********************
! WI(3) = MAX (WI(3), 1.D-10) ! NH4+ : 1e-4 umoles/m3
! WI(5) = MAX (WI(5), 1.D-10) ! Cl- : 1e-4 umoles/m3
! *** ADJUST FOR TOO LITTLE SODIUM, SULFATE AND NITRATE COMBINED ********
! IF (WI(1)+WI(2)+WI(4) .LE. 1d-10) THEN
! WI(1) = 1.D-10 ! Na+ : 1e-4 umoles/m3
! WI(2) = 1.D-10 ! SO4- : 1e-4 umoles/m3
! ENDIF
! *** INITIALIZE ALL VARIABLES IN COMMON BLOCK **************************
CALL INIT4 (WI, RHI, TEMPI)
! *** CHECK IF TOO MUCH SODIUM+CRUSTALS ; ADJUST AND ISSUE ERROR MESSAGE
REST = 2.D0*W(2) + W(4) + W(5)
IF (W(1)+W(6)+W(7)+W(8) > REST) THEN
CCASO4I = MIN (W(2),W(6))
FRSO4I = MAX (W(2) - CCASO4I, ZERO)
CAFRI = MAX (W(6) - CCASO4I, ZERO)
CCANO32I = MIN (CAFRI, 0.5D0*W(4))
CAFRI = MAX (CAFRI - CCANO32I, ZERO)
NO3FRI = MAX (W(4) - 2.D0*CCANO32I, ZERO)
CCACL2I = MIN (CAFRI, 0.5D0*W(5))
CLFRI = MAX (W(5) - 2.D0*CCACL2I, ZERO)
REST1 = 2.D0*FRSO4I + NO3FRI + CLFRI
CNA2SO4I = MIN (FRSO4I, 0.5D0*W(1))
FRSO4I = MAX (FRSO4I - CNA2SO4I, ZERO)
NAFRI = MAX (W(1) - 2.D0*CNA2SO4I, ZERO)
CNACLI = MIN (NAFRI, CLFRI)
NAFRI = MAX (NAFRI - CNACLI, ZERO)
CLFRI = MAX (CLFRI - CNACLI, ZERO)
CNANO3I = MIN (NAFRI, NO3FRI)
NO3FR = MAX (NO3FRI - CNANO3I, ZERO)
REST2 = 2.D0*FRSO4I + NO3FRI + CLFRI
CMGSO4I = MIN (FRSO4I, W(8))
FRMGI = MAX (W(8) - CMGSO4I, ZERO)
FRSO4I = MAX (FRSO4I - CMGSO4I, ZERO)
CMGNO32I = MIN (FRMGI, 0.5D0*NO3FRI)
FRMGI = MAX (FRMGI - CMGNO32I, ZERO)
NO3FRI = MAX (NO3FRI - 2.D0*CMGNO32I, ZERO)
CMGCL2I = MIN (FRMGI, 0.5D0*CLFRI)
CLFRI = MAX (CLFRI - 2.D0*CMGCL2I, ZERO)
REST3 = 2.D0*FRSO4I + NO3FRI + CLFRI
IF (W(6) > REST) THEN ! Ca > 2*SO4+CL+NO3 ?
W(6) = (ONE-1D-6)*REST ! Adjust Ca amount
W(1)= ZERO ! Adjust Na amount
W(7)= ZERO ! Adjust K amount
W(8)= ZERO ! Adjust Mg amount
CALL PUSHERR (0051, 'ISRP4F') ! Warning error: Ca, Na, K, Mg in excess
ELSE IF (W(1) > REST1) THEN ! Na > 2*FRSO4+FRCL+FRNO3 ?
W(1) = (ONE-1D-6)*REST1 ! Adjust Na amount
W(7)= ZERO ! Adjust K amount
W(8)= ZERO ! Adjust Mg amount
CALL PUSHERR (0052, 'ISRP4F') ! Warning error: Na, K, Mg in excess
ELSE IF (W(8) > REST2) THEN ! Mg > 2*FRSO4+FRCL+FRNO3 ?
W(8) = (ONE-1D-6)*REST2 ! Adjust Mg amount
W(7)= ZERO ! Adjust K amount
CALL PUSHERR (0053, 'ISRP4F') ! Warning error: K, Mg in excess
ELSE IF (W(7) > REST3) THEN ! K > 2*FRSO4+FRCL+FRNO3 ?
W(7) = (ONE-1D-6)*REST3 ! Adjust K amount
CALL PUSHERR (0054, 'ISRP4F') ! Warning error: K in excess
ENDIF
ENDIF
! *** CALCULATE RATIOS *************************************************
SO4RAT = (W(1)+W(3)+W(6)+W(7)+W(8))/W(2)
CRNARAT = (W(1)+W(6)+W(7)+W(8))/W(2)
CRRAT = (W(6)+W(7)+W(8))/W(2)
! *** FIND CALCULATION REGIME FROM (SO4RAT, CRNARAT, CRRAT, RRH) ********
! *** SULFATE POOR: Rso4>2; (DUST + SODIUM) POOR: R(Cr+Na)<2
IF (2.0 <= SO4RAT .AND. CRNARAT < 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'O7'
CALL CALCO7 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4NO3) THEN
SCASE = 'O1'
CALL CALCO1 ! CaSO4, NH4NO3, NH4CL, (NH4)2SO4, MGSO4, NA2SO4, K2SO4
ELSEIF (DRNH4NO3 <= RH .AND. RH < DRNH4CL) THEN
SCASE = 'O2'
CALL CALCO2 ! CaSO4, NH4CL, (NH4)2SO4, MGSO4, NA2SO4, K2SO4
ELSEIF (DRNH4CL <= RH .AND. RH < DRNH42S4) THEN
SCASE = 'O3'
CALL CALCO3 ! CaSO4, (NH4)2SO4, MGSO4, NA2SO4, K2SO4
ELSEIF (DRNH42S4 <= RH .AND. RH < DRMGSO4) THEN
SCASE = 'O4'
CALL CALCO4 ! CaSO4, MGSO4, NA2SO4, K2SO4
ELSEIF (DRMGSO4 <= RH .AND. RH < DRNA2SO4) THEN
SCASE = 'O5'
CALL CALCO5 ! CaSO4, NA2SO4, K2SO4
ELSEIF (DRNA2SO4 <= RH .AND. RH < DRK2SO4) THEN
SCASE = 'O6'
CALL CALCO6 ! CaSO4, K2SO4
ELSEIF (DRK2SO4 <= RH) THEN
SCASE = 'O7'
CALL CALCO7 ! CaSO4
ENDIF
ENDIF
! *** SULFATE POOR: Rso4>2; (DUST + SODIUM) RICH: R(Cr+Na)>2; DUST POOR: Rcr<2.
ELSEIF (SO4RAT >= 2.0 .AND. CRNARAT >= 2.0) THEN
IF (CRRAT <= 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'M8'
CALL CALCM8 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4NO3) THEN
SCASE = 'M1'
CALL CALCM1 ! CaSO4, NH4NO3, NH4CL, MGSO4, NA2SO4, K2SO4, NACL, NANO3
ELSEIF (DRNH4NO3 <= RH .AND. RH < DRNANO3) THEN
SCASE = 'M2'
CALL CALCM2 ! CaSO4, NH4CL, MGSO4, NA2SO4, K2SO4, NACL, NANO3
ELSEIF (DRNANO3 <= RH .AND. RH < DRNACL) THEN
SCASE = 'M3'
CALL CALCM3 ! CaSO4, NH4CL, MGSO4, NA2SO4, K2SO4, NACL
ELSEIF (DRNACL <= RH .AND. RH < DRNH4Cl) THEN
SCASE = 'M4'
CALL CALCM4 ! CaSO4, NH4CL, MGSO4, NA2SO4, K2SO4
ELSEIF (DRNH4Cl <= RH .AND. RH < DRMGSO4) THEN
SCASE = 'M5'
CALL CALCM5 ! CaSO4, MGSO4, NA2SO4, K2SO4
ELSEIF (DRMGSO4 <= RH .AND. RH < DRNA2SO4) THEN
SCASE = 'M6'
CALL CALCM6 ! CaSO4, NA2SO4, K2SO4
ELSEIF (DRNA2SO4 <= RH .AND. RH < DRK2SO4) THEN
SCASE = 'M7'
CALL CALCM7 ! CaSO4, K2SO4
ELSEIF (DRK2SO4 <= RH) THEN
SCASE = 'M8'
CALL CALCM8 ! CaSO4
ENDIF
ENDIF
! CALL CALCHCO3
! *** SULFATE POOR: Rso4>2; (DUST + SODIUM) RICH: R(Cr+Na)>2; DUST POOR: Rcr<2.
ELSEIF (CRRAT > 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'P13'
CALL CALCP13 ! Only liquid (metastable)
ELSE
IF (RH < DRCACL2) THEN
SCASE = 'P1'
CALL CALCP1 ! CaSO4, CA(NO3)2, CACL2, K2SO4, KNO3, KCL, MGSO4,
! ! MG(NO3)2, MGCL2, NANO3, NACL, NH4NO3, NH4CL
ELSEIF (DRCACL2 <= RH .AND. RH < DRMGCL2) THEN
SCASE = 'P2'
CALL CALCP2 ! CaSO4, CA(NO3)2, K2SO4, KNO3, KCL, MGSO4,
! ! MG(NO3)2, MGCL2, NANO3, NACL, NH4NO3, NH4CL
ELSEIF (DRMGCL2 <= RH .AND. RH < DRCANO32) THEN
SCASE = 'P3'
CALL CALCP3 ! CaSO4, CA(NO3)2, K2SO4, KNO3, KCL, MGSO4,
! ! MG(NO3)2, NANO3, NACL, NH4NO3, NH4CL
ELSEIF (DRCANO32 <= RH .AND. RH < DRMGNO32) THEN
SCASE = 'P4'
CALL CALCP4 ! CaSO4, K2SO4, KNO3, KCL, MGSO4,
! ! MG(NO3)2, NANO3, NACL, NH4NO3, NH4CL
ELSEIF (DRMGNO32 <= RH .AND. RH < DRNH4NO3) THEN
SCASE = 'P5'
CALL CALCP5 ! CaSO4, K2SO4, KNO3, KCL, MGSO4,
! ! NANO3, NACL, NH4NO3, NH4CL
ELSEIF (DRNH4NO3 <= RH .AND. RH < DRNANO3) THEN
SCASE = 'P6'
CALL CALCP6 ! CaSO4, K2SO4, KNO3, KCL, MGSO4, NANO3, NACL, NH4CL
ELSEIF (DRNANO3 <= RH .AND. RH < DRNACL) THEN
SCASE = 'P7'
CALL CALCP7 ! CaSO4, K2SO4, KNO3, KCL, MGSO4, NACL, NH4CL
ELSEIF (DRNACL <= RH .AND. RH < DRNH4CL) THEN
SCASE = 'P8'
CALL CALCP8 ! CaSO4, K2SO4, KNO3, KCL, MGSO4, NH4CL
ELSEIF (DRNH4CL <= RH .AND. RH < DRKCL) THEN
SCASE = 'P9'
CALL CALCP9 ! CaSO4, K2SO4, KNO3, KCL, MGSO4
ELSEIF (DRKCL <= RH .AND. RH < DRMGSO4) THEN
SCASE = 'P10'
CALL CALCP10 ! CaSO4, K2SO4, KNO3, MGSO4
ELSEIF (DRMGSO4 <= RH .AND. RH < DRKNO3) THEN
SCASE = 'P11'
CALL CALCP11 ! CaSO4, K2SO4, KNO3
ELSEIF (DRKNO3 <= RH .AND. RH < DRK2SO4) THEN
SCASE = 'P12'
CALL CALCP12 ! CaSO4, K2SO4
ELSEIF (DRK2SO4 <= RH) THEN
SCASE = 'P13'
CALL CALCP13 ! CaSO4
ENDIF
ENDIF
! CALL CALCHCO3
ENDIF
! *** SULFATE RICH (NO ACID): 1<Rso4<2;
ELSEIF (1.0 <= SO4RAT .AND. SO4RAT < 2.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'L9'
CALL CALCL9 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4HS4) THEN
SCASE = 'L1'
CALL CALCL1 ! CASO4,K2SO4,MGSO4,KHSO4,NA2SO4,(NH4)2SO4,NAHSO4,NH4HSO4,LC
ELSEIF (DRNH4HS4 <= RH .AND. RH < DRNAHSO4) THEN
SCASE = 'L2'
CALL CALCL2 ! CASO4,K2SO4,MGSO4,KHSO4,NA2SO4,(NH4)2SO4,NAHSO4,LC
ELSEIF (DRNAHSO4 <= RH .AND. RH < DRLC) THEN
SCASE = 'L3'
CALL CALCL3 ! CASO4,K2SO4,MGSO4,KHSO4,NA2SO4,(NH4)2SO4,LC
ELSEIF (DRLC <= RH .AND. RH < DRNH42S4) THEN
SCASE = 'L4'
CALL CALCL4 ! CASO4,K2SO4,MGSO4,KHSO4,NA2SO4,(NH4)2SO4
ELSEIF (DRNH42S4 <= RH .AND. RH < DRKHSO4) THEN
SCASE = 'L5'
CALL CALCL5 ! CASO4,K2SO4,MGSO4,KHSO4,NA2SO4
ELSEIF (DRKHSO4 <= RH .AND. RH < DRMGSO4) THEN
SCASE = 'L6'
CALL CALCL6 ! CASO4,K2SO4,MGSO4,NA2SO4
ELSEIF (DRMGSO4 <= RH .AND. RH < DRNA2SO4) THEN
SCASE = 'L7'
CALL CALCL7 ! CASO4,K2SO4,NA2SO4
ELSEIF (DRNA2SO4 <= RH .AND. RH < DRK2SO4) THEN
SCASE = 'L8'
CALL CALCL8 ! CASO4,K2SO4
ELSEIF (DRK2SO4 <= RH) THEN
SCASE = 'L9'
CALL CALCL9 ! CaSO4
ENDIF
ENDIF
CALL CALCNHA ! MINOR SPECIES: HNO3, HCl
CALL CALCNH3 ! NH3
! *** SULFATE SUPER RICH (FREE ACID): Rso4<1;
ELSEIF (SO4RAT < 1.0) THEN
IF(METSTBL == 1) THEN
SCASE = 'K4'
CALL CALCK4 ! Only liquid (metastable)
ELSE
IF (RH < DRNH4HS4) THEN ! RH < 0.4
SCASE = 'K1'
CALL CALCK1 ! NH4HSO4,NAHSO4,KHSO4,CASO4
ELSEIF (DRNH4HS4 <= RH .AND. RH < DRNAHSO4) THEN
SCASE = 'K2'
CALL CALCK2 ! NAHSO4,KHSO4,CASO4
ELSEIF (DRNAHSO4 <= RH .AND. RH < DRKHSO4) THEN
SCASE = 'K3'
CALL CALCK3 ! KHSO4,CASO4 0.52 < RH < 0.86
ELSEIF (DRKHSO4 <= RH) THEN
SCASE = 'K4'
CALL CALCK4 ! CASO4
ENDIF
ENDIF
CALL CALCNHA ! MINOR SPECIES: HNO3, HCl
CALL CALCNH3 ! NH3
ENDIF
RETURN
END SUBROUTINE ISRP4F
!=======================================================================
! *** ISORROPIA CODE
! *** SUBROUTINE CALCA2
! *** CASE A2
! THE MAIN CHARACTERISTICS OF THIS REGIME ARE:
! 1. SULFATE POOR (SULRAT >= 2.0)
! 2. LIQUID AEROSOL PHASE ONLY POSSIBLE
! FOR CALCULATIONS, A BISECTION IS PERFORMED TOWARDS X, THE
! AMOUNT OF HYDROGEN IONS (H+) FOUND IN THE LIQUID PHASE.
! FOR EACH ESTIMATION OF H+, FUNCTION FUNCB2A CALCULATES THE
! CONCENTRATION OF IONS FROM THE NH3(GAS) - NH4+(LIQ) EQUILIBRIUM.
! ELECTRONEUTRALITY IS USED AS THE OBJECTIVE FUNCTION.
! *** COPYRIGHT 1996-2006, UNIVERSITY OF MIAMI, CARNEGIE MELLON UNIVERSITY,
! *** GEORGIA INSTITUTE OF TECHNOLOGY
! *** WRITTEN BY ATHANASIOS NENES
! *** UPDATED BY CHRISTOS FOUNTOUKIS
!=======================================================================
SUBROUTINE CALCA2
INCLUDE 'isrpia.inc'
! *** SETUP PARAMETERS ************************************************
CALAOU = .TRUE. ! Outer loop activity calculation flag
OMELO = TINY ! Low limit: SOLUTION IS VERY BASIC
OMEHI = 2.0D0*W(2) ! High limit: FROM NH4+ -> NH3(g) + H+(aq)
! *** CALCULATE WATER CONTENT *****************************************
MOLAL(5) = W(2)
MOLAL(6) = ZERO
CALL CALCMR
! *** INITIAL VALUES FOR BISECTION ************************************
X1 = OMEHI
Y1 = FUNCA2 (X1)
IF (ABS(Y1) <= EPS) RETURN
! *** ROOT TRACKING ; FOR THE RANGE OF HI AND LO **********************
DX = (OMEHI-OMELO)/FLOAT(NDIV)
DO 10 I=1,NDIV
X2 = MAX(X1-DX, OMELO)
Y2 = FUNCA2 (X2)
IF (SIGN(1.0,Y1)*SIGN(1.0,Y2) < ZERO) GOTO 20 ! (Y1*Y2 < ZERO)
X1 = X2
Y1 = Y2
10 END DO
IF (ABS(Y2) <= EPS) THEN
RETURN
ELSE
CALL PUSHERR (0001, 'CALCA2') ! WARNING ERROR: NO SOLUTION
RETURN
ENDIF
! *** PERFORM BISECTION ***********************************************
20 DO 30 I=1,MAXIT
X3 = 0.5*(X1+X2)
Y3 = FUNCA2 (X3)
IF (SIGN(1.0,Y1)*SIGN(1.0,Y3) <= ZERO) THEN ! (Y1*Y3 <= ZERO)
Y2 = Y3
X2 = X3
ELSE
Y1 = Y3
X1 = X3
ENDIF
IF (ABS(X2-X1) <= EPS*X1) GOTO 40
30 END DO
CALL PUSHERR (0002, 'CALCA2') ! WARNING ERROR: NO CONVERGENCE
! *** CONVERGED ; RETURN **********************************************
40 X3 = 0.5*(X1+X2)
Y3 = FUNCA2 (X3)
RETURN
! *** END OF SUBROUTINE CALCA2 ****************************************
END SUBROUTINE CALCA2
!=======================================================================
! *** ISORROPIA CODE
! *** FUNCTION FUNCA2
! *** CASE A2
! FUNCTION THAT SOLVES THE SYSTEM OF EQUATIONS FOR CASE A2 ;
! AND RETURNS THE VALUE OF THE ZEROED FUNCTION IN FUNCA2.
!=======================================================================
real FUNCTION FUNCA2 (OMEGI)
INCLUDE 'isrpia.inc'
real :: LAMDA
! *** SETUP PARAMETERS ************************************************
FRST = .TRUE.
CALAIN = .TRUE.
PSI = W(2) ! INITIAL AMOUNT OF (NH4)2SO4 IN SOLUTION
! *** SOLVE EQUATIONS ; WITH ITERATIONS FOR ACTIVITY COEF. ************
DO 10 I=1,NSWEEP
A1 = XK1*WATER/GAMA(7)*(GAMA(8)/GAMA(7))**2.
A2 = XK2*R*TEMP/XKW*(GAMA(8)/GAMA(9))**2.
A3 = XKW*RH*WATER*WATER
LAMDA = PSI/(A1/OMEGI+ONE)
ZETA = A3/OMEGI
! *** SPECIATION & WATER CONTENT ***************************************
MOLAL (1) = OMEGI ! HI
MOLAL (5) = MAX(PSI-LAMDA,TINY) ! SO4I
MOLAL (3) = MAX(W(3)/(ONE/A2/OMEGI + ONE), 2.*MOLAL(5)) ! NH4I
MOLAL (6) = LAMDA ! HSO4I
GNH3 = MAX (W(3)-MOLAL(3), TINY) ! NH3GI
COH = ZETA ! OHI
! *** CALCULATE ACTIVITIES OR TERMINATE INTERNAL LOOP *****************
IF (FRST .AND. CALAOU .OR. .NOT. FRST .AND. CALAIN) THEN
CALL CALCACT
ELSE
GOTO 20
ENDIF
10 END DO
! *** CALCULATE OBJECTIVE FUNCTION ************************************
20 DENOM = (2.0*MOLAL(5)+MOLAL(6))
FUNCA2= (MOLAL(3)/DENOM - ONE) + MOLAL(1)/DENOM
RETURN
! *** END OF FUNCTION FUNCA2 ********************************************
END FUNCTION FUNCA2
!=======================================================================
! *** ISORROPIA CODE
! *** SUBROUTINE CALCA1
! *** CASE A1
! THE MAIN CHARACTERISTICS OF THIS REGIME ARE:
! 1. SULFATE POOR (SULRAT > 2.0)
! 2. SOLID AEROSOL ONLY
! 3. SOLIDS POSSIBLE : (NH4)2SO4
! A SIMPLE MATERIAL BALANCE IS PERFORMED, AND THE SOLID (NH4)2SO4
! IS CALCULATED FROM THE SULFATES. THE EXCESS AMMONIA REMAINS IN
! THE GAS PHASE.
! *** COPYRIGHT 1996-2006, UNIVERSITY OF MIAMI, CARNEGIE MELLON UNIVERSITY,
! *** GEORGIA INSTITUTE OF TECHNOLOGY
! *** WRITTEN BY ATHANASIOS NENES
! *** UPDATED BY CHRISTOS FOUNTOUKIS
!=======================================================================
SUBROUTINE CALCA1
INCLUDE 'isrpia.inc'
CNH42S4 = W(2)
GNH3 = MAX (W(3)-2.0*CNH42S4, ZERO)
RETURN
! *** END OF SUBROUTINE CALCA1 ******************************************
END SUBROUTINE CALCA1
!=======================================================================
! *** ISORROPIA CODE
! *** SUBROUTINE CALCB4
! *** CASE B4
! THE MAIN CHARACTERISTICS OF THIS REGIME ARE:
! 1. SULFATE RICH, NO FREE ACID (1.0 <= SULRAT < 2.0)
! 2. LIQUID AEROSOL PHASE ONLY POSSIBLE
! FOR CALCULATIONS, A BISECTION IS PERFORMED WITH RESPECT TO H+.
! THE OBJECTIVE FUNCTION IS THE DIFFERENCE BETWEEN THE ESTIMATED H+
! AND THAT CALCULATED FROM ELECTRONEUTRALITY.
! *** COPYRIGHT 1996-2006, UNIVERSITY OF MIAMI, CARNEGIE MELLON UNIVERSITY,
! *** GEORGIA INSTITUTE OF TECHNOLOGY
! *** WRITTEN BY ATHANASIOS NENES
! *** UPDATED BY CHRISTOS FOUNTOUKIS
!=======================================================================
SUBROUTINE CALCB4
INCLUDE 'isrpia.inc'
! *** SOLVE EQUATIONS **************************************************
FRST = .TRUE.
CALAIN = .TRUE.
CALAOU = .TRUE.
! *** CALCULATE WATER CONTENT ******************************************
CALL CALCB1A ! GET DRY SALT CONTENT, AND USE FOR WATER.
MOLALR(13) = CLC
MOLALR(9) = CNH4HS4
MOLALR(4) = CNH42S4
CLC = ZERO
CNH4HS4 = ZERO
CNH42S4 = ZERO
WATER = MOLALR(13)/M0(13)+MOLALR(9)/M0(9)+MOLALR(4)/M0(4)
MOLAL(3) = W(3) ! NH4I
DO 20 I=1,NSWEEP
AK1 = XK1*((GAMA(8)/GAMA(7))**2.)*(WATER/GAMA(7))
BET = W(2)
GAM = MOLAL(3)
BB = BET + AK1 - GAM