-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrad_constituents.F90
2470 lines (1917 loc) · 93.9 KB
/
rad_constituents.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 rad_constituents
!------------------------------------------------------------------------------------------------
!
! Provide constituent distributions and properties to the radiation and
! cloud microphysics routines.
!
! The logic to control which constituents are used in the climate calculations
! and which are used in diagnostic radiation calculations is contained in this module.
!
!------------------------------------------------------------------------------------------------
use shr_kind_mod, only: r8 => shr_kind_r8
use spmd_utils, only: masterproc
use ppgrid, only: pcols, pver
use physconst, only: rga
use physics_types, only: physics_state
use constituents, only: cnst_name, cnst_get_ind
use radconstants, only: gasnamelength, nradgas, rad_gas_index, ot_length
use phys_prop, only: physprop_accum_unique_files, physprop_init, &
physprop_get_id, physprop_get
use cam_history, only: addfld, fieldname_len, phys_decomp, outfld
use physics_buffer, only: physics_buffer_desc, pbuf_get_field, pbuf_get_index
use error_messages, only: alloc_err
use cam_abortutils, only: endrun
use cam_logfile, only: iulog
implicit none
private
save
! Public interfaces
public :: &
rad_cnst_readnl, &! read namelist values and parse
rad_cnst_init, &! find optics files and all constituents
rad_cnst_get_info, &! return info about climate/diagnostic lists
rad_cnst_get_mode_idx, &! return mode index of specified mode type
rad_cnst_get_spec_idx, &! return specie index of specified specie type
rad_cnst_get_gas, &! return pointer to mmr for gasses
rad_cnst_get_aer_mmr, &! return pointer to mmr for aerosols
rad_cnst_get_mam_mmr_idx, &! get constituent index of mam specie mmr (climate list only)
rad_cnst_get_aer_props, &! return physical properties for aerosols
rad_cnst_get_mode_props, &! return physical properties for aerosol modes
rad_cnst_get_mode_num, &! return mode number mixing ratio
rad_cnst_get_mode_num_idx, &! get constituent index of mode number m.r. (climate list only)
rad_cnst_out, &! output constituent diagnostics (mass per layer and column burden)
rad_cnst_get_call_list ! return list of active climate/diagnostic calls to radiation
integer, parameter :: cs1 = 256
integer, public, parameter :: N_DIAG = 10
character(len=cs1), public :: iceopticsfile, liqopticsfile
character(len=32), public :: icecldoptics,liqcldoptics
logical, public :: oldcldoptics = .false.
! Private module data
! max number of strings in mode definitions
integer, parameter :: n_mode_str = 60
! max number of externally mixed entities in the climate/diag lists
integer, parameter :: n_rad_cnst = N_RAD_CNST
! Namelist variables
character(len=cs1), dimension(n_mode_str) :: mode_defs = ' '
character(len=cs1) :: rad_climate(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_1(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_2(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_3(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_4(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_5(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_6(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_7(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_8(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_9(n_rad_cnst) = ' '
character(len=cs1) :: rad_diag_10(n_rad_cnst) = ' '
! type to provide access to the components of a mode
type :: mode_component_t
integer :: nspec
! For "source" variables below, value is:
! 'N' if in pbuf (non-advected)
! 'A' if in state (advected)
character(len= 1) :: source_num_a ! source of interstitial number conc field
character(len= 32) :: camname_num_a ! name registered in pbuf or constituents for number mixing ratio of interstitial species
character(len= 1) :: source_num_c ! source of cloud borne number conc field
character(len= 32) :: camname_num_c ! name registered in pbuf or constituents for number mixing ratio of cloud borne species
character(len= 1), pointer :: source_mmr_a(:) ! source of interstitial specie mmr fields
character(len= 32), pointer :: camname_mmr_a(:) ! name registered in pbuf or constituents for mmr of interstitial components
character(len= 1), pointer :: source_mmr_c(:) ! source of cloud borne specie mmr fields
character(len= 32), pointer :: camname_mmr_c(:) ! name registered in pbuf or constituents for mmr of cloud borne components
character(len= 32), pointer :: type(:) ! specie type (as used in MAM code)
character(len=cs1), pointer :: props(:) ! file containing specie properties
integer :: idx_num_a ! index in pbuf or constituents for number mixing ratio of interstitial species
integer :: idx_num_c ! index in pbuf for number mixing ratio of interstitial species
integer, pointer :: idx_mmr_a(:) ! index in pbuf or constituents for mmr of interstitial species
integer, pointer :: idx_mmr_c(:) ! index in pbuf for mmr of interstitial species
integer, pointer :: idx_props(:) ! ID used to access physical properties of mode species from phys_prop module
end type mode_component_t
! type to provide access to all modes
type :: modes_t
integer :: nmodes
character(len= 32), pointer :: names(:) ! names used to identify a mode in the climate/diag lists
character(len= 32), pointer :: types(:) ! type of mode (as used in MAM code)
type(mode_component_t), pointer :: comps(:) ! components which define the mode
end type modes_t
type(modes_t), target :: modes ! mode definitions
! type to provide access to the data parsed from the rad_climate and rad_diag_* strings
type :: rad_cnst_namelist_t
integer :: ncnst
character(len= 1), pointer :: source(:) ! 'A' for state (advected), 'N' for pbuf (non-advected),
! 'M' for mode, 'Z' for zero
character(len= 64), pointer :: camname(:) ! name registered in pbuf or constituents
character(len=cs1), pointer :: radname(:) ! radname is the name as identfied in radiation,
! must be one of (rgaslist if a gas) or
! (/fullpath/filename.nc if an aerosol)
character(len= 1), pointer :: type(:) ! 'A' if aerosol, 'G' if gas, 'M' if mode
end type rad_cnst_namelist_t
type(rad_cnst_namelist_t) :: namelist(0:N_DIAG) ! gas, bulk aerosol, and modal components used in
! climate/diagnostic calculations
logical :: active_calls(0:N_DIAG) ! active_calls(i) is true if the i-th call to radiation is
! specified. Note that the 0th call is for the climate
! calculation which is always made.
! Storage for gas components in the climate/diagnostic lists
type :: gas_t
character(len=1) :: source ! A for state (advected), N for pbuf (non-advected), Z for zero
character(len=64) :: camname ! name of constituent in physics state or buffer
character(len=32) :: mass_name ! name for mass per layer field in history output
integer :: idx ! index from constituents or from pbuf
end type gas_t
type :: gaslist_t
integer :: ngas
character(len=2) :: list_id ! set to " " for climate list, or two character integer
! (include leading zero) to identify diagnostic list
type(gas_t), pointer :: gas(:) ! dimension(ngas) where ngas = nradgas is from radconstants
end type gaslist_t
type(gaslist_t), target :: gaslist(0:N_DIAG) ! gasses used in climate/diagnostic calculations
! Storage for bulk aerosol components in the climate/diagnostic lists
type :: aerosol_t
character(len=1) :: source ! A for state (advected), N for pbuf (non-advected), Z for zero
character(len=64) :: camname ! name of constituent in physics state or buffer
character(len=cs1) :: physprop_file ! physprop filename
character(len=32) :: mass_name ! name for mass per layer field in history output
integer :: idx ! index of constituent in physics state or buffer
integer :: physprop_id ! ID used to access physical properties from phys_prop module
end type aerosol_t
type :: aerlist_t
integer :: numaerosols ! number of aerosols
character(len=2) :: list_id ! set to " " for climate list, or two character integer
! (include leading zero) to identify diagnostic list
type(aerosol_t), pointer :: aer(:) ! dimension(numaerosols)
end type aerlist_t
type(aerlist_t), target :: aerosollist(0:N_DIAG) ! list of aerosols used in climate/diagnostic calcs
! storage for modal aerosol components in the climate/diagnostic lists
type :: modelist_t
integer :: nmodes ! number of modes
character(len=2) :: list_id ! set to " " for climate list, or two character integer
! (include leading zero) to identify diagnostic list
integer, pointer :: idx(:) ! index of the mode in the mode definition object
character(len=cs1), pointer :: physprop_files(:) ! physprop filename
integer, pointer :: idx_props(:) ! index of the mode properties in the physprop object
end type modelist_t
type(modelist_t), target :: ma_list(0:N_DIAG) ! list of aerosol modes used in climate/diagnostic calcs
! values for constituents with requested value of zero
real(r8), allocatable, target :: zero_cols(:,:)
! define generic interface routines
interface rad_cnst_get_info
module procedure rad_cnst_get_info
module procedure rad_cnst_get_info_by_mode
module procedure rad_cnst_get_info_by_mode_spec
module procedure rad_cnst_get_info_by_spectype
end interface
interface rad_cnst_get_aer_mmr
module procedure rad_cnst_get_aer_mmr_by_idx
module procedure rad_cnst_get_mam_mmr_by_idx
end interface
interface rad_cnst_get_aer_props
module procedure rad_cnst_get_aer_props_by_idx
module procedure rad_cnst_get_mam_props_by_idx
end interface
logical :: verbose = .true.
character(len=1), parameter :: nl = achar(10)
integer, parameter :: num_mode_types = 11 !kzm
integer, parameter :: num_spec_types = 8
character(len=14), parameter :: mode_type_names(num_mode_types) = (/ &
'accum ', 'aitken ', 'primary_carbon', 'fine_seasalt ', &
'fine_dust ', 'coarse ', 'coarse_seasalt', 'coarse_dust ', &
'coarse_dust1 ', 'coarse_dust2 ', 'coarse_dust3 ' /) !kzm
character(len=9), parameter :: spec_type_names(num_spec_types) = (/ &
'sulfate ', 'ammonium ', 'nitrate ', 'p-organic', &
's-organic', 'black-c ', 'seasalt ', 'dust '/)
!==============================================================================
contains
!==============================================================================
subroutine rad_cnst_readnl(nlfile)
! Read rad_cnst_nl namelist group. Parse input.
use namelist_utils, only: find_group_name
use units, only: getunit, freeunit
use mpishorthand
character(len=*), intent(in) :: nlfile ! filepath for file containing namelist input
! Local variables
integer :: unitn, ierr, i
character(len=2) :: suffix
character(len=1), pointer :: ctype(:)
character(len=*), parameter :: subname = 'rad_cnst_readnl'
namelist /rad_cnst_nl/ mode_defs, &
rad_climate, &
rad_diag_1, &
rad_diag_2, &
rad_diag_3, &
rad_diag_4, &
rad_diag_5, &
rad_diag_6, &
rad_diag_7, &
rad_diag_8, &
rad_diag_9, &
rad_diag_10, &
iceopticsfile, &
liqopticsfile, &
icecldoptics, &
liqcldoptics, &
oldcldoptics
!-----------------------------------------------------------------------------
if (masterproc) then
unitn = getunit()
open( unitn, file=trim(nlfile), status='old' )
call find_group_name(unitn, 'rad_cnst_nl', status=ierr)
if (ierr == 0) then
read(unitn, rad_cnst_nl, iostat=ierr)
if (ierr /= 0) then
call endrun(subname // ':: ERROR reading namelist')
end if
end if
close(unitn)
call freeunit(unitn)
end if
#ifdef SPMD
! Broadcast namelist variables
call mpibcast (mode_defs, len(mode_defs(1))*n_mode_str, mpichar, 0, mpicom)
call mpibcast (rad_climate, len(rad_climate(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_1, len(rad_diag_1(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_2, len(rad_diag_2(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_3, len(rad_diag_3(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_4, len(rad_diag_4(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_5, len(rad_diag_5(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_6, len(rad_diag_6(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_7, len(rad_diag_7(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_8, len(rad_diag_8(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_9, len(rad_diag_9(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (rad_diag_10, len(rad_diag_10(1))*n_rad_cnst, mpichar, 0, mpicom)
call mpibcast (iceopticsfile, len(iceopticsfile), mpichar, 0, mpicom)
call mpibcast (liqopticsfile, len(liqopticsfile), mpichar, 0, mpicom)
call mpibcast (liqcldoptics, len(liqcldoptics), mpichar, 0, mpicom)
call mpibcast (icecldoptics, len(icecldoptics), mpichar, 0, mpicom)
call mpibcast (oldcldoptics, 1, mpilog , 0, mpicom)
#endif
! Parse the namelist input strings
! Mode definition stings
call parse_mode_defs(mode_defs, modes)
! Lists of externally mixed entities for climate and diagnostic calculations
do i = 0,N_DIAG
select case (i)
case(0)
call parse_rad_specifier(rad_climate, namelist(i))
case (1)
call parse_rad_specifier(rad_diag_1, namelist(i))
case (2)
call parse_rad_specifier(rad_diag_2, namelist(i))
case (3)
call parse_rad_specifier(rad_diag_3, namelist(i))
case (4)
call parse_rad_specifier(rad_diag_4, namelist(i))
case (5)
call parse_rad_specifier(rad_diag_5, namelist(i))
case (6)
call parse_rad_specifier(rad_diag_6, namelist(i))
case (7)
call parse_rad_specifier(rad_diag_7, namelist(i))
case (8)
call parse_rad_specifier(rad_diag_8, namelist(i))
case (9)
call parse_rad_specifier(rad_diag_9, namelist(i))
case (10)
call parse_rad_specifier(rad_diag_10, namelist(i))
end select
enddo
! were there any constituents specified for the nth diagnostic call?
! if so, radiation will make a call with those consituents
active_calls(:) = (namelist(:)%ncnst > 0)
! Initialize the gas and aerosol lists with the information from the
! namelist. This is done here so that this information is available via
! the query functions at the time when the register methods are called.
! Set the list_id fields which distinquish the climate and diagnostic lists
do i = 0, N_DIAG
if (active_calls(i)) then
if (i > 0) then
write(suffix, fmt = '(i2.2)') i
else
suffix=' '
end if
aerosollist(i)%list_id = suffix
gaslist(i)%list_id = suffix
ma_list(i)%list_id = suffix
end if
end do
! Create a list of the unique set of filenames containing property data
! Start with the bulk aerosol species in the climate/diagnostic lists.
! The physprop_accum_unique_files routine has the side effect of returning the number
! of bulk aerosols in each list (they're identified by type='A').
do i = 0, N_DIAG
if (active_calls(i)) then
call physprop_accum_unique_files(namelist(i)%radname, namelist(i)%type)
endif
enddo
! Add physprop files for the species from the mode definitions.
do i = 1, modes%nmodes
allocate(ctype(modes%comps(i)%nspec))
ctype = 'A'
call physprop_accum_unique_files(modes%comps(i)%props, ctype)
deallocate(ctype)
end do
! Initialize the gas, bulk aerosol, and modal aerosol lists. This step splits the
! input climate/diagnostic lists into the corresponding gas, bulk and modal aerosol
! lists.
if (masterproc) write(iulog,*) nl//subname//': Radiation constituent lists:'
do i = 0, N_DIAG
if (active_calls(i)) then
call list_init1(namelist(i), gaslist(i), aerosollist(i), ma_list(i))
if (masterproc .and. verbose) then
call print_lists(gaslist(i), aerosollist(i), ma_list(i))
end if
end if
end do
if (masterproc .and. verbose) call print_modes(modes)
end subroutine rad_cnst_readnl
!================================================================================================
subroutine rad_cnst_init()
! The initialization of the gas and aerosol lists is finished by
! 1) read the physprop files
! 2) find the index of each constituent in the constituent or physics buffer arrays
! 3) find the index of the aerosol constituents used to access its properties from the
! physprop module.
integer :: i
integer :: num_aerosols
logical, parameter :: stricttest = .true.
character(len=*), parameter :: subname = 'rad_cnst_init'
!-----------------------------------------------------------------------------
! memory to point to if zero value requested
allocate(zero_cols(pcols,pver))
zero_cols = 0._r8
! Allocate storage for the physical properties of each aerosol; read properties from
! the data files.
call physprop_init()
! Start checking that specified radiative constituents are present in the constituent
! or physics buffer arrays.
if (masterproc) write(iulog,*) nl//subname//': checking for radiative constituents'
! Finish initializing the mode definitions.
call init_mode_comps(modes)
! Finish initializing the gas, bulk aerosol, and mode lists.
do i = 0, N_DIAG
if (active_calls(i)) then
call list_init2(gaslist(i), aerosollist(i), ma_list(i))
end if
end do
! Check that all gases supported by the radiative transfer code have been specified.
if (stricttest) then
do i = 1, nradgas
if (gaslist(0)%gas(i)%source .eq. 'Z' ) then
call endrun(subname//': list of radiative gasses must include all radiation gasses for the climate specication')
endif
enddo
endif
! Initialize history output of climate diagnostic quantities
call rad_gas_diag_init(gaslist(0))
call rad_aer_diag_init(aerosollist(0))
end subroutine rad_cnst_init
!================================================================================================
subroutine rad_cnst_get_gas(list_idx, gasname, state, pbuf, mmr)
! Return pointer to mass mixing ratio for the gas from the specified
! climate or diagnostic list.
! Arguments
integer, intent(in) :: list_idx ! index of the climate or a diagnostic list
character(len=*), intent(in) :: gasname
type(physics_state), target, intent(in) :: state
type(physics_buffer_desc), pointer :: pbuf(:)
real(r8), pointer :: mmr(:,:)
! Local variables
integer :: lchnk
integer :: igas
integer :: idx
character(len=1) :: source
type(gaslist_t), pointer :: list
character(len=*), parameter :: subname = 'rad_cnst_get_gas'
!-----------------------------------------------------------------------------
if (list_idx >= 0 .and. list_idx <= N_DIAG) then
list => gaslist(list_idx)
else
write(iulog,*) subname//': list_idx =', list_idx
call endrun(subname//': list_idx out of bounds')
endif
lchnk = state%lchnk
! Get index of gas in internal arrays. rad_gas_index will abort if the
! specified gasname is not recognized by the radiative transfer code.
igas = rad_gas_index(trim(gasname))
! Get data source
source = list%gas(igas)%source
idx = list%gas(igas)%idx
select case( source )
case ('A')
mmr => state%q(:,:,idx)
case ('N')
call pbuf_get_field(pbuf, idx, mmr)
case ('Z')
mmr => zero_cols
end select
end subroutine rad_cnst_get_gas
!================================================================================================
subroutine rad_cnst_get_info(list_idx, gasnames, aernames, &
use_data_o3, ngas, naero, nmodes)
! Return info about gas and aerosol lists
! Arguments
integer, intent(in) :: list_idx ! index of the climate or a diagnostic list
character(len=64), optional, intent(out) :: gasnames(:)
character(len=64), optional, intent(out) :: aernames(:)
logical, optional, intent(out) :: use_data_o3
integer, optional, intent(out) :: naero
integer, optional, intent(out) :: ngas
integer, optional, intent(out) :: nmodes
! Local variables
type(gaslist_t), pointer :: g_list ! local pointer to gas list of interest
type(aerlist_t), pointer :: a_list ! local pointer to aerosol list of interest
type(modelist_t), pointer :: m_list ! local pointer to mode list of interest
integer :: i
integer :: arrlen ! length of assumed shape array
integer :: gaslen ! length of assumed shape array
integer :: igas ! index of a gas in the gas list
character(len=1) :: source ! A for state, N for pbuf, Z for zero
character(len=*), parameter :: subname = 'rad_cnst_get_info'
!-----------------------------------------------------------------------------
g_list => gaslist(list_idx)
a_list => aerosollist(list_idx)
m_list => ma_list(list_idx)
! number of bulk aerosols in list
if (present(naero)) then
naero = a_list%numaerosols
endif
! number of aerosol modes in list
if (present(nmodes)) then
nmodes = m_list%nmodes
endif
! number of gases in list
if (present(ngas)) then
ngas = g_list%ngas
endif
! names of aerosols in list
if (present(aernames)) then
! check that output array is long enough
arrlen = size(aernames)
if (arrlen < a_list%numaerosols) then
write(iulog,*) subname//': ERROR: naero=', a_list%numaerosols, ' arrlen=', arrlen
call endrun(subname//': ERROR: aernames too short')
end if
do i = 1, a_list%numaerosols
aernames(i) = a_list%aer(i)%camname
end do
end if
! names of gas in list
if (present(gasnames)) then
! check that output array is long enough
gaslen = size(gasnames)
if (gaslen < g_list%ngas) then
write(iulog,*) subname//': ERROR: ngas=', g_list%ngas, ' gaslen=', gaslen
call endrun(subname//': ERROR: gasnames too short')
end if
do i = 1, g_list%ngas
gasnames(i) = g_list%gas(i)%camname
end do
end if
! Does the climate calculation use data ozone?
if (present(use_data_o3)) then
! get index of O3 in gas list
igas = rad_gas_index('O3')
! Get data source
source = g_list%gas(igas)%source
use_data_o3 = .false.
if (source == 'N') use_data_o3 = .true.
endif
end subroutine rad_cnst_get_info
!================================================================================================
subroutine rad_cnst_get_info_by_mode(list_idx, m_idx, &
mode_type, num_name, num_name_cw, nspec)
! Return info about modal aerosol lists
! Arguments
integer, intent(in) :: list_idx ! index of the climate or a diagnostic list
integer, intent(in) :: m_idx ! index of mode in the specified list
character(len=32), optional, intent(out) :: mode_type ! type of mode (as used in MAM code)
character(len=32), optional, intent(out) :: num_name ! name of interstitial number mixing ratio
character(len=32), optional, intent(out) :: num_name_cw ! name of cloud borne number mixing ratio
integer, optional, intent(out) :: nspec ! number of species in the mode
! Local variables
type(modelist_t), pointer :: m_list ! local pointer to mode list of interest
integer :: nmodes
integer :: mm
character(len=*), parameter :: subname = 'rad_cnst_get_info_by_mode'
!-----------------------------------------------------------------------------
m_list => ma_list(list_idx)
! check for valid mode index
nmodes = m_list%nmodes
if (m_idx < 1 .or. m_idx > nmodes) then
write(iulog,*) subname//': ERROR - invalid mode index: ', m_idx
call endrun(subname//': ERROR - invalid mode index')
end if
! get index into the mode definition object
mm = m_list%idx(m_idx)
! mode type
if (present(mode_type)) then
mode_type = modes%types(mm)
endif
! number of species in the mode
if (present(nspec)) then
nspec = modes%comps(mm)%nspec
endif
! name of interstitial number mixing ratio
if (present(num_name)) then
num_name = modes%comps(mm)%camname_num_a
endif
! name of cloud borne number mixing ratio
if (present(num_name_cw)) then
num_name_cw = modes%comps(mm)%camname_num_c
endif
end subroutine rad_cnst_get_info_by_mode
!================================================================================================
subroutine rad_cnst_get_info_by_mode_spec(list_idx, m_idx, s_idx, &
spec_type, spec_name, spec_name_cw)
! Return info about modal aerosol lists
! Arguments
integer, intent(in) :: list_idx ! index of the climate or a diagnostic list
integer, intent(in) :: m_idx ! index of mode in the specified list
integer, intent(in) :: s_idx ! index of specie in the specified mode
character(len=32), optional, intent(out) :: spec_type ! type of specie
character(len=32), optional, intent(out) :: spec_name ! name of interstitial specie
character(len=32), optional, intent(out) :: spec_name_cw ! name of cloud borne specie
! Local variables
type(modelist_t), pointer :: m_list ! local pointer to mode list of interest
integer :: nmodes
integer :: nspec
integer :: mm
character(len=*), parameter :: subname = 'rad_cnst_get_info_by_mode_spec'
!-----------------------------------------------------------------------------
m_list => ma_list(list_idx)
! check for valid mode index
nmodes = m_list%nmodes
if (m_idx < 1 .or. m_idx > nmodes) then
write(iulog,*) subname//': ERROR - invalid mode index: ', m_idx
call endrun(subname//': ERROR - invalid mode index')
end if
! get index into the mode definition object
mm = m_list%idx(m_idx)
! check for valid specie index
nspec = modes%comps(mm)%nspec
if (s_idx < 1 .or. s_idx > nspec) then
write(iulog,*) subname//': ERROR - invalid specie index: ', s_idx
call endrun(subname//': ERROR - invalid specie index')
end if
! specie type
if (present(spec_type)) then
spec_type = modes%comps(mm)%type(s_idx)
endif
! interstitial specie name
if (present(spec_name)) then
spec_name = modes%comps(mm)%camname_mmr_a(s_idx)
endif
! cloud borne specie name
if (present(spec_name_cw)) then
spec_name_cw = modes%comps(mm)%camname_mmr_c(s_idx)
endif
end subroutine rad_cnst_get_info_by_mode_spec
!================================================================================================
subroutine rad_cnst_get_info_by_spectype(list_idx, spectype, mode_idx, spec_idx)
! Return info about modes in the specified climate/diagnostics list
! Arguments
integer, intent(in) :: list_idx ! index of the climate or a diagnostic list
character(len=*), intent(in) :: spectype ! species type
integer, optional, intent(out) :: mode_idx ! index of a mode that contains a specie of spectype
integer, optional, intent(out) :: spec_idx ! index of the species of spectype
! Local variables
type(modelist_t), pointer :: m_list ! local pointer to mode list of interest
integer :: i, nmodes, m_idx, nspec, ispec
logical :: found_spectype
character(len=*), parameter :: subname = 'rad_cnst_get_info_by_spectype'
!-----------------------------------------------------------------------------
m_list => ma_list(list_idx)
! number of modes in specified list
nmodes = m_list%nmodes
! loop through modes in specified climate/diagnostic list
found_spectype = .false.
do i = 1, nmodes
! get index of the mode in the definition object
m_idx = m_list%idx(i)
! number of species in the mode
nspec = modes%comps(m_idx)%nspec
! loop through species looking for spectype
do ispec = 1, nspec
if (trim(modes%comps(m_idx)%type(ispec)) == trim(spectype)) then
if (present(mode_idx)) mode_idx = i
if (present(spec_idx)) spec_idx = ispec
found_spectype = .true.
exit
end if
end do
if (found_spectype) exit
end do
if (.not. found_spectype) then
if (present(mode_idx)) mode_idx = -1
if (present(spec_idx)) spec_idx = -1
end if
end subroutine rad_cnst_get_info_by_spectype
!================================================================================================
function rad_cnst_get_mode_idx(list_idx, mode_type) result(mode_idx)
! Return mode index of the specified type in the specified climate/diagnostics list.
! Return -1 if not found.
! Arguments
integer, intent(in) :: list_idx ! index of the climate or a diagnostic list
character(len=*), intent(in) :: mode_type ! mode type
! Return value
integer :: mode_idx ! mode index
! Local variables
type(modelist_t), pointer :: m_list
integer :: i, nmodes, m_idx
character(len=*), parameter :: subname = 'rad_cnst_get_mode_idx'
!-----------------------------------------------------------------------------
! if mode type not found return -1
mode_idx = -1
! specified mode list
m_list => ma_list(list_idx)
! number of modes in specified list
nmodes = m_list%nmodes
! loop through modes in specified climate/diagnostic list
do i = 1, nmodes
! get index of the mode in the definition object
m_idx = m_list%idx(i)
! look in mode definition object (modes) for the mode types
if (trim(modes%types(m_idx)) == trim(mode_type)) then
mode_idx = i
exit
end if
end do
end function rad_cnst_get_mode_idx
!================================================================================================
function rad_cnst_get_spec_idx(list_idx, mode_idx, spec_type) result(spec_idx)
! Return specie index of the specified type in the specified mode of the specified
! climate/diagnostics list. Return -1 if not found.
! Arguments
integer, intent(in) :: list_idx ! index of the climate or a diagnostic list
integer, intent(in) :: mode_idx ! mode index
character(len=*), intent(in) :: spec_type ! specie type
! Return value
integer :: spec_idx ! specie index
! Local variables
type(modelist_t), pointer :: m_list
type(mode_component_t), pointer :: mode_comps
integer :: i, m_idx, nspec
character(len=*), parameter :: subname = 'rad_cnst_get_spec_idx'
!-----------------------------------------------------------------------------
! if specie type not found return -1
spec_idx = -1
! modes in specified list
m_list => ma_list(list_idx)
! get index of the specified mode in the definition object
m_idx = m_list%idx(mode_idx)
! object containing the components of the mode
mode_comps => modes%comps(m_idx)
! number of species in specified mode
nspec = mode_comps%nspec
! loop through species in specified mode
do i = 1, nspec
! look in mode definition object (modes) for the mode types
if (trim(mode_comps%type(i)) == trim(spec_type)) then
spec_idx = i
exit
end if
end do
end function rad_cnst_get_spec_idx
!================================================================================================
subroutine rad_cnst_get_call_list(call_list)
! Return info about which climate/diagnostic calculations are requested
! Arguments
logical, intent(out) :: call_list(0:N_DIAG)
!-----------------------------------------------------------------------------
call_list(:) = active_calls(:)
end subroutine rad_cnst_get_call_list
!================================================================================================
subroutine rad_cnst_out(list_idx, state, pbuf)
! Output the mass per layer, and total column burdens for gas and aerosol
! constituents in either the climate or diagnostic lists
! Arguments
integer, intent(in) :: list_idx
type(physics_state), target, intent(in) :: state
type(physics_buffer_desc), pointer :: pbuf(:)
! Local variables
integer :: i, naer, ngas, lchnk, ncol
integer :: idx
character(len=1) :: source
character(len=32) :: name, cbname
real(r8) :: mass(pcols,pver)
real(r8) :: cb(pcols)
real(r8), pointer :: mmr(:,:)
type(aerlist_t), pointer :: aerlist
type(gaslist_t), pointer :: g_list
character(len=*), parameter :: subname = 'rad_cnst_out'
!-----------------------------------------------------------------------------
lchnk = state%lchnk
ncol = state%ncol
! Associate pointer with requested aerosol list
if (list_idx >= 0 .and. list_idx <= N_DIAG) then
aerlist => aerosollist(list_idx)
else
write(iulog,*) subname//': list_idx = ', list_idx
call endrun(subname//': list_idx out of range')
endif
naer = aerlist%numaerosols
do i = 1, naer
source = aerlist%aer(i)%source
idx = aerlist%aer(i)%idx
name = aerlist%aer(i)%mass_name
! construct name for column burden field by replacing the 'm_' prefix by 'cb_'
cbname = 'cb_' // name(3:len_trim(name))
select case( source )
case ('A')
mmr => state%q(:,:,idx)
case ('N')
call pbuf_get_field(pbuf, idx, mmr)
end select
mass(:ncol,:) = mmr(:ncol,:) * state%pdeldry(:ncol,:) * rga
call outfld(trim(name), mass, pcols, lchnk)
cb(:ncol) = sum(mass(:ncol,:),2)
call outfld(trim(cbname), cb, pcols, lchnk)
end do
! Associate pointer with requested gas list
g_list => gaslist(list_idx)
ngas = g_list%ngas
do i = 1, ngas
source = g_list%gas(i)%source
idx = g_list%gas(i)%idx
name = g_list%gas(i)%mass_name
cbname = 'cb_' // name(3:len_trim(name))
select case( source )
case ('A')
mmr => state%q(:,:,idx)
case ('N')
call pbuf_get_field(pbuf, idx, mmr)
end select
mass(:ncol,:) = mmr(:ncol,:) * state%pdeldry(:ncol,:) * rga
call outfld(trim(name), mass, pcols, lchnk)
cb(:ncol) = sum(mass(:ncol,:),2)
call outfld(trim(cbname), cb, pcols, lchnk)
end do
end subroutine rad_cnst_out
!================================================================================================
! Private methods
!================================================================================================
subroutine init_mode_comps(modes)
! Initialize the mode definitions by looking up the relevent indices in the
! constituent and pbuf arrays, and getting the physprop IDs
! Arguments
type(modes_t), intent(inout) :: modes
! Local variables
integer :: m, ispec, nspec
character(len=*), parameter :: routine = 'init_modes'
!-----------------------------------------------------------------------------
do m = 1, modes%nmodes
! indices for number mixing ratio components
modes%comps(m)%idx_num_a = get_cam_idx(modes%comps(m)%source_num_a, modes%comps(m)%camname_num_a, routine)
modes%comps(m)%idx_num_c = get_cam_idx(modes%comps(m)%source_num_c, modes%comps(m)%camname_num_c, routine)
! allocate memory for species
nspec = modes%comps(m)%nspec
allocate( &
modes%comps(m)%idx_mmr_a(nspec), &
modes%comps(m)%idx_mmr_c(nspec), &
modes%comps(m)%idx_props(nspec) )
do ispec = 1, nspec
! indices for species mixing ratio components
modes%comps(m)%idx_mmr_a(ispec) = get_cam_idx(modes%comps(m)%source_mmr_a(ispec), &
modes%comps(m)%camname_mmr_a(ispec), routine)
modes%comps(m)%idx_mmr_c(ispec) = get_cam_idx(modes%comps(m)%source_mmr_c(ispec), &
modes%comps(m)%camname_mmr_c(ispec), routine)