-
Notifications
You must be signed in to change notification settings - Fork 0
/
Derived_mod.f90
executable file
·2400 lines (2086 loc) · 96.7 KB
/
Derived_mod.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
module Derived_mod
!---------------------------------------------------------------------------
! DESCRIPTION
! This module performs the calculations associated with "derived" 2D and 3D,
! such as accumulated precipitation or sulphate, daily, monthly or yearly
! averages, depositions. These fields are all typically output as netCDF
! fields.
!
! This routine defines many possible derived outputs.
! The names of the derived fields actualy required should have been specified
! in the user-defined My_Derived_mod.
!
! User-defined routines and treatments are often needed here. Here there is
! added stuff for VOC, AOTs, accsu. In
! general such code should be added in such a way that it isn't activated if
! not needed. It then doesn't need to be commented out if not used.
!---------------------------------------------------------------------------
use AeroConstants_mod, only: AERO
use AOD_PM_mod, only: AOD_init,aod_grp,wavelength,& ! group and
wanted_wlen,wanted_ext3d ! wavelengths
use AOTx_mod, only: Calc_GridAOTx
use Biogenics_mod, only: EmisNat, NEMIS_BioNat, EMIS_BioNat
use CheckStop_mod, only: CheckStop
use Chemfields_mod, only: xn_adv, xn_shl, cfac,xn_bgn, AOD, &
SurfArea_um2cm3, &
Fgas3d, & ! FSOA
Extin_coeff, PM25_water, PM25_water_rh50
use Chemfields_mod , only: so2nh3_24hr,Grid_snow
use ChemDims_mod, only: NSPEC_ADV, NSPEC_SHL,NEMIS_File
use ChemGroups_mod ! SIA_GROUP, PMCO_GROUP -- use tot indices
use ChemSpecs_mod ! IXADV_ indices etc
use Config_module, only: &
KMAX_MID,KMAX_BND & ! => z dimension: layer number,level number
,NPROC & ! No. processors
,dt_advec &
,PPBINV & ! 1.0e9, for conversion of units
,PPTINV & ! 1.0e12, for conversion of units
,PT &
,NTDAY & ! Number of 2D O3 to be saved each day (for SOMO)
,num_lev3d,lev3d & ! 3D levels on 3D output
! output types corresponding to instantaneous,year,month,day
,IOU_INST,IOU_YEAR,IOU_MON,IOU_DAY,IOU_HOUR,IOU_HOUR_INST,IOU_KEY &
,MasterProc, SOURCE_RECEPTOR &
,USES, USE_OCEAN_DMS, USE_OCEAN_NH3, USE_uEMEP, uEMEP, startdate,enddate,&
HourlyEmisOut, SecEmisOutWanted, spinup_enddate
use Debug_module, only: DEBUG ! -> DEBUG%DERIVED and COLSRC
use DerivedFields_mod, only: MAXDEF_DERIV2D, MAXDEF_DERIV3D, &
def_2d, def_3d, f_2d, f_3d, d_2d, d_3d, VGtest_out_ix
use EcoSystem_mod, only: DepEcoSystem, NDEF_ECOSYSTEMS, &
EcoSystemFrac,FULL_ECOGRID
use EmisDef_mod, only: NSECTORS, EMIS_FILE, O_DMS, O_NH3, loc_frac, Nneighbors&
,SecEmisOut, EmisOut, SplitEmisOut, &
isec2SecOutWanted
use EmisGet_mod, only: nrcemis,iqrc2itot
use GasParticleCoeffs_mod, only: DDdefs
use GridValues_mod, only: debug_li, debug_lj, debug_proc, A_mid, B_mid, &
dA,dB,xm2, GRIDWIDTH_M, GridArea_m2,xm_i,xm_j,glon,glat
use Io_Progs_mod, only: datewrite
use MetFields_mod, only: roa,pzpbl,Kz_m2s,th,zen, ustar_nwp, u_ref,&
met, derivmet, & !TEST of targets
ws_10m, rh2m, z_bnd, z_mid, u_mid,v_mid,ps, t2_nwp, &
SoilWater_deep, SoilWater_uppr, Idirect, Idiffuse
use MosaicOutputs_mod, only: nMosaic, MosaicOutput
use My_Derived_mod, only : &
wanted_deriv2d, wanted_deriv3d, & ! names of wanted derived fields
Init_My_Deriv, My_DerivFunc, &
OutputFields, nOutputFields, &
nOutputMisc, OutputMisc, &
nOutputWdep, WDEP_WANTED, D3_OTHER,&
PS_needed
use NumberConstants, only: UNDEF_R
use OwnDataTypes_mod, only: Deriv, print_Deriv_type, &
TXTLEN_DERIV,TXTLEN_SHORT,TXTLEN_IND ! type & length of names
use Par_mod, only: me, & ! for print outs
limax, ljmax ! => used x, y area
use PhysicalConstants_mod, only: PI,KAPPA,ATWAIR,GRAV
use ZchemData_mod, only: Fpart ! for FSOA work
use SmallUtils_mod, only: find_index, LenArray, NOT_SET_STRING, trims
use TimeDate_mod, only: day_of_year,daynumber,current_date,&
tdif_days
use TimeDate_ExtraUtil_mod,only: to_stamp, date_is_reached
use uEMEP_mod, only: av_uEMEP
use Units_mod, only: Units_Scale,Group_Units,&
to_molec_cm3 ! converts roa [kg/m3] to M [molec/cm3]
implicit none
private
public :: Init_Derived
public :: ResetDerived ! Resets values to zero
public :: DerivedProds ! Calculates any production terms
public :: AddDeriv ! Adds Deriv type to def_2d, def_3d
public :: AddNewDeriv ! Creates & Adds Deriv type to def_2d, def_3d
private :: Define_Derived
public :: wanted_iou ! (iotyp, def%iotyp)
private :: Setups
private :: write_debug
private :: write_debugadv
public :: Derived ! Calculations of sums, avgs etc.
private :: voc_2dcalc ! Calculates sum of VOC for 2d fields
private :: voc_3dcalc ! Calculates sum of VOC for 3d fields
private :: group_calc ! Calculates sum of groups, e.g. pm25 from group array
logical, private, parameter :: T = .true., F = .false. ! shorthands only
integer, public, save :: num_deriv2d, num_deriv3d
integer, private,save :: Nadded2d = 0, Nadded3d=0 ! No. defined derived
! List of wanted IOUs
integer, parameter :: &
IOU_MIN=lbound(IOU_KEY,DIM=1), &
IOU_MAX=ubound(IOU_KEY,DIM=1)
logical, public, save :: &
iou_list(IOU_MIN:IOU_MAX)=.false.
! The 2-d and 3-d fields use the above as a time-dimension. We define
! LENOUTxD according to how fine resolution we want on output. For 2d
! fields we use daily outputs. For the big 3d fields, monthly output
! is sufficient.
integer, public, parameter :: &
LENOUT2D = IOU_HOUR,& ! Allows INST..DAY for 2d fields
LENOUT3D = IOU_HOUR ! Allows INST..DAY for 3d fields
!will be used for:
!e.g. d_2d( num_deriv2d,LIMAX, LJMAX, LENOUT2D)
! & d_3d( num_deriv3d,LIMAX, LJMAX, num_lev3d, LENOUT3D )
! save O3 every hour during one day to find running max
real, save , allocatable , public :: & ! to be used for SOMO35
D2_O3_DAY( :,:,:)
! Fraction of NO3_c below 2.5 um (v. crude so far)
real, save, private :: fracPM25 = -999.9
! Counters to keep track of averaging
! Initialise to zero in Init.
integer, public, allocatable, dimension(:,:), save :: nav_2d,nav_3d
!-- some variables for the VOC sum done for ozone models
! (have no effect in non-ozone models - leave in code)
integer, private, save :: nvoc ! No. VOCs
integer, private, dimension(NSPEC_ADV), save :: &
voc_index, & ! Index of VOC in xn_adv
voc_carbon ! Number of C atoms
logical, private, save :: Is3D
logical, private, save :: dbg0 ! = DEBUG%DERIVED .and. MasterProc
logical, private, save :: dbgP ! = DEBUG%DERIVED .and. debug_proc
character(len=100), private :: errmsg
integer, private :: i,j,k,l,n, ivoc, iou, isec ! Local loop variables
integer, private, save :: iadv_O3=-999, & ! Avoid hard codded IXADV_SPCS
iadv_NO3_C=-999,iadv_EC_C_WOOD=-999,iadv_EC_C_FFUEL=-999,iadv_POM_C_FFUEL=-999
real, private, save :: & ! Avoid hard codded molwt
ug_NO3_C=-999.0,ug_EC_C_WOOD=-999.0,ug_EC_C_FFUEL=-999.0,ug_POM_C_FFUEL=-999.0
contains
!=========================================================================
subroutine Init_Derived()
integer :: alloc_err
integer :: iddefPMc
character(len=*), parameter :: dtxt='IniDeriv:' !debug label
dbg0 = (DEBUG%DERIVED .and. MasterProc )
allocate(D2_O3_DAY( LIMAX, LJMAX, NTDAY))
D2_O3_DAY = 0.0
if(USE_uEMEP .and. (uEMEP%HOUR_INST.or.uEMEP%HOUR)) HourlyEmisOut = .true.
if(dbg0) write(*,*) dtxt//"INIT STUFF"
call Init_My_Deriv() !-> wanted_deriv2d, wanted_deriv3d
! get lengths of wanted arrays (excludes notset values)
num_deriv2d = LenArray(wanted_deriv2d,NOT_SET_STRING)
num_deriv3d = LenArray(wanted_deriv3d,NOT_SET_STRING)
call CheckStop(num_deriv2d<1,dtxt//"num_deriv2d<1 !!")
if(num_deriv2d > 0) then
if(dbg0) write(*,*) dtxt//"Allocate arrays for 2d:", num_deriv2d
allocate(f_2d(num_deriv2d),stat=alloc_err)
call CheckStop(alloc_err,dtxt//"Allocation of f_2d")
allocate(d_2d(num_deriv2d,LIMAX,LJMAX,LENOUT2D),stat=alloc_err)
call CheckStop(alloc_err,dtxt//"Allocation of d_2d")
call CheckStop(alloc_err,dtxt//"Allocation of d_3d")
allocate(nav_2d(num_deriv2d,LENOUT2D),stat=alloc_err)
call CheckStop(alloc_err,dtxt//"Allocation of nav_2d")
nav_2d = 0
end if
if(num_deriv3d > 0) then
if(dbg0) write(*,*) dtxt//"Allocate arrays for 3d: ", num_deriv3d
allocate(f_3d(num_deriv3d),stat=alloc_err)
call CheckStop(alloc_err,dtxt//"Allocation of f_3d")
allocate(d_3d(num_deriv3d,LIMAX,LJMAX,num_lev3d,LENOUT3D),&
stat=alloc_err)
allocate(nav_3d(num_deriv3d,LENOUT3D),stat=alloc_err)
call CheckStop(alloc_err,dtxt//"Allocation of nav_3d")
nav_3d = 0
end if
! Avoid hard codded IXADV_SPCS
iadv_O3 =find_index('O3' ,species_adv(:)%name, any_case=.true. )
iadv_NO3_C =find_index('NO3_c' ,species_adv(:)%name, any_case=.true. )
iadv_EC_C_WOOD =find_index('EC_C_WOOD' ,species_adv(:)%name, any_case=.true. )
iadv_EC_C_FFUEL =find_index('EC_C_FFUEL' ,species_adv(:)%name, any_case=.true. )
iadv_POM_C_FFUEL=find_index('POM_C_FFUEL',species_adv(:)%name, any_case=.true. )
! units scaling
! e.g. ug_NO3_C = 1.0+e9 * MW(NO3)/MW(air)
if(iadv_NO3_C >0)call Units_Scale('ug',iadv_NO3_C ,ug_NO3_C )
if(iadv_EC_C_WOOD >0)call Units_Scale('ug',iadv_EC_C_WOOD ,ug_EC_C_WOOD )
if(iadv_EC_C_FFUEL >0)call Units_Scale('ug',iadv_EC_C_FFUEL ,ug_EC_C_FFUEL )
if(iadv_POM_C_FFUEL>0)call Units_Scale('ug',iadv_POM_C_FFUEL,ug_POM_C_FFUEL)
call Define_Derived()
call Setups() ! just for VOC now
iddefPMc = find_index('PMc',DDdefs(:)%name, any_case=.true.)
select case(nint(DDdefs(iddefPMc)%umDpgV*10))
case(25);fracPM25=0.37
case(30);fracPM25=0.27
end select
if(dbg0) write(*,"(a,i4,2g12.3,i4)") dtxt//' CFAC INIT PMFRACTION Dpgv(um)',&
iddefPMc, fracPM25, nint(10* DDdefs(iddefPMc)%umDpgV )
!S2018 fracPM25, AERO%DpgV(2), nint(1.0e7*AERO%DpgV(2))
call CheckStop( fracPM25 < 0.01, dtxt//"NEED TO SET FRACPM25")
end subroutine Init_Derived
!=========================================================================
subroutine AddNewDeriv( name,class,subclass,txt,unit,index,f2d,&
dt_scale,scale, avg,iotype,Is3D)
character(len=*), intent(in) :: name ! e.g. DDEP_SO2_m2Conif
character(len=*), intent(in) :: class ! Type of data, e.g. ADV or VOC
character(len=*), intent(in) :: subclass
character(len=*), intent(in) :: txt ! text where needed, e.g. "Conif"
character(len=*), intent(in) :: unit ! writen in netCDF output
integer, intent(in) :: index ! index in concentation array, or other
integer, intent(in) :: f2d ! index in f_2d arrays
logical, intent(in) :: dt_scale ! where scaling by dt_advec needed,
real, intent(in) :: scale ! e.g. use 100.0 to get cm/s
logical, intent(in) :: avg ! True => average data (divide by
! nav at end), else accumulate over run period
character(len=*), intent(in) :: iotype ! sets daily, monthly, etc.
logical, intent(in), optional :: Is3D
type(Deriv) :: inderiv
if(trim(name)=="HMIX".and.DEBUG%DERIVED .and. MasterProc)&
write(*,*) "ADDNEWDERIVE", iotype
inderiv=Deriv(trim(name),trim(class),trim(subclass),&
trim(txt),trim(unit),index,f2d,dt_scale, scale,&
avg,iotype)
call AddDeriv(inderiv,Is3D=Is3D)
end subroutine AddNewDeriv
!=========================================================================
subroutine AddDeriv(inderiv,Is3D)
type(Deriv), intent(in) :: inderiv
logical, intent(in), optional :: Is3D
logical :: Is3D_local
dbg0 = (DEBUG%DERIVED .and. MasterProc )
Is3D_local = .false.
if(present(Is3D)) Is3D_local = Is3D
if(Is3D_local) then
Nadded3d = Nadded3d + 1
N = Nadded3d
if(dbg0) write(*,*) "Define 3d deriv ", N, trim(inderiv%name)
call CheckStop(N>MAXDEF_DERIV3D,"Nadded3d too big! Increase MAXDEF_DERIV3D in DerivedFields_mod")
def_3d(N) = inderiv
else
Nadded2d = Nadded2d + 1
N = Nadded2d
if(dbg0)then
write(*,"(a,i6)") "DEBUG AddDeriv 2d ", N
call print_Deriv_type(inderiv)
end if
!if(dbg0) write(*,*) "DALL", inderiv
call CheckStop(N>MAXDEF_DERIV2D,"Nadded2d too big! Increase MAXDEF_DERIV2D in DerivedFields_mod")
def_2d(N) = inderiv
end if
end subroutine AddDeriv
!=========================================================================
subroutine Define_Derived()
! Set the parameters for the derived parameters, including the codes
! used by MET.NO/xfelt and scaling factors. (The scaling factors may
! be changed later in Derived_mod.
! And, Initialise the fields to zero.
real :: unitscale
logical :: volunit,semivol ! set true for volume units (e.g. ppb),group with semivol
!FAILED logical :: outmm, outdd ! sets time-intervals
character(len=30) :: dname, class
character(len=10) :: unittxt
character(len=TXTLEN_SHORT) :: outname, outunit, outtyp, outdim, subclass
character(len=*), parameter:: dtxt="DefDerived:"
character(len=TXTLEN_IND) :: outind
integer :: ind, iadv, ishl, idebug, n, igrp, iout, isec_poll
logical :: found
if(dbg0) write(6,*) " START DEFINE DERIVED "
! same mol.wt assumed for PPM25 and PPMCOARSE
!-- Deposition fields. Define all possible fields and their xfelt codes here:
!code class avg? ind scale rho Inst Yr Mn Day name unit
Is3D = .false.
! We process the various combinations of gas-species and ecosystem:
! stuff from My_Derived
!Deriv(name, class, subc, txt, unit
!Deriv index, f2d, dt_scale, scale, avg? rho Inst Yr Mn Day atw
! for AOT we can use index for the threshold, usually 40
call AddNewDeriv( "AOT40_Grid", "GRIDAOT","subclass","-", "ppb h", &
40, -99, T, 1.0/3600.0, F, 'YM' )
!-------------------------------------------------------------------------------
!Deriv(name, class, subc, txt, unit
!Deriv index, f2d, dt_scale, scale, avg? rho Inst Yr Mn Day atw
! NOT YET: Scale pressure by 0.01 to get hPa
call AddNewDeriv( "PSURF","PSURF", "SURF","-", "hPa", &
-99, -99, F, 1.0, T, 'YM' )
!NB: do not remove or change name. PS is part of vertical coordinates definition!!
call AddNewDeriv( "PS","PSURF", "SURF","-", "hPa", &
-99, -99, F, 1.0, T, 'YMD'//trim(PS_needed) )
!Added for TFMM scale runs
!A17 call AddNewDeriv( "Kz_m2s","Kz_m2s", "-","-", "m2/s", &
!A17 -99, -99, F, 1.0, T, 'Y' )
!A17 call AddNewDeriv( "u_ref","u_ref", "-","-", "m/s", &
!A17 -99, -99, F, 1.0, T, 'Y' )
! call AddNewDeriv( "SoilWater_deep","SoilWater_deep", "-","-", "m", &
! -99, -99, F, 1.0, T, 'YMD' )
! call AddNewDeriv( "SoilWater_uppr","SoilWater_uppr", "-","-", "m", &
! -99, -99, F, 1.0, T, 'YMD' )
call AddNewDeriv( "T2m","T2m", "-","-", "deg. C", &
-99, -99, F, 1.0, T, 'YM' )
!A17 call AddNewDeriv( "Idirect","Idirect", "-","-", "W/m2", &
!A17 -99, -99, F, 1.0, T, 'YM' )
!A17 call AddNewDeriv( "Idiffuse","Idiffuse", "-","-", "W/m2", &
!A17 -99, -99, F, 1.0, T, 'YM' )
! OutputFields can contain both 2d and 3d specs.
! Settings for 2D and 3D are independant.
do ind = 1, nOutputFields
outname= trim(OutputFields(ind)%txt1)
outunit= trim(OutputFields(ind)%txt2) ! eg ugN, which gives unitstxt ugN/m3
outdim = trim(OutputFields(ind)%txt3) ! 2d or 3d or e.g. k20
outtyp = trim(OutputFields(ind)%txt5) ! SPEC or GROUP or MISC
outind = OutputFields(ind)%ind ! H, D, M - fequency of output
subclass = '-' ! default
Is3D = .false.
if(outtyp=="MISC") then ! Simple species
iout = -99 ! find_index( wanted_deriv2d(i), def_2d(:)%name )
class = trim(OutputFields(ind)%txt4)
select case(class)
case ('Z_MID','Z','Z_BND','Zlev','dZ_BND','dZ')
iadv = -1
unitscale=1.0
unittxt="m"
Is3D=.true.
case('PM25','PM25X','PM25_rh50','PM25X_rh50','PM10_rh50',&
'PM25water','PM25_wet','PM10_wet')
iadv = -1 ! Units_Scale(iadv=-1) returns 1.0
! group_calc gets the unit conversion factor from Group_Units
call Units_Scale(outunit,iadv,unitscale,unittxt)
Is3D=(outdim=='3d')
! if(MasterProc) write(*,*)"FRACTION UNITSCALE ", unitscale
case('FLYmax6h','FLYmax6h:SPEC') ! Fly Level, 6 hourly maximum
iout=find_index(outname, species_adv(:)%name, any_case=.true. )
!-- Volcanic Emission: Skipp if not found
if(outname(1:3)=="ASH")then
if(MasterProc.and.DEBUG%COLSRC)&
write(*,"(A,':',A,1X,I0,':',A)")'ColumSource',trim(outtyp),iout,trim(outname)
if(iout<1)cycle
end if
call CheckStop(iout<0,dtxt//"OutputFields "//trim(outtyp)//&
" not found "//trim(outname))
call Units_Scale(outunit,iout,unitscale,unittxt)
outtyp = "FLYmax6h:SPEC"
subclass = outdim ! flxxx-yyy: xxx to yyy 100 feet
outname = "MAX6h_"//trim(outname)//"_"//trim(subclass)
case('FLYmax6h:GROUP') ! Fly Level, 6 hourly maximum
iout=find_index(outname,chemgroups(:)%name, any_case=.true.)
!-- Volcanic Emission: Skipp if not found
if(outname(1:3)=="ASH")then
if(MasterProc.and.DEBUG%COLSRC)&
write(*,"(A,':',A,1X,I0,':',A)")'ColumSource',trim(class),iout,trim(outname)
if(iout<1)cycle
end if
call CheckStop(iout<0,dtxt//"OutputFields "//trim(outtyp)//&
" not found "//trim(outname))
call Units_Scale(outunit,-1,unitscale,unittxt)
outtyp = "FLYmax6h:GROUP"
subclass = outdim ! flxxx-yyy: xxx to yyy 100 feet
outname = "MAX6h_"//trim(outname)//"_"//trim(subclass)
case('COLUMN','COLUMN:SPEC')
!COL 'NO2', 'molec/cm2' ,'k20','COLUMN' ,'MISC' ,4,
iout=find_index(outname, species_adv(:)%name, any_case=.true. )
call CheckStop(iout<0,dtxt//"OutputFields "//trim(outtyp)//&
" not found "//trim(outname))
call Units_Scale(outunit,iout,unitscale,unittxt)
outtyp = "COLUMN:SPEC"
subclass = outdim ! k20, k16...
outname = "COLUMN_" // trim(outname) // "_" // trim(subclass)
case('COLUMN:GROUP')
iout=find_index(outname,chemgroups(:)%name, any_case=.true.)
call CheckStop(iout<0,dtxt//"OutputFields "//trim(outtyp)//&
" not found "//trim(outname))
call Units_Scale(outunit,-1,unitscale,unittxt)
outtyp = "COLUMN:GROUP"
subclass = outdim ! k20, k16...
outname = "COLUMN_" // trim(outname) // "_" // trim(subclass)
case('AOD','AOD:TOTAL','AOD:SPEC','AOD:SHL','AOD:GROUP',&
'EXT','EXT:TOTAL','EXT:SPEC','EXT:SHL','EXT:GROUP')
if(.not.USES%AOD)cycle
select case(class)
case('AOD:GROUP','EXT:GROUP')
select case(outname)
case('AOD','EXT') ! take the full aod_group
iout=find_index('EXTINC',chemgroups_maps(:)%name, any_case=.true.)
case default ! cherry pick from aod_group
iout=find_index(outname,chemgroups(:)%name, any_case=.true.)
end select
case('AOD:SPEC','EXT:SPEC' )
iout=find_index(outname,species_adv(:)%name, any_case=.true.)
case default
call CheckStop(dtxt//"OutputFields%class Unsupported "//&
trim(outtyp)//":"//trim(outname)//":"//trim(outdim))
end select
call CheckStop(iout<0,dtxt//"OutputFields%class "//trim(class)//&
" not found "//trim(outname))
unitscale = 1.0
unittxt = trim(outunit)
subclass = outdim ! 330nm .. 1020nm
if(outname(1:3)/=class(1:3))&
outname = class(1:3)//"_"//trim(outname)
outname = trim(outname)//"_"//trim(subclass)
Is3D = (class(1:3)=="EXT")
call AOD_init("Derived:"//trim(class),wlen=trim(subclass),out3d=Is3D)
case default
if(outdim=='3d')Is3D=.true.
unitscale = 1.0
if(outunit=="ppb") unitscale = PPBINV
unittxt=trim(outunit)
end select
if(MasterProc)write(*,"(3a)") &
"Deriv:MISC "//trim(outname),outind,trim(class)
call AddNewDeriv(outname,class,subclass,"-",trim(unittxt),&
iout,-99,F,unitscale,T,outind,Is3D=Is3D)
else ! SPEC and GROUPS of specs.
select case(outtyp)
case("SPEC") ! Simple species
iadv = find_index(outname, species_adv(:)%name, any_case=.true. )
!-- Volcanic Emission: Skipp if not found
if(outname(1:3)=="ASH")then
if(MasterProc.and.DEBUG%COLSRC)&
write(*,"(A,':',A,1X,I0,':',A)")'ColumSource',trim(outtyp),iadv,trim(outname)
if(iadv<1)cycle
end if
call CheckStop(iadv<0,dtxt//"OutputFields Species not found "//trim(outname))
iout = iadv
call Units_Scale(outunit,iadv,unitscale,unittxt,volunit)
case("SHL")
ishl = find_index(outname,species_shl(:)%name, any_case=.true.)
call CheckStop(ishl<0,dtxt//"OutputFields Short lived Species not found "//trim(outname))
if(MasterProc) &
write(*,*)"OutputFields Short lived Species found: "//trim(outname)
iout = ishl
unitscale = 1.0
unittxt = "molec/cm3" ! No PPB possibility here !!!
volunit = .true.
case("GROUP") ! groups of species
igrp = find_index(outname, chemgroups(:)%name, any_case=.true. )
!-- Volcanic Emission: Skipp if not found
if(outname(1:3)=="ASH")then
if(MasterProc.and.DEBUG%COLSRC)&
write(*,"(A,':',A,1X,I0,':',A)")'ColumSource',trim(outtyp),igrp,trim(outname)
if(igrp<1)cycle
end if
call CheckStop(igrp<0,dtxt//"OutputFields Group not found "//trim(outname))
iout = igrp
call Units_Scale(outunit,-1,unitscale,unittxt,volunit,semivol=semivol)
! Units_Scale(iadv=-1) returns 1.0
! group_calc gets the unit conversion factor from Group_Units
if( semivol ) subclass = 'FSOA'
if(debug_proc.and.DEBUG%DERIVED) write(*,"(2a)") 'FSOA GRPOM:', &
trims( outname // ':' // outunit // ':' // subclass )
case default
call CheckStop(dtxt//" Unsupported OutputFields%outtyp "//&
trim(outtyp)//":"//trim(outname)//":"//trim(outdim))
end select
class="MASS";if(volunit)class="PPB" ! CHANGE PPB to VOL
select case(outdim)
case("2d","2D","SURF")
Is3D = .false.
class = "SURF_"//trim(class) //"_"//trim(outtyp)
dname = "SURF_"//trim(outunit)//"_"//trim(outname)
call CheckStop(find_index(dname,def_2d(:)%name, any_case=.true.)>0,&
dtxt//"OutputFields already defined output "//trim(dname))
case("Local_Correct")
Is3D = .false.
class = "SURF_"//trim(class) //"_"//trim(outtyp)
dname = "SURF_LF_"//trim(outunit)//"_"//trim(outname)
subclass = 'LocFrac_corrected'
call CheckStop(find_index(dname,def_2d(:)%name, any_case=.true.)>0,&
dtxt//"OutputFields already defined output "//trim(dname))
if(dbg0) write(*,"(a,2i4,4(1x,a),es10.2)")"ADD",&
ind, iout, trim(dname),";", trim(class), outind,unitscale
case("3d","3D","MLEV")
Is3D = .true.
class = "3D_"//trim(class) //"_"//trim(outtyp)
dname = "D3_"//trim(outunit)//"_"//trim(outname)
call CheckStop(find_index(dname,def_3d(:)%name, any_case=.true.)>0,&
dtxt//"OutputFields already defined output "//trim(dname))
! Always print out 3D info. Good to help avoid using 3d unless really needed!
if( MasterProc ) write(*,"(a,2i4,4(1x,a),es10.2)")"ADD 3D outputs", &
ind, iout, trim(dname),";", trim(class), outind,unitscale
case default
call CheckStop(dtxt//" Unsupported OutputFields%outdim "//&
trim(outtyp)//":"//trim(outname)//":"//trim(outdim))
end select
!FSOA call AddNewDeriv(dname,class,"-","-",trim(unittxt),&
call AddNewDeriv(dname,class,subclass,"-",trim(unittxt),&
iout,-99,F,unitscale,T,outind,Is3D=Is3D)
end if
end do ! OutputFields
!<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
do n = 1, nOutputMisc
Is3D=(OutputMisc(n)%class=="MET3D").or.(OutputMisc(n)%name(1:2)=='D3')&
.or.(OutputMisc(n)%subclass(1:2)=='D3')
if(MasterProc) write(*,"(3(A,1X),L1)") &
'ADDMISC',trim(OutputMisc(n)%name),'Is3D',Is3D
call AddDeriv(OutputMisc(n),Is3D=Is3D)
end do
!-------------------------------------------------------------------------------
do n = 1, nMosaic
if ( dbg0 ) write(*,*) "DEBUG MOSAIC AddDeriv ", n, MosaicOutput(n)
call AddDeriv( MosaicOutput(n) )
end do
!-------------------------------------------------------------------------------
! Areas of deposition-related ecosystems. Set externally
do n = 1, NDEF_ECOSYSTEMS
if(dbg0) write(*,*) "ECODEF ",n, trim( DepEcoSystem(n)%name )
call AddDeriv( DepEcoSystem(n) )
end do
!!-------------------------------------------------------------------------------
!<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
do ind = 1, size(WDEP_WANTED(1:nOutputWdep)%txt1)
dname = "WDEP_"//trim(WDEP_WANTED(ind)%txt1)
outind = trim(WDEP_WANTED(ind)%txt4)
select case(WDEP_WANTED(ind)%txt2)
case("PREC")
call AddNewDeriv("WDEP_PREC","PREC ","-","-", "mm", &
-1, -99, F, 1.0, F, outind)
case("SPEC")
iadv = find_index(WDEP_WANTED(ind)%txt1, species_adv(:)%name, any_case=.true.)
call CheckStop(iadv<1, "WDEP_WANTED Species not found " // trim(dname) )
call Units_Scale(WDEP_WANTED(ind)%txt3,iadv,unitscale,unittxt)
call AddNewDeriv( dname, "WDEP", "-", "-", unittxt , &
iadv, -99, F, unitscale, F, outind)
case("GROUP")
igrp = find_index(dname, chemgroups(:)%name, any_case=.true.)
call CheckStop(igrp<1, "WDEP_WANTED Group not found " // trim(dname) )
! Just get units text here.
! Init_WetDep gets the unit conversion factors from Group_Scale.
call Units_Scale(WDEP_WANTED(ind)%txt3,-1,unitscale,unittxt)
call AddNewDeriv( dname, "WDEP ","-","-", unittxt , &
igrp, -99, F, 1.0, F, outind)
case default
call CheckStop("Unknown WDEP_WANTED type " // trim(WDEP_WANTED(ind)%txt2) )
end select
if(MasterProc) write(*,*)"Wet deposition output: ",trim(dname)," ",trim(unittxt)
end do
!Emissions:
! We use mg/m2 outputs for consistency with depositions
! Would need to multiply by GridArea_m2 later to get ktonne/grid, but not
! done here.
!
! BVOC called every dt_advec, so use dt_scale=1.0e6 to get from kg/m2/s to
! mg/m2 accumulated (after multiplication by dt_advec)
! AddNewDeriv( name,class,subclass,txt,unit,
! index,f2d, dt_scale,scale, avg,iotype,Is3D)
do ind = 1, NEMIS_BioNat
if(EMIS_BioNat(ind)(1:5)=="ASH_L")cycle ! skip ASH_LxxByy for AshInversion
dname = "Emis_mgm2_BioNat" // trim(EMIS_BioNat(ind) )
if(MasterProc) write(*,'(a,i4,a)') dtxt//'NatEmis ', ind, trim(dname)
call AddNewDeriv( dname, "NatEmis", "-", "-", "mg/m2", &
ind , -99, T , 1.0e6, F, 'YM' )
end do
! SNAP emissions called every hour, given in kg/m2/s, but added to
! d_2d every advection step, so get kg/m2.
! Need 1.0e6 to get from kg/m2 to mg/m2 accumulated.
!
! Future option - might make use of Emis_Molwt to get mg(N)/m2
do ind = 1, size(EMIS_FILE)
dname = "Emis_mgm2_" // trim(EMIS_FILE(ind))
if(HourlyEmisOut)then
call AddNewDeriv( dname, "TotEmis", "-", "-", "mg/m2", &
ind , -99, T, 1.0e6, F, 'YMH' )
else
call AddNewDeriv( dname, "TotEmis", "-", "-", "mg/m2", &
ind , -99, T, 1.0e6, F, 'YM' )
endif
end do ! ind
isec_poll = 0
do i = 1, NEMIS_File
dname = "Sec_Emis_mgm2_"//trim(EMIS_FILE(i))
isec_poll = i
if(HourlyEmisOut)then
call AddNewDeriv( dname, "SecEmis", "-", "-", "mg/m2", &
isec_poll , -99, T, 1.0e6, F, 'YMH' )
else
call AddNewDeriv( dname, "SecEmis", "-", "-", "mg/m2", &
isec_poll , -99, T, 1.0e6, F, 'YM' )
endif
enddo
do isec=1,NSECTORS
if(SecEmisOutWanted(isec))then
do i = 1, NEMIS_File
write(dname,"(A,I0,A)")"Sec",isec,"_Emis_mgm2_"//trim(EMIS_FILE(i))
isec_poll = (isec-1)*NEMIS_File + i
if(HourlyEmisOut)then
call AddNewDeriv( dname, "SecEmis", "-", "-", "mg/m2", &
isec_poll , -99, T, 1.0e6, F, 'YMH' )
else
call AddNewDeriv( dname, "SecEmis", "-", "-", "mg/m2", &
isec_poll , -99, T, 1.0e6, F, 'YM' )
endif
end do
endif
end do
if(USE_OCEAN_DMS)then
dname = "Emis_mgm2_DMS"
call AddNewDeriv( dname, "Emis_mgm2_DMS", "-", "-", "mg/m2", &
ind , -99, T, 1.0, F, 'YM' )
end if
if(USE_OCEAN_NH3)then
dname = "Emis_mgm2_Ocean_NH3"
call AddNewDeriv( dname, "Emis_mgm2_Ocean_NH3", "-", "-", "mg/m2", &
ind , -99, T, 1.0, F, 'YM' )
end if
!Splitted total emissions (inclusive Natural)
do ind=1,nrcemis
dname = "EmisSplit_mgm2_"//trim(species(iqrc2itot(ind))%name)
call AddNewDeriv(dname, "EmisSplit_mgm2", "-", "-", "mg/m2", &
ind , -99, T, 1.0e6, F, 'YM' )
end do
if(find_index("SURF_PM25water",def_2d(:)%name,any_case=.true.)<1)&
call AddNewDeriv("SURF_PM25water", "PM25water", "-", "-","ug/m3", &
-99 , -99, F, 1.0, T, 'YMD' )
! call AddNewDeriv("SURF_PM25", "PM25", "-", "-", "-", &
! -99 , -99, F, 1.0, T, 'YMD' )
! As for GRIDAOT, we can use index for the threshold
call AddNewDeriv( "SOMO35","SOMO", "SURF","-", "ppb.day", &
35, -99, F, 1.0, F, 'YM' )
call AddNewDeriv( "SOMO0 ","SOMO", "SURF","-", "ppb.day", &
0 , -99, F, 1.0, F, 'YM' )
if(iadv_o3>0) &
call AddNewDeriv( "SURF_MAXO3","MAXADV", "O3","-", "ppb", &
iadv_o3, -99, F, PPBINV, F, 'YMD')
!-- 3-D fields
Is3D = .true.
do ind = 1, size(D3_OTHER)
select case ( trim(D3_OTHER(ind)) )
case ("D3_PM25water")
if(find_index("D3_PM25water",def_3d(:)%name,any_case=.true.)<1)&
call AddNewDeriv("D3_PM25water", "PM25water", "-", "-","ug/m3", &
-99, -99, F, 1.0, T, 'YM', Is3D ) !
case ("D3_m_TH")
call AddNewDeriv("D3_m_TH","TH", "-","-", "m", &
-99, -99, F, 1.0, F, 'YM', Is3D )
case ("D3_m2s_Kz")
call AddNewDeriv( "D3_Kz","Kz", "-","-", "-", &
-99, -99, F, 1.0, F, 'YM', Is3D )
case ("D3_T")
call AddNewDeriv("D3_T","T", "-","-", "K", &
-99, -99, F, 1.0, T, 'YM', Is3D )
case ("D3_Zmid")
if(find_index("D3_Zmid",def_3d(:)%name,any_case=.true.)<1)&
call AddNewDeriv("D3_Zmid", "Z_MID", "-", "-", "m", &
-99 , -99, F, 1.0, T, 'YMD', Is3D )
case ("D3_Zlev")
if(find_index("D3_Zlev",def_3d(:)%name,any_case=.true.)<1)&
call AddNewDeriv("D3_Zlev", "Z_BND", "-", "-", "m", &
-99 , -99, F, 1.0, T, 'YMD', Is3D )
end select
end do
! Get indices of wanted fields in larger def_xx arrays:
do i = 1, num_deriv2d
if(dbg0) print *,"CHECK 2d", num_deriv2d, i, trim(wanted_deriv2d(i))
if(MasterProc) call CheckStop(count(f_2d(:i)%name==wanted_deriv2d(i))>0,&
dtxt//"REQUESTED 2D DERIVED ALREADY DEFINED: "//trim(wanted_deriv2d(i)))
ind = find_index( wanted_deriv2d(i), def_2d(:)%name,any_case=.true. )
if(ind>0)then
f_2d(i) = def_2d(ind)
if(dbg0) print "(2(a,i4),3(1x,a))","Index f_2d ",i, &
" = def ",ind,trim(def_2d(ind)%name),trim(def_2d(ind)%unit),trim(def_2d(ind)%class)
elseif(MasterProc)then
print *,"D2IND OOOPS wanted_deriv2d not found: ", wanted_deriv2d(i)
print *,"OOOPS N,N :", num_deriv2d, Nadded2d
print "(a,i4,a)",("Had def_2d: ",idebug,&
trim(def_2d(idebug)%name),idebug = 1, Nadded2d)
call CheckStop(dtxt//"OOPS1 STOPPED" // trim( wanted_deriv2d(i) ) )
end if
end do
do i = 1, num_deriv3d
if(dbg0) print *,"CHECK 3d", num_deriv3d, i, trim(wanted_deriv3d(i))
if(MasterProc)&
call CheckStop(count(f_3d(:i)%name==wanted_deriv3d(i))>0,&
dtxt//"REQUESTED 3D DERIVED ALREADY DEFINED: "//trim(wanted_deriv3d(i)))
ind = find_index( wanted_deriv3d(i), def_3d(:)%name,any_case=.true. )
if(ind>0)then
f_3d(i) = def_3d(ind)
if(dbg0) print "(2(a,i4),3(1x,a))","Index f_3d ",i, &
" = def ",ind,trim(def_3d(ind)%name),trim(def_3d(ind)%unit),trim(def_3d(ind)%class)
elseif(MasterProc)then
print *,"D3IND OOOPS wanted_deriv3d not found: ", wanted_deriv3d(i)
print *,"OOOPS N,N :", num_deriv3d, Nadded3d
print "(a,i4,a)",("Had def_3d: ",idebug,&
trim(def_3d(idebug)%name),idebug = 1, Nadded3d)
call CheckStop(dtxt//"OOPS STOPPED" // trim( wanted_deriv3d(i) ) )
end if
end do
!Initialise to zero
if (num_deriv2d > 0) d_2d(:,:,:,:) = 0.0
if (num_deriv3d > 0) d_3d(:,:,:,:,:) = 0.0
dbgP = ( DEBUG%DERIVED .and. debug_proc )
! Determine actual output time ranges for Wanted output
iou_list(:)=.false.
do iou=IOU_MIN,IOU_MAX
do i=1,num_deriv2d
if(iou_list(iou))exit
iou_list(iou)=(index(f_2d(i)%iotype,IOU_KEY(iou))>0)
end do
do i=1,num_deriv3d
if(iou_list(iou))exit
iou_list(iou)=(index(f_3d(i)%iotype,IOU_KEY(iou))>0)
end do
end do
VGtest_out_ix = 0
if(allocated(f_2d)) &
VGtest_out_ix = find_index("VgRatio", f_2d(:)%subclass)
if(VGtest_out_ix>0 .and. me==0)then
write(*,*)'will output Vg Ratio'
else
if(me==0) write(*,*)'will NOT output Vg Ratio',find_index("VgRatio", f_2d(:)%subclass),find_index("logz0", f_2d(:)%subclass)
endif
if(SOURCE_RECEPTOR)& ! We include daily and monthly also
iou_list(IOU_DAY+1:)=.false. ! for SOURCE_RECEPTOR mode which makes
! it easy for debugging
if(USES%SKIP_INCOMPLETE_OUTPUT)then ! reduce output
! skip daily/monthly/full-run for runs under 1/28/181 days
select case(INT(tdif_days(to_stamp(startdate),to_stamp(enddate))))
case( 0);iou_list(:IOU_HOUR-1)=.false. ! Only hourly outputs
case( 1: 27);iou_list(: IOU_DAY-1)=.false. ! .. and dayly
case( 28:180);iou_list(: IOU_MON-1)=.false. ! .. and monthly
case(181: ); ! .. and full-run
end select
end if
if(dbgP) write(*,"(A,': ',10(I2,A2,L2,:,','))")"Wanted IOUs",&
(iou,IOU_KEY(iou),iou_list(iou),iou=IOU_MIN,IOU_MAX)
end subroutine Define_Derived
!=========================================================================
function wanted_iou(iou,iotype,only_iou) result(wanted)
integer, intent(in) :: iou
character(len=*),intent(in),optional:: iotype
integer ,intent(in),optional:: only_iou
logical :: wanted
wanted=(iou>=IOU_MIN).and.(iou<=IOU_MAX) ! in range ov valid IOUs?
if(wanted)wanted=iou_list(iou) ! any output requires iou?
if(wanted.and.present(iotype))then
wanted=(index(iotype,IOU_KEY(iou))>0) ! iotype contains IOU_KEY(iou)?
end if
if(wanted.and.present(only_iou))then
wanted=(iou==only_iou) ! is only_iou?
end if
end function wanted_iou
!=========================================================================
subroutine Setups()
integer :: n
!*** flexibility note. By making use of character-based tests such
! as for "VOC" below, we achieve code which can stay for
! different chemical mechanisms, without having to define non-used indices.
!*** if voc wanted, set up voc_array. Works for all ozone chemistries
if ( any( f_2d(:)%class == "VOC" ) ) then !TMP .or. &
!TMP any( f_3d(:)%class == "VOC" ) ) then
! was call Setup_VOC(), moved here Mar 2010
!--------------------------------------------------------
! Searches through the advected species and colects the
! index and carbon content of nmhc/voc species, as they are
! defined in CM_ChemSpecs_mod
!
!--------------------------------------------------------
!====================================================================
do n = 1, NSPEC_ADV
if(species( NSPEC_SHL+n )%carbons > 0 .and. &
species( NSPEC_SHL+n )%name /= "CO" .and. &
species( NSPEC_SHL+n )%name /= "CH4" ) then
nvoc = nvoc + 1
voc_index(nvoc) = n
voc_carbon(nvoc) = species( NSPEC_SHL+n )%carbons
end if
end do
!====================================================================
!if (DEBUG .and. MasterProc )then
if ( MasterProc )then
write(6,*) "Derived VOC setup returns ", nvoc, "vocs"
write(6,"(a12,/,(20i3))") "indices ", voc_index(1:nvoc)
write(6,"(a12,/,(20i3))") "carbons ", voc_carbon(1:nvoc)
end if
end if
end subroutine Setups
!=========================================================================
subroutine Derived(dt,End_of_Day,ONLY_IOU)
!*** DESCRIPTION
! Integration and averaging of chemical fields. Intended to be
! a more flexible version of the old chemint routine.
! Includes AOT40, AOT60 if present
real, intent(in) :: dt ! time-step used in intergrations
logical, intent(in) :: End_of_Day ! e.g. 6am for EMEP sites
integer, intent(in), optional :: ONLY_IOU ! IOU_INST update only instantenous fields,
! IOU_HOUR update (mean) hourly and inst. fields.
character(len=len(f_2d%name)) :: name ! See defs of f_2d
character(len=len(f_2d%class)) :: class ! See defs of f_2d
character(len=len(f_2d%subclass)) :: subclass ! See defs of f_2d
character(len=TXTLEN_SHORT) :: txt2
real :: thour ! Time of day (GMT)
real :: timefrac ! dt as fraction of hour (3600/dt)
real :: dayfrac ! fraction of day elapsed (in middle of dt)
real :: af, fl0, fl1
real, save :: km2_grid
integer :: ntime ! 1...NTDAYS
integer :: klow ! lowest extent of column data
real, dimension(LIMAX,LJMAX) :: density ! roa[kgair m-3] when scale in ug, else 1
real, dimension(LIMAX,LJMAX) :: tmpwork
logical, dimension(LIMAX,LJMAX) :: mask2d
real, dimension(LIMAX,LJMAX,KMAX_MID) :: inv_air_density3D
! Inverse of No. air mols/cm3 = 1/M
! where M = roa (kgair m-3) * to_molec_cm3 when ! scale in ug, else 1
logical, save :: first_call = .true.
integer :: igrp, ngrp ! group methods
logical :: needroa
integer, save :: & ! needed for PM25*,PM10*
ind2d_pmfine=-999 ,ind3d_pmfine=-999, &
ind2d_pmwater=-999,ind3d_pmwater=-999, &
ind2d_pm10=-999 ,ind3d_pm10=-999
integer :: imet_tmp, index
real, pointer, dimension(:,:,:) :: met_p => null()
logical, allocatable, dimension(:) :: ingrp
integer :: wlen,ispc,kmax,iem
integer :: isec_poll,isec,iisec,ii,ipoll
real :: default_frac,tot_frac,loc_frac_corr
if(.not. date_is_reached(spinup_enddate))return ! we do not average during spinup
timefrac = dt/3600.0
thour = current_date%hour+current_date%seconds/3600.0
daynumber=day_of_year(current_date%year,current_date%month,&
current_date%day)
! Just calculate once, and use where needed
forall(i=1:limax,j=1:ljmax) density(i,j) = roa(i,j,KMAX_MID,1)
!****** 2-D fields **************************
do n = 1, num_deriv2d
class = f_2d(n)%class
subclass = f_2d(n)%subclass
name = f_2d(n)%name
index = f_2d(n)%index
if( dbgP .and. first_call ) &
write(*,"(a,i3,9a)") "Derive2d-name-class", n, " C:", trim(class), &
" U:", trim(f_2d(n)%unit), " N:", trim(name), ":END"
!*** user-defined time-averaging. Here we have defined TADV and TVOC
! so that 8-hour daytime averages will be calculated.
! Just comment out if not wanted, or (better!) don't define any
! f_2d as TADV or TVOC
if ( class == "TADV" .or. class == "TVOC" ) then
if(thour <= 8.0 .or. thour > 16.0 ) cycle ! Start next species
end if
! hmix average at 00 and 12:
if ( class == "HMIX00" .or. class == "XKSIG00" ) then
if(thour /= 0.0 ) cycle ! Start next species
end if
if ( class == "HMIX12" .or. class == "XKSIG12" ) then
if(thour /= 12.0 ) cycle ! Start next species
end if
!if ( DEBUG .and. MasterProc .and. first_call ) then
if(MasterProc.and.first_call)&
write(*,"(a,i4,1x,a,i4,1x,a)") "1st call Derived 2d", n, &
trim(name), index, trim(class)
select case ( class )
case ( "MET2D")
!DS May 2015
! Meteo fields are available through their names and a pointer, either
! from the read-in NWP fields (met%) or the derived met fields
! (metderiv%), see MetFields_mod. We thus use the required name and see
! if we can find it in either met% or metderiv%
imet_tmp = find_index(subclass, met(:)%name ) ! subclass has meteo name from MetFields
if( imet_tmp > 0 ) then
!Note: must write bounds explicitly for "special2d" to work
met_p => met(imet_tmp)%field(1:limax,1:ljmax,1:1,1)
else
imet_tmp = find_index(subclass, derivmet(:)%name )
if( imet_tmp > 0 ) met_p => derivmet(imet_tmp)%field(1:limax,1:ljmax,1:1,1)
end if
if( imet_tmp > 0 ) then
kmax=1
if(met(imet_tmp)%dim==3)kmax=KMAX_MID!take lowest level
if( MasterProc.and.first_call) write(*,*) "MET2D"//trim(name), &
imet_tmp, met_p(1,1,kmax),loc(met(imet_tmp)%field(1,1,1,1))