Newer
Older
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
! radiation_config.F90 - Derived type to configure the radiation scheme
!
! (C) Copyright 2014- ECMWF.
!
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
!
! In applying this licence, ECMWF does not waive the privileges and immunities
! granted to it by virtue of its status as an intergovernmental organisation
! nor does it submit to any jurisdiction.
!
! Author: Robin Hogan
! Email: r.j.hogan@ecmwf.int
!
! Modifications
! 2017-07-22 R. Hogan Added Yi et al. ice optics model
! 2017-10-23 R. Hogan Renamed single-character variables
! 2018-03-15 R. Hogan Added logicals controlling surface spectral treatment
! 2018-08-29 R. Hogan Added monochromatic single-scattering albedo / asymmetry factor
! 2018-09-03 R. Hogan Added min_cloud_effective_size
! 2018-09-04 R. Hogan Added encroachment_scaling
! 2018-09-13 R. Hogan Added IEncroachmentFractal
! 2019-01-02 R. Hogan Added Cloudless solvers
! 2019-01-14 R. Hogan Added out_of_bounds_[1,2,3]d for checker routines
! 2019-01-18 R. Hogan Added albedo weighting
! 2019-02-03 R. Hogan Added ability to fix out-of-physical-bounds inputs
! 2019-02-10 R. Hogan Renamed "encroachment" to "entrapment"
!
! Note: The aim is for ecRad in the IFS to be as similar as possible
! to the offline version, so if you make any changes to this or any
! files in this directory, please inform Robin Hogan.
!
module radiation_config
use parkind1, only : jprb
use radiation_cloud_optics_data, only : cloud_optics_type
use radiation_aerosol_optics_data, only : aerosol_optics_type
use radiation_pdf_sampler, only : pdf_sampler_type
use radiation_cloud_cover, only : OverlapName, &
& IOverlapMaximumRandom, IOverlapExponentialRandom, IOverlapExponential
implicit none
public
! Configuration codes: use C-style enumerators to avoid having to
! remember the numbers
! Solvers: can be specified for longwave and shortwave
! independently, except for "Homogeneous", which must be the same
! for both
enum, bind(c)
enumerator ISolverCloudless, ISolverHomogeneous, ISolverMcICA, &
& ISolverSpartacus, ISolverTripleclouds
end enum
character(len=*), parameter :: SolverName(0:4) = (/ 'Cloudless ', &
& 'Homogeneous ', &
& 'McICA ', &
& 'SPARTACUS ', &
& 'Tripleclouds' /)
! SPARTACUS shortwave solver can treat the reflection of radiation
! back up into different regions in various ways
enum, bind(c)
enumerator &
& IEntrapmentZero, & ! No entrapment, as Tripleclouds
& IEntrapmentEdgeOnly, & ! Only radiation passed through cloud edge is horizontally homogenized
& IEntrapmentExplicit, & ! Estimate horiz migration dist, account for fractal clouds
& IEntrapmentExplicitNonFractal, & ! As above but ignore fractal nature of clouds
& IEntrapmentMaximum ! Complete horizontal homogenization within regions (old SPARTACUS assumption)
end enum
! Names available in the radiation namelist for variable
! sw_entrapment_name
character(len=*), parameter :: EntrapmentName(0:4) = [ 'Zero ', &
& 'Edge-only ', &
& 'Explicit ', &
& 'Non-fractal', &
& 'Maximum ' ]
! For backwards compatibility, the radiation namelist also supports
! the equivalent variable sw_encroachment_name with the following
! names
character(len=*), parameter :: EncroachmentName(0:4) = [ 'Zero ', &
& 'Minimum ', &
& 'Fractal ', &
& 'Computed', &
& 'Maximum ' ]
! Two-stream models
! This is not configurable at run-time
! Gas models
enum, bind(c)
enumerator IGasModelMonochromatic, IGasModelIFSRRTMG
end enum
character(len=*), parameter :: GasModelName(0:1) = (/ 'Monochromatic', &
& 'RRTMG-IFS ' /)
! Hydrometeor scattering models
enum, bind(c)
enumerator ILiquidModelMonochromatic, &
& ILiquidModelSOCRATES, ILiquidModelSlingo
end enum
character(len=*), parameter :: LiquidModelName(0:2) = (/ 'Monochromatic', &
& 'SOCRATES ', &
& 'Slingo ' /)
enum, bind(c)
enumerator IIceModelMonochromatic, IIceModelFu, &
& IIceModelBaran, IIceModelBaran2016, IIceModelBaran2017, &
& IIceModelYi
end enum
character(len=*), parameter :: IceModelName(0:5) = (/ 'Monochromatic', &
& 'Fu-IFS ', &
& 'Baran ', &
& 'Baran2016 ', &
& 'Baran2017 ', &
& 'Yi ' /)
! Cloud PDF distribution shapes
enum, bind(c)
enumerator IPdfShapeLognormal, IPdfShapeGamma
end enum
character(len=*), parameter :: PdfShapeName(0:1) = (/ 'Lognormal', &
& 'Gamma ' /)
! Maximum number of different aerosol types that can be provided
integer, parameter :: NMaxAerosolTypes = 256
! Maximum number of shortwave albedo and longwave emissivity
! intervals
integer, parameter :: NMaxAlbedoIntervals = 256
! Length of string buffer for printing config information
integer, parameter :: NPrintStringLen = 60
!---------------------------------------------------------------------
! Derived type containing all the configuration information needed
! to run the radiation scheme. The intention is that this is fixed
! for a given model run. The parameters are to list first those
! quantities that can be set directly by the user, for example using a
! namelist, and second those quantities that are computed afterwards
! from the user-supplied numbers, especially the details of the gas
! optics model.
type config_type
! USER-CONFIGURABLE PARAMETERS
! Override default solar spectrum
logical :: use_spectral_solar_scaling = .false.
! Directory in which gas, cloud and aerosol data files are to be
! found
character(len=511) :: directory_name = '.'
! Cloud is deemed to be present in a layer if cloud fraction
! exceeds this value
real(jprb) :: cloud_fraction_threshold = 1.0e-6_jprb
! ...and total cloud water mixing ratio exceeds this value
real(jprb) :: cloud_mixing_ratio_threshold = 1.0e-9_jprb
! Overlap scheme
integer :: i_overlap_scheme = IOverlapExponentialRandom
! Use the Shonk et al. (2010) "beta" overlap parameter, rather
! than the "alpha" overlap parameter of Hogan and Illingworth
! (2000)?
logical :: use_beta_overlap = .false.
! Shape of sub-grid cloud water PDF
integer :: i_cloud_pdf_shape = IPdfShapeGamma
! The ratio of the overlap decorrelation length for cloud
! inhomogeneities to the overlap decorrelation length for cloud
! boundaries. Observations suggest this has a value of 0.5
! (e.g. from the decorrelation lengths of Hogan and Illingworth
! 2003 and Hogan and Illingworth 2000).
real(jprb) :: cloud_inhom_decorr_scaling = 0.5_jprb
! Factor controlling how much of the cloud edge length interfaces
! directly between the clear-sky region (region a) and the
! optically thick cloudy region (region c). If Lxy is the length
! of the interfaces between regions x and y, and Lab and Lbc have
! been computed already, then
! Lac=clear_to_thick_fraction*min(Lab,Lbc).
real(jprb) :: clear_to_thick_fraction = 0.0_jprb
! Factor allowing lateral transport when the sun is close to
! overhead; consider atand(overhead_sun_factor) to be the number
! of degrees that the sun angle is perturbed from zenith for the
! purposes of computing lateral transport. A value of up to 0.1
! seems to be necessary to account for the fact that some forward
! scattered radiation is treated as unscattered by delta-Eddington
! scaling; therefore it ought to have the chance to escape.
real(jprb) :: overhead_sun_factor = 0.0_jprb
! Minimum gas optical depth in a single layer at any wavelength,
! for stability
real(jprb) :: min_gas_od_lw = 1.0e-15_jprb
real(jprb) :: min_gas_od_sw = 0.0_jprb
! Maximum gas optical depth in a layer before that g-point will
! not be considered for 3D treatment: a limit is required to avoid
! expensive computation of matrix exponentials on matrices with
! large elements
real(jprb) :: max_gas_od_3d = 8.0_jprb
! Maximum total optical depth of a cloudy region for stability:
! optical depth will be capped at this value in the SPARTACUS
! solvers
real(jprb) :: max_cloud_od = 16.0_jprb
! How much longwave scattering is included?
logical :: do_lw_cloud_scattering = .true.
logical :: do_lw_aerosol_scattering = .true.
! Number of regions used to describe clouds and clear skies. A
! value of 2 means one clear and one cloudy region, so clouds are
! horizontally homogeneous, while a value of 3 means two cloudy
! regions with different optical depth, thereby representing
! inhomogeneity via the Shonk & Hogan (2008) "Tripleclouds"
! method.
integer :: nregions = 3
! Code specifying the solver to be used: use the enumerations
! defined above
integer :: i_solver_sw = ISolverMcICA
integer :: i_solver_lw = ISolverMcICA
! Do shortwave delta-Eddington scaling on the cloud-aerosol-gas
! mixture (as in the original IFS scheme), rather than the more
! correct approach of separately scaling the cloud and aerosol
! scattering properties before merging with gases. Note that
! .true. is not compatible with the SPARTACUS solver.
logical :: do_sw_delta_scaling_with_gases = .false.
! Codes describing the gas and cloud scattering models to use, the
! latter of which is currently not used
integer :: i_gas_model = IGasModelIFSRRTMG
! integer :: i_cloud_model
! Optics if i_gas_model==IGasModelMonochromatic.
! The wavelength to use for the Planck function in metres. If this
! is positive then the output longwave fluxes will be in units of
! W m-2 um-1. If this is zero or negative (the default) then
! sigma*T^4 will be used and the output longwave fluxes will be in
! W m-2.
real(jprb) :: mono_lw_wavelength = -1.0_jprb
! Total zenith optical depth of the atmosphere in the longwave and
! shortwave, distributed vertically according to the pressure.
! Default is zero.
real(jprb) :: mono_lw_total_od = 0.0_jprb
real(jprb) :: mono_sw_total_od = 0.0_jprb
! Single-scattering albedo and asymmetry factor: values typical
! for liquid clouds with effective radius of 10 microns, at (SW)
! 0.55 micron wavelength and (LW) 10.7 microns wavelength
real(jprb) :: mono_sw_single_scattering_albedo = 0.999999_jprb
real(jprb) :: mono_sw_asymmetry_factor = 0.86_jprb
real(jprb) :: mono_lw_single_scattering_albedo = 0.538_jprb
real(jprb) :: mono_lw_asymmetry_factor = 0.925_jprb
! Codes describing particle scattering models
integer :: i_liq_model = ILiquidModelSOCRATES
integer :: i_ice_model = IIceModelBaran
! The mapping from albedo/emissivity intervals to SW/LW bands can
! either be done by finding the interval containing the central
! wavenumber of the band (nearest neighbour), or by a weighting
! according to the spectral overlap of each interval with each
! band
logical :: do_nearest_spectral_sw_albedo = .true.
logical :: do_nearest_spectral_lw_emiss = .true.
! User-defined monotonically increasing wavelength bounds (m)
! between input surface albedo/emissivity intervals. Implicitly
! the first interval starts at zero and the last ends at infinity.
real(jprb) :: sw_albedo_wavelength_bound(NMaxAlbedoIntervals-1) = -1.0_jprb
real(jprb) :: lw_emiss_wavelength_bound( NMaxAlbedoIntervals-1) = -1.0_jprb
! The index to the surface albedo/emissivity intervals for each of
! the wavelength bounds specified in sw_albedo_wavelength_bound
! and lw_emiss_wavelength_bound
integer :: i_sw_albedo_index(NMaxAlbedoIntervals) = 0
integer :: i_lw_emiss_index (NMaxAlbedoIntervals) = 0
! Do we compute longwave and/or shortwave radiation?
logical :: do_lw = .true.
logical :: do_sw = .true.
! Do we compute clear-sky fluxes and/or solar direct fluxes?
logical :: do_clear = .true.
logical :: do_sw_direct = .true.
! Do we include 3D effects?
logical :: do_3d_effects = .true.
! To what extent do we include "entrapment" effects in the
! SPARTACUS solver? This essentially means that in a situation
! like this
!
! 000111
! 222222
!
! Radiation downwelling from region 1 may be reflected back into
! region 0 due to some degree of homogenization of the radiation
! in region 2. Hogan and Shonk (2013) referred to this as
! "anomalous horizontal transport" for a 1D model, although for 3D
! calculations it is desirable to include at least some of it. The
! options are described by the IEntrapment* parameters above.
integer :: i_3d_sw_entrapment = IEntrapmentExplicit
! In the longwave, the equivalent process it either "on" (like
! maximum entrapment) or "off" (like zero entrapment):
logical :: do_3d_lw_multilayer_effects = .false.
! Do we account for the effective emissivity of the side of
! clouds?
logical :: do_lw_side_emissivity = .true.
! The 3D transfer rate "X" is such that if transport out of a
! region was the only process occurring then by the base of a
! layer only exp(-X) of the original flux would remain in that
! region. The transfer rate computed geometrically can be very
! high for the clear-sky regions in layers with high cloud
! fraction. For stability reasons it is necessary to provide a
! maximum possible 3D transfer rate.
real(jprb) :: max_3d_transfer_rate = 10.0_jprb
! It has also sometimes been found necessary to set a minimum
! cloud effective size for stability (metres)
real(jprb) :: min_cloud_effective_size = 100.0_jprb
! Given a horizontal migration distance, there is still
! uncertainty about how much entrapment occurs associated with how
! one assumes cloud boundaries line up in adjacent layers. This
! factor can be varied between 0.0 (the boundaries line up to the
! greatest extent possible given the overlap parameter) and 1.0
! (the boundaries line up to the minimum extent possible). In the
! Hogan et al. entrapment paper it is referred to as the overhang
! factor zeta, and a value of 0 matches the Monte Carlo
! calculations best.
real(jprb) :: overhang_factor = 0.0_jprb
! By default, the Meador & Weaver (1980) expressions are used
! instead of the matrix exponential whenever 3D effects can be
! neglected (e.g. cloud-free layers or clouds with infinitely
! large effective cloud size), but setting the following to true
! uses the matrix exponential everywhere, enabling the two
! methods to be compared. Note that Meador & Weaver will still be
! used for very optically thick g points where the matrix
! exponential can produce incorrect results.
logical :: use_expm_everywhere = .false.
! Aerosol descriptors: aerosol_type_mapping must be of length
! n_aerosol_types, and contains 0 if that type is to be ignored,
! positive numbers to map on to the indices of hydrophobic
! aerosols in the aerosol optics configuration file, and negative
! numbers to map on to (the negative of) the indices of
! hydrophilic aerosols in the configuration file.
logical :: use_aerosols = .false.
integer :: n_aerosol_types = 0
integer :: i_aerosol_type_map(NMaxAerosolTypes)
! Save the gas and cloud optical properties for each g point in
! "radiative_properties.nc"?
logical :: do_save_radiative_properties = .false.
! Save the flux profiles in each band?
logical :: do_save_spectral_flux = .false.
! Save the surface downwelling shortwave fluxes in each band?
logical :: do_surface_sw_spectral_flux = .true.
! Compute the longwave derivatives needed to apply the approximate
! radiation updates of Hogan and Bozzo (2015)
logical :: do_lw_derivatives = .false.
! Save the flux profiles in each g-point (overrides
! do_save_spectral_flux if TRUE)?
logical :: do_save_gpoint_flux = .false.
! In the IFS environment, setting up RRTM has already been done
! so not needed to do it again
logical :: do_setup_ifsrrtm = .true.
! In the IFS environment the old scheme has a bug in the Fu
! longwave ice optics whereby the single scattering albedo is one
! minus what it should be. Unfortunately fixing it makes
! forecasts worse. Setting the following to true reproduces the
! bug.
logical :: do_fu_lw_ice_optics_bug = .false.
! Control verbosity: 0=none (no output to standard output; write
! to standard error only if an error occurs), 1=warning, 2=info,
! 3=progress, 4=detailed, 5=debug. Separate settings for the
! setup of the scheme and the execution of it.
integer :: iverbosesetup = 2
integer :: iverbose = 1
! Are we doing radiative transfer in complex surface canopies
! (streets/vegetation), in which case tailored downward fluxes are
! needed at the top of the canopy?
logical :: do_canopy_fluxes_sw = .false.
logical :: do_canopy_fluxes_lw = .false.
! If so, do we use the full spectrum as in the atmosphere, or just
! the reduced spectrum in which the shortwave albedo and longwave
! emissivity are provided?
logical :: use_canopy_full_spectrum_sw = .false.
logical :: use_canopy_full_spectrum_lw = .false.
! Do we treat gas radiative transfer in streets/vegetation?
logical :: do_canopy_gases_sw = .false.
logical :: do_canopy_gases_lw = .false.
! Optics file names for overriding the ones generated from the
! other options. If these remain empty then the generated names
! will be used (see the "consolidate_config" routine below). If
! the user assigns one of these and it starts with a '/' character
! then that will be used instead. If the user assigns one and it
! doesn't start with a '/' character then it will be prepended by
! the contents of directory_name.
character(len=511) :: ice_optics_override_file_name = ''
character(len=511) :: liq_optics_override_file_name = ''
character(len=511) :: aerosol_optics_override_file_name = ''
! Optionally override the look-up table file for the cloud-water
! PDF used by the McICA solver
character(len=511) :: cloud_pdf_override_file_name = ''
! Has "consolidate" been called?
logical :: is_consolidated = .false.
! COMPUTED PARAMETERS
! Users of this library should not edit these parameters directly;
! they are set by the "consolidate" routine
! Wavenumber range for each band, in cm-1, which will be allocated
! to be of length n_bands_sw or n_bands_lw
real(jprb), allocatable, dimension(:) :: wavenumber1_sw
real(jprb), allocatable, dimension(:) :: wavenumber2_sw
real(jprb), allocatable, dimension(:) :: wavenumber1_lw
real(jprb), allocatable, dimension(:) :: wavenumber2_lw
! If the nearest surface albedo/emissivity interval is to be used
! for each SW/LW band then the following arrays will be allocated
! to the length of the number of bands and contain the index to
! the relevant interval
integer, allocatable, dimension(:) :: i_albedo_from_band_sw
integer, allocatable, dimension(:) :: i_emiss_from_band_lw
! ...alternatively, this matrix dimensioned
! (n_albedo_intervals,n_bands_sw) providing the weights needed for
! computing the albedo in each ecRad band from the albedo in each
! native albedo band - see radiation_single_level.F90
real(jprb), allocatable, dimension(:,:) :: sw_albedo_weights
! ...and similarly in the longwave, dimensioned
! (n_emiss_intervals,n_bands_lw)
real(jprb), allocatable, dimension(:,:) :: lw_emiss_weights
! Arrays of length the number of g-points that convert from
! g-point to the band index
integer, allocatable, dimension(:) :: i_band_from_g_lw
integer, allocatable, dimension(:) :: i_band_from_g_sw
! We allow for the possibility for g-points to be ordered in terms
! of likely absorption (weakest to strongest) across the shortwave
! or longwave spectrum, in order that in SPARTACUS we select only
! the first n g-points that will not have too large an absorption,
! and therefore matrix exponentials that are both finite and not
! too expensive to compute. The following two arrays map the
! reordered g-points to the original ones.
integer, allocatable, dimension(:) :: i_g_from_reordered_g_lw
integer, allocatable, dimension(:) :: i_g_from_reordered_g_sw
! The following map the reordered g-points to the bands
integer, allocatable, dimension(:) :: i_band_from_reordered_g_lw
integer, allocatable, dimension(:) :: i_band_from_reordered_g_sw
! The following map the reordered g-points to the spectral
! information being saved: if do_save_gpoint_flux==TRUE then this
! will map on to the original g points, but if only
! do_save_spectral_flux==TRUE then this will map on to the bands
integer, pointer, dimension(:) :: i_spec_from_reordered_g_lw
integer, pointer, dimension(:) :: i_spec_from_reordered_g_sw
! Number of spectral intervals used for the canopy radiative
! transfer calculation; they are either equal to
! n_albedo_intervals/n_emiss_intervals or n_g_sw/n_g_lw
integer :: n_canopy_bands_sw = 1
integer :: n_canopy_bands_lw = 1
! Data structure containing cloud scattering data
type(cloud_optics_type) :: cloud_optics
! Data structure containing aerosol scattering data
type(aerosol_optics_type) :: aerosol_optics
! Object for sampling from a gamma or lognormal distribution
type(pdf_sampler_type) :: pdf_sampler
! Optics file names
character(len=511) :: ice_optics_file_name, &
& liq_optics_file_name, &
& aerosol_optics_file_name
! McICA PDF look-up table file name
character(len=511) :: cloud_pdf_file_name
! Number of gpoints and bands in the shortwave and longwave - set
! to zero as will be set properly later
integer :: n_g_sw = 0, n_g_lw = 0
integer :: n_bands_sw = 0, n_bands_lw = 0
! Number of spectral points to save (equal either to the number of
! g points or the number of bands
integer :: n_spec_sw = 0, n_spec_lw = 0
! Dimensions to store variables that are only needed if longwave
! scattering is included. "n_g_lw_if_scattering" is equal to
! "n_g_lw" if aerosols are allowed to scatter in the longwave,
! and zero otherwise. "n_bands_lw_if_scattering" is equal to
! "n_bands_lw" if clouds are allowed to scatter in the longwave,
! and zero otherwise.
integer :: n_g_lw_if_scattering = 0, n_bands_lw_if_scattering = 0
! Treat clouds as horizontally homogeneous within the gribox
logical :: is_homogeneous = .false.
! If the solvers are both "Cloudless" then we don't need to do any
! cloud processing
logical :: do_clouds = .true.
contains
procedure :: read => read_config_from_namelist
procedure :: consolidate => consolidate_config
procedure :: set => set_config
procedure :: print => print_config
procedure :: get_sw_weights
procedure :: define_sw_albedo_intervals
procedure :: define_lw_emiss_intervals
procedure :: consolidate_intervals
end type config_type
! procedure, private :: print_logical, print_real, print_int
contains
!---------------------------------------------------------------------
! This subroutine reads configuration data from a namelist file, and
! anything that is not in the namelists will be set to default
! values. If optional output argument "is_success" is present, then
! on error (e.g. missing file) it will be set to .false.; if this
! argument is missing then on error the program will be aborted. You
! may either specify the file_name or the unit of an open file to
! read, but not both.
subroutine read_config_from_namelist(this, file_name, unit, is_success)
use yomhook, only : lhook, dr_hook
use radiation_io, only : nulout, nulerr, nulrad, radiation_abort
class(config_type), intent(inout) :: this
character(*), intent(in), optional :: file_name
integer, intent(in), optional :: unit
logical, intent(out), optional :: is_success
integer :: iosopen, iosread ! Status after calling open and read
! The following variables are read from the namelists and map
! directly onto members of the config_type derived type
! To be read from the radiation_config namelist
logical :: do_sw, do_lw, do_clear, do_sw_direct
logical :: do_3d_effects, use_expm_everywhere, use_aerosols
logical :: do_lw_side_emissivity
logical :: do_3d_lw_multilayer_effects, do_fu_lw_ice_optics_bug
logical :: do_lw_aerosol_scattering, do_lw_cloud_scattering
logical :: do_save_radiative_properties, do_save_spectral_flux
logical :: do_save_gpoint_flux, do_surface_sw_spectral_flux
logical :: use_beta_overlap, do_lw_derivatives
logical :: do_sw_delta_scaling_with_gases
logical :: do_canopy_fluxes_sw, do_canopy_fluxes_lw
logical :: use_canopy_full_spectrum_sw, use_canopy_full_spectrum_lw
logical :: do_canopy_gases_sw, do_canopy_gases_lw
integer :: n_regions, iverbose, iverbosesetup, n_aerosol_types
real(jprb):: mono_lw_wavelength, mono_lw_total_od, mono_sw_total_od
real(jprb):: mono_lw_single_scattering_albedo, mono_sw_single_scattering_albedo
real(jprb):: mono_lw_asymmetry_factor, mono_sw_asymmetry_factor
real(jprb):: cloud_inhom_decorr_scaling, cloud_fraction_threshold
real(jprb):: clear_to_thick_fraction, max_gas_od_3d, max_cloud_od
real(jprb):: cloud_mixing_ratio_threshold, overhead_sun_factor
real(jprb):: max_3d_transfer_rate, min_cloud_effective_size
real(jprb):: overhang_factor, encroachment_scaling
character(511) :: directory_name, aerosol_optics_override_file_name
character(511) :: liq_optics_override_file_name, ice_optics_override_file_name
character(511) :: cloud_pdf_override_file_name
character(63) :: liquid_model_name, ice_model_name, gas_model_name
character(63) :: sw_solver_name, lw_solver_name, overlap_scheme_name
character(63) :: sw_entrapment_name, sw_encroachment_name, cloud_pdf_shape_name
integer :: i_aerosol_type_map(NMaxAerosolTypes) ! More than 256 is an error
logical :: do_nearest_spectral_sw_albedo = .true.
logical :: do_nearest_spectral_lw_emiss = .true.
real(jprb) :: sw_albedo_wavelength_bound(NMaxAlbedoIntervals-1)
real(jprb) :: lw_emiss_wavelength_bound( NMaxAlbedoIntervals-1)
integer :: i_sw_albedo_index(NMaxAlbedoIntervals)
integer :: i_lw_emiss_index (NMaxAlbedoIntervals)
integer :: iunit ! Unit number of namelist file
namelist /radiation/ do_sw, do_lw, do_sw_direct, &
& do_3d_effects, do_lw_side_emissivity, do_clear, &
& do_save_radiative_properties, sw_entrapment_name, sw_encroachment_name, &
& do_3d_lw_multilayer_effects, do_fu_lw_ice_optics_bug, &
& do_save_spectral_flux, do_save_gpoint_flux, &
& do_surface_sw_spectral_flux, do_lw_derivatives, &
& do_lw_aerosol_scattering, do_lw_cloud_scattering, &
& n_regions, directory_name, gas_model_name, &
& ice_optics_override_file_name, liq_optics_override_file_name, &
& aerosol_optics_override_file_name, cloud_pdf_override_file_name, &
& liquid_model_name, ice_model_name, max_3d_transfer_rate, &
& min_cloud_effective_size, overhang_factor, encroachment_scaling, &
& use_canopy_full_spectrum_sw, use_canopy_full_spectrum_lw, &
& do_canopy_fluxes_sw, do_canopy_fluxes_lw, &
& do_canopy_gases_sw, do_canopy_gases_lw, &
& do_sw_delta_scaling_with_gases, overlap_scheme_name, &
& sw_solver_name, lw_solver_name, use_beta_overlap, &
& use_expm_everywhere, iverbose, iverbosesetup, &
& cloud_inhom_decorr_scaling, cloud_fraction_threshold, &
& clear_to_thick_fraction, max_gas_od_3d, max_cloud_od, &
& cloud_mixing_ratio_threshold, overhead_sun_factor, &
& n_aerosol_types, i_aerosol_type_map, use_aerosols, &
& mono_lw_wavelength, mono_lw_total_od, mono_sw_total_od, &
& mono_lw_single_scattering_albedo, mono_sw_single_scattering_albedo, &
& mono_lw_asymmetry_factor, mono_sw_asymmetry_factor, &
& cloud_pdf_shape_name, &
& do_nearest_spectral_sw_albedo, do_nearest_spectral_lw_emiss, &
& sw_albedo_wavelength_bound, lw_emiss_wavelength_bound, &
& i_sw_albedo_index, i_lw_emiss_index
real(jprb) :: hook_handle
if (lhook) call dr_hook('radiation_config:read',0,hook_handle)
! Copy default values from the original structure
do_sw = this%do_sw
do_lw = this%do_lw
do_sw_direct = this%do_sw_direct
do_3d_effects = this%do_3d_effects
do_3d_lw_multilayer_effects = this%do_3d_lw_multilayer_effects
do_lw_side_emissivity = this%do_lw_side_emissivity
do_clear = this%do_clear
do_lw_aerosol_scattering = this%do_lw_aerosol_scattering
do_lw_cloud_scattering = this%do_lw_cloud_scattering
do_sw_delta_scaling_with_gases = this%do_sw_delta_scaling_with_gases
do_fu_lw_ice_optics_bug = this%do_fu_lw_ice_optics_bug
do_canopy_fluxes_sw = this%do_canopy_fluxes_sw
do_canopy_fluxes_lw = this%do_canopy_fluxes_lw
use_canopy_full_spectrum_sw = this%use_canopy_full_spectrum_sw
use_canopy_full_spectrum_lw = this%use_canopy_full_spectrum_lw
do_canopy_gases_sw = this%do_canopy_gases_sw
do_canopy_gases_lw = this%do_canopy_gases_lw
n_regions = this%nregions
directory_name = this%directory_name
cloud_pdf_override_file_name = this%cloud_pdf_override_file_name
liq_optics_override_file_name = this%liq_optics_override_file_name
ice_optics_override_file_name = this%ice_optics_override_file_name
aerosol_optics_override_file_name = this%aerosol_optics_override_file_name
use_expm_everywhere = this%use_expm_everywhere
use_aerosols = this%use_aerosols
do_save_radiative_properties = this%do_save_radiative_properties
do_save_spectral_flux = this%do_save_spectral_flux
do_save_gpoint_flux = this%do_save_gpoint_flux
do_lw_derivatives = this%do_lw_derivatives
do_surface_sw_spectral_flux = this%do_surface_sw_spectral_flux
iverbose = this%iverbose
iverbosesetup = this%iverbosesetup
cloud_fraction_threshold = this%cloud_fraction_threshold
cloud_mixing_ratio_threshold = this%cloud_mixing_ratio_threshold
use_beta_overlap = this%use_beta_overlap
cloud_inhom_decorr_scaling = this%cloud_inhom_decorr_scaling
clear_to_thick_fraction = this%clear_to_thick_fraction
overhead_sun_factor = this%overhead_sun_factor
max_gas_od_3d = this%max_gas_od_3d
max_cloud_od = this%max_cloud_od
max_3d_transfer_rate = this%max_3d_transfer_rate
min_cloud_effective_size = this%min_cloud_effective_size
overhang_factor = this%overhang_factor
encroachment_scaling = -1.0_jprb
gas_model_name = '' !DefaultGasModelName
liquid_model_name = '' !DefaultLiquidModelName
ice_model_name = '' !DefaultIceModelName
sw_solver_name = '' !DefaultSwSolverName
lw_solver_name = '' !DefaultLwSolverName
sw_entrapment_name = ''
sw_encroachment_name = ''
overlap_scheme_name = ''
cloud_pdf_shape_name = ''
n_aerosol_types = this%n_aerosol_types
mono_lw_wavelength = this%mono_lw_wavelength
mono_lw_total_od = this%mono_lw_total_od
mono_sw_total_od = this%mono_sw_total_od
mono_lw_single_scattering_albedo = this%mono_lw_single_scattering_albedo
mono_sw_single_scattering_albedo = this%mono_sw_single_scattering_albedo
mono_lw_asymmetry_factor = this%mono_lw_asymmetry_factor
mono_sw_asymmetry_factor = this%mono_sw_asymmetry_factor
i_aerosol_type_map = this%i_aerosol_type_map
do_nearest_spectral_sw_albedo = this%do_nearest_spectral_sw_albedo
do_nearest_spectral_lw_emiss = this%do_nearest_spectral_lw_emiss
sw_albedo_wavelength_bound = this%sw_albedo_wavelength_bound
lw_emiss_wavelength_bound = this%lw_emiss_wavelength_bound
i_sw_albedo_index = this%i_sw_albedo_index
i_lw_emiss_index = this%i_lw_emiss_index
if (present(file_name) .and. present(unit)) then
write(nulerr,'(a)') '*** Error: cannot specify both file_name and unit in call to config_type%read'
call radiation_abort('Radiation configuration error')
else if (.not. present(file_name) .and. .not. present(unit)) then
write(nulerr,'(a)') '*** Error: neither file_name nor unit specified in call to config_type%read'
call radiation_abort('Radiation configuration error')
end if
if (present(file_name)) then
! Open the namelist file
iunit = nulrad
open(unit=iunit, iostat=iosopen, file=trim(file_name))
else
! Assume that iunit represents and open file
iosopen = 0
iunit = unit
end if
if (iosopen /= 0) then
! An error occurred opening the file
if (present(is_success)) then
is_success = .false.
! We now continue the subroutine so that the default values
! are placed in the config structure
else
write(nulerr,'(a,a,a)') '*** Error: namelist file "', &
& trim(file_name), '" not found'
call radiation_abort('Radiation configuration error')
end if
else
read(unit=iunit, iostat=iosread, nml=radiation)
if (iosread /= 0) then
! An error occurred reading the file
if (present(is_success)) then
is_success = .false.
! We now continue the subroutine so that the default values
! are placed in the config structure
else if (present(file_name)) then
write(nulerr,'(a,a,a)') '*** Error reading namelist "radiation" from file "', &
& trim(file_name), '"'
close(unit=iunit)
call radiation_abort('Radiation configuration error')
else
write(nulerr,'(a,i0)') '*** Error reading namelist "radiation" from unit ', &
& iunit
call radiation_abort('Radiation configuration error')
end if
end if
if (present(file_name)) then
close(unit=iunit)
end if
end if
! Copy namelist data into configuration object
! Start with verbosity levels, which should be within limits
if (iverbose < 0) then
iverbose = 0
end if
this%iverbose = iverbose
if (iverbosesetup < 0) then
iverbosesetup = 0
end if
this%iverbosesetup = iverbosesetup
this%do_lw = do_lw
this%do_sw = do_sw
this%do_clear = do_clear
this%do_sw_direct = do_sw_direct
this%do_3d_effects = do_3d_effects
this%do_3d_lw_multilayer_effects = do_3d_lw_multilayer_effects
this%do_lw_side_emissivity = do_lw_side_emissivity
this%use_expm_everywhere = use_expm_everywhere
this%use_aerosols = use_aerosols
this%do_lw_cloud_scattering = do_lw_cloud_scattering
this%do_lw_aerosol_scattering = do_lw_aerosol_scattering
this%nregions = n_regions
this%do_surface_sw_spectral_flux = do_surface_sw_spectral_flux
this%do_sw_delta_scaling_with_gases = do_sw_delta_scaling_with_gases
this%do_fu_lw_ice_optics_bug = do_fu_lw_ice_optics_bug
this%do_canopy_fluxes_sw = do_canopy_fluxes_sw
this%do_canopy_fluxes_lw = do_canopy_fluxes_lw
this%use_canopy_full_spectrum_sw = use_canopy_full_spectrum_sw
this%use_canopy_full_spectrum_lw = use_canopy_full_spectrum_lw
this%do_canopy_gases_sw = do_canopy_gases_sw
this%do_canopy_gases_lw = do_canopy_gases_lw
this%mono_lw_wavelength = mono_lw_wavelength
this%mono_lw_total_od = mono_lw_total_od
this%mono_sw_total_od = mono_sw_total_od
this%mono_lw_single_scattering_albedo = mono_lw_single_scattering_albedo
this%mono_sw_single_scattering_albedo = mono_sw_single_scattering_albedo
this%mono_lw_asymmetry_factor = mono_lw_asymmetry_factor
this%mono_sw_asymmetry_factor = mono_sw_asymmetry_factor
this%use_beta_overlap = use_beta_overlap
this%cloud_inhom_decorr_scaling = cloud_inhom_decorr_scaling
this%clear_to_thick_fraction = clear_to_thick_fraction
this%overhead_sun_factor = overhead_sun_factor
this%max_gas_od_3d = max_gas_od_3d
this%max_cloud_od = max_cloud_od
this%max_3d_transfer_rate = max_3d_transfer_rate
this%min_cloud_effective_size = max(1.0e-6_jprb, min_cloud_effective_size)
if (encroachment_scaling >= 0.0_jprb) then
this%overhang_factor = encroachment_scaling
if (iverbose >= 1) then
write(nulout, '(a)') 'Warning: radiation namelist parameter "encroachment_scaling" is deprecated: use "overhang_factor"'
end if
else
this%overhang_factor = overhang_factor
end if
this%directory_name = directory_name
this%cloud_pdf_override_file_name = cloud_pdf_override_file_name
this%liq_optics_override_file_name = liq_optics_override_file_name
this%ice_optics_override_file_name = ice_optics_override_file_name
this%aerosol_optics_override_file_name = aerosol_optics_override_file_name
this%cloud_fraction_threshold = cloud_fraction_threshold
this%cloud_mixing_ratio_threshold = cloud_mixing_ratio_threshold
this%n_aerosol_types = n_aerosol_types
this%do_save_radiative_properties = do_save_radiative_properties
this%do_lw_derivatives = do_lw_derivatives
this%do_save_spectral_flux = do_save_spectral_flux
this%do_save_gpoint_flux = do_save_gpoint_flux
this%do_nearest_spectral_sw_albedo = do_nearest_spectral_sw_albedo
this%do_nearest_spectral_lw_emiss = do_nearest_spectral_lw_emiss
this%sw_albedo_wavelength_bound = sw_albedo_wavelength_bound
this%lw_emiss_wavelength_bound = lw_emiss_wavelength_bound
this%i_sw_albedo_index = i_sw_albedo_index
this%i_lw_emiss_index = i_lw_emiss_index
if (do_save_gpoint_flux) then
! Saving the fluxes every g-point overrides saving as averaged
! in a band, but this%do_save_spectral_flux needs to be TRUE as
! it is tested inside the solver routines to decide whether to
! save anything
this%do_save_spectral_flux = .true.
end if
! Determine liquid optics model
call get_enum_code(liquid_model_name, LiquidModelName, &
& 'liquid_model_name', this%i_liq_model)
! Determine ice optics model
call get_enum_code(ice_model_name, IceModelName, &
& 'ice_model_name', this%i_ice_model)
! Determine gas optics model
call get_enum_code(gas_model_name, GasModelName, &
& 'gas_model_name', this%i_gas_model)
! Determine solvers
call get_enum_code(sw_solver_name, SolverName, &
& 'sw_solver_name', this%i_solver_sw)
call get_enum_code(lw_solver_name, SolverName, &
& 'lw_solver_name', this%i_solver_lw)
if (len_trim(sw_encroachment_name) > 1) then
call get_enum_code(sw_encroachment_name, EncroachmentName, &
& 'sw_encroachment_name', this%i_3d_sw_entrapment)
write(nulout, '(a)') 'Warning: radiation namelist string "sw_encroachment_name" is deprecated: use "sw_entrapment_name"'
else
call get_enum_code(sw_entrapment_name, EntrapmentName, &
& 'sw_entrapment_name', this%i_3d_sw_entrapment)
end if
! Determine overlap scheme
call get_enum_code(overlap_scheme_name, OverlapName, &
& 'overlap_scheme_name', this%i_overlap_scheme)
! Determine cloud PDF shape
call get_enum_code(cloud_pdf_shape_name, PdfShapeName, &
& 'cloud_pdf_shape_name', this%i_cloud_pdf_shape)
this%i_aerosol_type_map = 0
if (this%use_aerosols) then
this%i_aerosol_type_map(1:n_aerosol_types) &
& = i_aerosol_type_map(1:n_aerosol_types)
end if
! Will clouds be used at all?
if ((this%do_sw .and. this%i_solver_sw /= ISolverCloudless) &
& .or. (this%do_lw .and. this%i_solver_lw /= ISolverCloudless)) then
this%do_clouds = .true.
else
this%do_clouds = .false.
end if
! Normal subroutine exit
if (present(is_success)) then
is_success = .true.
end if
if (lhook) call dr_hook('radiation_config:read',1,hook_handle)
end subroutine read_config_from_namelist
!---------------------------------------------------------------------
! This routine is called by radiation_interface:setup_radiation and
! it converts the user specified options into some more specific
! data such as data file names
subroutine consolidate_config(this)
use yomhook, only : lhook, dr_hook
use radiation_io, only : nulout, nulerr, radiation_abort
class(config_type), intent(inout) :: this
real(jprb) :: hook_handle
if (lhook) call dr_hook('radiation_config:consolidate',0,hook_handle)
! Check consistency of models
if (this%do_canopy_fluxes_sw .and. .not. this%do_surface_sw_spectral_flux) then
if (this%iverbosesetup >= 1) then
write(nulout,'(a)') 'Warning: turning on do_surface_sw_spectral_flux as required by do_canopy_fluxes_sw'
end if
this%do_surface_sw_spectral_flux = .true.
end if
! Will clouds be used at all?
if ((this%do_sw .and. this%i_solver_sw /= ISolverCloudless) &
& .or. (this%do_lw .and. this%i_solver_lw /= ISolverCloudless)) then
this%do_clouds = .true.
else
this%do_clouds = .false.
end if
! SPARTACUS only works with Exp-Ran overlap scheme
if (( this%i_solver_sw == ISolverSPARTACUS &
& .or. this%i_solver_lw == ISolverSPARTACUS &
& .or. this%i_solver_sw == ISolverTripleclouds &
& .or. this%i_solver_lw == ISolverTripleclouds) &
& .and. this%i_overlap_scheme /= IOverlapExponentialRandom) then
write(nulerr,'(a)') '*** Error: SPARTACUS/Tripleclouds solvers can only do Exponential-Random overlap'
call radiation_abort('Radiation configuration error')
end if
! Set aerosol optics file name
if (len_trim(this%aerosol_optics_override_file_name) > 0) then
if (this%aerosol_optics_override_file_name(1:1) == '/') then
this%aerosol_optics_file_name = trim(this%aerosol_optics_override_file_name)
else
this%aerosol_optics_file_name = trim(this%directory_name) &
& // '/' // trim(this%aerosol_optics_override_file_name)
end if
else
! In the IFS, the aerosol optics file should be specified in
! ifs/module/radiation_setup.F90, not here
this%aerosol_optics_file_name &
& = trim(this%directory_name) // "/aerosol_ifs_rrtm_45R2.nc"
end if
! Set liquid optics file name
if (len_trim(this%liq_optics_override_file_name) > 0) then
if (this%liq_optics_override_file_name(1:1) == '/') then
this%liq_optics_file_name = trim(this%liq_optics_override_file_name)
else
this%liq_optics_file_name = trim(this%directory_name) &
& // '/' // trim(this%liq_optics_override_file_name)
end if
else if (this%i_liq_model == ILiquidModelSOCRATES) then
this%liq_optics_file_name &
& = trim(this%directory_name) // "/socrates_droplet_scattering_rrtm.nc"
else if (this%i_liq_model == ILiquidModelSlingo) then
this%liq_optics_file_name &
& = trim(this%directory_name) // "/slingo_droplet_scattering_rrtm.nc"
end if
! Set ice optics file name
if (len_trim(this%ice_optics_override_file_name) > 0) then
if (this%ice_optics_override_file_name(1:1) == '/') then
this%ice_optics_file_name = trim(this%ice_optics_override_file_name)
else
this%ice_optics_file_name = trim(this%directory_name) &
& // '/' // trim(this%ice_optics_override_file_name)
end if
else if (this%i_ice_model == IIceModelFu) then
this%ice_optics_file_name &
& = trim(this%directory_name) // "/fu_ice_scattering_rrtm.nc"
else if (this%i_ice_model == IIceModelBaran) then
this%ice_optics_file_name &
& = trim(this%directory_name) // "/baran_ice_scattering_rrtm.nc"
else if (this%i_ice_model == IIceModelBaran2016) then