-
Notifications
You must be signed in to change notification settings - Fork 23
/
PhotoMain.f
executable file
·3098 lines (2651 loc) · 104 KB
/
PhotoMain.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
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
PROGRAM PhotoMain
c
c- at some point go through and clean up all comments
c
c
c - this code contains the variable grid size changes used to compute
c - the suite of models for the whiff paper.
c - this code could/should be modified to use a variable grid size at some point
c - to make it faster all common blocks abstracted to DATA/INCLUDE
c - g77 will no longer work as there are some F90 built-ins being used
c see makefile for compilation syntax
cc
c-mc
c this code has iterated jacobian and batch multipliers
c-072406 - has 195K CO2 cross-section ! turned off for photo development
c-mc 080206 - iterated jacobion, new co2 x-section are turned off,TSTOP is 1e16
c-mc 112107 - iterated jacobians back in play for reruns of kevin's models for
c- the whiff paper
c-mc 111308 - iterated jacbians off for chlorine testing...
c-mc 010609 - iterated jacobians back on during chlorine testing...
c-mc THIS VERSION OF THE CODE WILL BE TIME-INDEPENDENT
c- (i.e. P,T,zenith angle remain constant) (or maybe not...)
c-mc things to research at some point
c CO photolysis
c - whats up with HO2 photolysis?
c- where is HNO2?
c the code reads in 4 files:
c aerosol.table
c photo.dat
c sulfur.rx
c in.dist
c fixed typo in molecular transport terms 8-13-05
c this version uses N, O3, and HNO3 as long-lived
c it does not use CO2 as long-lived. there problems be.
c I need to do some CO expts for MC and DC.
c but for giggles I am doing an experiment wiht big O2 and CH4 fluxes
c to see what happens
c this is hard to do if one uses O2 flux; it works better by setting
c the O2 mixing ratio
c some observations
c 1. problems with NOx at the upper boundary often means a problem with
c H escape; NOx problems often resolve themselves with patience...
c 2. getting lost often means a problem with H escape
c 3. problems with S also means that there is a problem with redox balance.
c update 6-23-05 inserts molecular diffusion of H
c looks good
c I added molecular diffusion for H2 and H.
c
c the more general equation would include the molecular diffusive flux
c \phi = b*f*({1/over H_A}-{1/over H}) - b*df/dz
c
c [ w_1 - w_2 = {b_{12}\over n} \left( (1/n_1)(dn_1/dz) - (1/n_2)(dn_2/dz)
c - (1/f)(df/dz) \right) ]
c (I've not been careful. here f=n_1/n_2 <<1, so n=n_2.
c I should look this up for the general case)
c
c where H would be the scale height in vacuum of the species corresponding
c to f and H_A is the scale height of the atmosphere.
c \phi = b*f*({1/over H_A}-{1/over H}) - (b+KN)*df/dz
c N df/dt = P - LNf - d\phi/dz - f*dN/dt
c I have not done the work to allow for N to change with time - so let dN/dt=0
c
c From this point hence one must be careful
c
C df/dt = P/N - L*f + (1/N)*d/dz[(K*N+b)*(df/dz)]
c + (b/N)*d/dz({1/over H}-{1/over H_A})f
c
c the finite difference form is
c
C df(j)/dt = P(j)/N(j) + (DU(j) +ADU(j))*f(j+1)
c + (DL(j) +ADL(j))*f(j-1) - (DD(j) + ADD(j) + L(j)) *f(j)
c
c where
c DU(j) = [KN(j+) + b(j+)]/[N(j)*dz*dz]
c ADU(j) = +b(j+)/[2N(j)*dz] *({1/over H} - {1/over H_A})
c DL(j) = [KN(j-) + b(j-)]/[N(j)*dz*dz]
c ADL(j) = -b(j-)/[2N(j)*dz] *({1/over H} - {1/over H_A})
c DD(j) = DU(j) + DL(j)
c ADD(j) = -ADU(j) - ADL(j)
c at the lower boundary
c
C df(0)/dt = P(0)/N(0) + DU(0)*(f(1)-f(0)) + ADU(0)*(f(1)+f(0))
c + FLUX(0)/N(0)/dz
c where
c DU(0) = [KN(0.5) + b(0.5)]/[N(0)*dz*dz]
c ADU(0) = +b(0.5)/[2N(0)*dz] *({1/over H} - {1/over H_A})
c in constant flux
c djac(0) = chemistry(0) + 1/dt + DU(0) - ADU(0)
c djac(1) = - DU(0) - ADU(0) (off diagonal)
c
c in constant vdep
c djac(0) = chemistry(0) + 1/dt + DU(0) - ADU(0) + vdep/dz
c djac(1) = - DU(0) - ADU(0) (off diagonal)
c
c in constant mixing ratio - i've left the chemistry out...
c djac(0) = 1/dt + DU(0) - ADU(0)
c djac(1) = 0.0 (off diagonal - is this correct??
c - it may not be, but it should not matter given that it can't change f)
c
c
c at the upper boundary:
C df(nz)/dt = P(nz)/N(nz) + DL(nz)*(f(nz)-f(nz-1))
c + ADL(nz)*(f(nz)+f(nz-1)) - FLUX(nz)/N(nz)/dz
c where
c DL(nz) = [KN(nz-0.5) + b(nz-0.5)]/[N(nz)*dz*dz]
c ADL(nz) = +b(nz-0.5)/[2N(nz)*dz] *({1/over H} - {1/over H_A})
c
c in constant flux
c djac(nz) = chemistry(nz) + 1/dt + DL(nz) - ADL(nz)
c djac(nz-1) = - DL(nz) - ADL(nz) (off diagonal)
c
c in constant veff
c djac(nz) = chemistry(nz) + 1/dt + DL(nz) - ADL(nz) + veff/dz
c djac(nz-1) = - DL(nz) - ADL(nz) (off diagonal)
c
c in zero mixing ratio gradient (df/dz=0) (I've never used this...)
c this turns out to be exactly the same as constant veff with
c veff == +b(nz+0.5)/[ N(nz)*dz] *({1/over H} - {1/over H_A})
c
c
c - what Jim did was to set the gradient of the H, H2 mixing ratios
c to zero at the top (no flux upper boundary).
c This does a better job with the chemistry.
c i've left this intact for ch4co2.for
c
c
c- 4-25-05 jfk suggests distributing SO2 source over the troposphere
c this way i can use a surface BC
c This was implemented successfully
c
c 4-27-05 FIXED the accounting errors with fluxes.
c the tridiagonal was not being included in the accounting
c I wasn't sure how to do this save by putting S8aer into long lived species
c This has now been done. Fluxes are now under control.
c redox balance and S conservation are both enforced. Fundamentally
c nothing has really changed, but it has the advantage of being done right.
c checked reactions 4/11/05
c HSO is problematic - very few known reactions.
c It does not react with O2
c I have also likely over-estimated abstraction by S
c CH3OH, C2H4, and C2H2 are missed in the chemical scheme
c and would need to return if CH4 is made big
c to use this for Mars I need to make SO3 a long-lived species
c while making S, S2, S4, and S8 short-lived if possible
c program does not work well.
c it gets lost on CO, which wanders all over the place...
c jim suggests that I need to do H2 better
c I think he is right.
c I need to add OCS and treat CO2 as free
c I have a lot of OCS reactions...
c for giggles I added fictional reaction
c SO3 CO -> CO2 SO2 1.00E-19
c
c to add OCS, I'd want these (taken from hncos.f)
c I'd also want to find out if S + CO can go...
c H OCS CO HS 9.10E-12 0.00 1940.0 0.0 0.0
c HS CO OCS H 5.95E-14 1.12 8330.0 0.0 0.0
c O OCS CO SO 7.83E-11 0.00 2620.0 0.0 0.0
c O OCS S CO2 8.33E-11 0.0 5.53E+03 0.0 0.0
c OCS S CO S2 1.00E-10 0.0 4.56E+03 0.0 0.0
c OCS OH CO2 HS 1.10E-13 0.0 1.20E+03 0.0 0.0
c S HCO OCS H 6.00E-11 0.0 0.0 0.0 0.0
c OCS HV CO S
c and...
c S CO OCS 1.70E-33 0.0 1.51E+03 1.0 0.0
c I'm guessing that S + CO goes at the same rate as O + CO
c the current version has the fictional
c SO3 CO CO2 SO2 1.00E-16 0.0 0.0 0.0 0.0
C THIS PROGRAM DIFFERS FROM PRIMS2 BY EXPLICITLY INCLUDING VAPOR
C PHASE S8. IT WAS USED TO GENERATE THE RESULTS FOR THE UV SCREEN
C PAPER AT 2 BARS OF CO2.
c-mc the above needs to be exorcised...
C THIS PROGRAM IS DESIGNED FOR EXTREMELY LOW (PRE-PHOTOSYNTHETIC
C O2 LEVELS. THE PHOTOLYSIS OF O2 IN THE SCHUMANN-RUNGE BANDS CAN
C BE CALCULATED EITHER BY THE METHOD OF ALLEN AND FREDERICK OR BY
C EXPONENTIAL SUMS. THE LATTER METHOD SHOULD BE USED FOR LOW-O2
C ATMOSPHERES (I.E. USE IO2 = 1). LIKEWISE, NO PHOTOLYSIS SHOULD
C BE CALCULATED USING THE CIESLIK AND NICOLET METHOD (INO = 1),
C WHICH HAS BEEN MODIFIED TO AGREE WITH THE BAND INTENSITIES OF
C FREDERICK AND HUDSON (1979).
C THIS VERSION OF THE PROGRAM HAS A NEW OPTION FOR INCLUDING
C TRANSPORT OF SPECIES THAT ONE DOES NOT WISH TO INCLUDE IN THE BIG
C REVERSE EULER MATRIX. THEY CAN BE SOLVED SEPARATELY USING A TRI-
C DIAGONAL INVERSION METHOD. S8 PARTICLES ARE TREATED THIS WAY IN
C THIS PROGRAM BECAUSE THEY ARE VIRTUALLY NON-EXISTENT UP HIGH.
C THE TOP OF THE TRIDIAGONAL MATRIX IS AT GRID POINT MZ, WHICH CAN
C BE SET EQUAL TO OR LESS THAN NZ.
C
C THIS PROGRAM IS A ONE-DIMENSIONAL MODEL OF THE PRIMORDIAL
C ATMOSPHERE. THE MIXING RATIOS OF THE LONG-LIVED SPECIES
C ARE CALCULATED FROM THE EQUATION
C
C DF/DT = (1/N)*D/DZ(KN*DF/DZ + WNF) + P/N - LF
C
C WHERE
C F = MIXING RATIO (USOL)
C K = EDDY DIFFUSION COEFFICIENT (EDD)
C N = TOTAL NUMBER DENSITY (DEN)
C L = CHEMICAL LOSS FREQUENCY (XL)
C P = CHEMICAL PRODUCTION RATE (XP)
C W = FALL VELOCITY (WFALL) FOR PARTICLES, POSITIVE DOWNWARD (ALL
C FLUXES, BY CONTRAST, ARE POSITIVE UPWARD)
C
C TWO TYPES OF PARTICLES ARE INCLUDED: SULFATE (SO4AER) AND
C ELEMENTAL SULFUR (S8AER). SULFATE IS INCLUDED IN THE BIG MATRIX,
C WHEREAS S8 IS TREATED SEPARATELY. THE PARTICLES ARE ASSUMED TO
C BE 0.1 UM IN RADIUS UP HIGH; THEY GET BIGGER AT LOW ALTITUDES BE-
C CAUSE OF COAGULATION. THIS IS DONE CRUDELY, BASED ON A COMPARISON
C OF THE RELATIVE LIFETIMES AGAINST DIFFUSION, SEDIMENTATION, AND
C RAINOUT.
C
C THE SYSTEM OF PDES IS SOLVED USING THE REVERSE EULER
C METHOD. LETTING THE TIME STEP GO TO INFINITY GIVES YOU NEWTONS
C METHOD, E.G. IT REVERTS TO AN EFFICIENT STEADY-STATE SOLVER.
C
C THE LIST OF SUBROUTINES IS AS FOLLOWS:
C (1) GRID - SETS UP THE ALTITUDE GRID
C (2) RATES - DEFINES CHEMICAL REACTION RATES AND RAINOUT RATE
C (3) RAINOUT - COMPUTES RAINOUT RATES USING THE METHOD OF GIORGI
C AND CHAMEIDES (1985)
C (3.1) AQUEOUS - DOES RAINWATER CHEMISTRY (CALLED BY RAINOUT)
c-mc Initphoto sets wl grid and cross-sections
c-mc Initmie read scattering params
c-mc should fill this out at some point
C (3.2) PHOTO - COMPUTES PHOTOLYSIS RATES (CALLS MSCAT)
C (3.3) O3PHOT - COMPUTES COEFFICIENTS USED TO FIND O(1D) QUANTUM
C YIELDS IN O3 PHOTOLYSIS
c-mc the above is no longer used...
C (4) DENSTY - COMPUTES ATMOSPHERIC NUMBER DENSITIES FROM HYDRO-
C STATIC EQUILIBRIUM
C (5) DIFCO - COMPUTES DK = K*N BETWEEN GRID POINTS; ALSO FINDS
C DIFFUSION LIFETIMES H*H/K
C (5.1) SEDMNT - CALCULATES FALL VELOCITIES AND ESTIMATES PARTICLE
C SIZES
C (5.2) SATRAT - COMPUTES SATURATION H2O MIXING RATIOS AT ALL HEIGHTS
C FINDS MANABE/WETHERALD RH DISTRIBUTION IN TROPOSPHERE
C (5.3) AERTAB - READS PAT HAMILL'S H2SO4 TABLE AND CALCULATES VAPOR
C PRESSURES OF H2O AND H2SO4 AT EACH HEIGHT AS A FUNC-
C TION OF SULFATE CONTENT OF THE PARTICLES
C (5.4) AERCON - FINDS WEIGHT PERCENT OF H2SO4 IN SULFATE PARTICLES
C ALONG WITH H2SO4 VAPOR PRESSURE, GIVEN T AND H2O AT
C EACH HEIGHT
C (6) OUTPUT - PRINTS OUT RESULTS
C (7) DOCHEM - DOES CHEMISTRY FOR ALL SPECIES AT ALL GRID
C POINTS BY CALLING CHEMPL
C (8) CHEMPL - COMPUTES CHEMICAL PRODUCTION AND LOSS RATES
C FOR ONE SPECIES AT ALL GRID POINTS
C (9) LTNING - COMPUTES LIGHTNING PRODUCTION RATES FOR O2 AND
C N2 BASED ON CHAMEIDES' RESULTS
C (11) MSCAT - DOES RAYLEIGH SCATTERING USING YUK YUNG'S TECHNIQUE
C
C OTHER DEFINED FUNCTIONS INCLUDE:
C (1) TBDY - COMPUTES 3-BODY REACTION RATES
C (2) E1 - EXPONENTIAL INTEGRAL OF ORDER ONE
c - some of Kevin's notes on possible reactions
c-keeping around for the time when more research is done on the chemical species
C 9.6e-12. HSO2 is not a species in this system - it reacts quickly with O2
C ) HSO + NO2 -> NO + HSO2
C this has measured but very slow reaction
c ) H + SO2 + M -> HSO2 + M
C 3e-13 measured HO2 as product. not a clear situation;
c - my temptation is to assign OH, H rates measured at high T
c ) HSO2 + O2 -> HO2 + SO2
c RATE: 3e-12
c ) HSO2 + H -> H2 + SO2
c RATE: 8e-12
c ) HSO2 + OH -> H2O + SO2
C JPL has this! but what do you do with it??
c ) HS + NO + M -> HSNO + M
C NIST 2e-12*exp(-1000/T)
c ) HCO + HNO -> H2CO + NO
C
C NIST - v. fast: 2.5e-27*(298/T)^-3.8, 1.5e-10 limit
C ) CH3 + OH + M -> CH3OH + M
C ) CH3 + OH -> H2O + CH2 ! NIST 1.2e-10 *exp(-1400/T)
C ) CH3 + OH -> HCOH + H2 ! NIST 9e-11 *exp(-1500/T)
C ) CH3 + OH -> H2COH + H ! NIST 1.3e-11
c ) S2 + H + M -> HS2 + M
c ) S2 + OH -> ! SO +OH -> H + SO2 8.6e-11
c ) S3 + OH ->
c ) S3 + O -> SO + S2
c ) S3 + H + M -> HS3 + M
c ) S4 + OH ->
c ) S4 + O -> SO + S3
c ) S4 + H + M -> HS4 + M
c ) HS2 + OH -> H2O + S2
c ) HS2 + O -> OH + S2
c ) HS2 + H -> H2 + S2
c ) HS2 + S -> H + S3
c etc.
C
C THIS PROGRAM DOES THE CHEMISTRY AUTOMATICALLY.
C THE CHEMICAL
C REACTIONS ARE ENTERED ON DATA CARDS IN FIVE 10-DIGIT COLUMNS
C STARTING IN COLUMN 11, I.E.
C
C REAC1 REAC2 PROD1 PROD2 PROD3
C
C THE IMPORTANT PARAMETERS DESCRIBING THE CHEMISTRY ARE
C NR = NUMBER OF REACTIONS
C NSP = NUMBER OF CHEMICAL SPECIES
C NSP1 = NSP + 1 (INCLUDES HV)
C NSP2 = NSP + 2 (INCLUDES M)
C NQ = NUMBER OF SPECIES FOR WHICH A DIFFUSION EQUATION
C IS SOLVED AND WHICH ARE IN THE BIG, REVERSE EULER MATRIX
C NQ1 = TOTAL NUMBER OF SPECIES FOR WHICH TRANSPORT IS INCLUDED
C (THOSE NOT IN THE BIG MATRIX ARE SOLVED WITH A STEADY-STATE
C TRIDIAGONAL INVERSION METHOD)
C NMAX = MAXIMUM NUMBER OF REACTIONS IN WHICH AN INDIVIDUAL
C SPECIES PARTICIPATES
C
C PHOTOLYSIS REACTIONS ARE IDENTIFIED BY THE SYMBOL HV (NOT
C COUNTED IN EVALUATING NSP). THREE-BODY REACTIONS ARE WRITTEN
C IN TWO-BODY FORM, SO THE DENSITY FACTOR MUST BE INCLUDED IN
C THE RATE CONSTANT.
C THE CHEMICAL REACTION SCHEME IS STORED IN THE FOLLOWING MATRICE
C
C ISPEC(NSP2) = VECTOR CONTAINING THE character NAMES OF THE
C CHEMICAL SPECIES. THE LAST TWO ENTRIES ARE HV AND M.
C CHEMJ(5,NR) = MATRIX OF CHEMICAL REACTIONS (chars). THE FIRST TWO ARE
C REACTANTS, THE LAST THREE ARE PRODUCTS.
C JCHEM(5,NR) = MATRIX OF CHEMICAL REACTIONS (indexed). THE FIRST TWO ARE
C REACTANTS, THE LAST THREE ARE PRODUCTS.
C ILOSS(2,NSP,NMAX) = MATRIX OF LOSS PROCESSES. ILOSS(1,I,L)
C HOLDS REACTION NUMBER J, ILOSS(2,I,L) HOLDS
C REACTANT NUMBER.
C IPROD(NSP,NMAX) = MATRIX OF PRODUCTION PROCESSES. IPROD(I,L)
C HOLDS REACTION NUMBER J.
C NUML(NSP) = NUMBER OF NON-ZERO ELEMENTS FOR EACH ROW OF ILOSS
C NUMP(NSP) = NUMBER OF NON-ZERO ELEMENTS FOR EACH ROW OF IPROD
C
INCLUDE 'PHOTOCHEM/INPUTFILES/parameters.inc'
implicit real*8(A-H,O-Z)
character*10 buffer
character*8 pstar
CHARACTER*8 ISPEC, CHEMJ,SPECIES,SPECTYPE,REACTYPE,PLANET
CHARACTER*20 string,fmtstr,fmtstr2
real*8 mass
DIMENSION FVAL(NQ,NZ),FV(NQ,NZ),DJAC(LDA,NEQ),RHS(NEQ),IPVT(NEQ)
dimension SMFLUX(NQ),SGFLUX(NQ),VDEP(NQ),VEFF(NQ)
dimension DD(NQ1,NZ),DL(NQ1,NZ),DU(NQ1,NZ)
dimension ADL(NQ,NZ), ADU(NQ,NZ), ADD(NQ,NZ)
dimension USAVE(NQ,NZ),R(NZ),U(NQ),VDEP0(NQ),VEFF0(NQ)
dimension USAVEOLD(NQ,NZ), USOLPREV(NQ,NZ)
dimension USOLORIG(NQ,NZ)
dimension alt_new(NZ), T_new(NZ), water(NZ)
dimension alt_dontuse(NZ), T_dontuse(NZ), water_fix(NZ)
Cc-mc USOLSAVE added for convergence testing 4/29/06,
Cc-mc removed from code on 2/28/07
Cc-mc going to keep declaration here and reserve it in case I ever bring back
Cc-mc the convergence-testing code, which is r37:36 in the /td branch
Cc-mc USOLPREV(NQ,NZ) added for second order reverse Euler calculations
DIMENSION DPU(NZ,NP),DPL(NZ,NP)
DIMENSION TA(NZ),TB(NZ),TC(NZ),TY(NZ)
dimension PRES_bar(NZ)
integer rhOcount,rhHcount,rhCcount,rhScount,rhNcount,rhCLcount
c dimension atomsO(NSP2),atomsH(NSP2),atomsC(NSP2)
c dimension atomsN(NSP2),atomsCL(NSP2),atomsS(NSP2)
!temp
dimension testvec(NR),fixedmr(nq)
dimension distheight(nq)
CHARACTER*11 photolabel, AA
CHARACTER*8 AX
LOGICAL newphot
c for sgbco testing (to get at Jacobian condition number)
c real*8 RCOND
c real*8 WORK(neq)
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/PHOTABLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/BBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/CBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/DBLOK.inc'
C !can go away when MSCAT does WARNING DO WE NEED THIS COMMENT
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/EBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/FBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/GBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/JBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/NBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/RBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/SBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/ZBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/LTBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/AERBLK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/SULBLK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/SATBLK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/PBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/QBLOK.inc'
INCLUDE 'PHOTOCHEM/DATA/INCLUDE/comPRESS1.inc'
C CONSTANTS FOR 1ST EXPONENTIAL INTEGRAL !can go away when MSCAT does
C -WARNING do we need can go away comment?
DATA AI/.99999193, -.24991055, .05519968, -.00976004,
2 .00107857, -.57721566/
DATA BI/8.5733287401, 18.0590169730, 8.6347608925,
2 .2677737343/
DATA CI/9.5733223454, 25.6329561486, 21.0996530827,
2 3.9584969228/
DATA NUML,NUMP/NSP*0,NSP*0/
c OPEN FILES
C ,form='UNFORMATTED')
open(2, file='PHOTOCHEM/DATA/aerosol.table',status='OLD')
open(3, file='PHOTOCHEM/DATA/photo.dat',status='OLD')
open(4, file='PHOTOCHEM/INPUTFILES/species.dat',status='OLD')
!planet parameters (G, FSCALE, ALB,ZTROP,etc)
open(7, file='PHOTOCHEM/INPUTFILES/PLANET.dat',status='OLD')
C Model Parameters (AGL, IO2,INO, LGRID, etc)
open(231, file='PHOTOCHEM/INPUTFILES/input_photchem.dat',
& status='OLD')
open(15, file='PHOTOCHEM/OUTPUT/int.rates.out',status='UNKNOWN')
C ^ formatted rates.f
C REACTION FILE
open(9, file='PHOTOCHEM/INPUTFILES/reactions.rx',status='OLD')
C CODE OUTPUT
open(14, file='PHOTOCHEM/OUTPUT/out.out',status='UNKNOWN')
C FORMATTED INPUT
open(17, file='PHOTOCHEM/in.dist',status='OLD')
C FORMATTED OUTPUT
open(18, file='PHOTOCHEM/OUTPUT/out.dist',status='UNKNOWN')
open(34, file='PHOTOCHEM/PTZ_mixingratios_in.dist',
& status='UNKNOWN')
open(35, file='PHOTOCHEM/OUTPUT/PTZ_mixingratios_out.dist',
& status='UNKNOWN')
C TERSE OUTPUT
open(19, file='PHOTOCHEM/OUTPUT/out.terse',status='UNKNOWN')
C PARTIAL OUTPUT OF MIXING RATIOS
open(67, file='PHOTOCHEM/OUTPUT/profile.pt',status='UNKNOWN')
C HYDROCARBONS
open(68, file='PHOTOCHEM/OUTPUT/hcaer.out',status='UNKNOWN')
C OTHER HYDROCARBONS
open(69, file='PHOTOCHEM/OUTPUT/hcaer2.out',status='UNKNOWN')
C VERY TERSE OUTPUT
open(21, file='PHOTOCHEM/OUTPUT/out.trs',status='UNKNOWN')
C TIME OUTPUTS
open(23, file='PHOTOCHEM/OUTPUT/out.time',status='UNKNOWN')
open(24, file='PHOTOCHEM/OUTPUT/out.tim',status='UNKNOWN')
C-AVB,MAB Final Output for P, T, Z and species fluxes (to be added)
open(255, file='PHOTOCHEM/OUTPUT/PTZ_out.flux')
c-mc
C redox output - eventually combine into out.trs
open(25, file='PHOTOCHEM/OUTPUT/out.redox',status='UNKNOWN')
C Temporary output file for looking at convergence
C in the reverse Euler iteration
open(26, file='PHOTOCHEM/OUTPUT/out.converge',status='UNKNOWN')
C Printing out relevant SO2 photolysis pieces
C between 190-220 as MIF signature
open(27, file='PHOTOCHEM/OUTPUT/out.so2',status='UNKNOWN')
C Reaction rates,reactions,species,densities,rate constants
open(28, file='PHOTOCHEM/OUTPUT/out.rates',status='UNKNOWN')
C FOLLOWING ARE CROSS SECTIONS, HEIGHT GRID, WAVELENGTH GRID:
open(29, file='PHOTOCHEM/OUTPUT/out.xsec',status='UNKNOWN')
open(30, file='PHOTOCHEM/OUTPUT/out.gridz',status='UNKNOWN')
open(31, file='PHOTOCHEM/OUTPUT/out.gridw',status='UNKNOWN')
c-mc unit 33 reserved for wavelength grids...
open(41, file='PHOTOCHEM/OUTPUT/out.rad',status='UNKNOWN')
C File below should contain TATLTUAE
open(42, file='PHOTOCHEM/OUTPUT/out.finalden',status='UNKNOWN')
C Number densities at each timestep
open(43, file='PHOTOCHEM/OUTPUT/out.densities',status='UNKNOWN')
C Total production and loss at steady state
open(44, file='PHOTOCHEM/OUTPUT/out.prod',status='UNKNOWN')
C Fluxes
open(45, file='PHOTOCHEM/OUTPUT/out.flux',status='UNKNOWN')
C tau=1 (at final step) in out.tau
open(48, file='PHOTOCHEM/OUTPUT/out.tau',status='UNKNOWN')
C Some model parameters
open(49, file='PHOTOCHEM/OUTPUT/out.params',status='UNKNOWN')
C NGE and L2 are normally between start and finish
open(50, file='PHOTOCHEM/OUTPUT/out.error',status='UNKNOWN')
C TP/FLOW for chlorine species,nitrate, adn sulfate
open(51, file='PHOTOCHEM/OUTPUT/out.cl',status='UNKNOWN')
C For testing O2 prates with various grid sizes
open(58, file='PHOTOCHEM/OUTPUT/out.O2prates',status='UNKNOWN')
C rainggc out - ISOHACK
open(59, file='PHOTOCHEM/OUTPUT/out.raingc',status='UNKNOWN')
!c-mc 60 and 61 are opened below after LGRID is read in
C lower boundary fluxes (not including rainout)
open(62, file='PHOTOCHEM/OUTPUT/out.flow',status='UNKNOWN')
C Haze optical depths
open(63, file='PHOTOCHEM/OUTPUT/out.od',status='UNKNOWN')
C Haze TOA and sur rpar
open(73, file='PHOTOCHEM/OUTPUT/out.rp',status='UNKNOWN')
C - This file gives the input needed for SMART - radiative transfer code
c-mab: Commenting out smart inputs for now. (11/4/2016)
c open(159, file='photochem_smart/photchem/photfile.pt',
c & status='UNKNOWN')
c open(164, file='photochem_smart/atm/tag.atm',
c & status='UNKNOWN')
C - Seperating the out.dist file into seperate files
open(70, file='PHOTOCHEM/OUTPUT/out.chem', status='UNKNOWN')
open(66, file='PHOTOCHEM/OUTPUT/out.strctr', status='UNKNOWN')
open(71, file='PHOTOCHEM/OUTPUT/out.aersol', status='UNKNOWN')
open(72, file='PHOTOCHEM/OUTPUT/out.tridag', status='UNKNOWN')
open(80, file='PHOTOCHEM/OUTPUT/nsteps.out', status='UNKNOWN')
C - other model parameters read in from input_photochem.dat
READ(231,555)
if(IDEBUG.eq.1) print *, "input_photochem.dat data:"
READ(231,*)AA,AGL
IF(IDEBUG.eq.1) print *, "AGL =",AGL
READ(231,*)AA,ISEASON
IF(IDEBUG.eq.1) print *, "ISEASON =",ISEASON
READ(231,*)AA,IZYO2
IF(IDEBUG.eq.1) print *, "IZYO2 =",IZYO2
READ(231,*)AA,LGRID
IF(IDEBUG.eq.1) print *, "LGRID =",LGRID
READ(231,*)AA,IO2
IF(IDEBUG.eq.1) print *, "IO2 =",IO2
READ(231,*)AA,INO
IF(IDEBUG.eq.1) print *, "INO =",INO
READ(231,*)AA,EPSJ
IF(IDEBUG.eq.1) print *, "EPSJ =",EPSJ
READ(231,*)AA,PRONO
IF(IDEBUG.eq.1) print *, "PRONO =",PRONO
READ(231,*)AA,frak
IF(IDEBUG.eq.1) print *, "frak =",frak
READ(231,*)AA,HCDENS
IF(IDEBUG.eq.1) print *, "HCDENS =",HCDENS
READ(231,*)AA, ICOUPLE
IF(IDEBUG.eq.1) print *, "ICOUPLE =",ICOUPLE
READ(231,*)AA, ihztype
IF(IDEBUG.eq.1) print *, "IHZTYPE =",ihztype
READ(231,*)AA, ZY
IF(IDEBUG.eq.1) print *, "ZY =",ZY
READ(231,*)AA, USOLMIN
IF(IDEBUG.eq.1) print *, "USOLMIN =",USOLMIN
READ(231,*)AA, KIDA
IF(IDEBUG.eq.1) print *, "KIDA =",KIDA
555 format(3/)
close(231)
C NO photolysis rates output
if (LGRID.EQ.0) open(60, file='PHOTOCHEM/OUTPUT/out.NOprates',
& status='UNKNOWN')
C Wavelength specific SO2 photorates on HR grid
if (LGRID.EQ.1) open(61, file='PHOTOCHEM/OUTPUT/out.so2HR',
& status='UNKNOWN')
c The next four files are used when this model is coupled
C with the climate model (ICOUPLE=1)
C To be used as input for the climate model
C they are created and updated regardless of whether ICOUPLE=1 in input_photochem
open(90, file='COUPLE/hcaer.photoout.out',status='UNKNOWN')
open(84, file='COUPLE/fromPhoto2Clima.dat', status='UNKNOWN')
open(116, file='COUPLE/fromClima2Photo.dat', status='UNKNOWN')
open(117, file='COUPLE/mixing_ratios.dat', status='UNKNOWN')
open(118, file='COUPLE/aux_p_couple.dat', status='UNKNOWN') ! STB - auxiliary coupling file for RH_surf calculation according to Ramirez et al. 2014
C - READ IN SPECIES NAMES, ATOMIC NUMBERS, AND BOUNDARY CONDITIONS
C counter for long lived species
iLL=0
C counter for short lived species
iSL=0
C counter for tridiagonal species
iTD=0
C counter for inert species
iIN=0
C counter for number of lines in species.dat file
iSP=0
C So the species.dat statements print only once
iprint = 0
do while (I.LT.300)
C Note: Below will crash if species.dat is longer than 300 lines.
read(4,*, end=96) SPECIES,SPECTYPE
if (scan(species,'*').LT.1) then ! else ignore comments in species.dat file (lines that start with *)
iSP=iSP+1
ISPEC(iSP)=species
! print *, iSP, species
C This loads the "Lnumbers" for ease of use later in the code
call LNUM(ISPEC(isP),iSP)
C Return to previous line in species.dat file
backspace 4
C read in atmoic number data, NEVER use LC,LH,LN,LO,LS as placeholders
C as they mean something else...
read(4,*) AX,AX,LA,LB,LD,LE,LF,LM
if (SPECTYPE.EQ.'LL') then
iLL=iLL+1
C Return to previous line in species.dat file
backspace 4
C This section reads in the boundary conditions from species.dat.
C Note this now uses non-fixed formatting! :-D
read(4,*) AX,AX,LX,LX,LX,LX,LX,LX,LBC,XX,YY,ZZ,XXX,LG
& ,YYY,ZZZ
! print *, LBC
LBOUND(iLL)=LBC
VDEP0(iLL)=XX
FIXEDMR(iLL)=YY
if (LBOUND(iLL).eq.3) then
C distributed flux
distflux(iLL)=ZZ
else
C lower boundary flux
SGFLUX(iLL)=ZZ
endif
distheight(iLL)=XXX
MBOUND(iLL)=LG
SMFLUX(iLL)=YYY
VEFF0(iLL)=ZZZ
C CO2 only works as fixed mixing ratio. This could be handled better.
C-mab: What does above comment mean? It is NOT fixed/inert in my giant templates...
if (species.EQ.'CO2') FCO2=YY
endif
if (SPECTYPE.EQ.'IN') then
iIN=iIN+1
C Returns to previous line in species.dat file
backspace 4
C Reads in fixed mixing ratios
read(4,*) AX,AX,LX,LX,LX,LX,LX,LX,XX !read in fixed mixing ratios
C Hardcoding woohoo! need to do N2 as well WARNING
if (species.EQ.'HE') FHE=XX
if (species.EQ.'CO2') FCO2=XX
if (species.EQ.'N2') FN2=XX
endif
if (SPECTYPE.EQ.'TD')iTD=iTD+1
if (SPECTYPE.EQ.'SL') iSL=iSL+1
if (SPECTYPE.EQ.'HV') iIN=iIN+1
if (SPECTYPE.EQ.'M') iIN=iIN+1
atomsO(iLL+iTD+iSL+iIN)=LA
atomsH(iLL+iTD+iSL+iIN)=LB
atomsC(iLL+iTD+iSL+iIN)=LD
atomsS(iLL+iTD+iSL+iIN)=LE
atomsN(iLL+iTD+iSL+iIN)=LF
atomsCL(iLL+iTD+iSL+iIN)=LM
endif
I=I+1
enddo
C format for species name and type
203 FORMAT(A8,3X,A2)
C format for elemental counts
207 format(15X,6(I1,1X))
206 format(15X,6(I2,1X))
C-mab format for two-column elemental count
C FOLLOWING FORMATS BELOW ARE FOR BOUNDARY CONDITIONS
!Original boundary conditions
C 208 format(30X,I1,5X,4(E7.1,1X),I1,6X,2(E7.1,1X))
208 format(30X,I1,5X,2(E8.2,1X),E9.3,1X,E7.1,1X,I1,6X,2(E7.1,1X))
210 format(30X,I1,5X,2(E7.1,1X),E9.3,1X,E7.1,1X,I1,6X,2(E7.1,1X))
211 format(30X,I1,5X,E8.2,1X,E11.2,1X,E9.3,1X,E7.1,1X,I1,6X,2E8.1)
C Above - 211 - added as boundary conditions for Hot Jupiters
c 208 format(30X,I1,5X,2(E8.1),E9.3,1X,E7.1,1X,I1,6X,2(E7.1,1X))
C Format for INERT species boundary conditions
209 format(30X,E7.1)
212 format(30X,F7.5) !for INERT species boundary conditions
96 CONTINUE
c stop
C so far, the only use of mass in Difco,where it is summed over NQ,
C -so it would be OK to go higher
C Below are molecular weights (NQ1)
mass=atomsO*16.+atomsH*1.+atomsC*12.+atomsS*32.+atomsN*14.
$ + atomsCL*34.
C !we are setting CLO as 'neutral"
C !redoxstate goes from 1-NQ1 in Output
redoxstate = atomsO*1.0 + atomsH*(-0.5) + atomsS*(-2.) +
$ atomsCL*(-1.0) + atomsC*(-2) !N=0
c print *, redoxstate
c print *, fixedmr
c print *, sgflux
c print *, distflux
c print *, distheight
c stop
if (iTD.gt.0) then
USETD=1
print *, 'using tri-diagonal solver for particles'
print *, 'redox and sulfur consevation diagnostics not '
print *, 'guaranteed to work correctly'
else
USETD=0
endif
C Reading in the temperature and water profiles from the climate code
IF (ICOUPLE.eq.1) then
print *, 'alt_new, T_new, water'
DO J=1, NZ
C Reading the altitude, temperature, and water profiles from the climate code
READ(116,*) alt_new(J), T_new(J), water(J)
print 351, alt_new(J), T_new(J), water(J)
END DO
close(116)
endif
351 FORMAT (1PE10.3, 1PE12.3, 1PE12.3)
C ***** READ THE CHEMISTRY DATA CARDS *****
corig read (9,200) CHEMJ
! print *, 'this is nr', NR
! Skip header
read(9, *)
read (9,200) CHEMJ
! 200 FORMAT(A8,2X,A8,2X,A8,2X,A8,2X,A8)
! Format changed from skipping 10 first W.S.
200 FORMAT(A8,2X,A8,2X,A8,2X,A8,2X,A8)
write(14, 201) (J,(CHEMJ(M,J),M=1,5),J=1,NR)
201 FORMAT(1X,I3,' ',5X,A8,' + ',A8,' = ',A8,' + ',A8,4X,A8)
KJAC = LDA*NEQ
write(14, 202) NQ,NZ,KJAC
202 FORMAT(//1X,'NQ=',I2,5X,'NZ=',I3,5X,'KJAC=',I7)
c-mc this is bad code. there is probably some way to do this
c-mc -with the read in above
c-mc or even if necessary, some way to redo the read without
c-mc closing and opening the file again WARNING
close(9)
! chemical reaction file
open(9, file='PHOTOCHEM/INPUTFILES/reactions.rx',status='OLD')
read(9, *)
read(9,204) REACTYPE
! print 204, REACTYPE
! Changed from 48 to 50 W.S.
204 FORMAT(50X,A5)
C close this because Rates.f and Initphoto.f will re-open it later.
close(9)
C **** JCHEM has species numbers; CHEMJ is corresponding characters
C ***** REPLACE HOLLERITH LABELS WITH SPECIES NUMBERS IN JCHEM *****
DO J=1,NR
DO M=1,5
IF(CHEMJ(M,J).EQ.' ') GO TO 5
DO I=1,NSP2
! print *, CHEMJ(M,J),ISPEC(I)
IF(CHEMJ(M,J).NE.ISPEC(I)) GO TO 6
JCHEM(M,J) = I
GO TO 5
6 CONTINUE
END DO
IERR = J
print *, ISPEC
print *, 'ispec(i)', ISPEC(i)
print *, (CHEMJ(L,J),L=1,5)
! quit; error in reactions
GOTO 25
5 CONTINUE
END DO
END DO
C
C ***** FILL UP CHEMICAL PRODUCTION AND LOSS MATRICES *****
DO M=1,2
C so N=2, then 1
N = 3-M
DO J=1,NR
C so I = JCHEM(1,NR) then JCEHM(2,NR)
I = JCHEM(M,J)
C skips 0 (i.e. nothing) and NSP1 (HV)
IF(I.LT.1.OR.I.GT.NSP) GO TO 7
C counter for how many reactions species I is involved with
NUML(I) = NUML(I) + 1
C quit; too many reactions (seems unnecesary, but whatever)
IF(NUML(I).GT.NMAX) GOTO 20
K = NUML(I)
C ILOSS(1,species in pos 1, species reac#)
C -then ILOSS(1,spec in pos 2, reac#)= global reaction #
ILOSS(1,I,K) = J
C ILOSS(1,species in pos 1, species reac#)
C -then ILOSS(1,spec in pos 2, reac#)= other species
ILOSS(2,I,K) = JCHEM(N,J)
7 CONTINUE
END DO
END DO
C
DO M=3,5
DO J=1,NR
I = JCHEM(M,J)
IF(I.LT.1.OR.I.GT.NSP) GO TO 8
NUMP(I) = NUMP(I) + 1
IF(NUMP(I).GT.NMAX) GO TO 20
K = NUMP(I)
IPROD(I,K) = J
8 CONTINUE
END DO
END DO
c-mc check mass balance of chemical reactions
do i=1,nr
rhOcount=0
rhHcount=0
rhCcount=0
rhScount=0
rhNcount=0
rhCLcount=0
C !assume 3 products unless..
numprod=3
if (JCHEM(5,i).EQ.0) numprod=2
if (JCHEM(4,i).EQ.0) numprod=1
C This loop counts up the mass on the right hand side of the .rx
do j=0,numprod-1
rhOcount=rhOcount+atomsO(JCHEM(3+j,i))
rhHcount=rhHcount+atomsH(JCHEM(3+j,i))
rhCcount=rhCcount+atomsC(JCHEM(3+j,i))
rhScount=rhScount+atomsS(JCHEM(3+j,i))
rhNcount=rhNcount+atomsN(JCHEM(3+j,i))
rhCLcount=rhCLcount+atomsCL(JCHEM(3+j,i))
enddo
bad=0
if (rhOcount.ne.atomsO(JCHEM(1,i))+atomsO(JCHEM(2,i))) bad=1
if (rhHcount.ne.atomsH(JCHEM(1,i))+atomsH(JCHEM(2,i))) bad=1
if (rhCcount.ne.atomsC(JCHEM(1,i))+atomsC(JCHEM(2,i))) bad=1
if (rhScount.ne.atomsS(JCHEM(1,i))+atomsS(JCHEM(2,i))) bad=1
if (rhNcount.ne.atomsN(JCHEM(1,i))+atomsN(JCHEM(2,i))) bad=1
if (rhCLcount.ne.atomsCL(JCHEM(1,i))+atomsCL(JCHEM(2,i))) bad=1
if (bad .eq. 1) then
print *, 'bad mass balance in reaction',i
print *, (CHEMJ(j,i),j=1,5)
print *, numprod
!the problem is either in the .rx file or the species.dat file
print *, rhNcount,atomsN(JCHEM(1,i)),atomsN(JCHEM(2,i))
stop
endif
enddo !end mass balance check
C PROCESS the photolysis reactions
c
c this next little bit creates:
c photoreac(kj) - an array of species numbers for each photolysis reaction.
c used in absorbers/columndepth computations
c photospec(ks) - the unique photolysis reaction numbers
C (i.e. unique elements of photoreac)
c used in Initphoto.f to fill up sq, the cross section vector
c photonums(kj) - the reaction number of each photolysis reaction
c used in Photo.f to fill up the A vector of rates
jcount=1
jrcount=1
juniq=1
do i=1,nr
if (REACTYPE(i)(1:4).eq.'PHOT') then
photoreac(jrcount)=JCHEM(1,i) !capture the species number of each photo reaction
photonums(jrcount)=i !capture the reaction number of each photoreaction
c print *, jrcount,i,JCHEM(1,i),(CHEMJ(m,i),m=1,5)
jrcount=jrcount+1
newphot = .TRUE.
m = 1
! if(juniq.eq.1) then
! photospec(juniq) = JCHEM(1,i)
! juniq = juniq + 1
! endif
! Loop photospec, if species at JCHEM(1, i) has already been seen
! then set newphot to false
do while(m <= ks)
if(JCHEM(1, i).eq.photospec(m)) then
newphot = .FALSE.
m = ks + 1 ! break loop
else
m = m + 1
endif
enddo
! If this reaction is new, add it to photospec and increment juniq
if (newphot .eqv. .TRUE.) then
photospec(juniq) = JCHEM(1,i)
juniq = juniq + 1
end if
endif
jcount = jcount + 1
enddo
c print *, jnums
c print *, photoreac
c print *, ''
c print *, INT(photospec)
c print *, juniq
c print *, photonums
c stop
C - SOME CHECKS TO MAKE SURE THE INPUT FILES JIVE WITH PARAMATERS.INC
if (juniq-1.ne.ks) then
print *, 'discrepency between unique photolysis reactions/ks'
print *, juniq-1, ks
stop
endif
if (SUM(INDEX(REACTYPE,'PHOT')) .NE. kj) then
print *,'discrepency between number of photo reactions and kj'
print *, SUM(INDEX(REACTYPE(1:4),'PHOT')), kj
stop
endif
IF (ILL.NE.NQ.OR.iLL+iTD.NE.NQ1.OR.iLL+iTD+iSL+iIN.NE.NSP2) then
print *, 'discrepancy between INPUTFILES/species.dat and
$ INPUTFILES/parameters.inc'
PRINT *, ILL,NQ, iLL+iTD,NQ1,iLL+iTD+iSL+iIN,NSP2
stop
endif
c-mc the below could be made into a nice printout in the out.out file
c WARNING was this dealt with
c print *, SUM(INDEX(REACTYPE,'PHOTO'))
c print *, SUM(INDEX(REACTYPE,'2BODY'))
c print *, SUM(INDEX(REACTYPE,'3BODY'))
c print *, SUM(INDEX(REACTYPE,'2BACK'))
c print *, SUM(INDEX(REACTYPE,'3BACK'))
c print *, SUM(INDEX(REACTYPE,'WEIRD'))
c print *, NR
C ***** READ THE PLANET PARAMETER DATAFILE *****
c-mab: Uncomment below for debugging with this part
C print*,'G,FSCALE,ALB,ZTROP,FAR,R0 = ',G,FSCALE,ALB,ZTROP,FAR,R0
C print*,'P0,PLANET,TIMEGA,IRESET = ',P0,PLANET,TIMEGA,IRESET
Read(7,*) G
Read(7,*) FSCALE
Read(7,*) ALB
Read(7,*) ZTROP
Read(7,*) FAR
Read(7,*) R0