forked from NordicESMhub/OsloCTM3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteflux.f90
1576 lines (1380 loc) · 64.6 KB
/
steflux.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
!//=========================================================================
!// Oslo CTM3
!//=========================================================================
!// Based on UCI CTM core p-7.1 (1/2013).
!//
!// Ole Amund Sovde, April 2015
!//=========================================================================
!// STE budget
!//=========================================================================
module steflux
!//-----------------------------------------------------------------------
!// MODULE: steflux
!// DESCRIPTION: Routines to calculate horizontal fluxes and STE.
!//
!// Contains
!// subroutine CHEMFLUX
!// subroutine CHEMFLUX_E90
!// subroutine dumpuvflux
!// subroutine DUMPTRMASS
!// subroutine DUMPTRMASS_E90
!// subroutine SAVETRMASS
!// subroutine STEBGT_CLR
!// subroutine STEBGT_WRITE
!// subroutine ctm3_pml
!// subroutine ctm3_o3scav
!// subroutine chemflux_setup
!//-----------------------------------------------------------------------
implicit none
!// ----------------------------------------------------------------------
character(len=*), parameter, private :: f90file = 'steflux.f90'
!//-----------------------------------------------------------------------
private
public CHEMFLUX, CHEMFLUX_E90, dumpuvflux, DUMPTRMASS, DUMPTRMASS_E90, &
SAVETRMASS, STEBGT_CLR, STEBGT_WRITE, ctm3_pml, ctm3_o3scav, &
chemflux_setup
!//-----------------------------------------------------------------------
contains
!//-----------------------------------------------------------------------
subroutine CHEMFLUX(DTADV,L,QFU,QFV,N,RX,CHMFLX)
!//---------------------------------------------------------------------
!// Saves the horizontal flux of specified tracer (O3) in troposphere,
!// but only for tropospheric to tropospheric boxes.
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR, NPAR
use cmn_ctm, only: ALFA, BETA
use cmn_met, only: ZOFLE
use cmn_chem, only: N_STE, TMASSMIX2MOLMIX
use cmn_diag, only: LFLXDG
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
INTEGER, intent(in) :: L
REAL(r8), intent(in) :: DTADV
REAL(r8), intent(in) :: QFU(IPAR+1,JPAR,NPAR,2)
REAL(r8), intent(in) :: QFV(IPAR,JPAR+1,NPAR,2)
!// Output
REAL(r8), intent(out):: CHMFLX(IPAR+1,JPAR+1,2)
INTEGER :: I, J, II, N
!// Locals
REAL(r8) :: QU,QV,Q0F,Q1F,F0,XF,QF0,RX
logical :: LTROPAIR
!//---------------------------------------------------------------------
character(len=*), parameter :: subr = 'CHEMFLUX'
!//---------------------------------------------------------------------
!// N_STE may be either N_LZ or CTM3 O3.
if (LFLXDG .and. N .ne. N_STE) then
write(6,'(a)') f90file//':'//subr// &
': This program is only '// &
'written to collect O3 STE fluxes so far'
stop
end if
F0 = RX / TMASSMIX2MOLMIX(N) !// RX is mole/mole vmr for o3strat
!// U-flux
do J = 1, JPAR
do I = 1, IPAR + 1
QU = ALFA(I,J,L) * DTADV !// Air mass flux out
Q0F = QFU(I,J,N,1) !// tracer N flux out
Q1F = QFU(I,J,N,2) !// tracer N 1 moment flux out
!// Define air below 4km as tropospheric
if (I .eq. IPAR+1) then
LTROPAIR = 0.5_r8 * (ZOFLE(L,IPAR,J) + ZOFLE(L,1,J)) .lt. 4000._r8
else if (I .eq. 1) then
LTROPAIR = 0.5_r8 * (ZOFLE(L,IPAR,J) + ZOFLE(L,1,J)) .lt. 4000._r8
else
LTROPAIR = 0.5_r8 * (ZOFLE(L,I,J) + ZOFLE(L,I-1,J)) .lt. 4000._r8
end if
!// Count out-of-box flux from troposphere to troposphere:
!// Note that F0 = mass mixing ratio of isopleth mixing ratio
if ((F0 * ABS(QU) .ge. (ABS(Q0F) + ABS(Q1F))) .or. LTROPAIR) then
!// Pure troposphere
!// Maximum mass mixing ratio in flux is
!// ( ABS(Q0F)+ABS(Q1F) ) / ABS(QU)
!// so if this mass mixing ratio is smaller than F0, air
!// is tropospheric. Hence, we count the whole flux.
XF = 1._r8
QF0 = Q0F
else if (F0 * ABS(QU) .lt. (ABS(Q0F) - ABS(Q1F)) ) then
!// Pure stratospheric: count no flux
!// Minimum mass mixing ratio in flux is
!// ( ABS(Q0F)-ABS(Q1F) ) / ABS(QU)
!// so if this is larger than F0, air is stratospheric,
!// and we count no flux.
XF = 0._r8
QF0 = 0._r8
ELSE
!// Partly trop/strat
!// Fraction of tropospheric air can be calculated by
!// the mixing ratio in the flux. For mean values, if
!// ABS(Q0F)/ABS(QU) = F0 we have "tropopause".
!// To find F0 around Q0F, we recognize that F0 must be some
!// distance X between abs(Q0F)-abs(Q1F) and abs(Q0F)+abs(Q1F):
!// abs(Q0F)-abs(Q1F) + X*(2*abs(Q1F)) = F0*QU
!// X = (F0*QU - abs(Q0F) + abs(Q1F))/(2*abs(Q1F))
!// Then we limit abs(Q1F) with 1.D-10*ABS(Q0F) in case Q1F
!// is approximately zero.
XF = (F0*ABS(QU) - ABS(Q0F) + ABS(Q1F)) / &
(2._r8 * MAX(ABS(Q1F), 1.e-10_r8*ABS(Q0F)))
!// Now, how to use this fraction:
!// Tropospheric ozone flux is then the integral over the area
!// bound by the lower base (q0f-q1f), and upper base (f0*qu),
!// with height xf:
QF0 = (F0 * abs(QU) + ABS(Q0F) - ABS(Q1F)) / 2._r8 * XF
QF0 = SIGN(QF0, Q0F)
end if
CHMFLX(I,J,1) = QF0
end do
end do
!// V-flux
do J = 1, JPAR + 1
do I = 1, IPAR
QV = BETA(I,J,L) * DTADV
Q0F = QFV(I,J,N,1)
Q1F = QFV(I,J,N,2)
!// Define air below 4km as tropospheric
if (J .eq. JPAR + 1) then
LTROPAIR = ZOFLE(L,I,JPAR) .lt. 4000._r8
else if (J .eq. 1) then
LTROPAIR = ZOFLE(L,I,1) .lt. 4000._r8
else
LTROPAIR = 0.5_r8*(ZOFLE(L,I,J) + ZOFLE(L,I,J-1)) .lt. 4000._r8
end if
!// For comments, see U-flux comments.
if ( (F0 * ABS(QV) .ge. (ABS(Q0F) + ABS(Q1F))) .or. LTROPAIR) then
XF = 1._r8
QF0 = Q0F
else if (F0 * ABS(QV) .lt. (ABS(Q0F) - ABS(Q1F)) ) then
XF = 0._r8
QF0 = 0._r8
else
XF = (F0 * ABS(QV) - ABS(Q0F) + ABS(Q1F)) / &
(2._r8 * MAX(ABS(Q1F), 1.e-10_r8*ABS(Q0F)))
QF0 = (F0 * ABS(QV) + ABS(Q0F) - ABS(Q1F)) / 2._r8 * XF
QF0 = SIGN(QF0,Q0F)
end if
CHMFLX(I,J,2) = QF0
end do
end do
!//---------------------------------------------------------------------
end subroutine CHEMFLUX
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine CHEMFLUX_E90(DTADV,L,QFU,QFV,CHMFLX, NN)
!//---------------------------------------------------------------------
!// Finds horizontal fluxes within the troposphere based
!// on e90-tracer.
!// NN is tracer number, and should be either N_STE or N_LZ.
!//
!// Ole Amund Sovde, February 2012
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR, NPAR
use cmn_ctm, only: ALFA, BETA
use cmn_met, only: ZOFLE
use cmn_chem, only: Ne90, N_STE, N_LZ, E90VMR_TP, TMASSMIX2MOLMIX
use cmn_diag, only: LFLXDG
use utilities, only: ctmExitC
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
integer, intent(in) :: L, NN
real(r8), intent(in) :: DTADV
real(r8), intent(in) :: QFU(IPAR+1,JPAR,NPAR,2)
real(r8), intent(in) :: QFV(IPAR,JPAR+1,NPAR,2)
!// Output
real(r8), intent(out) :: CHMFLX(IPAR+1,JPAR+1,2)
!// Locals
integer :: I, J, II
real(r8) :: QU,QV,Q0F,Q1F,F0,XF,QF0,RX,Y
real(r8) :: Q0F_E90,Q1F_E90
logical :: LTROPAIR
!//---------------------------------------------------------------------
character(len=*), parameter :: subr = 'CHEMFLUX_E90'
!//---------------------------------------------------------------------
!// Find flux using e90 tracer
if (Ne90 .le. 0) &
CALL ctmExitC(f90file//':'//subr//': This routine needs e90 tacer')
!// Find flux using e90 tracer or linoz tracer
if (.not.(NN .eq. N_STE .or. NN .eq. N_LZ)) &
CALL ctmExitC(f90file//':'//subr//': This routine needs N_STE/linoz')
!// mass mixing ratio of e90 tracer at tropopause
F0 = E90VMR_TP / TMASSMIX2MOLMIX(Ne90) !RX is mole/mole vmr for o3strat
!// trapezoid y axis lower (left) base |q0f|-|q1f|
!// upper base (right) |q0f|+|q1f|
!// trapezoid x axis from 0 to 1
!// U-flux
do J = 1, JPAR
do I = 1, IPAR + 1
QU = ALFA(I,J,L) * DTADV !// Air mass flux out
Q0F_E90 = QFU(I,J,Ne90,1) !// tracer N_E90 flux out
Q1F_E90 = QFU(I,J,Ne90,2) !// tracer N_E90 1 moment flux out
Q0F = QFU(I,J,NN,1) !// O3 tracer flux out
Q1F = QFU(I,J,NN,2) !// O3 tracer 1 moment flux out
!// Define air below 4km as tropospheric
if (I .eq. IPAR + 1) then
LTROPAIR = 0.5_r8 * (ZOFLE(L,IPAR,J) + ZOFLE(L,1,J)) .lt. 4000._r8
else if (I .eq. 1) then
LTROPAIR = 0.5_r8 * (ZOFLE(L,IPAR,J) + ZOFLE(L,1,J)) .lt. 4000._r8
else
LTROPAIR = 0.5_r8 * (ZOFLE(L,I,J) + ZOFLE(L,I-1,J)) .lt. 4000._r8
end if
!// To calculate the flux, we must decide whether the air is
!// tropospheric, stratospheric or both. To do this, we apply the
!// mean flux of E90 tracer out of the grid box (Q0F_E90) and the
!// first moment (Q1F_E90).
!// Figuratively, Q0F_E90 and Q1F_E90 set up a trapezoid, with left
!// top point at ABS(Q0F_E90)+ABS(Q1F_E90) ant right top point at
!// ABS(Q0F_E90)-ABS(Q1F_E90).
!// The signs are opposite of the original CHEMFLUX, where the
!// gradient in O3 is used: E90 and O3 has opposite gradients.
!//
!// Stratospheric air is found when the mass mixing ratio of the
!// E90-tracer is smaller than F0 given above. We have to compare
!// this with the mass mixing ratio in the flux, and for simplicity
!// we compare masses:
!// Tropospheric air:
!// Mass in left corner of trapezoid is higher than the
!// stratospheric limit F0*ABS(QU):
!// F0*ABS(QU) < (ABS(Q0F_E90)-ABS(Q1F_E90))
!// Stratospheric air:
!// Mass in right corner of trapezoid is lower than the
!// stratospheric limit F0*ABS(QU):
!// F0*ABS(QU) >= (ABS(Q0F_E90)+ABS(Q1F_E90))
!// Partly tropospheric and partly stratospheric air:
!// We need to locate the tropopause first. Having the range of
!// the trapezoid x-axis [0,1], the tropopause lies within, at
!// a point X. X is therefore the fraction of tropospheric air,
!// and lies between abs(Q0F_E90)+abs(Q1F_E90) and
!// abs(Q0F_E90)-abs(Q1F_E90):
!// abs(Q0F_E90)+abs(Q1F_E90) - X*(2*abs(Q1F_E90)) = F0*QU
!// X = -(F0*QU - abs(Q0F_E90) - abs(Q1F_E90))/(2*abs(Q1F_E90))
!// Stratospheric fraction is therefore (perhaps more easily
!// derived by looking from right to left on the trapezoid):
!// XF = (1 - X)
!// = (F0*QU - abs(Q0F_E90) + abs(Q1F_E90))/(2*abs(Q1F_E90))
!// To avoid dividing by zero, we limit the divisor abs(Q1F_E90)
!// with 1.D-10*ABS(Q0F_E90), in case Q1F_E90 is approximately
!// zero.
!// Again: Note that when using Q0F and Q1F for O3, XF is the
!// tropospheric fraction because its gradient is opposite
!// of E90.
!//
!// We now have XF, and then calculate the O3 flux at (1-XF), which
!// we call Y. This equation is based on the fact that the O3
!// gradient is of opposite sign as for E90, and we interpolate
!// linearly from the left corner of the ozone trapezoid (not E90,
!// thus opposite signs).
!// Y = ABS(Q0F)-ABS(Q1F) + (1-XF) * (2*ABS(Q1F))
!//
!// Having the flux (ABS(Q0F)-ABS(Q1F)) at the left corner, and
!// Y at (1-XF), we need to integrate over the ozone trapezoid
!// (i.e. finding the area bound by x=[0,1-XF] and
!// y=[(ABS(Q0F)-ABS(Q1F)),Y]:
!// QF0 = (ABS(Q0F) - ABS(Q1F) + Y) * (1.0d0 - XF) / 2.0d0
!//
!// If you are not familiar with the fluxes, you may find it strange
!// that we need to integrate. Q0F is the mean flux out of the box,
!// and if Q1F=0, the tropospheric part is just (1-XF)*Q0F, which
!// is actually the area of a trapezoid with Q1F=0.
!// Given a gradient Q1F, there is less O3 flux to the left
!// (ABS(Q0F)-ABS(Q1F)) and more to the right (Y), integration
!// is necessary.
if ( (F0 * ABS(QU) .lt. (ABS(Q0F_E90) - ABS(Q1F_E90)) ) &
.or. LTROPAIR ) then
!// Pure troposphere:
XF = 1._r8
QF0 = Q0F !// Count O3 flux
else if (F0 * ABS(QU) .ge. (ABS(Q0F_E90) + ABS(Q1F_E90))) then
!// Pure stratosphere
XF = 0._r8
QF0 = 0._r8 !// Zero O3 flux
else
!// Partly trop/strat
!// Find fraction of strat air (e90 gradient is opposite of O3)
XF = (F0 * ABS(QU) - ABS(Q0F_E90) + ABS(Q1F_E90)) / &
(2._r8 * MAX(ABS(Q1F_E90), 1.e-10_r8*ABS(Q0F_E90)))
!// XF is where f0*abs(qu)= tracer flux in between the lower bound
!// and the upper bound for e90. Solve XF to get the dividing
!// point of the box for stratospheric/tropospheric for e90.
!// For e90: 1 to xf is stratospheric part on the right of
!// trapezoid.
!//
!// The x-axis in the trapezoid (with upper and lower bound of
!// tracer fluxes) is the fraction of air mass.
!// We should solve the ozone flux at (1-XF), which
!// is named Y here. (0 to (1-XF) is tropospheric air.)
!// And then we integrate the area from (Q0F-Q1F)
!// to Y (another trapezoid inside the big one).
Y = (1 - XF) * (2._r8*ABS(Q1F)) + (ABS(Q0F) - ABS(Q1F))
!// Tropospheric ozone flux is then the integral over the area
!// bound by the lower base (q0f-q1f), and upper base y,
!// with height (1-xf).
QF0 = (ABS(Q0F) - ABS(Q1F) + Y) * (1.0_r8 - XF) / 2._r8
QF0 = SIGN(QF0, Q0F)
end if
CHMFLX(I,J,1) = QF0
end do
end do
!// V-flux
do J = 1, JPAR+1
do I = 1,IPAR
QV = BETA(I,J,L) * DTADV
Q0F_E90 = QFV(I,J,Ne90,1)
Q1F_E90 = QFV(I,J,Ne90,2)
Q0F = QFV(I,J,NN,1)
Q1F = QFV(I,J,NN,2)
!// Define air below 4km as tropospheric
if (J .eq. JPAR + 1) then
LTROPAIR = ZOFLE(L,I,JPAR) .lt. 4000._r8
else if (J .eq. 1) then
LTROPAIR = ZOFLE(L,I,1) .lt. 4000._r8
else
LTROPAIR = 0.5_r8 * (ZOFLE(L,I,J) + ZOFLE(L,I,J-1)) .lt. 4000._r8
end if
!// For comments, see U-flux comments.
if ( (F0 * ABS(QV) .lt. (ABS(Q0F_E90) - ABS(Q1F_E90)) ) &
.or. LTROPAIR) then
!// Pure troposphere
XF = 1._r8
QF0 = Q0F
else if (F0 * ABS(QV) .ge. (ABS(Q0F_E90) + ABS(Q1F_E90))) then
!// Pure stratosphere
XF = 0._r8
QF0 = 0._r8
else
XF = (F0 * ABS(QV) - ABS(Q0F_E90) + ABS(Q1F_E90)) / &
(2._r8 * MAX(ABS(Q1F_E90), 1.e-10_r8*ABS(Q0F_E90)))
!// See comments on U-flux for info on the following:
!QF0= Q0F * (1._r8-XF)
Y = (1 - XF) * (2._r8*ABS(Q1F)) + (ABS(Q0F)-ABS(Q1F))
QF0 = (ABS(Q0F) - ABS(Q1F) + Y) * (1._r8 - XF) / 2._r8
QF0 = SIGN(QF0, Q0F)
end if
CHMFLX(I,J,2)= QF0
end do
end do
!//---------------------------------------------------------------------
end subroutine CHEMFLUX_E90
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine dumpuvflux(uflux,vflux,k) ! for flux less than x ppb
!//---------------------------------------------------------------------
!// Accumulate horizontal fluxes into 3D arrays. Accumulates over
!// time period defined by STE flux calendar.
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR, LPAR
use cmn_diag, only: UFLX, VFLX
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
real(r8), intent(in) :: uflux(ipar+1,jpar,lpar)
real(r8), intent(in) :: vflux(ipar,jpar+1,lpar)
integer, intent(in):: k
!// Locals
integer :: i,j,l
!//---------------------------------------------------------------------
!// note uflx(x,y,1) sum of uflx below isopleth value 1
!// dump flux every time after the flux is computed
do L = 1, LPAR
do J = 1, JPAR
do I = 1, IPAR+1
uflx(I,J,K) = uflx(I,J,K) + uflux(I,J,L)
end do
end do
end do
do L = 1, LPAR
do J = 1, JPAR+1
do I = 1, IPAR
vflx(I,J,K) = vflx(I,J,K) + vflux(I,J,L)
end do
end do
end do
!//---------------------------------------------------------------------
end subroutine dumpuvflux
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine DUMPTRMASS(LO3PAUZ,K)
!//---------------------------------------------------------------------
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR, LPAR
use cmn_ctm, only: NRMETD, STT
use cmn_chem, only: N_STE
use cmn_diag, only: TROPM
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
integer, intent(in) :: K
logical, intent(in) :: LO3PAUZ(LPAR,IPAR,JPAR,2)
!// Locals
real(r8) :: PPB, ZNRMETD
integer :: I,J,L
!//---------------------------------------------------------------------
!// CTM3: Have changed N_LZ to N_STE
if (N_STE .le. 0) return
!// Get daily average to avoid diurnal changes and small variability.
!// This routine has to be placed in met step (8 times a day).
!// TROPM is reset every day, in SAVETRMASS
ZNRMETD = 1._r8 / real(NRMETD, r8)
do L = 1, LPAR
do J = 1, JPAR
do I = 1, IPAR
if (.not.LO3PAUZ(L,I,J,K)) &
TROPM(I,J,K) = TROPM(I,J,K) + STT(I,J,L,N_STE) * ZNRMETD
end do
end do
end do
!//---------------------------------------------------------------------
end subroutine DUMPTRMASS
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine DUMPTRMASS_E90(K,N_TRACER)
!//---------------------------------------------------------------------
!// Save daily average of tropospheric O3 mass, using e90-tracer,
!// through LSTRATAIR_E90.
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR, LPAR
use cmn_ctm, only: NRMETD, STT
use cmn_chem, only: Ne90, LSTRATAIR_E90
use cmn_diag, only: TROPM
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
integer, intent(in) :: K, N_TRACER
!// Locals
real(r8) :: PPB, ZNRMETD
integer :: I,J,L
!//---------------------------------------------------------------------
if (N_TRACER .le. 0) return ! *** exit
if (Ne90 .le. 0) return ! *** exit
!// Get daily average to avoid diurnal changes and small variability.
!// This routine has to be placed in met step (8 times a day).
!// TROPM is reset every day, in SAVETRMASS
ZNRMETD = 1._r8 / real(NRMETD,r8)
do L = 1, LPAR
do J = 1,JPAR
do I = 1,IPAR
if (.not.LSTRATAIR_E90(L,I,J)) then
TROPM(I,J,K) = TROPM(I,J,K) + STT(I,J,L,N_TRACER) * ZNRMETD
end if
end do
end do
end do
!//---------------------------------------------------------------------
end subroutine DUMPTRMASS_E90
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine SAVETRMASS(N)
!//---------------------------------------------------------------------
!// Saves daily average TROPM in TROPMASS and clears TROPM.
!// First timestep sets TROPMASS_0 = TROPM
!//
!// Amund Sovde Haslerud, August 2017
!// Removed loops.
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR
use cmn_chem, only: N_STE, N_LZ
use cmn_diag, only: TROPM, TROPMASS, TROPMASS_0
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
integer, intent(in):: N
!//---------------------------------------------------------------------
!// Skip if relevant tracers are not included
if (N_STE .le. 0 .and. N_LZ .le. 0) return
!// dump daily average to tropmass
!// clear tropm
if (N .eq. 0) then
!// Initialise
TROPMASS_0(:,:,:) = TROPM(:,:,:)
end if
if (N .eq. 1) then
!// Save current TROPM
TROPMASS(:,:,:) = TROPM(:,:,:)
!// Reset TROPM
TROPM(:,:,:) = 0._r8
end if
!//---------------------------------------------------------------------
end subroutine SAVETRMASS
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine STEBGT_CLR(NDAY,N)
!//---------------------------------------------------------------------
!// Clear STE budget arrays; save TROPMASS_0.
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR
use cmn_ctm, only: GMTAU, JDATE, JMON, JYEAR
use cmn_chem, only: N_STE
use cmn_diag, only: O3PBLSINK, N2OPBLSINK, UFLX, VFLX, O3PML, &
TROPMASS, TROPMASS_0, O3WSCAV, &
IDAY0_STE, ITAU0_STE, JDATE0_STE, JMON0_STE, JYEAR0_STE
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
integer, intent(in) :: NDAY,N
!// Locals
integer :: I, J
!//---------------------------------------------------------------------
character(len=*), parameter :: subr = 'STEBGT_CLR'
!//---------------------------------------------------------------------
if (N_STE.eq.0) return ! *** exit
!// save before clear
if (N .eq. 0) then
O3PBLSINK(:,:,:) = 0._r8
N2OPBLSINK(:,:) = 0._r8
UFLX(:,:,:) = 0._r8
VFLX(:,:,:) = 0._r8
O3PML(:,:,:) = 0.0_r8
TROPMASS_0(:,:,:) = 0.0_r8
TROPMASS(:,:,:) = 0.0_r8
O3WSCAV(:,:,:) = 0.0_r8
!//RTN2O(:,:) = 0.0_r8
IDAY0_STE = NDAY
ITAU0_STE = int(GMTAU)
JDATE0_STE = JDATE
JMON0_STE = JMON
JYEAR0_STE = JYEAR
end if
if (N .eq. 1) then
O3PBLSINK(:,:,:) = 0._r8
N2OPBLSINK(:,:) = 0._r8
UFLX(:,:,:) = 0._r8
VFLX(:,:,:) = 0._r8
O3PML(:,:,:) = 0.0_r8
O3WSCAV(:,:,:) = 0.0_r8
!//RTN2O(:,:) = 0._r8
!// Set TROPMASS_0 to current TROPMASS
TROPMASS_0(:,:,:) = TROPMASS(:,:,:)
!// Zero current TROPMASS
TROPMASS(:,:,:) = 0.0_r8
!// Date stuff
IDAY0_STE = NDAY
ITAU0_STE = int(GMTAU)
JDATE0_STE = JDATE
JMON0_STE = JMON
JYEAR0_STE = JYEAR
write(6,'(2(A,I6))') f90file//':'//subr// &
': jdate0_STE=',jdate0_STE,', jmon0_STE',jmon
end if
!//---------------------------------------------------------------------
end subroutine STEBGT_CLR
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine STEBGT_WRITE_OLD
!//---------------------------------------------------------------------
!// Write STE budget to file.
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR, LLINOZ
use cmn_ctm, only: IDAY, AREAXY, JYEAR, JMON, JDATE, GMTAU
use cmn_chem, only: N_STE, o3iso1, o3iso2, E90VMR_TP
use cmn_diag, only: IDAY0_STE, itau0_STE, jmon0_STE, jdate0_STE, &
jyear0_STE, NFLX, UFLX, VFLX, O3PML, O3WSCAV, &
O3PBLSINK, TROPMASS, TROPMASS_0
use utilities, only: get_free_fileid
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Locals
character(len=28) :: filnm
character(len=4) :: fryrlab, toyrlab
character(len=6) :: frdaylab, todaylab
integer :: itau,ia,ib,i,j,nc,k,NNFX, fnr
real(r8) :: xflx, yflx, dyear,zdyear, stesum, pmlsum, scavsum
real(r8) :: ste(ipar,jpar,NFLX), hflx(ipar,jpar), dm(ipar,jpar,NFLX)
!//---------------------------------------------------------------------
if (N_STE .le. 0) return ! *** exit
dyear = real(IDAY - IDAY0_STE, r8) / 365.0_r8
write(6,'(2(A,I6,5X),A,1PE12.5)') &
'iday=',iday,'iday0_STE',iday0_STE,'dyear=',dyear
zdyear = 1._r8 / dyear
do nc = 1, NFLX ! for 2 diff o3 isopleths + e90 + linoz
do j = 1,jpar
do i = 1,ipar
xflx = uflx(i+1,j,nc) - uflx(i,j,nc)
yflx = vflx(i, j+1,nc) - vflx(i,j,nc)
hflx(i,j) = xflx + yflx
end do
end do
!// This is just to smooth down the noise of flux divergence.
!// do 1-2-1 filtering for horizontal flux for k=1,2 twice.
do k = 1, 2
do j = 1, jpar
do i = 1, ipar
ib = mod(i, ipar) + 1
ia = mod(i-2+ipar, ipar) + 1
hflx(i,j) = 0.25_r8 * hflx(ib,j) &
+ 0.5_r8 * hflx(i,j) &
+ 0.25_r8 *hflx(ia,j)
end do
end do
do i = 1,ipar
do j = 6, jpar - 5
hflx(i,j) = 0.25_r8 * hflx(i,j-1) &
+ 0.5_r8 * hflx(i,j) &
+ 0.25_r8 * hflx(i,j+1)
end do
end do
end do ! end of k-loop 1-2-1 filter
!// the last 5 grid points in the polar region
!do i = 1,ipar
! do j = 1,5
! hflx(i,jpar-j+1) = hflx(i,jpar-5)
! hflx(i,j) = hflx(i, 6)
! end do
!end do
!// Change in tropospheric mass
do i = 1, ipar
do j = 1, jpar
dm(i,j,nc) = tropmass(i,j,nc) - tropmass_0(i,j,nc)
end do
end do
do j = 1, jpar
do i = 1, ipar
ib = mod(i, ipar) + 1
ia = mod(i-2+ipar, ipar) + 1
dm(i,j,nc) = 0.25_r8 * dm(ia,j,nc) &
+ 0.5_r8 * dm(i,j,nc) &
+ 0.25_r8 * dm(ib,j,nc)
end do
end do
do j = 2, jpar-1
do i = 1, ipar
ib = mod(i,ipar) + 1
ia = mod(i-2+ipar, ipar) + 1
dm(i,j,nc) = 0.25_r8 * dm(i,j-1,nc) &
+ 0.5_r8 * dm(i,j,nc) &
+ 0.25_r8 * dm(i,j+1,nc)
end do
end do
!// Polar boxes
do i = 1, ipar
dm(i,jpar,nc) = dm(i,jpar-1,nc)
dm(i,1,nc) = dm(i,2,nc)
end do
stesum = 0._r8
pmlsum = 0._r8
scavsum = 0._r8
!// Do the trop mass o3 budget of ste by add and subtract all terms
do j = 1, jpar
do i = 1, ipar
ste(i,j,nc) = dm(i,j,nc) + hflx(i,j) &
- o3pml(i,j,nc) - o3pblsink(i,j,nc) &
- o3wscav(i,j,nc)
stesum = stesum + ste(i,j,nc)
pmlsum = pmlsum + o3pml(i,j,nc)
scavsum = scavsum + o3wscav(i,j,nc)
!// Convert to grams/m2/year from kg
ste(i,j,nc) = ste(i,j,nc) * 1.e3_r8 / areaxy(i,j) * zdyear
end do
end do
!// print to std.out
if (nc .le. 2) then
write(6,'(A,I3,1P,2(A,ES14.6),A)') &
'isopleth ', nc, ' total ste=', stesum*1.e-9_r8, &
' Tg. PML from CTM3 O3',pmlsum*1.e-9_r8, ' Tg'
else if (nc .eq. 3) then
write(6,'(A,ES14.6,A,ES14.6,A)') &
'below e90 tpz, total ste=', stesum*1.e-9_r8, &
' Tg. PML from CTM3 O3',pmlsum*1.e-9_r8, ' Tg'
else if (nc .eq. 4) then
if (LLINOZ) write(6,'(A,ES14.6,A,ES14.6,A)') &
'LZ below e90 tpz, total ste=', stesum*1.e-9_r8, &
' Tg. PML from LINOZ',pmlsum*1.e-9_r8, ' Tg'
end if
if (nc .eq. 4 .and. LLINOZ) then
write(6,'(A,i1,A,5(1X,es10.3))') &
'STE',nc,'/PML/HFLX/DM/PSINK:', &
stesum*1.e-9_r8*zdyear, &
pmlsum*1.e-9_r8*zdyear, &
sum(hflx)*1.e-9_r8*zdyear, &
sum(dm(:,:,nc))*1.e-9_r8*zdyear, &
sum(o3pblsink(:,:,nc))*1.e-9_r8*zdyear
else
write(6,'(A,i1,A,5(1X,es10.3))') &
'STE',nc,'/PML/HFLX/DM/SCAV: ', &
stesum*1.e-9_r8*zdyear, &
pmlsum*1.e-9_r8*zdyear, &
sum(hflx)*1.e-9_r8*zdyear, &
sum(dm(:,:,nc))*1.e-9_r8*zdyear, &
scavsum*1.e-9_r8*zdyear
end if
end do
!// write out to files and rezero variables
itau = int(gmtau)
write(fryrlab,'(i4.4)') jyear0_STE
write(frdaylab,'(3i2.2)') jmon0_STE,jdate0_STE,itau0_STE
print*,'frdaylab=',frdaylab
write(toyrlab,'(i4.4)') jyear
write(todaylab,'(3i2.2)')jmon,jdate,itau
print*,'todaylab=',todaylab
write(filnm,'(a28)') &
'stea_'//fryrlab//frdaylab//'z_'//toyrlab//todaylab//'z'
write(6,'(a,a28)') 'write in files named: ',filnm
!// Get free file id
fnr = get_free_fileid()
open(fnr,file=filnm,form='unformatted',status='unknown')
write(fnr) NFLX
write(fnr) o3iso1, o3iso2, E90VMR_TP, E90VMR_TP
do nc = 1, NFLX
write(fnr) uflx(:,:,nc), vflx(:,:,nc), &
tropmass_0(:,:,nc), tropmass(:,:,nc), o3pml(:,:,nc), &
o3pblsink, ste(:,:,nc), dm(:,:,nc)
end do
close(fnr)
!//---------------------------------------------------------------------
end subroutine STEBGT_WRITE_OLD
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine STEBGT_WRITE
!//---------------------------------------------------------------------
!// Write STE budget to file.
!//
!// Amund Sovde Haslerud, August 2017
!// To netCDF4. Skip filtering (better to post process).
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR, LLINOZ
use cmn_ctm, only: IDAY, AREAXY, JYEAR, JMON, JDATE, &
XDGRD, YDGRD, XDEDG, YDEDG
use cmn_chem, only: N_STE, o3iso1, o3iso2, E90VMR_TP
use cmn_diag, only: IDAY0_STE, jmon0_STE, jdate0_STE, &
jyear0_STE, NFLX, UFLX, VFLX, O3PML, O3WSCAV, &
O3PBLSINK, TROPMASS, TROPMASS_0, &
RUNTITLE, metTypeInfo, resolutionInfo, &
nc4deflate_global, nc4shuffle_global
use cmn_met, only: METTYPE, MET_ROOT, MPATH1,MPATH2
use netcdf
use ncutils, only: handle_error
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Locals
character(len=80) :: filename
character(len=8) :: datestamp0, datestamp1
integer :: nc, k
real(r8) :: dyear, zdyear
real(r8), dimension(NFLX) :: &
stesum, pmlsum, scavsum, hflxsum, dmsum, pblsinksum
real(r8) :: ste(ipar,jpar,NFLX), hflx(ipar,jpar,NFLX), dm(ipar,jpar,NFLX)
!// netCDF variables
!//---------------------------------------------------------------------
integer :: &
status, & ! Status for netcdf file 0=OK
ncid, & ! file id for output netcdf file
lon_dim_id, & ! Dimension id for longitude
lat_dim_id, & ! Dimension id for latitude
ilon_dim_id, & ! Dimension id for longitude interstices
ilat_dim_id, & ! Dimension id for latitude interstices
nflx_dim_id, & ! Dimension id for NFLX
date_size_dim_id, & ! Dimension id for date sizes
lon_id, & ! Variable id for longitude
lat_id, & ! Variable id for latitude
ilon_id, & ! Variable id for longitude interstices
ilat_id, & ! Variable id for latitude interstices
start_time_id, end_time_id, & ! IDs for start/end time
ndays_id, &
areaxy_id, & ! grid area
isopleths_id, & ! isopleths
uflx_id, vflx_id, & ! flux
tropmass0_id, tropmass_id, &
pml_id, sink_id, wetscav_id, ste_id, dm_id
!// --------------------------------------------------------------------
integer, parameter :: nc4deflate = nc4deflate_global
integer, parameter :: nc4shuffle = nc4shuffle_global
!//---------------------------------------------------------------------
character(len=*), parameter :: subr = 'STEBGT_WRITE'
!//---------------------------------------------------------------------
if (N_STE .le. 0) return ! *** exit
dyear = real(IDAY - IDAY0_STE, r8) / 365.0_r8
write(6,'(2(a,i6),a,es12.5)') f90file//':'//subr// &
': iday=',iday,', iday0_STE',iday0_STE,', dyear=',dyear
zdyear = 1._r8 / dyear
!// For NFLX (2 diff o3 isopleths + e90 + linoz) calculate hflx and dm.
!// Change caused by horizontal flux
hflx(:,:,:) = uflx(2:ipar+1,:,:) - uflx(1:ipar,:,:) &
+ vflx(:,2:jpar+1,:) - vflx(:,1:jpar,:)
!// Change in tropospheric mass
dm(:,:,:) = tropmass(:,:,:) - tropmass_0(:,:,:)
!// Original UCI code uses a 1-2-1 filter method (0.25:0.5:0.25 weight)
!// to reduce noise on hflx (zonal direction then meridional direction,
!// repeated / done twice) and dm (zonal direction then meridional
!// direction, done once).
!// This should be done in post processing. Here we calculate global STE
!// without filters. The filters are described in the manual.
!// Find STE
ste(:,:,:) = dm(:,:,:) + hflx(:,:,:) &
- o3pml(:,:,:) - o3pblsink(:,:,:) - o3wscav(:,:,:)
!// print to std.out part 1
do nc = 1, NFLX
!// Sums in Tg
stesum(nc) = sum(ste(:,:,nc)) * 1.e-9_r8
pmlsum(nc) = sum(o3pml(:,:,nc)) * 1.e-9_r8
scavsum(nc) = sum(o3wscav(:,:,nc)) * 1.e-9_r8
hflxsum(nc) = sum(hflx(:,:,nc)) * 1.e-9_r8
dmsum(nc) = sum(dm(:,:,nc)) * 1.e-9_r8
pblsinksum(nc) = sum(o3pblsink(:,:,nc)) * 1.e-9_r8
if (nc .le. 2) then
write(6,'(A,I3,1P,2(A,ES14.6),A)') &
'isopleth ', nc, ' total ste=', stesum(nc), &
' Tg. PML from CTM3 O3',pmlsum(nc), ' Tg'
else if (nc .eq. 3) then
write(6,'(A,ES14.6,A,ES14.6,A)') &
'below e90 tpz, total ste=', stesum(nc), &
' Tg. PML from CTM3 O3',pmlsum(nc), ' Tg'
else if (nc .eq. 4) then
if (LLINOZ) write(6,'(A,ES14.6,A,ES14.6,A)') &
'LZ below e90 tpz, total ste=', stesum(nc), &
' Tg. PML from LINOZ',pmlsum(nc), ' Tg'
end if
end do !// do nc = 1, NFLX
!// print to std.out part 2
do nc = 1, NFLX
write(6,'(a3,i1,a,6(1x,es10.3))') &
'STE',nc,'/PML/HFLX/DM/WSCV/PBL: ', &
stesum(nc) * zdyear, &
pmlsum(nc) * zdyear, &
hflxsum(nc) * zdyear, &
dmsum(nc) * zdyear, &
scavsum(nc) * zdyear, &
pblsinksum(nc) * zdyear
end do !// do nc = 1, NFLX
!// Save to file
!//---------------------------------------------------------------------
write(datestamp0(1:8),'(i4.4,2i2.2)') jyear0_STE,jmon0_STE,jdate0_STE
write(datestamp1(1:8),'(i4.4,2i2.2)') jyear,jmon,jdate
filename = 'ste_'//datestamp0//'_'//datestamp1//'.nc'
!//---------------------------------------------------------------------
!// Open netCDF4 file for writing
status=nf90_create(path=filename,cmode=nf90_netcdf4,ncid=ncid)
if (status .ne. nf90_noerr) call handle_error(status, &
f90file//':'//subr//': in creating file')
!//---------------------------------------------------------------------
!//---------------------------------------------------------------------
!//File headers
status=nf90_put_att(ncid,nf90_global,'title', &
'Oslo CTM3 Stratosphere-Troposphere Exchange (STE)')
if (status .ne. nf90_noerr) call handle_error(status, &
f90file//':'//subr//': file header')
status=nf90_put_att(ncid,nf90_global,'model_info', &
'Oslo CTM3 is a 3D Chemical Transport Model')
if (status .ne. nf90_noerr) call handle_error(status, &
f90file//':'//subr//': model_info')
status=nf90_put_att(ncid,nf90_global,'driving_meteorology',metTypeInfo)
if (status .ne. nf90_noerr) call handle_error(status, &
f90file//':'//subr//': driving_meteorology')
status=nf90_put_att(ncid,nf90_global,'driving_meteorology_path',MPATH1)
if (status .ne. nf90_noerr) call handle_error(status, &
f90file//':'//subr//': driving_meteorology_path')
status=nf90_put_att(ncid,nf90_global,'resolution_info',resolutionInfo)
if (status .ne. nf90_noerr) call handle_error(status, &
f90file//':'//subr//': resolution_info')
status=nf90_put_att(ncid,nf90_global,'runtitle',trim(runtitle))
if (status .ne. nf90_noerr) call handle_error(status, &
f90file//':'//subr//': runtitle')