forked from NordicESMhub/OsloCTM3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaverages.f90
1593 lines (1446 loc) · 62.9 KB
/
averages.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, March 2015
!//=========================================================================
!// CTM averages
!//=========================================================================
module averages
!//-----------------------------------------------------------------------
!// MODULE: averages
!// DESCRIPTION: Routines to make tracer averages (mostly not used).
!//
!// Important
!// The main work on making averages is done in oc_diagnostics.f90.
!// Here are some of the basic routines for making simple averages,
!// and also some print-to-screen routines.
!//
!// Contains
!// subroutine AVG_WRT_NC4
!// subroutine AVG_ADD2
!// subroutine AVG_CLR2
!// subroutine AVG_ADD2_H2O
!// subroutine AVG_P1
!// subroutine AVG_WRT2_OLD
!//-----------------------------------------------------------------------
implicit none
!// ----------------------------------------------------------------------
character(len=*), parameter, private :: f90file = 'averages.f90'
!//-----------------------------------------------------------------------
public
!//-----------------------------------------------------------------------
contains
!//-----------------------------------------------------------------------
subroutine AVG_WRT_NC4
!//---------------------------------------------------------------------
!// Writes average for STT and XSTT, as netCDF4 files.
!// Includes tracer info and grid info.
!//
!// This routine is a bit long, since it does all the netcdf
!// calls necessary. Sorry about that.
!//
!// Amund Sovde Haslerud, May 2017
!//---------------------------------------------------------------------
use cmn_precision, only: r8, r4, i8
use cmn_size, only: IPAR, JPAR, LPAR, NPAR, NOTRPAR, IPARW, JPARW, &
LPARW, IDBLK, JDBLK, MPBLK, TNAMELEN
use cmn_ctm, only: JYEAR, JMON, JDATE, IDAY, &
XDGRD, YDGRD, XDEDG, YDEDG, ETAA, ETAB, AREAXY, NTM, &
ZGRD, ZEDG, ETAA, ETAB
use cmn_met, only: METTYPE, metCYCLE, metREVNR, MET_ROOT, MPATH1,MPATH2
use cmn_diag, only: NRAVG, STTAVG, AIRAVG, DVAVG, ZHAVG, PSFCAVG, &
RUNTITLE, NDAY1, JYEAR1, JMON1, JDATE1, &
metTypeInfo, resolutionInfo, nc4deflate_global, nc4shuffle_global
use cmn_chem, only: TMASS, TNAME
use cmn_parameters, only: M_AIR
use cmn_oslo, only: chem_idx, Xchem_idx, XTMASS, trsp_idx, XTNAME, &
TEMPAVG, H2OAVG, QAVG, AMAVG, LMTROPAVG, H2OAVG_LMT1, &
RESULTDIR, XSTTAVG
use netcdf
use ncutils, only: handle_error
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
integer :: I, J, L, N, ioerr
integer, dimension(6) :: start_time, end_time
real(r8) :: ZNRAVG
character(len=80) :: FN_AVG
character(LEN=8) :: datestamp, datestamp0
real(r4) :: r4xyz(IPAR,JPAR,LPAR) !// To put out reverse-order XSTTAVG
!//---------------------------------------------------------------------
!// Version number
integer, parameter :: version = 8
!// Update version 8: File format is netCDF4
!//---------------------------------------------------------------------
!// netCDF variables
!//---------------------------------------------------------------------
integer :: &
status, & !Status for netcdf file 0=OK
ncid, & !file id for output netcdf file
lon_dim_id, & !Dimension id for longitude
lon_id, & !Variable id for longitude
lat_dim_id, & !Dimension id for latitude
lat_id, & !Variable id for latitude
lev_dim_id, & !Dimension id for level
lev_id, & !Variable id for level
ilon_dim_id, & !Dimension id for longitude interstices
ilon_id, & !Variable id for longitude interstices
ilat_dim_id, & !Dimension id for latitude interstices
ilat_id, & !Variable id for latitude interstices
ilev_dim_id, & !Dimension id for level interstices
ilev_id, & !Variable id for level interstices
ihya_dim_id, & !Dimension id for hybrid A on interstices
ihya_id, & !Variable id for hybrid A on interstices
ihyb_dim_id, & !Dimension id for hybrid B on interstices
ihyb_id, & !Variable id for hybrid B on interstices
ncomps_dim_id, & !Dimension id for NPAR+NOTRPAR
tracer_name_len_dim_id, & !Dimension id for tname charater length
date_size_dim_id, & !Dimension id for date sizes
dim_lon_lat_id(2), &
dim_lon_lat_lev_id(3), &
dim_ilev_lon_lat_id(3), &
nravg_id, & !ID for nNumber of accumulations in average
version_id, & !ID for file version number
start_time_id, end_time_id, & !IDs for start/end dates for average
start_day_id, end_day_id, & !IDs for start/end day (NDAY)
npar_id, notrpar_id, & !IDs for scalar output NPAR/NOTRPAR
tracer_idx_id, & !ID for all tracer number
tracer_molw_id, & !ID for all tracer molecular weights
tracer_name_id, & !ID for all tracer names
tracer_transported_id, & !ID for transport flag
native_lon_id, & !Variable id for native longitude size
native_lat_id, & !Variable id for native latitude size
native_lev_id, & !Variable id for native level size
areaxy_id, &
psfc_id, &
air_id, volume_id, airdens_id, temperature_id, &
height_id, lmtrop_id, h2o_id, q_id, &
comps_id(NPAR+NOTRPAR)
character(len=TNAMELEN), dimension(NPAR+NOTRPAR) :: tracer_name
real(r8), dimension(NPAR+NOTRPAR) :: tracer_molw
integer, dimension(NPAR+NOTRPAR) :: tracer_idx
integer, dimension(NPAR+NOTRPAR) :: tracer_transported
!// --------------------------------------------------------------------
integer, parameter :: nc4deflate = nc4deflate_global
integer, parameter :: nc4shuffle = nc4shuffle_global
!// --------------------------------------------------------------------
character(len=*), parameter :: subr = 'AVG_WRT_NC4'
!//---------------------------------------------------------------------
ZNRAVG = 1._r8 / real(NRAVG,r8)
write(6,'(A,I5,F9.5)') 'avg_wrt_nc ',NRAVG,ZNRAVG
!// The transported species
do N = 1, NTM
do L = 1, LPAR
do J = 1, JPAR
do I = 1, IPAR
STTAVG(I,J,L,N) = ZNRAVG * STTAVG(I,J,L,N)
end do
end do
end do
end do
!// H2O
do L = 1, LPAR
do J = 1, JPAR
do I = 1, IPAR
H2OAVG(I,J,L) = ZNRAVG * H2OAVG(I,J,L)
end do
end do
end do
!// Q
do L = 1,LPAR
do J = 1,JPAR
do I = 1,IPAR
QAVG(I,J,L) = ZNRAVG * QAVG(I,J,L)
end do
end do
end do
!// Air
do L = 1,LPAR
do J = 1,JPAR
do I = 1,IPAR
AIRAVG(I,J,L) = ZNRAVG * AIRAVG(I,J,L)
end do
end do
end do
!// DV
do L = 1,LPAR
do J = 1,JPAR
do I = 1,IPAR
DVAVG(I,J,L) = ZNRAVG * DVAVG(I,J,L)
end do
end do
end do
!// Air density
do L = 1,LPAR
do J = 1,JPAR
do I = 1,IPAR
AMAVG(I,J,L) = ZNRAVG * AMAVG(I,J,L)
end do
end do
end do
!// Temperature
do L = 1,LPAR
do J = 1,JPAR
do I = 1,IPAR
TEMPAVG(I,J,L) = ZNRAVG * TEMPAVG(I,J,L)
end do
end do
end do
!// Surface pressure
do J = 1,JPAR
do I = 1,IPAR
PSFCAVG(I,J) = ZNRAVG * PSFCAVG(I,J)
end do
end do
!// Height
do J = 1,JPAR
do I = 1,IPAR
do L = 1,LPAR+1
ZHAVG(L,I,J) = ZNRAVG * ZHAVG(L,I,J)
end do
end do
end do
!// LMTROP
do J = 1,JPAR
do I = 1,IPAR
LMTROPAVG(I,J) = ZNRAVG * LMTROPAVG(I,J)
end do
end do
!// H2O mixing ratio at LMTROP+1
do J = 1,JPAR
do I = 1,IPAR
H2OAVG_LMT1(I,J) = ZNRAVG * H2OAVG_LMT1(I,J)
end do
end do
!// Non-transported species if present
if (NOTRPAR .gt. 0) then
do J = 1,JPAR
do I = 1,IPAR
do N = 1,NOTRPAR
do L = 1,LPAR
XSTTAVG(L,N,I,J) = ZNRAVG * XSTTAVG(L,N,I,J)
end do
end do
end do
end do
end if
!// Make list of all tracer names
do N = 1, NPAR
tracer_name(N) = TNAME(N)
end do
do N = 1, NOTRPAR
tracer_name(NPAR + N) = XTNAME(N)
end do
!// List of component numbers
do N = 1, NPAR
tracer_idx(N) = chem_idx(N)
end do
do N = 1, NOTRPAR
tracer_idx(NPAR + N) = Xchem_idx(N)
end do
!// List of flags for transported (1) or non-transported (0)
do N = 1, NPAR
tracer_transported(N) = 1
end do
do N = 1, NOTRPAR
tracer_transported(NPAR + N) = 0
end do
!// Make list of their molecular mass
do N = 1, NPAR
tracer_molw(N) = TMASS(N)
end do
do N = 1, NOTRPAR
tracer_molw(NPAR + N) = XTMASS(N)
end do
!//---------------------------------------------------------------------
!// Write netcdf4 file.
!//---------------------------------------------------------------------
!// File name is avgsavSTARTDATE-ENDDATE.nc, where STARTDATE is taken
!// from JYEAR1,JMON1,JDATE1,00UTC and ENDDATE is taken from current
!// time, which is JYEAR,JMON,JDATE,00UTC (already updated by calendar).
!// Format of the dates are YYYYMMDDHHMM, where HHMM always is 0000.
!//---------------------------------------------------------------------
!// Start of average period at 00:00UTC
start_time = (/JYEAR1,JMON1,JDATE1,0,0,0/)
write(datestamp0(1:8),'(i4.4,2i2.2)') JYEAR1,JMON1,JDATE1
!// End of average period at 00:00UTC
end_time = (/JYEAR,JMON,JDATE,0,0,0/)
write(datestamp(1:8),'(i4.4,2i2.2)') JYEAR,JMON,JDATE
!//---------------------------------------------------------------------
!// File name
FN_AVG = trim(RESULTDIR)//'avgsav_'//datestamp0//'_'//datestamp//'.nc'
!// Open netCDF4 file for writing
status=nf90_create(path=FN_AVG,cmode=nf90_netcdf4,ncid=ncid)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': in creating file')
!//---------------------------------------------------------------------
!//---------------------------------------------------------------------
!//File headers
status=nf90_put_att(ncid,nf90_global,'title','Oslo CTM3 averages')
if (status/=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/=nf90_noerr) call handle_error(status, f90file//':'//subr//': model_info')
status=nf90_put_att(ncid,nf90_global,'driving_meteorology',metTypeInfo)
if (status/=nf90_noerr) call handle_error(status, f90file//':'//subr//': driving_meteorology')
status=nf90_put_att(ncid,nf90_global,'driving_meteorology_path',MPATH1)
if (status/=nf90_noerr) call handle_error(status, f90file//':'//subr//': driving_meteorology_path')
status=nf90_put_att(ncid,nf90_global,'resolution_info',resolutionInfo)
if (status/=nf90_noerr) call handle_error(status, f90file//':'//subr//': resolution_info')
status=nf90_put_att(ncid,nf90_global,'runtitle',trim(runtitle))
if (status/=nf90_noerr) call handle_error(status, f90file//':'//subr//': runtitle')
status=nf90_put_att(ncid,nf90_global,'contact_info','For errors, contact CICERO')
if (status/=nf90_noerr) call handle_error(status, f90file//':'//subr//': contact_info')
!// Define lat/lon/lev
status = nf90_def_dim(ncid,"lat",JPAR,lat_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define lat dim')
status = nf90_def_dim(ncid,"lon",IPAR,lon_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define lon dim')
status = nf90_def_dim(ncid,"lev",LPAR,lev_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define lev dim')
!// Define ilat/ilon/ilev
status = nf90_def_dim(ncid,"ilat",JPAR+1,ilat_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define ilat dim')
status = nf90_def_dim(ncid,"ilon",IPAR+1,ilon_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//':define ilon dim')
status = nf90_def_dim(ncid,"ilev",LPAR+1,ilev_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define ilev dim')
!// Define NCOMPS = NPAR+NOTRPAR
status = nf90_def_dim(ncid,"NCOMPS",NPAR+NOTRPAR,ncomps_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define NCOMPS dim')
!// Define length of tracer name string (use TNAME for this)
status = nf90_def_dim(ncid,"tracer_name_len",TNAMELEN,tracer_name_len_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define tracer_name_len dim')
!// Define size of date stamps
status = nf90_def_dim(ncid,"date_size",size(start_time),date_size_dim_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define date_size dim')
!// Defining the combined id for a 2d field (lon,lat)
dim_lon_lat_id(1) = lon_dim_id
dim_lon_lat_id(2) = lat_dim_id
!// Defining the combined id for a 3d field (lon,lat,lev)
dim_lon_lat_lev_id(1) = lon_dim_id
dim_lon_lat_lev_id(2) = lat_dim_id
dim_lon_lat_lev_id(3) = lev_dim_id
!// Defining the combined id for a reversed 3d field (ilev,lon,lat)
dim_ilev_lon_lat_id(1) = ilev_dim_id
dim_ilev_lon_lat_id(2) = lon_dim_id
dim_ilev_lon_lat_id(3) = lat_dim_id
!// Defining the lon variable
status = nf90_def_var(ncid,"lon",nf90_double,lon_dim_id,lon_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define lon variable')
!// Attributes
status = nf90_put_att(ncid,lon_id,'units','degrees east')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units lon')
status = nf90_put_att(ncid,lon_id,'description','Value at grid box center.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description lon')
!// Defining the lat variable
status = nf90_def_var(ncid,"lat",nf90_double,lat_dim_id,lat_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define lat variable')
!// Attributes
status = nf90_put_att(ncid,lat_id,'units','degrees north')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units lat')
status = nf90_put_att(ncid,lat_id,'description','Value at grid box center.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description lat')
!// Defining the lev variable
status = nf90_def_var(ncid,"lev",nf90_double,lev_dim_id,lev_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define lev variable')
!// Attributes
status = nf90_put_att(ncid,lev_id,'units','hPa')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units lev')
status = nf90_put_att(ncid,lev_id,'description', &
'Pressure at mass-weighted grid box center (mean of pressures at upper and lower edges), assuming surface at 1000hPa.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description lev')
!// Defining ilon variable (lon on interstices)
status = nf90_def_var(ncid,"ilon",nf90_double,ilon_dim_id,ilon_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define ilon variable')
!// Attributes
status = nf90_put_att(ncid,ilon_id,'units','degrees east')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units ilon')
status = nf90_put_att(ncid,ilon_id,'description','Value at eastern edge of grid box.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description ilon')
!// Defining ilat variable (lat on interstices)
status = nf90_def_var(ncid,"ilat",nf90_double,ilat_dim_id,ilat_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define ilat variable')
!// Attributes
status = nf90_put_att(ncid,ilat_id,'units','degrees north')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units ilat')
status = nf90_put_att(ncid,ilat_id,'description','Value at southern edge of grid box.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description ilat')
!// Defining ilev variable (lev on interstices)
status = nf90_def_var(ncid,"ilev",nf90_double,ilev_dim_id,ilev_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define ilev variable')
!// Attributes
status = nf90_put_att(ncid,ilev_id,'units','hPa')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units ilev')
status = nf90_put_att(ncid,ilev_id,'description', &
'Pressure at lower edge of grid box, assuming surface at 1000hPa.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description ilev')
!// Defining hybrid sigma coordinate A
status = nf90_def_var(ncid,"ihya",nf90_double,ilev_dim_id,ihya_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define ihya variable')
!// Attributes
status = nf90_put_att(ncid,ihya_id,'units','hPa')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units ihya')
status = nf90_put_att(ncid,ihya_id,'description', 'Sigma hybrid coordinate A.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description ihya')
status = nf90_put_att(ncid,ihya_id,'usage','p_box_bottom(L) = ihya(L) + ihyb(L)*p_surface')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute usage ihya')
!// Defining hybrid sigma coordinate B
status = nf90_def_var(ncid,"ihyb",nf90_double,ilev_dim_id,ihyb_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define ihyb variable')
!// Attributes
status = nf90_put_att(ncid,ihyb_id,'units','1')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units ihyb')
status = nf90_put_att(ncid,ihyb_id,'description', 'Sigma hybrid coordinate B.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description ihyb')
status = nf90_put_att(ncid,ihyb_id,'usage','p_box_bottom(L) = ihya(L) + ihyb(L)*p_surface')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute usage ihyb')
!// Info about native size IPARW
status = nf90_def_var(ncid,"IPARW",nf90_int,native_lon_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define IPARW variable')
status = nf90_put_att(ncid,native_lon_id,'description', &
'Meteorological data native longitudinal resolution')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description IPARW')
!// Info about native size JPARW
status = nf90_def_var(ncid,"JPARW",nf90_int,native_lat_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define JPARW variable')
status = nf90_put_att(ncid,native_lat_id,'description', &
'Meteorological data native latitudinal resolution')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description JPARW')
!// Info about native size LPARW
status = nf90_def_var(ncid,"LPARW",nf90_int,native_lev_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define LPARW variable')
status = nf90_put_att(ncid,native_lev_id,'description', &
'Meteorological data vertical resolution')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description LPARW')
!// Number of time steps accumulated - NRAVG
status = nf90_def_var(ncid,"NRAVG",nf90_int,nravg_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define NRAVG variable')
status = nf90_put_att(ncid,nravg_id,'description', &
'Number of time steps accumulated')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description NRAVG')
!// Start time for accumulating data - START_TIME
status = nf90_def_var(ncid,"START_TIME",nf90_int,date_size_dim_id,start_time_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define START_TIME variable')
status = nf90_put_att(ncid,start_time_id,'description', &
'Start date [YYYY,MM,DD,hh,mm,ss] for accumulating data.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description START_TIME')
!// End time for accumulating data - END_TIME
status = nf90_def_var(ncid,"END_TIME",nf90_int,date_size_dim_id,end_time_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define END_TIME variable')
status = nf90_put_att(ncid,end_time_id,'description', &
'End date [YYYY,MM,DD,hh,mm,ss] for accumulating data.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description END_TIME')
!// Start day for accumulating data - START_DAY (NDAY)
status = nf90_def_var(ncid,"START_DAY",nf90_int,start_day_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define START_DAY variable')
status = nf90_put_att(ncid,start_day_id,'description', &
'Start day for accumulating data (model counter NDAY).')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description START_DAY')
!// End day for accumulating data - END_DAY
status = nf90_def_var(ncid,"END_DAY",nf90_int,end_day_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define END_DAY variable')
status = nf90_put_att(ncid,end_day_id,'description', &
'End day for accumulating data (model counter NDAY).')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description END_DAY')
!// File version number
status = nf90_def_var(ncid,"VERSION",nf90_int,version_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define VERSION variable')
status = nf90_put_att(ncid,version_id,'description', &
'Output file version number')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description VERSION')
!// NPAR and NOTRPAR - they could be handy
status = nf90_def_var(ncid,"NPAR",nf90_int,npar_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define NPAR variable')
status = nf90_put_att(ncid,npar_id,'description', &
'Number of transported species in simulation.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description NPAR')
status = nf90_def_var(ncid,"NOTRPAR",nf90_int,notrpar_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define NOTRPAR variable')
status = nf90_put_att(ncid,notrpar_id,'description', &
'Number of non-transported species in simulation.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description NOTRPAR')
!// All the components
status = nf90_def_var(ncid,"tracer_idx",nf90_int,ncomps_dim_id,tracer_idx_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define tracer_idx variable')
status = nf90_put_att(ncid,tracer_idx_id,'description', &
'ID numbers for species used in Oslo CTM3.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description tracer_idx')
!// Molecular masses of transported components (r8)
status = nf90_def_var(ncid,"tracer_molweight",nf90_double,ncomps_dim_id,tracer_molw_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define tracer_molweight variable')
status = nf90_put_att(ncid,tracer_molw_id,'units','g/mol')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units tracer_molweight')
status = nf90_put_att(ncid,tracer_molw_id,'description', &
'Molecular weights.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description tracer_molweight')
!// Tracer names
status = nf90_def_var(ncid,"tracer_name",nf90_char, &
(/tracer_name_len_dim_id,ncomps_dim_id/),tracer_name_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define tracer_name variable')
status = nf90_put_att(ncid,tracer_name_id,'description', &
'Tracer/species names.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description tracer_name')
!// Transported or not?
status = nf90_def_var(ncid,"tracer_transported",nf90_int,ncomps_dim_id,tracer_transported_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define tracer_transported variable')
status = nf90_put_att(ncid,tracer_transported_id,'units','1/0')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units tracer_transported')
status = nf90_put_att(ncid,tracer_transported_id,'description', &
'Flag if tracer is transported or not.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description tracer_transported')
!// Grid area (r8), deflate netcdf4
status = nf90_def_var(ncid,"gridarea",nf90_double,dim_lon_lat_id,areaxy_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define gridarea variable')
status = nf90_def_var_deflate(ncid,areaxy_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate gridarea variable')
status = nf90_put_att(ncid,areaxy_id,'units','m2')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute unit gridarea')
!// Average surface pressure (r4), deflate netcdf4
status = nf90_def_var(ncid,"Psfc",nf90_float,dim_lon_lat_id,psfc_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define Psfc variable')
status = nf90_def_var_deflate(ncid,psfc_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate Psfc variable')
status = nf90_put_att(ncid,psfc_id,'units','hPa')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute unit Psfc')
!// Air (r4), deflate netcdf4
status = nf90_def_var(ncid,"AIR",nf90_float,dim_lon_lat_lev_id,air_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define AIR variable')
status = nf90_def_var_deflate(ncid,air_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate AIR variable')
status = nf90_put_att(ncid,air_id,'units','kg')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute unit AIR')
!// Volume (r4), deflate netcdf4
status = nf90_def_var(ncid,"volume",nf90_float,dim_lon_lat_lev_id,volume_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define volume variable')
status = nf90_def_var_deflate(ncid,volume_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate volume variable')
status = nf90_put_att(ncid,volume_id,'units','m3')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute unit volume')
!// Air density (r4), deflate netcdf4
status = nf90_def_var(ncid,"air_density",nf90_float,dim_lon_lat_lev_id,airdens_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define air_density variable')
status = nf90_def_var_deflate(ncid,airdens_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate air_density variable')
status = nf90_put_att(ncid,airdens_id,'units','molec/cm3')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute unit air_density')
!// Tempterature (r4), deflate netcdf4
status = nf90_def_var(ncid,"temperature",nf90_float,dim_lon_lat_lev_id,temperature_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define temperature variable')
status = nf90_def_var_deflate(ncid,temperature_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate temperature variable')
status = nf90_put_att(ncid,temperature_id,'units','K')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute unit temperature')
!// Height (r4), deflate netcdf4
status = nf90_def_var(ncid,"height",nf90_float,dim_ilev_lon_lat_id,height_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define height variable')
status = nf90_def_var_deflate(ncid,height_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate height variable')
status = nf90_put_att(ncid,height_id,'units','m')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units height')
status = nf90_put_att(ncid,height_id,'info','Reverse order (ilev,lon,lat)')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute info height')
!// LMTROP, deflate netcdf4
status = nf90_def_var(ncid,"LMTROP",nf90_float,dim_lon_lat_id,lmtrop_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define LMTROP variable')
status = nf90_def_var_deflate(ncid,lmtrop_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate LMTROP variable')
status = nf90_put_att(ncid,lmtrop_id,'units','Uppermost model level in troposphere.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute unit LMTROP')
!// H2O (r4), deflate netcdf4
status = nf90_def_var(ncid,"H2O_all",nf90_float,dim_lon_lat_lev_id,h2o_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define H2O_all variable')
status = nf90_def_var_deflate(ncid,h2o_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate H2O_all variable')
status = nf90_put_att(ncid,h2o_id,'units','kg')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units H2O_all')
status = nf90_put_att(ncid,h2o_id,'info','H2O from metdata Q, but overwritten in the stratosphere by calculated H2O when available.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units H2O_all')
!// Q (r4), deflate netcdf4
status = nf90_def_var(ncid,"Q",nf90_float,dim_lon_lat_lev_id,q_id)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define Q variable')
status = nf90_def_var_deflate(ncid,q_id,nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate Q variable')
status = nf90_put_att(ncid,q_id,'units','kg(H2O)/kg(air)')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units Q')
status = nf90_put_att(ncid,q_id,'description', &
'Specific humidity retrieved from meteorological data.')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute description QAVG')
!// Component by component (r4)
do N = 1, NPAR+NOTRPAR
status = nf90_def_var(ncid,trim(tracer_name(N)),nf90_float,dim_lon_lat_lev_id,comps_id(N))
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define '//trim(tracer_name(N))//' variable')
status = nf90_def_var_deflate(ncid,comps_id(N),nc4shuffle,1,nc4deflate)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': define deflate '//trim(tracer_name(N))//' variable')
status = nf90_put_att(ncid,comps_id(N),'units','kg of species')
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': attribute units '//trim(tracer_name(N)))
end do
!//---------------------------------------------------------------------
!// End definition mode
status = nf90_enddef(ncid)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': end defmode')
!//---------------------------------------------------------------------
!// Putting the lon/lat/lev variables
status = nf90_put_var(ncid,lon_id,XDGRD)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting lon')
status = nf90_put_var(ncid,lat_id,YDGRD)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting lat')
status = nf90_put_var(ncid,lev_id,ZGRD)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting lev')
status = nf90_put_var(ncid,ilon_id,XDEDG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting ilon')
status = nf90_put_var(ncid,ilat_id,YDEDG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting ilat')
status = nf90_put_var(ncid,ilev_id,ZEDG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting ilev')
status = nf90_put_var(ncid,ihya_id,ETAA)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting ihya')
status = nf90_put_var(ncid,ihyb_id,ETAB)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting ihyb')
!// Info about native size
status = nf90_put_var(ncid,native_lon_id,IPARW)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting IPARW')
status = nf90_put_var(ncid,native_lat_id,JPARW)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting JPARW')
status = nf90_put_var(ncid,native_lev_id,LPARW)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting LPARW')
!// Number of time steps added
status = nf90_put_var(ncid,NRAVG_id,NRAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting NRAVG')
!// Start time
status = nf90_put_var(ncid,start_time_id,start_time)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting START_TIME')
!// End time
status = nf90_put_var(ncid,end_time_id,end_time)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting END_TIME')
!// Start day (NDAY counter)
status = nf90_put_var(ncid,start_day_id,NDAY1)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting START_DAY')
!// End day (NDAY counter)
status = nf90_put_var(ncid,end_day_id,IDAY-1)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting END_DAY')
!// File version number
status = nf90_put_var(ncid,version_id,version)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting VERSION')
!// NPAR and NOTRPAR
status = nf90_put_var(ncid,npar_id,NPAR)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting NPAR')
status = nf90_put_var(ncid,notrpar_id,NOTRPAR)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting NOTRPAR')
!// All the transported components
status = nf90_put_var(ncid,tracer_idx_id,tracer_idx)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//':putting tracer_idx')
!// Molecular masses of transported components (r8)
status = nf90_put_var(ncid,tracer_molw_id,tracer_molw)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting tracer_molw')
!// Tracer names
status = nf90_put_var(ncid,tracer_name_id,tracer_name)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting tracer_name')
!// Tracer transport flag
status = nf90_put_var(ncid,tracer_transported_id,tracer_transported)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting tracer_transported')
!// Grid area (r8)
status = nf90_put_var(ncid,areaxy_id,AREAXY)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting AREAXY')
!// Average surface pressure (r4)
status = nf90_put_var(ncid,psfc_id,PSFCAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting PSFCAVG')
!// Average gridbox air mass (r4)
status = nf90_put_var(ncid,air_id,AIRAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting AIRAVG')
!// Average gridbox volume (r4)
status = nf90_put_var(ncid,volume_id,DVAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting DVAVG')
!// Average air density (r4)
status = nf90_put_var(ncid,airdens_id,AMAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting AMAVG')
!// Average temperature (r4)
status = nf90_put_var(ncid,temperature_id,TEMPAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting TEMPAVG')
!// Average heights (r4)
status = nf90_put_var(ncid,height_id,ZHAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting ZHAVG')
!// Average LMTROP (r4)
status = nf90_put_var(ncid,lmtrop_id,LMTROPAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting LMTROPAVG')
!// Average H2O (trop+strat) (r4)
status = nf90_put_var(ncid,h2o_id,H2OAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting H2OAVG')
!// Average Q (r4)
status = nf90_put_var(ncid,q_id,QAVG)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting QAVG')
!// Component by component (r4) - transported first
do N = 1, NPAR
status = nf90_put_var(ncid,comps_id(N),STTAVG(:,:,:,N))
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting '//trim(TNAME(N)))
end do
!// Component by component - not-transported (r4)
if (NOTRPAR .gt. 0) then
do N = 1, NOTRPAR
!// Back from reversed order
do J = 1, JPAR
do I = 1, IPAR
do L = 1, LPAR
r4xyz(I,J,L) = XSTTAVG(L,N,I,J)
end do
end do
end do
status = nf90_put_var(ncid,comps_id(NPAR+N),r4xyz)
if (status/=nf90_noerr) call handle_error(status, &
f90file//':'//subr//': putting '//trim(XTNAME(N)))
end do
end if !// if (NOTRPAR .gt. 0) then
!//---------------------------------------------------------------------
!// close netcdf file
status = nf90_close(ncid)
if (status/=nf90_noerr) call handle_error(status,'close file: '//trim(fn_avg))
write(6,'(a,2i8)') &
f90file//':'//subr//': averages: '//trim(FN_AVG),NRAVG,IDAY-1
write(6,'(a71)') '--------------------------------------------'// &
'---------------------------'
!//---------------------------------------------------------------------
end subroutine AVG_WRT_NC4
!//-----------------------------------------------------------------------
!//-----------------------------------------------------------------------
subroutine AVG_ADD2_H2O(BTT,AIRB,MP)
!//---------------------------------------------------------------------
!// Routine for H2O 3D averages, when H2O is not calculated in
!// chemistry. Works in IJ-blocks.
!//
!// Ole Amund Sovde, March 2010
!//---------------------------------------------------------------------
use cmn_precision, only: r8
use cmn_size, only: IPAR, JPAR, LPAR, NPAR, IDBLK, JDBLK, &
MPBLK, LOSLOCSTRAT
use cmn_ctm, only: MPBLKIB, MPBLKIE, MPBLKJB, MPBLKJE
use cmn_chem, only: TMASSMIX2MOLMIX
use cmn_met, only: Q
use cmn_parameters, only: M_AIR
use cmn_oslo, only: H2OAVG, LMTROP, trsp_idx, QAVG, H2OAVG_LMT1
use strat_h2o, only: STR_H2O
!//---------------------------------------------------------------------
implicit none
!//---------------------------------------------------------------------
!// Input
real(r8), dimension(LPAR,IDBLK,JDBLK), intent(in) :: AIRB
real(r8), dimension(LPAR,NPAR,IDBLK,JDBLK), intent(in) :: BTT
integer, intent(in) :: MP
!// Locals
integer :: I, J, L, II, JJ, LL
!//---------------------------------------------------------------------
!// Q from metdata
do L = 1, LPAR
do J = 1, JPAR
do I = 1, IPAR
QAVG(I,J,L) = QAVG(I,J,L) + Q(I,J,L)
end do
end do
end do
!// Tropospheric H2O from metdata (stratosphere fetched below)
do J = MPBLKJB(MP), MPBLKJE(MP)
JJ = J - MPBLKJB(MP) + 1
do I = MPBLKIB(MP), MPBLKIE(MP)
II = I - MPBLKIB(MP) + 1
do L = 1, LMTROP(I,J)
H2OAVG(I,J,L) = H2OAVG(I,J,L) + Q(I,J,L)*AIRB(L,II,JJ)
end do
end do
end do
!// Stratospheric H2O from BTT or STR_H2O
if (trsp_idx(114).gt.0) then
!// Aircraft H2O is included in tracer 114
do J = MPBLKJB(MP), MPBLKJE(MP)
JJ = J - MPBLKJB(MP) + 1
do I = MPBLKIB(MP), MPBLKIE(MP)
II = I - MPBLKIB(MP) + 1
do L = LMTROP(I,J)+1, LPAR
H2OAVG(I,J,L) = H2OAVG(I,J,L) + BTT(L,trsp_idx(114),II,JJ)
end do