-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathClimaMain.f
executable file
·1653 lines (1398 loc) · 56.1 KB
/
ClimaMain.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
cC 1 C PROGRAM SURFT(INPUT,OUTPUT,TAPE1,TAPE2,TAPE3)
c
C This program is a modified version of the climate model SURFTEM made
c by James Kasting. The program has been modified by Michael Mischna (mm),
c Alex Pavlov (AP), Kara Krelove (KK), Hilary Justh (HJ), Ravi Kopparapu (RK),
c Ramses Ramirez(RR), and Antigona Segura (AS). Some changes are identified
c with the initials of the author.
c The code is mostly written in f77 but is compiled in f90 and it
c contains some f90 features.
c This code is a 1-D, cloud-free, radiative-convective climate model.R
c The calculation of temperature profiles begins with an initial
c temperature-pressure profile and a solar constant.
c The net absorbed solar radiation is calculated by a delta two-stream
c approximation (Toon, et al. JGR Vol. 94, 16287-16301, 1989). It uses
c 4-term correlated k coefficients to parameterize absorption by O3,
c CO2, H2O, O2 and CH4 in 38 spectral intervals.
c The IR is calculated by the RRTM routine developed by Mlawer et. al
c (JGR, Vol.102 (D14), 16663-16682, 1997). It uses 16 term sums in
c each of its spectral bands in which the k-coefficients are concentrated
c in areas of most rapidly changing absorption. The version 3.0 of RRTM
c was implemeted on August/2003 (www.rtweb.aer.com).
c When the mixing ratio of CO2 is greater than CO2MAX, the maximum
c level of CO2 that RRTM can manage, the former IR subroutine is used.
c (Pavlov et al. J. Geophys. Res. 105: 11,981-11,990, 2000).
c Units in cgs unless otherwise is stated.
c Temperature in each layer is calculated from:
c dT/dt = - (g/c_p) dF/dp
c in this case the derivates are partial. T= temperature, t= time,
c g= gravitational constant, F=Flux, c_p= Heat capacity, p=pressure.
c Two types of reach convergence have been set up. One uses a non-strict
c time stepping mode which is faster and better for high O2-low CO2 runs,
c like present Earth. The other one is slower but needed on high CO2
c atmospheres.
c This model can work alone or coupled to a photochemical model.
c Modifications for the coupled mode were made by Kara Krelove.
c Input data files required by the program are:
C Unit File
C 3 H2O_tables.pdatC 4 solar_data_38.pdat (Read by 2-stream code)
C 8 nearir_expsums.pdat
c 9 CO2_tables.pdat
c 20 ir_expsums.pdat
c 21 BIG_DATAFILE.dat
C
C THE VERTICAL GRID IS STAGGERED BETWEEN TEMPERATURE AND FLUX
C GRID POINTS. THE FLUX GRID IS DEFINED FROM THE VERY TOP OF THE
C ATMOSPHERE (J=1) TO THE GROUND (J=ND). THE TEMPERATURE GRID POINTS
C ARE HALFWAY BETWEEN THE FLUX POINTS, EXCEPT FOR T(ND) WHICH IS
C LOCATED AT THE GROUND.
C
C PARAMETERS:
C ND = # OF ALTITUDE POINTS (J)
C NF = # OF FREQUENCIES (N)
C NA = # OF ANGLES (M)
C NS = # OF CHEMICAL SPECIES (I)
C NT = # OF TEMPERATURES IN THE STEAM TABLE
C NSOL = # OF SOLAR FREQUENCIES
C
C T = TEMPERATURE (K)
C P = PRESSURE (bar)
C Z = LOG PRESSURE + A CONSTANT (ZCON)
C PF = PRESSURE AT FLUX GRID POINTS
C ZF = LOG P AT FLUX POINTS
C ALT = ALTITUDE (KM)
C GAM = DTDZ
C BVK = PLANCK FUNCTION
C LAM = WAVELENGTHS (MICRONS)
C AV = FREQUENCIES (1/S)
C TAU = SLANT OPTICAL DEPTH TO OTHER PRESSURE LEVELS
C F = INTEGRATED NET FLUX
C FS = INTEGRATED SOLAR FLUX
C FI = SPECIES MIXING RATIOS 1 = water, 2 = co2, 3 = ch4, 4 = o3, 5 = ethane
C FH2O - H2O MIXING RATIO
C T,TN - TEMPERATURES
C FLAGCONVEC - Tags for the type of convection
c 1. = Water moist adiabat
c 2. = Water dry diabat
c 3. = CO2 adiabat
c 0. = Non convective layer
C-KK NLAYERS is a translation parameter between this climate model
C-KK and Mlawer's RRTM code.
C_KK SurfTem indexes from 1 at the top to ND at the ground, while
C_KK RRTM indexes from 0 at the ground to NLAYERS at the top.
C-KK NZ is the number of layers being carried in atm_chem.
INCLUDE 'CLIMA/INCLUDE/header.inc'
c PARAMETER(ND=52)
PARAMETER(NF=55, NA=1, NLAYERS=ND-1, NZ=200)
c PARAMETER(NF=55, NA=1, NLAYERS=51, NZ=64)
PARAMETER(NS=3, NS1=NS+2, NS4=NS+5) !gna: changed NS1 from NS+1 to NS+2 to add ethane
PARAMETER(NT=76, MT=36)
PARAMETER(NSOL=38, NGS=8, IK=8) ! Added IK=8 parameter and NGS is 7 now, 3/26/2012
!gna - changed ngs to 8 (ethane)
parameter(nrow=11)
character*8 pstar
C CHARACTER*5 :: ICH4A !Changed to make STARR hold up to 5 characters
C CHARACTER*5 :: ICO2A !Changed to make STARR hold up to 5 characters
CHARACTER*5 :: STARR !Changed to make STARR hold up to 5 characters
CHARACTER*11 :: AA
CHARACTER :: DIRINOUT*8,DIRDATA*10
LOGICAL :: file_e
DIMENSION TRAD(ND),DZ(ND),Z(ND),ZF(ND)
DIMENSION temp_alt(NZ), water(NZ), O3(NZ), PRESS(NZ), !EWS - temp_t(NZ) removed because it wasn't used
& CH4(NZ), CO2(NZ), ethane(NZ)
DIMENSION T(ND),TOLD(ND),FTOTAL(ND),FTIR(ND),
& FTSO(ND),PF1(ND),DELT(ND),DELTRAD(ND),TN(ND),
& DIVF(ND),TCOOL(ND),THEAT(ND),FLAGCONVEC(ND)
DIMENSION FSATURATION(ND),FSATUR(ND),FSAVE(ND) !EWS dt(ND) removed, not used 8/18/2015
C DIMENSION newalt(ND),HEATNET(ND),BETA(ND),FCO2V(ND),FH2O(ND)
DIMENSION HEATNET(ND),BETA(ND),FCO2V(ND),FH2O(ND)
DIMENSION AVOLD(NF) !EWS - ALAM not used
C-jdh DIMENSION LAM(NF),ALAM(NF),AVOLD(NF)
DIMENSION PSATCO2(ND) !EWS - PML(ND) removed because it wasn't used
DIMENSION FNC(ND) ! Added FNC array c-rr 6/7/2012
c vectors for gaussian zenith angles
dimension fdnsoltot(nd), fupsoltot(nd)
dimension xi(nrow,20), wi(nrow,20), ngauss(nrow)
REAL*8 newalt ! removed extraneous kappa, kappa_ir, and FLAGCONVE(ND) declarations
COMMON/DIR/DIRINOUT,DIRDATA
COMMON/WAVE/AV(NF),LAM(NF),W(NF)
COMMON/ABLOK/LTYPE(NF,3),XH2O(NF),YH2O(NF),XCO2(NF),YCO2(NF),
2 AXH(NF),AYH(NF),BXH(NF),BYH(NF),AXC(NF),AYC(NF),BXC(NF),
3 BYC(NF),PDOP(NF),CPR(NF),TPR(NF),PATH(NS4),PATHP(NS4),
4 PATHT(NS4),P1,P2,T1,T2,TAU2,TAUP2,
5 ALPHA(4),BETH2O(4,5,NF),
6 BETCO2(4,5,NF),CA(19),CB(19),CC(19),CD(19),CE(19),CH(19),
7 CK(19)
c COMMON/CBLOK/FO2,FN2,FCO2,FAR,FCH4
COMMON/CBLOK/FO2,FN2,FCO2,FAR,FCH4,FC2H6,FNO2, FI(NS1,ND),FH22
! Added FH2 to CBLOK 5/29/2012 c-rr
COMMON/ALTBLOK/DALT(ND-1),RADIUS(ND-1),PARTICLES(ND),RAER(ND),
2 ALT(ND)
COMMON/EBLOK/PG,TG,PG0,IMW,RSURF,OMEGA,POCEAN,IMOIST,
2 BETA1,BETA2,FVDRY,PDRY
COMMON/FBLOK/TTAB(NT),PVAP(NT),DPVAP(NT),SVC(NT),DSV(NT),DSC(NT)
2 ,RHOV(NT),DRHOV(NT),BETAM(70,75),TCP(75),PCP(70),DPDTL(70,75),
3 DRDTL(70,75)
COMMON/GBLOK/TCTAB(MT),PCVAP(MT),BETASC(MT),DPCVAP(MT),
& DRCVAP(MT),SVSC(MT),DSCC(MT),TKTAB(MT),TCC(25),PCC(36),
& BETAMC(25,36),CPC(25,36),DVDTC(25,36),DVDPC(25,36),
& DSVC(MT)
COMMON/SBLOK/P0P,T0P,R,SUBL
COMMON/PRESSURE/P(ND),PLOG(ND)
COMMON/PRESS/BETIR1(4,5,NSOL),BETIR2(4,5,NSOL),
& kappa_solh2o(NSOL,8,8,IK), kappa_solco2(NSOL,8,8,IK) ! Added new kappa matricies for each of CO2 and H2O coefficients. 8/26/2012
COMMON/AOZONE/BETAO3(nsol), BETAO2(2),
& WGHTO2(NSOL,2)
COMMON/RSOL/ALPHAZ(4,2),BETAZ(4,2),NPROB(2),
& NG(2),SIGG(4,2,NSOL)
! COMMON/SOLARDATA/weightco2_h2oSOL(16), weights(2,NSOL,IK)
! & ,kmatrix_sol(NSOL,IK) ! Added SOLARDATA block here 3/26/2012
COMMON/SOLARBLK/AMU0,SRFALB,OMG0A(NSOL,ND-1),
& ASYA(NSOL,ND-1),TAUAER(NSOL),SIGERT(NSOL),FMA(NSOL),PF(ND),
& ALAMBDA(NSOL),CGAS(ND,NGS),FUPSOL(ND),FDNSOL(ND),
& NGAS(2,NSOL),WGHT(4,2,NSOL),NPR(2,NSOL),SOLINT(NSOL),
& TAULAM(ND-1),ASY(ND-1),OMG0(ND-1),FMT(ND-1),QEXT(NSOL,ND-1)
C new common block, von Paris, 21/04/2006
COMMON/IRDATA/WEIGHTCH4(6),xkappa(3,12,55,8),
& CIA(7,NF), CPRW(ND,NF)
c-rr !3/23/11 put CIA matrix in IRDATA
COMMON/VARIR/kappa_irh2o(NF,8,8,IK), kappa_irco2(NF,8,8,IK)! Added kappa matrix in IR for kpsectrum Co2 and H2O coefficients 8/26/2012
COMMON/weightsIR/ weightco2_h2oIR(IK)
COMMON/IRBLK/FUPIR(ND),FDNIR(ND),SRFALBIR,OMG0AIR(NF,ND-1),
& ASYAIR(NF,ND-1),IO3,QEXTIR(NF,ND-1)
COMMON/HYDROCARB/Qextirst(73,55),w0irst(73,55),
& girst(73,55),Qextsolst(73,38),w0solst(73,38),gsolst(73,38),
& radstand(73)
COMMON/CH4BLOCK/ALPHACH4T188(4,17),BETACH4T188(4,17),
& ALPHACH4T295(4,17),BETACH4T295(4,17),ALPHACH4Kark(4,21),
& BETACH4Kark(4,21),GAMMAEXP188(17),GAMMAEXP295(17),
& ALPHACH4NEW(6),BETACH4NEW(17,3,5,6),ALCH4(6,38)
COMMON/CO2BLOK/betac1,betac2,PC0,TC0,VAPCL0,SUBCL0,DLVCDT
& ,DLSCDT,CCL,CCS
COMMON/NO2BLOK/SIGNO2(NSOL)
C
C-KK Added 6/15/01 to integrate Mlawer RRTM.
COMMON/ MLAWERI/ layers, numspec, newalt(ND), TempT(0:NLAYERS),
& Pres(0:NLAYERS), gasses(7, 0:NLAYERS), COLDEP(ND)
COMMON/CONSS/C,BK,G,GNEW(ND),PI,SM,DM,DM2 ! Adding DM2 to common block entry 5/3/2011. DM and DM2 are AMN and AMN2 respectively in CONVEC
c-rr 3/29/11
COMMON/CPHEAT/CPO2(ND),CPCO2(ND), CPN2(ND), CPH2O(ND),
& CPN(ND), CPNT(ND), CPH2(ND) ! Added CPH2 5/31/2012 c-rr
C
DATA BETA/ND*1./
DATA BETH2O/1100*0./
DATA BETCO2/1100*0./
DATA SIGNO2/1.1E-20, 5.0E-20, 9.5E-20, 2.23E-19, 3.36E-19,
2 5.1E-19, 5.36E-19, 2.58E-19, 1.07E-19, 8.0E-20, 4.75E-20,
3 2.65E-20, 1.25E-20, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
4 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0./
C-KK Change to allow differing T-profiles in differing atmospheres.
c-jdh commented out to allow ND!=52
c DATA ALT / 69., 67.9, 66.8, 65.7, 64.5, 63.1, 61.7, 60.3,
c 2 58.4, 56.4, 53.9, 50.5, 47.2, 44.9, 42.9, 40.9,
c 3 38.9, 36.9, 34.9, 32.9, 30.8, 29.1, 27.6, 26.2,
c 4 24.9, 23.7, 22.5, 21.3, 20.2, 19.1, 18., 16.9,
c 5 15.8, 14.7, 13.6, 12.4, 11.7, 11., 10.3, 9.6,
c 6 8.9, 8.2, 7.5, 6.8, 6.1, 5.3, 4.5, 3.7, 2.9, 2.1,
c 7 1.1, 0.0/
C
C FREQUENCIES AT ENDS OF SPECTRAL INTERVALS (1/CM)
DATA AV/40., 100., 160., 220., 280., 330., 380., 440., 495.,
2 545., 617., 667., 720., 800., 875., 940., 1000., 1065.,
3 1108., 1200., 1275., 1350., 1450., 1550., 1650., 1750., 1850.,
4 1950., 2050., 2200., 2397., 2494., 2796., 3087., 3425., 3760.,
5 4030., 4540., 4950., 5370., 5925., 6390., 6990., 7650., 8315.,
6 8850., 9350., 9650., 10400., 11220., 11870., 12790., 13300.,
7 14470., 15000./
DATA C,HP,BK,SIGMA,PI,SM/3.E10, 6.63E-27, 1.38E-16, 5.67E-5,
2 3.14159, 1.67E-24/
c Names of the subdirectories for the data, inputs and outputs
DIRINOUT = 'CLIMA/IO'
DIRDATA = 'CLIMA/DATA'
c ============= FILE SECTION ==================
c print *, 'running'
C INPUT FILES
OPEN (unit=1,file= DIRINOUT//'/input_clima.dat')
OPEN (unit=3,file= DIRDATA//'/H2O_tables.pdat',status='old')
OPEN (unit=4,file= DIRDATA//'/solar_data_38.pdat',status='old')
OPEN (unit=8,file= DIRDATA//'/nearIR_expsums.pdat',status='old')
!====================================================================
C New k-coefficients for H2O and CO2 were calculated by Eric Wolf
C using HELIOS-K (https://github.com/exoclime/HELIOS-K), an
C ultrafast GPU-driven correlated-k sorting program
C (Grimm et al. 2015, doi.org/10.1088/0004-637X/808/2/182).
C For H2O we use the HITRAN2016 line-list, assuming 25 cm-1
C line cut-offs using Lorentz profiles and with the plinth removed.
C For CO2 we also use the HITRAN2016 database, but we assume
C 500 cm-1 line cut-offs using the Perrin and Hartman
C (1989, doi.org/10.1016/0022-4073(89)90077-0) sub-Lorentzian
C line profiles. These conventions represent the current standard
C practices for the treatment of H2O and CO2 lines within coarse
C spectral resolution climate model radiation schemes.
C It is assumed that the H2O self and foreign broadening components,
C and CO2-CO2 CIA, are included elsewhere in the code,
C both of which are independent of the line treatment.
C For further discussions contact [email protected].
OPEN (unit=15, file=DIRDATA//'/Wolf_HITRAN2016_solar_38_H2O.dat',
& status='old') ! H2O solar coefficients
C
OPEN (unit=16, file=DIRDATA//'/Wolf_HITRAN2016_solar_38_CO2.dat',
& status='old') ! CO2 solar coefficients
C
OPEN (unit=17, file=DIRDATA//'/Wolf_HITRAN2016_ir_55_H2O.dat',
& status='old') ! H2O ir coefficients
OPEN (unit=18, file=DIRDATA//'/Wolf_HITRAN2016_ir_55_CO2.dat',
& status='old') ! CO2 ir coefficients
!====================================================================
OPEN (unit=9,file= DIRDATA//'/CO2_tables.pdat',status='old')
OPEN (unit=21,file= DIRDATA//'/BIG_DATAFILE.DAT',status='old')
OPEN(unit=66, file = DIRINOUT//'/weight_factors.txt')
c OPEN(unit=10, file=DIRDATA//'/GJ581_1AU.dat',status='old')
c OPEN(unit=10,
c . file=DIRDATA//'/STELLAR_SPECTRA_new.pdat',status='old')
OPEN(unit=10,
. file=DIRDATA//'/STELLAR_SPECTRA_update.pdat',status='old')
!EWS - new stellar spectra updated
OPEN(unit=30, file=DIRDATA//'/FinalCIAcoeffs2.dat', status='old')
c OPEN(unit=30, file=DIRDATA//'/FinalCIAcoeffs.dat', status='old')
c OPEN(unit=89, file=DIRINOUT//'/TPRIND.dat') !write tau sums experiment
open(unit=90, file=DIRINOUT//'/FTIR.dat')
open(unit=91, file=DIRINOUT//'/FTSO.dat')
c Starting temperature profile
OPEN (unit=11,file= DIRINOUT//'/TempIn.dat')
c US standard atmosphere O3 profile used when the climate model is not
c coupled to the photochemical model - no - it calls SUBROUTINE OZONE for this...
c OPEN (unit=22,file= DIRINOUT//'/Ozone_standard.dat')
c-mc commenting these out as they are not currently being written to
c-mc If you turn them back on, please direct them to the IO directory and
c-mc add them to the .gitignore files. We don't want output files clogging up
c-mc version contril
c OPEN(UNIT=244,file='IHZ.dat')
c OPEN(UNIT=24,file='waterloss_IHZ.dat')
c Ozone and water profiles from the photochemical model
c File formerly called Pass2SurfMP.dat
OPEN (unit=113,file= 'COUPLE/fromPhoto2Clima.dat')
c Surface mixing rations to set the chemical composition of the atmosphere.
c gna - eek! was choosing which mixing_ratios.dat file to read BEFORE
c reading in whether ICOUPLE = 1 or 0! Moving this block of code down below...
C These INPUT files are open along the program
c Subroutine IR
c UNIT NAME
c 20 DIRDATA/ir_expsums.pdat
c IMPORTANT Files these are read in the subroutine CHOOSE_STAR
c IF the character variable STARR is different than "Sun"
c 80 DIRDATA/fluxesKGF_surf.pdat
c 81 DIRINOUT/M star flux (name it as you like)
c Next files are used for the subroutine AERABSDATA
c 40 DIRDATA/irtotal.DAT
c 41 DIRDATA/soltotal.DAT
C OUTPUT FILES
c-as Next file has the same structure as TempIn.dat, and should be copied
c-as to TempIn.dat in order to start from the last solution, if IUP=0
OPEN (unit=12,file= DIRINOUT//'/TempOut.dat')
OPEN(unit=116,file= 'COUPLE/fromClima2Photo.dat')
OPEN(UNIT=98,FILE= DIRINOUT//'/clima_allout.tab')
OPEN(UNIT=96,FILE= DIRINOUT//'/SolarHeating.tab')
OPEN(UNIT=97,FILE= DIRINOUT//'/clima_last.tab')
OPEN(UNIT=80,FILE= DIRINOUT//'/IR_wavelength_grid.tab')
c======================================================
c VARIABLE INPUT PARAMETERS
c======================================================
C NSTEPS - NUMBER OF ITERATIONS
C IMW - 0 FOR SATURATED TROPOSPHERE, 1 FOR MANABE/WETHERALD
C RELATIVE HUMIDITY, 2 FOR M/W WITH CONSTANT
C STRATOSPHERIC H2O CONTENT
C RSURF - SURFACE RELATIVE HUMIDITY
C ZY - SOLAR ZENITH ANGLE (DEGREES)
C DTAU0 - OPTICAL DEPTH STEP IN SUBLEVEL INTEGRATION
C ZCON - ARBITRARY CONSTANT ADDED TO Z TO KEEP IT POSITIVE
C P0 - PRESSURE AT TOP OF GRID
C PG0 - DRY PRESSURE AT BOTTOM OF GRID (atm)
c G - Gravity aceleration (cgs)
C FAC - RATIO OF GRID SPACING AT TOP TO SPACING AT
C BOTTOM
C IO3 - 1 TO INCLUDE O3, 0 TO LEAVE IT OUT
C IUP - SPECIFIES TYPE OF INITIALIZATION (0 IF YOU WISH TO
C START FROM AN EXISTING SOLUTION, 1 IF YOU WISH TO
C SPECIFY A NEW SURFACE TEMPERATURE)
C IF OPTION 1 IS SELECTED YOU MUST MAKE SURE THAT
C THE STARTING TEMPERATURES ABOVE GROUND LEVEL ARE LESS
C THAN TG0, SINCE THE TROPOSPHERIC LAPSE RATE IS INTEGRA-
C TED UPWARDS IN THIS CASE.
C TG0 - INITIAL SURFACE TEMPERATURE (FOR IUP = 1 CASE)
C TSTRAT - Stratospheric temperature for IUP=1
C STARR - Character variable to choose a star, it can be:
c Sun, F2V, K2V, G2V
c NOTES: G2V is NOT the Sun.
c Write it exactly as it is listed.
c DO NOT FORGET quotation marks.
c ICONSERV - O = Non strict time-stepping method (faster)
c 1 = Each time step conservs energy (better for high CO2)
c ICOUPLE - 1 = Coupled to the photochemical model
c 0 = Not coupled
c SRFALB - Planetary albedo (0.2 for Present Earth)
c SOLCON - Solar constant (S/So)
c dtmax - Maximum time step in seconds
c CO2MAX - Maximum CO2 mixing ratio that RRTM can manage with accuracy,
c for greater values of CO2 the former IR subroutine is used.
c ***This version always uses the old IR
C JK Idry - If Idry = 0, use the moist adiabat. If Idry = 1, use a dry adiabat
Idry = 0
READ(1,51)
! print *,'reading in'
READ(1,*) AA,NSTEPS !step number
READ(1,*) AA,IMW
READ(1,*) AA,RSURF
READ(1,*) AA,zy
READ(1,*) AA,DTAU0
READ(1,*) AA,ZCON
READ(1,*) AA,P0 !Pressure at the top
c READ(1,*) AA,PG0 !Surface pressure (bar)
c*******Changed for now*********
READ(1,*) AA,PG0
READ(1,*) AA,G !Gravity (Mars=373., Earth=980.)
READ(1,*) AA,FAC
READ(1,*) AA,IO3 !Ozone?
READ(1,*) AA,IUP
READ(1,*) AA,TG0 !Surface temperature for IUP=1
READ(1,*) AA,TSTRAT !Stratospheric temperature for IUP=1
READ(1,*) AA,STARR !What star?
READ(1,*) AA,ICONSERV !Type of energy conservation
READ(1,*) AA,ICOUPLE !Coupled(1) or not(0)
READ(1,*) AA,SRFALB !fixed planetary albedo (0.2)
READ(1,*) AA,SOLCON !SOLCON=S/So
READ(1,*) AA,dtmax !maximum time step allowed (seconds)
READ(1,*) AA,CO2MAX
READ(1,*) AA, IMET ! IMET (flag 0 or 1)
READ(1,*) AA, IMETETH ! IMETETH (flag 0 or 1)
READ(1,*) AA, nga
READ(1,*) AA, IHAZE ! IHAZE (flag 0 or 1)
READ(1,*) AA, ihztype
READ(1,*) AA, icealbedo
READ(1,*) AA, INVERSE
READ(1,*) AA, FRAK !can get a fractal haze without being coupled now
! print *, 'inverse', inverse
!gna - moved this part here so now we know what ICOUPLE is supposed to be
!(before this piece of code was before ICOUPLE was read in)
IF (ICOUPLE.eq.0) THEN
OPEN (unit=114,file= DIRINOUT//'/mixing_ratios.dat')
ELSE
OPEN (unit=114,file= 'COUPLE/mixing_ratios.dat')
END IF
print *, 'icouple is', ICOUPLE
!gna - read more inputs from photo for coupling
IF (ICOUPLE.eq.1) THEN
OPEN(unit=999,FILE= 'COUPLE/coupling_params.out')
! 107 FORMAT(1X, F4.2, 5X, F8.3, 5X, F3.1, 5X, I2, 5X, I2,
! & 9X, I4, 6X, F4.2, 6X, F8.2)
! 107 FORMAT(1X, F4.2, 5X, F8.3, 5X, F3.1, 5X, A8, 5X, I2,
! & 9X, I4, 6X, F5.3, 6X, F7.3)
READ(999,*)
READ(999,*) timega, P0ground, frak, pstar, ihztype, nzp, fscale,
& G
print *, 'COUPLING PARAMETERS ARE:'
print *, 'TIMEGA = ', timega
print *, 'P0ground = ', P0ground
print *, 'frak = ', frak
print *, 'pstar = ', pstar
print *, 'ihztype = ', ihztype
print *, 'nzp = ', nzp
print *, 'fscale = ', fscale
print *, 'G = ', G
print *, 'RSURF = ', RSURF
!remove haze in input file if ihztype = 99 (this means no hcaer was run in PHOTO so nonsensical to include it)
if(ihztype.eq.99) IHAZE = 0
IF (pstar == '13') STARR = "Sun"
IF (pstar == '14') STARR = "Sun"
IF (pstar == '15') STARR = "ADLEO"
!using the stellar parameterization implemented by Ramses for these next few
!see pickstar.f for details
IF (pstar == '16') STARR = "B5034" !adleo ("adleo" isn't working well) B5035
IF (pstar == '17') STARR = "B5032" !T3200
IF (pstar == '18') STARR = "B5050" !K2V
IF (pstar == '19') STARR = "B4070" !F2V
IF (pstar == '76') STARR = "B5034" !GJ876
IF (pstar == '20') STARR = "B5026" !M8V
! IF (pstar == 21) STARR = "B5030" !M5V
IF (pstar == '21') STARR = "M5V" !EWS - testing this implementation
IF (pstar == '24') STARR = "B5050" !K2.5V
IF (pstar == '25') STARR = "B5042" !K6V
IF (pstar == '26') STARR = "B5052" !K1V
IF (pstar == '27') STARR = "B5040" !M0V
! Below are Teal's MUSCLES stars, see the end of the pickstar.f
! file
IF (pstar == '80') STARR = "G80" ! GJ876
IF (pstar == '81') STARR = "G81" ! GJ551 (Proxima)
IF (pstar == '82') STARR = "G82" ! GJ581
IF (pstar == '83') STARR = "G83" ! GJ667c
IF (pstar == '84') STARR = "G84" ! GJ1214b
IF (pstar == '85') STARR = "G85" ! GJ176
IF (pstar == '86') STARR = "G86" ! GJ436
IF (pstar == '87') STARR = "G87" ! GJ832
IF (pstar == '88') STARR = "G88" ! HD40307
IF (pstar == '89') STARR = "G89" ! HD40307
IF (pstar == '90') STARR = "G90" ! HD40307
IF (pstar == '91') STARR = "G91" ! HD40307
age = 4.7
time = age-timega
SOLCON = (1+0.4*(1-time/4.7))**(-1)*FSCALE
PG0 = P0ground
print *, 'STAR = ', STARR
!correction to SOLCON based on kopparapu HZ (earth distance ~> moist IHZ)
!IF (msun.eq.16) SOLCON = SOLCON * 0.870
!IF (msun.eq.17) SOLCON = SOLCON * 0.859
!IF (msun.eq.18) SOLCON = SOLCON * 0.950
!IF (msun.eq.19) SOLCON = SOLCON * 1.110
!IF (msun.eq.76) SOLCON = SOLCON * 0.866
call sleep(2)
c print *, timega
c print *, P0ground
c print *, frak
ENDIF !icouple = 1
51 FORMAT(4/)
DO I = 1, ND
GNEW(I) = 0.0D0 ! initialize GNEW
ENDDO
c print *, 'Hello1'
WRITE(80,3000)
3000 FORMAT(1X,'Wavelength intervals in 1/cm')
write(80,3001)
3001 FORMAT(/1x,'Int',2x,'Wavel',2x,'Waveu')
wavel = 0.
waveu = av(1)
i = 1
write(80,3002) i,wavel, waveu
3002 format(1x,i2,2f7.0)
DO I=2,NF
write(80,3002) i,av(i-1),av(i)
enddo
C
C **** Read the Gauss points and weights for the solar zenith angle int
call data_grabber(xi,wi,ngauss)
c*********Calculate PGO*************
c sk PG0 = .8 + PCO2
c print 999, PG0
c999 FORMAT(1x,'PG0 =',1PE12.5)
c print 999, PCO2
c===================================================================
c Reading the atmospheric composition from mixing_ratios.dat
READ(114,*) FAR !Argon
READ(114,*) FCH4 !Methane
READ(114,*) FC2H6 !Ethane
READ(114,*) FCO2 !Carbon dioxide
READ(114,*) FN2 !Nitrogen - added Nitrogen mixing ratio c-rr 6/5/2012
READ(114,*) FO2 !Oxygen
READ(114,*) FH22 ! c-rr 5/29/2012 added H2 mixing ratio
READ(114,*) FNO2 !Nitrogen dioxide
READ(114,*) Jcold !Tropopause layer read in, Photochem gives out the Tropopause layer on it's own grid, so that is not compatible
INQUIRE(FILE="COUPLE/aux_c_couple.dat", EXIST=file_e)
IF (IUP.EQ.0.AND.file_e) THEN
OPEN (unit=333,file= 'COUPLE/aux_c_couple.dat')
READ(333,*)
READ(333,*) aaa, aaa, aaa, aaa, Jcold, aaa
print *, 'Jcold (for coupling) is =', Jcold
close(333)
END IF
c***********Calculate new FCO2**************
c sk FCO2 = PCO2/((.8/28.+PCO2/44.)*44.)
c print 997, FCO2
c997 FORMAT(1x,'FCO2 =',1PE12.5)
c WJL- changed mixing ratios below to include NO2
c-rr Added methane flag. Ensures FCH4 is 0 when methane flag is turned off 5/2/11
IF ((IMET.eq.0).and.(IMETETH.eq.0)) THEN
FCH4=1.e-60
FC2H6=1.e-60
ENDIF
IF ((IMET.eq.1).and.(IMETETH.eq.0)) THEN
FC2H6=1.e-60
ENDIF
IO2 = 0
IF (FO2.ge.1e-40)IO2 = 1
c Nitrogen mixing ratio
! FN2 = 1. - FO2 - FAR - FCH4 - FNO2 - FH22 ! c-rr 5/29/2012 added H2 mixing ratio
c-rr Noncondensible molecular weight of the atmosphere when CO2 is condensing (for a colder planet) 5/3/2011
DM2 = 28.*FN2 + 32.*FO2 + 40.*FAR + 16.*FCH4
& + 46.*FNO2+ 2.*FH22 ! c-rr 5/29/2012 added H2 mixing ratio
c jfk DM is the noncondensible molecular weight when CO2 is not condensing
DM = 44.*FCO2 + (1.-FCO2)*DM2
c print*,FCH4, FCO2, FO2, JCOLD
c IF(FCO2.gt.CO2MAX) print 550
LAST = 0
AMU0 = COS(ZY * PI/180.)
C CONSTANT FACTORS (cgs)
BCON = 2.*HP/C/C
HK = HP/BK
BKM = BK/(SM*G)
ND1 = ND - 1
c print *, 'Hello2'
R = 1.9872
P0P = 6.103E-3
T0P = 273.15
SUBL = 677.
c print *, 'Hello10'
c TRIPLE POINT PARAMETERS FOR CO2
PC0 = 5.179
TC0 = 216.56
VAPCL0 = 83.2765
SUBCL0 = 130.893
DLVCDT = - 0.4817
DLSCDT = - 0.1732
CCL = 0.5
CCS = 0.3
C Read Solar Data
CALL READSOL
c Choosing a star
c-rr CALL CHOOSE_STAR(STARR,SOLINT) 3/29/11
CALL pickstar(STARR,SOLINT)
C try to accelerate ir.f, von Paris, 21/04/2006
c CALL IREXPSUMS(WEIGHT,XKAPPA)
CALL IREXPSUMS
c Reading an initial temperature and water profile
998 FORMAT(3x,F16.12,7x,E22.15)
c-jdh format statement to read in TempIn_Standard.tab
c 998 FORMAT(3x,F7.3,7x,E9.3)
IF(IUP.EQ.0) THEN
DO J = 1,ND
READ(11,998) T(J), FSAVE(J)
fi(1,j)=FSAVE(J)
END DO
TG=T(ND)
ENDIF
c print *, 'Hello11'
c Reading the ozone and water from the photochemical model
c IF(ICOUPLE.EQ.1) THEN
c DO JREAD=1,NZ !number of layers in photochem code
c READ(13,*) temp_alt(JREAD),PRESS(JREAD),O3(JREAD),water(JREAD) !want to put in methane there
c temp_alt(JREAD)=temp_alt(JREAD)/1.0e5
C print *, 'temp_alt, press, o3, water'
C print *, temp_alt(JREAD),PRESS(JREAD),O3(JREAD),water(JREAD)
c END DO
c 352 FORMAT("Alt = ",1PE12.3," H20=",1PE12.3)
c Interpolate the grid from the photochemical model to the grid of the
c climate model
c CALL INPUT_INTERP(temp_alt, water, O3, Jcold, T, FI)
c DO J=1,ND
c print *, alt(J), (FI(I,J),I=1,4)
c ENDDO
c ENDIF
C Initialize pressure grid
IF(IUP.EQ.1) TG = TG0
c PRINT *, "Calling Grid()..."
CALL GRID(P0,FAC,ZCON,Z,ZF,DZ)
c Reading the US Standard Atmosphere ozone profile
if(IO3.eq.1.and.ICOUPLE.eq.0) then
CALL OZONE(FI,P)
c do i=1,ND
c read(22,*) x, FI(4,i)
c enddo
endif
C CONVERT FREQUENCIES TO UNITS OF 1/SEC AND COMPUTE WEIGHTING FACTORS
DO N=1,NF
AV(N) = C*AV(N)
END DO
W(1) = AV(1)
DO N=2,NF
W(N) = AV(N) - AV(N-1)
END DO
C
C CENTER FREQUENCIES IN MIDDLE OF INTERVALS AND COMPUTE WAVELENGTHS
SAV = 0.
DO N=1,NF
AVOLD(N) = AV(N)/C
SAV2 = AV(N)
AV(N) = 0.5*(AV(N) + SAV)
LAM(N) = 3.E14/AV(N)
SAV = SAV2
END DO
c -rr Tstratospheric iteration loop 4/22/2011
c DO KK = 1,4
c Constructing temperature and water profiles in case they are not provided
IF(IUP.EQ.1) THEN
JCOLD = 1
CALL PROFILE(TSTRAT,P,T,DZ,FSAVE,FCO2V,BETA,JCOLD,
& IDRY,FLAGCONVEC)
ENDIF
c print *,' JCOLD =',JCOLD
c Building the water profile
if(ICOUPLE.eq.0)then
DO J = 1,ND
FI(1,J)=FSAVE(J)
END DO
c jfk 6/25/08 Added four lines below
IF(IMW.EQ.2) THEN
DO J=1,JCOLD
FI(1,J) = 4.E-6
c print *,'j =',j,' fi(1,j)=',fi(1,j)
END DO
END IF
else !icouple.eq.1
DO J=1,ND
CALL SATRAT(T(J),PSAT)
FSATURATION(J) = (PSAT/P(J))*RELHUM(P(J))
C-KK The following line was modified to finish filling H2O grid.
END DO
! print *, 'JCOLD original is', JCOLD
!first try to make JCOLD more sensible - giada
!it's looking for where FSATURATION goes above 1
!testing needed for all situations when it needs to change JCOLD?
if (IUP.EQ.0.and.P(ND).GE.0.93.AND. .NOT.file_e) then !it's starting w/ fresh JCOLD otherwise ! EWS- and pressure is high enough
IF (FSATURATION(1).GT.1) THEN !test if > 1 at start of grid
JCOLD_NEW = -1
DO j =1, ND
IF ((JCOLD_NEW .EQ. -1).and.(FSATURATION(J).LT.1)) THEN
JCOLD_NEW = J
END IF
END DO
!Update JCOLD if needed
IF (JCOLD_NEW.NE.-1) THEN
JCOLD = JCOLD_NEW
END IF
END IF
JCOLD = max(JCOLD,13) !EWS ensure JCOLD isn't too small.
end if !end cold trap search
C print *, 'JCOLD updated is ', JCOLD
DO J=1, ND
IF (J .GE. JCOLD) FI(1,J)=FSATURATION(J)
END DO
FI(1,JCOLD)=(3.*FI(1,JCOLD+1)+FI(1,JCOLD)+3.*FI(1,JCOLD-1))/7.
print*, 'it is in that loop that is icouple=0'
c
c jkf 6/26/08 Change H2O initialization in the stratosphere
do j=1,jcold
if (imw.eq.2) FI(1,J) = 4.e-6
end do
endif !end if icouple.eq.0
DO 2 J=1,ND
PF1(J) = PF(J)*1.E6 !PF1 in dyn/cm^2
TOLD(J) = T(J)
FI(2,J) = FCO2
IF(IUP.EQ.1) FI(2,J)=FCO2V(J)
FI(5,J) = max(FC2H6,1.e-60) !ethane !EWS - debug for low mixing ratios
2 FI(3,J) = max(FCH4,1.e-60) !methane !EWS - debug for low mixing ratios
c
c jfk 6/27/08
do j=1,nd
fsave(j) = fi(1,j)
end do
C *** Initial time step
c-rr 3/29/11 Changed time step from 5.e3 to 2.5e3
c dt0 = 5.e3
dt0=5.e3
IFLAGTIME = 0
TIME = 0.
c Altitude calculation
CALL ALTITUDE(NST,T,FI,DZ)
c Reading the ozone and water from the photochemical model
IF(ICOUPLE.EQ.1) THEN
c print *, 'temp_alt, press, o3, water, ch4, co2'
DO JREAD=1,NZ !number of layers in photochem code
READ(113,*) temp_alt(JREAD),PRESS(JREAD),O3(JREAD),
& water(JREAD),CH4(JREAD), CO2(JREAD),
& ethane(JREAD)
temp_alt(JREAD)=temp_alt(JREAD)/1.0e5
c print 353, temp_alt(JREAD),PRESS(JREAD),O3(JREAD),water(JREAD),
c & CH4(JREAD), CO2(JREAD)
END DO
FH2O=water(1)
c FI(1,ND)=FH2O
FCH4=CH4(1)
c FI(3,ND)=FCH4
FO3=O3(1)
c FI(4,ND)=FO3
FCO2=CO2(1)
c FI(2,ND)=FCO2
FC2H6 = ethane(1)
IF(FC2H6.LT.1.e-60) FC2H6 = 1.e-60 !!! Debug to prevent memory underflow issues - Eddie (8/3/2015)
IF(FCH4.LT.1.e-60) FCH4 = 1.e-60 !!! Note that these are read whether or not IMETH or IEMETH flags are set
print *, 'FC2H6 is ', FC2H6
c 352 FORMAT("Alt = ",1PE12.3," H20=",1PE12.3)
c 353 FORMAT(6(1PE9.2,1x))
c Interpolate the grid from the photochemical model to the grid of the
c climate model
CALL INPUT_INTERP(temp_alt, water, O3, CH4, CO2, ethane, Jcold,
& T, FI)
! print *,'called input_interp'
c print *, 'temp_alt,water,co2,ch4,o3(after input_interp)'
c DO J=1,ND
c print 353, alt(J), (FI(I,J),I=1,5)
c ENDDO
DO J=1, ND
IF (J .GE. JCOLD) FI(1,J)=FSATURATION(J)
END DO
ENDIF
! Initializing FNC c-rr 6/7/2012
do J = 1,ND
FNC(J) = 0.0
enddo
do J = 1, ND
FNC(J) = 1. - FI(1,J) - FI(2,J) ! Added initial FNC array c-rr 6/7/2012
c print *, 'IN CLIMA_FI(1,J)=', FI(1,J), J
c print *, 'IN CLIMA_FI(2,J)=', FI(2,J), J
c print *, 'IN CLIMA_FNC=', FNC(J), J
enddo
close(113)
c Initial non-condensible mixing ratio at surface (used for write statement in output file) 6/7/2011
FNCI = FNC(ND) ! c-rr 5/29/2012 added H2 mixing ratio
c Aerosol calculation (commented when not used)
CALL AERABSDATA(FRAK, ihztype)
CALL GRIDAER(ICOUPLE, IHAZE)
CALL INTERPAR1(RAER)
C***********************************************************
C ****************** START ITERATIVE LOOP *******************
DO 40 NST=1,NSTEPS
C************************************************************
print *, 'TIME STEP = ', NST
ITROP = 1
c PRINT 161,NST
c 160 FORMAT(/1X,"---------------------------------------------",
c 2 //1X,"NST =",I6)
c 161 format(1x,"NST =", I6)
TIME = Time + dt0
! print *, 'found time'
C Set up gas concentrations for Solar code and former IR code
CALL GASCON(T,PF,FO2,FH22,FI,FNC,CGAS,NST) ! Added FH2 to GASCON input argument 5/30/2012
! print *, 'called gascon'
C SWITCH FOR OLD IR CODE
c if(FCO2.gt.CO2MAX) then
c-as Old subroutine to calculate IR flux
C PLANCK FUNCTION WAS CHANGED
c-rr gna Created IRME.F (IR clone with methane and ethane loops turned on). When there is methane call IRM instead of IR. 5/2/2011
IF (IMET.eq.0) THEN
! print *, 'calling ir.f'
CALL IR(T,PF,P,FNC,CGAS) ! Passes FNC to IR c-rr 6/7/2012
ENDIF
IF ((IMET.eq.1).and.(IMETETH.eq.0)) THEN
! print *, 'calling IRM'
CALL IRM(T,PF,P,FNC,CGAS) ! Passes FNC to IRM c-rr 6/7/2012
! print *, 'called IRM'
ENDIF
IF (IMETETH.eq.1) THEN
! print *, 'calling IRME'
CALL IRME(T,PF,P,FNC,CGAS) ! Passes FNC to IRM c-rr 6/7/2012
! print *, 'called IRME'
ENDIF
c else
C Code modified 6/15/01 to integrate Mlawer's RRTM
c CALL TRANSLATEM(G,FI,T,PF,ND1,DM,BKM)
C IR subroutine v3.0 loaded August/2003 (www.rtweb.aer.com)
c CALL RRTM
c endif
IF (NST .EQ. NSTEPS) LAST = 1
C Solar code
c =================================================================
c approximating the solar zenith angle with a gaussian summation
c print *, 'Hello4'
do j = 1, nd
fdnsoltot(j) = 0.
fupsoltot(j) = 0.
enddo
C Find the right row in the matrix
do i=1,11
isave = i
if (ngauss(i).eq.nga) exit
enddo
C isave holds the correct row number for the matrix
do k=1,nga
amu0 = xi(isave,k)
zy = acos(amu0)*180./3.14159
c-rr setting zenith angle to 60 degrees when nga = 1.
if (nga.eq.1)then
amu0 = 0.5
zy=60.
endif
weightt = wi(isave,k)
C Heat capacity calculation
DO J=1,ND-1
c-rr 3/30/11 The new CPCO2 and CPN2 curve fit equations
CPCO2(J) = 5.89 + 6.06E-3*T(J) + 2.39E-5*T(J)*T(J)
& -3.44E-8*T(J)*T(J)*T(J)
c if(j.eq.1)print *, 'CPCO2new=', CPCO2(J), T(J)
CPN2(J) = 6.76 + 6.06E-4*T(J) + 1.3E-7*T(J)*T(J)
CPO2(J) = 7.47 -4.84E-3*T(J) + 1.38E-5*T(J)*T(J)
& -8.73E-9*T(J)*T(J)*T(J) - 1.76E-9/T(J)/T(J)
CPH2(J) = 7.17e-11*T(J)*T(J)*T(J)*T(J)
& -1.0e-07*T(J)*T(J)*T(J) + 4.77E-05*T(J)*T(J)
& -8.10E-03*T(J) + 7.17
CPH2O(J) = 7.46 +4.52E-3*T(J)-1.38E-5*T(J)*T(J)
& + 1.74E-08*T(J)*T(J)*T(J)
c-rr old curve fit equations
c CPCO2(J) = 7.7 + 5.3E-3*T(J) - 8.3E-7*T(J)*T(J)
c if(j.eq.1) print *, 'CPCO2old=', CPCO2(J), T(J)
c CPN2(J) = 6.76 + 6.06E-4*T(J) + 1.3E-7*T(J)*T(J)
c CPO2(J) = 8.27 + 2.58E-4*T(J) - 1.877E5/T(J)/T(J)
CPO2(J) = AMAX1(CPO2(J),CPN2(J))
c-rr Recalculation of mixing rations for the noncondensibles
c FI(1,J)= water
c FI(2,J)= carbon dioxide
c FI(3,J) = methane
c The condensibles are water and carbon dioxide. Water convects for planets closer in and CO2 condenses for planets further out
CpNC = FN2*CPN2(J) + FO2*CPO2(J) + FAR*4.97 +FCH4*8.3
c Total heat capacity
CPN(J) = FI(1,J)*CPH2O(J)+FI(2,J)*CPCO2(J) + FNC(J)*CPNC
c-rr This is the total cp of all the gases (condensible + noncondensible)
c CPN(J) = FI(2,J)*CPCO2(J) + FN2*CPN2(J) + FO2NC*CPO2(J) + ! CPN Modified to reflect above mixing ratio changes 5/3/2011
c & FARNC*4.97 +FCH4NC*8.3
C since CPN is in calories/mol/K we should convert them to erg/g/K