-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathradiation.F90
2847 lines (2434 loc) · 138 KB
/
radiation.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 radiation
!---------------------------------------------------------------------------------
! Purpose:
!
! CAM interface to RRTMGP
!
! Revision history:
! Nov 2017 B. Hillman Initial version, adapted from RRTMG interface.
!---------------------------------------------------------------------------------
! E3SM-specific modules that are used throughout this module. An effort was made
! to keep imports as local as possible, so we only load a few of these at the
! module (rather than the subroutine) level.
use iso_c_binding
use shr_kind_mod, only: r8=>shr_kind_r8, cl=>shr_kind_cl
use ppgrid, only: pcols, pver, pverp, begchunk, endchunk
use cam_abortutils, only: endrun
use scamMod, only: scm_crm_mode, single_column
use rad_constituents, only: N_DIAG
use radconstants, only: &
nswbands, nlwbands, &
get_band_index_sw, get_band_index_lw, test_get_band_index, &
get_sw_spectral_midpoints, get_lw_spectral_midpoints, &
get_sw_spectral_boundaries, &
rrtmg_to_rrtmgp_swbands
use cam_history_support, only: add_hist_coord
use physconst, only: cpair, cappa
! RRTMGP gas optics object to store coefficient information. This is imported
! here so that we can make the k_dist objects module data and only load them
! once.
use rrtmgp_interface, only: &
rrtmgp_initialize, rrtmgp_finalize, &
rrtmgp_run_sw, rrtmgp_run_lw, &
get_min_temperature, get_max_temperature, &
get_gpoint_bands_sw, get_gpoint_bands_lw, &
nswgpts, nlwgpts
! Use my assertion routines to perform sanity checks
use assertions, only: assert, assert_valid, assert_range
use radiation_state, only: ktop, kbot, nlev_rad
use radiation_utils, only: handle_error, clip_values, &
fluxes_t, initialize_fluxes, free_fluxes, reset_fluxes, &
expand_day_fluxes, get_gas_vmr
! For MMF
use crmdims, only: crm_nx_rad, crm_ny_rad, crm_nz
implicit none
private
save
! Public routines provided by this module.
! TODO: radiation_defaultopts, radiation_setops, and radiation_printops exist
! only because the radiation namelist has traditionally been read at the driver
! level by runtime_opts. I am not sure this is the best solution, and in fact
! CESM seems to have gone away from this practice altogether, opting instead for
! individual modules to be responsible for reading their own namelists. This
! might be a better practice going forward, and would simplify the logic here
! somewhat. To do this, we would need to use the radiation_readnl routine
! (copied below), and add a line in runtime_opts that calls this routine, and
! then remove the code in runtime_opts that reads the radiation namelist
! variables from the CAM namelist. The calls to radiation_defaultopts,
! radiation_setops, and radiation_printops would also then need to be removed
! from runtime_ops.
public :: &
radiation_register, &! registers radiation physics buffer fields
radiation_nextsw_cday, &! calendar day of next radiation calculation
radiation_do, &! query which radiation calcs are done this timestep
radiation_init, &! calls radini
radiation_final, &! deallocate
radiation_readnl, &! read radiation namelist
radiation_tend ! moved from radctl.F90
! Counter variables for use with the CFMIP Observation Simulator Package (COSP).
! TODO: This seems like somewhat of an awkward way of determining when to run
! COSP, and it might make more sense to implement a more elegant routine to call
! that determines whether or not to run COSP at a given timestep (similar to the
! radiation_do routine in this module).
! TODO: move these to COSP interface instead
integer, public, allocatable :: cosp_cnt(:) ! counter for cosp
integer, public :: cosp_cnt_init = 0 ! initial value for cosp counter
! Declare namelist variables as module data. This also sets default values for
! namelist variables.
integer, public :: iradsw = -1 ! freq. of shortwave radiation calc in time steps (positive)
! or hours (negative).
integer :: iradlw = -1 ! frequency of longwave rad. calc. in time steps (positive)
! or hours (negative).
integer :: irad_always = 0 ! Specifies length of time in timesteps (positive)
! or hours (negative) SW/LW radiation will be
! run continuously from the start of an
! initial or restart run
! The spectralflux flag determines whether or not spectral (per band) fluxes are
! calculated. If true, upward and downward fluxes are calculated per band,
! otherwise just broadband "shortwave" and "longwave" fluxes are calculated.
! TODO: while it seems that setting spectralflux = .true. add spectral fluxes to
! the physics buffer, I do not see where these fields are added to the history
! buffer. It might be that the output of these fields are just handled by the
! physics buffer output routines (they are declared with "global" scope, so
! written on restart files at least), but it would be good to include them on
! the history buffer too so that we can annotate them with a description of what
! they are, rather than expecting the user to know what they are from the pbuf
! fields.
logical :: spectralflux = .false. ! calculate fluxes (up and down) per band.
! Flag to indicate whether or not to use the radiation timestep for solar zenith
! angle calculations. If true, use the radiation timestep for all solar zenith
! angle (cosz) calculations.
! TODO: How does this differ if value is .false.?
logical, public :: use_rad_dt_cosz = .false.
! Flag to indicate whether to do aerosol optical calculations. This
! zeroes out the aerosol optical properties if False
logical :: do_aerosol_rad = .true.
! Value for prescribing an invariant solar constant (i.e. total solar
! irradiance at TOA). Used for idealized experiments such as RCE.
! Disabled when value is less than 0.
real(r8) :: fixed_total_solar_irradiance = -1
! The RRTMGP warnings are printed when the state variables need to be limted,
! such as when the temperature drops too low. This is not normally an issue,
! but in aquaplanet and RCE configurations these situations occur much more
! frequently, so this flag was added to be able to disable those messages.
logical :: rrtmgp_enable_temperature_warnings = .true.
! Model data that is not controlled by namelist fields specifically follows
! below.
! TODO: it seems CAM allows for multiple passes through the radiation (and other
! physics?) for different diagnostic purposes, but this does not seem to be well
! documented anywhere. We should add some documentation here on this if we are
! going to keep this functionality.
character(len=4) :: diag(0:N_DIAG) =(/' ','_d1 ','_d2 ','_d3 ','_d4 ','_d5 ', &
'_d6 ','_d7 ','_d8 ','_d9 ','_d10'/)
! Output diagnostic brightness temperatures at the top of the
! atmosphere for 7 TOVS/HIRS channels (2,4,6,8,10,11,12) and 4 TOVS/MSU
! channels (1,2,3,4).
! TODO: where are these options set?
logical :: dohirs = .false.
integer :: ihirsfq = 1 ! frequency (timesteps) of brightness temperature calcs
! time step to use for the shr_orb_cosz calculation, if use_rad_dt_cosz set to true
! TODO: where is this set, and what is shr_orb_cosz? Alternative solar zenith
! angle calculation? What is the other behavior?
real(r8) :: dt_avg = 0.0_r8
! k-distribution coefficients files to read from. These are set via namelist
! variables.
character(len=cl) :: rrtmgp_coefficients_file_sw, rrtmgp_coefficients_file_lw
! Band midpoints; these need to be module variables because of how cam_history works;
! add_hist_coord sets up pointers to these, so they need to persist.
real(r8), target :: sw_band_midpoints(nswbands), lw_band_midpoints(nlwbands)
! Set name for this module (for purpose of writing output and log files)
character(len=*), parameter :: module_name = 'radiation'
! Gases that we want to use in the radiative calculations. These need to be set
! here, because the RRTMGP kdist initialization needs to know the names of the
! gases before these are available via the rad_cnst interface. So, if we want to
! change which gases are used at some point, this needs to be changed here, or
! we need to come up with a more clever way of getting these from the model,
! since this is kind of a hack to hard-code them in here.
character(len=3), dimension(8) :: active_gases = (/ &
'H2O', 'CO2', 'O3 ', 'N2O', &
'CO ', 'CH4', 'O2 ', 'N2 ' &
/)
! Null-terminated C-compatible version of active gases for use with C++
! routines.
character(len=len(active_gases)+1), dimension(size(active_gases)), target :: active_gases_c
! Stuff to generate random numbers for perturbation growth tests. This needs to
! be public module data because restart_physics needs to read it to write it to
! restart files (I think). Making this public module data may not be the best
! way of doing this, so maybe this should be reconsidered in the future.
!
! kiss_seed_num is number of seed values to use?
integer, public, parameter :: kiss_seed_num = 4
! TODO: what does this mean? This seems to be part of the additions for the
! perturbation growth functionality.
integer, public, allocatable :: rad_randn_seedrst(:,:,:)
! Total number of physics chunks until this processor (TODO: what exactly does
! this mean?)
integer, public, allocatable :: tot_chnk_till_this_prc(:,:,:)
!============================================================================
contains
!============================================================================
subroutine radiation_readnl(nlfile, dtime_in)
!-------------------------------------------------------------------------------
! Purpose: Read radiation_nl namelist group.
!-------------------------------------------------------------------------------
use namelist_utils, only: find_group_name
use units, only: getunit, freeunit
use spmd_utils, only: mpicom, mstrid=>masterprocid, &
mpi_integer, mpi_logical, &
mpi_character, masterproc, &
mpi_real8
use time_manager, only: get_step_size
use cam_logfile, only: iulog
! File containing namelist input
character(len=*), intent(in) :: nlfile
integer, intent(in), optional :: dtime_in
! Local variables
integer :: unitn, ierr
integer :: dtime ! timestep size
character(len=*), parameter :: subroutine_name = 'radiation_readnl'
! Variables defined in namelist
namelist /radiation_nl/ rrtmgp_coefficients_file_lw, &
rrtmgp_coefficients_file_sw, &
iradsw, iradlw, irad_always, &
use_rad_dt_cosz, spectralflux, &
do_aerosol_rad, &
fixed_total_solar_irradiance, &
rrtmgp_enable_temperature_warnings
! Read the namelist, only if called from master process
! TODO: better documentation and cleaner logic here?
if (masterproc) then
unitn = getunit()
open(unitn, file=trim(nlfile), status='old')
call find_group_name(unitn, 'radiation_nl', status=ierr)
if (ierr == 0) then
read(unitn, radiation_nl, iostat=ierr)
if (ierr /= 0) then
call endrun(subroutine_name // ':: ERROR reading namelist')
end if
end if
close(unitn)
call freeunit(unitn)
end if
#ifdef SPMD
! Broadcast namelist variables
call mpibcast(rrtmgp_coefficients_file_lw, cl, mpi_character, mstrid, mpicom, ierr)
call mpibcast(rrtmgp_coefficients_file_sw, cl, mpi_character, mstrid, mpicom, ierr)
call mpibcast(iradsw, 1, mpi_integer, mstrid, mpicom, ierr)
call mpibcast(iradlw, 1, mpi_integer, mstrid, mpicom, ierr)
call mpibcast(irad_always, 1, mpi_integer, mstrid, mpicom, ierr)
call mpibcast(use_rad_dt_cosz, 1, mpi_logical, mstrid, mpicom, ierr)
call mpibcast(spectralflux, 1, mpi_logical, mstrid, mpicom, ierr)
call mpibcast(do_aerosol_rad, 1, mpi_logical, mstrid, mpicom, ierr)
call mpibcast(fixed_total_solar_irradiance, 1, mpi_real8, mstrid, mpicom, ierr)
call mpibcast(rrtmgp_enable_temperature_warnings, 1, mpi_logical, mstrid, mpicom, ierr)
#endif
! Convert iradsw, iradlw and irad_always from hours to timesteps if necessary
if (present(dtime_in)) then
dtime = dtime_in
else
dtime = get_step_size()
end if
if (iradsw < 0) iradsw = nint((-iradsw *3600._r8)/dtime)
if (iradlw < 0) iradlw = nint((-iradlw *3600._r8)/dtime)
if (irad_always < 0) irad_always = nint((-irad_always*3600._r8)/dtime)
! Print runtime options to log.
if (masterproc) then
write(iulog,*) 'RRTMGP radiation scheme parameters:'
write(iulog,10) trim(rrtmgp_coefficients_file_lw), trim(rrtmgp_coefficients_file_sw), &
iradsw, iradlw, irad_always, &
use_rad_dt_cosz, spectralflux, &
do_aerosol_rad, fixed_total_solar_irradiance, &
rrtmgp_enable_temperature_warnings
end if
10 format(' LW coefficents file: ', a/, &
' SW coefficents file: ', a/, &
' Frequency (timesteps) of Shortwave Radiation calc: ',i5/, &
' Frequency (timesteps) of Longwave Radiation calc: ',i5/, &
' SW/LW calc done every timestep for first N steps. N=',i5/, &
' Use average zenith angle: ',l5/, &
' Output spectrally resolved fluxes: ',l5/, &
' Do aerosol radiative calculations: ',l5/, &
' Fixed solar consant (disabled with -1): ',f10.4/, &
' Enable temperature warnings: ',l5/ )
end subroutine radiation_readnl
!================================================================================================
subroutine radiation_register()
!----------------------------------------------------------------------------
! Register radiation fields in the physics buffer
!----------------------------------------------------------------------------
use physics_buffer, only: pbuf_add_field, dtype_r8
integer :: idx ! dummy index for adding fields to physics buffer
! Heating rate profiles; QRS is the shortwave radiative heating rate, and QRL
! is the longwave radiative heating rate
! TODO: Do QRS and QRL need to be set to "global" scope on the physics
! buffer? Doing so forces them to be written to restart files, but is this
! needed? It does not look like their values get read anywhere in this
! module, just overwritten, so they may not need to be written to restarts.
call pbuf_add_field('QRS', 'global', dtype_r8, (/pcols,pver/), idx)
call pbuf_add_field('QRL', 'global', dtype_r8, (/pcols,pver/), idx)
! If the namelist has been configured for preserving the spectral fluxes, then create
! physics buffer variables to store the results. These are fluxes per
! spectral band, as follows:
! SU: shortwave up
! SD: shortwave down
! LU: longwave up
! LD: longwave down
! TODO: Do these need to be "global"? Why not "physpkg"?
if (spectralflux) then
call pbuf_add_field('SU', 'global', dtype_r8, (/pcols,pverp,nswbands/), idx)
call pbuf_add_field('SD', 'global', dtype_r8, (/pcols,pverp,nswbands/), idx)
call pbuf_add_field('LU', 'global', dtype_r8, (/pcols,pverp,nlwbands/), idx)
call pbuf_add_field('LD', 'global', dtype_r8, (/pcols,pverp,nlwbands/), idx)
end if
end subroutine radiation_register
!===============================================================================
function radiation_do(op, timestep)
!----------------------------------------------------------------------------
! Purpose: Returns true if the specified operation is done this timestep.
!
! History: Copied from RRTMG implementation.
!----------------------------------------------------------------------------
use time_manager, only: get_nstep
! Arguments
character(len=*), intent(in) :: op ! name of operation
integer, intent(in), optional :: timestep ! model timestep
logical :: radiation_do ! return value
! Local variables
integer :: nstep ! current timestep number
! If passed a timestep explicitly, use that. Otherwise, get timestep from
! time_manager routine.
if (present(timestep)) then
nstep = timestep
else
nstep = get_nstep()
end if
! Figure out whether or not to do radiation this timestep. In general, we
! allow different frequencies of call the radiation code for the shortwave
! and the longwave. In practice, these are probably usually the same.
select case (op)
case ('sw') ! do a shortwave heating calc this timestep?
if (iradsw==0) then
radiation_do = .false.
else
radiation_do = nstep == 0 .or. iradsw == 1 &
.or. (mod(nstep-1,iradsw) == 0 .and. nstep /= 1) &
.or. nstep <= irad_always
end if
case ('lw') ! do a longwave heating calc this timestep?
if (iradlw==0) then
radiation_do = .false.
else
radiation_do = nstep == 0 .or. iradlw == 1 &
.or. (mod(nstep-1,iradlw) == 0 .and. nstep /= 1) &
.or. nstep <= irad_always
end if
case default
call endrun('radiation_do: unknown operation:'//op)
end select
end function radiation_do
!================================================================================================
real(r8) function radiation_nextsw_cday()
!-----------------------------------------------------------------------
! Purpose: Returns calendar day of next sw radiation calculation
!
! History: Copied from RRTMG implementation.
!-----------------------------------------------------------------------
use time_manager, only: get_curr_calday, get_nstep, get_step_size
! Local variables
integer :: nstep ! timestep counter
logical :: dosw ! true => do shosrtwave calc
integer :: offset ! offset for calendar day calculation
integer :: dTime ! integer timestep size
real(r8):: calday ! calendar day of
!-----------------------------------------------------------------------
radiation_nextsw_cday = -1._r8
dosw = .false.
nstep = get_nstep()
dtime = get_step_size()
offset = 0
if (iradsw/=0) then
do while (.not. dosw)
nstep = nstep + 1
offset = offset + dtime
if (radiation_do('sw', nstep)) then
radiation_nextsw_cday = get_curr_calday(offset=offset)
dosw = .true.
end if
end do
end if
end function radiation_nextsw_cday
!================================================================================================
subroutine radiation_init(state)
!-------------------------------------------------------------------------------
! Purpose: Initialize the radiation parameterization and add fields to the
! history buffer
!
! History: Copied from RRTMG implemenation.
!-------------------------------------------------------------------------------
use physics_buffer, only: pbuf_get_index
use cam_history, only: addfld, horiz_only, add_default
use constituents, only: cnst_get_ind
use phys_control, only: phys_getopts
use rad_constituents, only: N_DIAG, rad_cnst_get_call_list, rad_cnst_get_info
use cospsimulator_intr, only: docosp, cospsimulator_intr_init
use hirsbt, only: hirsbt_init
use hirsbtpar, only: hirsname, msuname
use modal_aer_opt, only: modal_aer_opt_init
use time_manager, only: get_nstep, get_step_size, is_first_restart_step
use radiation_data, only: init_rad_data
use physics_types, only: physics_state
! For optics
use cloud_rad_props, only: cloud_rad_props_init
use ebert_curry, only: ec_rad_props_init
use slingo, only: slingo_rad_props_init
! Physics state is going to be needed for perturbation growth tests, but we
! have yet to implement this in RRTMGP. It is a vector because at the point
! where this subroutine is called, physics_state has not subset for a
! specific chunk (i.e., state is a vector of all chunks, indexed by lchnk)
type(physics_state), intent(in) :: state(:)
integer :: icall, nmodes
logical :: active_calls(0:N_DIAG)
integer :: nstep ! current timestep number
logical :: history_amwg ! output the variables used by the AMWG diag package
logical :: history_vdiag ! output the variables used by the AMWG variability diag package
logical :: history_budget ! output tendencies and state variables for CAM4
! temperature, water vapor, cloud ice and cloud
! liquid budgets.
integer :: history_budget_histfile_num ! output history file number for budget fields
integer :: err
integer :: dtime ! time step
integer :: cldfsnow_idx = 0
logical :: use_MMF ! MMF flag
character(len=128) :: error_message
character(len=32) :: subname = 'radiation_init'
character(len=10), dimension(3) :: dims_crm_rad = (/'crm_nx_rad','crm_ny_rad','crm_nz '/)
#ifdef MMF_ML_TRAINING
integer :: ml_solin_idx = -1
integer :: ml_coszrs_idx = -1
#endif
!-----------------------------------------------------------------------
! Initialize cloud optics
call cloud_rad_props_init()
call ec_rad_props_init()
call slingo_rad_props_init()
! Initialize output fields for offline driver.
! TODO: do we need to keep this functionality? Where is the offline driver?
! Do we need to write a new offline driver for RRTMGP?
call init_rad_data()
! Do initialization for perturbation growth tests
call perturbation_growth_init()
! Setup the RRTMGP interface
call rrtmgp_initialize(size(active_gases), active_gases, rrtmgp_coefficients_file_sw, rrtmgp_coefficients_file_lw)
! Set number of levels used in radiation calculations
#ifdef NO_EXTRA_RAD_LEVEL
nlev_rad = pver
#else
nlev_rad = pver + 1
#endif
! Indices on radiation grid that correspond to top and bottom of the model
! grid...this is for cases where we want to add an extra layer above the
! model top to deal with radiative heating above the model top.
ktop = nlev_rad - pver + 1
kbot = nlev_rad
! Set the radiation timestep for cosz calculations if requested using the
! adjusted iradsw value from radiation
if (use_rad_dt_cosz) then
dtime = get_step_size()
dt_avg = iradsw*dtime
end if
! Get options for history file outputs
call phys_getopts(history_amwg_out = history_amwg, &
history_vdiag_out = history_vdiag, &
history_budget_out = history_budget, &
history_budget_histfile_num_out = history_budget_histfile_num)
! Determine whether modal aerosols are affecting the climate, and if so
! then initialize the modal aerosol optics module
call rad_cnst_get_info(0, nmodes=nmodes)
if (nmodes > 0) call modal_aer_opt_init()
! TODO: what is this?
call hirsbt_init()
! "irad_always" is number of time steps to execute radiation continuously from start of
! initial OR restart run
nstep = get_nstep()
if (irad_always > 0) then
irad_always = irad_always + nstep
end if
! Initialize the satellite simulator package (COSP).
! TODO: Should this be moved to a higher level?
! This should probably not be specific to a given radiation
! package. Also move most of this to cospsimulator package to handle itself,
! rather than relying on radiation driver handling this logic. Too much
! duplicate code.
!if (docosp) call cospsimulator_intr_init()
if (docosp) then
! Initialization for the simulator package.
call cospsimulator_intr_init
! Allocate and initialize the counter that is used to determine when to
! call the simulator package.
allocate(cosp_cnt(begchunk:endchunk))
if (is_first_restart_step()) then
cosp_cnt(begchunk:endchunk) = cosp_cnt_init
else
cosp_cnt(begchunk:endchunk) = 0
end if
end if
!
! Add fields to history buffer
!
! Register new dimensions
call get_sw_spectral_midpoints(sw_band_midpoints, 'cm-1')
call get_lw_spectral_midpoints(lw_band_midpoints, 'cm-1')
call add_hist_coord('swband', nswbands, 'Shortwave wavenumber', 'cm-1', sw_band_midpoints)
call add_hist_coord('lwband', nlwbands, 'Longwave wavenumber', 'cm-1', lw_band_midpoints)
! Shortwave radiation
call addfld('TOT_CLD_VISTAU', (/ 'lev' /), 'A', '1', &
'Total gridbox cloud visible optical depth', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('TOT_ICLD_VISTAU', (/ 'lev' /), 'A', '1', &
'Total in-cloud visible optical depth', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('LIQ_ICLD_VISTAU', (/ 'lev' /), 'A', '1', &
'Liquid in-cloud visible optical depth', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('ICE_ICLD_VISTAU', (/ 'lev' /), 'A', '1', &
'Ice in-cloud visible optical depth', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call add_default('TOT_CLD_VISTAU', 1, ' ')
call add_default('TOT_ICLD_VISTAU', 1, ' ')
! Band-by-band cloud optical properties
call addfld('CLOUD_TAU_SW', (/'lev ','swband'/), 'I', '1', &
'Cloud shortwave extinction optical depth', sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('CLOUD_SSA_SW', (/'lev ','swband'/), 'I', '1', &
'Cloud shortwave single scattering albedo', sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('CLOUD_G_SW', (/'lev ','swband'/), 'I', '1', &
'Cloud shortwave assymmetry parameter', sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('CLOUD_TAU_LW', (/'lev ','lwband'/), 'I', '1', &
'Cloud longwave absorption optical depth', sampling_seq='rad_lwsw', flag_xyfill=.true.)
! Band-by-band shortwave albedos
call addfld('SW_ALBEDO_DIR', (/'swband'/), 'I', '1', &
'Shortwave direct-beam albedo', &
flag_xyfill=.true., sampling_seq='rad_lwsw')
call addfld('SW_ALBEDO_DIF', (/'swband'/), 'I', '1', &
'Shortwave diffuse-beam albedo', &
flag_xyfill=.true., sampling_seq='rad_lwsw')
! get list of active radiation calls
call rad_cnst_get_call_list(active_calls)
! TODO: what is active_calls and diag?
do icall = 0,N_DIAG
if (active_calls(icall)) then
call addfld('SOLIN'//diag(icall), horiz_only, 'A', 'W/m2', &
'Solar insolation', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('SOLL'//diag(icall), horiz_only, 'A', 'W/m2', &
'Solar downward near infrared direct to surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('SOLS'//diag(icall), horiz_only, 'A', 'W/m2', &
'Solar downward visible direct to surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('SOLLD'//diag(icall), horiz_only, 'A', 'W/m2', &
'Solar downward near infrared diffuse to surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('SOLSD'//diag(icall), horiz_only, 'A', 'W/m2', &
'Solar downward visible diffuse to surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('QRS'//diag(icall), (/ 'lev' /), 'A', 'K/s', &
'Solar heating rate', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('QRSC'//diag(icall), (/ 'lev' /), 'A', 'K/s', &
'Clearsky solar heating rate', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNS'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net solar flux at surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNT'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net solar flux at top of model', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNTOA'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net solar flux at top of atmosphere', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSUTOA'//diag(icall), horiz_only, 'A', 'W/m2', &
'Upwelling solar flux at top of atmosphere', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSUT'//diag(icall), horiz_only, 'A', 'W/m2', &
'Upwelling solar flux at top of model', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSUTC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky upwelling solar flux at top of model', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNTOAC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky net solar flux at top of atmosphere', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSUTOAC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky upwelling solar flux at top of atmosphere', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSN200'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net shortwave flux at 200 mb', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSN200C'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky net shortwave flux at 200 mb', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNTC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky net solar flux at top of model', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNSC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky net solar flux at surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSDSC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky downwelling solar flux at surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSDS'//diag(icall), horiz_only, 'A', 'W/m2', &
'Downwelling solar flux at surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FUS'//diag(icall), (/ 'ilev' /), 'A', 'W/m2', &
'Shortwave upward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FDS'//diag(icall), (/ 'ilev' /), 'A', 'W/m2', &
'Shortwave downward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FDS_DIR'//diag(icall), (/ 'ilev' /), 'A', 'W/m2', &
'Shortwave direct-beam downward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FNS'//diag(icall), (/ 'ilev' /), 'A', 'W/m2', &
'Shortwave net flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FUSC'//diag(icall), (/ 'ilev' /), 'A', 'W/m2', &
'Shortwave clear-sky upward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FDSC'//diag(icall), (/ 'ilev' /), 'A', 'W/m2', &
'Shortwave clear-sky downward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FDSC_DIR'//diag(icall), (/ 'ilev' /), 'A', 'W/m2', &
'Shortwave clear-sky direct-beam downward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FNSC'//diag(icall), (/ 'ilev' /), 'A', 'W/m2', &
'Shortwave clear-sky net flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNIRTOA'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net near-infrared flux (Nimbus-7 WFOV) at top of atmosphere', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNRTOAC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky net near-infrared flux (Nimbus-7 WFOV) at top of atmosphere', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FSNRTOAS'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net near-infrared flux (>= 0.7 microns) at top of atmosphere', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('SWCF'//diag(icall), horiz_only, 'A', 'W/m2', &
'Shortwave cloud forcing', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
if (history_amwg) then
call add_default('SOLIN'//diag(icall), 1, ' ')
call add_default('QRS'//diag(icall), 1, ' ')
call add_default('FSNS'//diag(icall), 1, ' ')
call add_default('FSNT'//diag(icall), 1, ' ')
call add_default('FSNTOA'//diag(icall), 1, ' ')
call add_default('FSUTOA'//diag(icall), 1, ' ')
call add_default('FSNTOAC'//diag(icall), 1, ' ')
call add_default('FSUTOAC'//diag(icall), 1, ' ')
call add_default('FSNTC'//diag(icall), 1, ' ')
call add_default('FSNSC'//diag(icall), 1, ' ')
call add_default('FSDSC'//diag(icall), 1, ' ')
call add_default('FSDS'//diag(icall), 1, ' ')
call add_default('SWCF'//diag(icall), 1, ' ')
end if ! history_amwg
end if ! active_calls(icall)
end do ! icall = 0,N_DIAG
! Cosine of solar zenith angle (primarily for debugging)
call addfld('COSZRS', horiz_only, 'A', 'None', &
'Cosine of solar zenith angle', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
if (single_column .and. scm_crm_mode) then
call add_default ('FUS ', 1, ' ')
call add_default ('FUSC ', 1, ' ')
call add_default ('FDS ', 1, ' ')
call add_default ('FDSC ', 1, ' ')
end if
! Longwave radiation
do icall = 0,N_DIAG
if (active_calls(icall)) then
call addfld('QRL'//diag(icall), (/'lev'/), 'A', 'K/s', &
'Longwave heating rate', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('QRLC'//diag(icall), (/'lev'/), 'A', 'K/s', &
'Clearsky longwave heating rate', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLDS'//diag(icall), horiz_only, 'A', 'W/m2', &
'Downwelling longwave flux at surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLDSC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky Downwelling longwave flux at surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLNS'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net longwave flux at surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLNT'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net longwave flux at top of model', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLUT'//diag(icall), horiz_only, 'A', 'W/m2', &
'Upwelling longwave flux at top of model', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLUTC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky upwelling longwave flux at top of model', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLNTC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky net longwave flux at top of model', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('LWCF'//diag(icall), horiz_only, 'A', 'W/m2', &
'Longwave cloud forcing', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLN200'//diag(icall), horiz_only, 'A', 'W/m2', &
'Net longwave flux at 200 mb', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLN200C'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky net longwave flux at 200 mb', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FLNSC'//diag(icall), horiz_only, 'A', 'W/m2', &
'Clearsky net longwave flux at surface', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FUL'//diag(icall), (/'ilev'/), 'A', 'W/m2', &
'Longwave upward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FDL'//diag(icall), (/'ilev'/), 'A', 'W/m2', &
'Longwave downward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FNL'//diag(icall), (/'ilev'/), 'A', 'W/m2', &
'Longwave net flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FULC'//diag(icall), (/'ilev'/), 'A', 'W/m2', &
'Longwave clear-sky upward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FDLC'//diag(icall), (/'ilev'/), 'A', 'W/m2', &
'Longwave clear-sky downward flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('FNLC'//diag(icall), (/'ilev'/), 'A', 'W/m2', &
'Longwave clear-sky net flux', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call add_default('QRL'//diag(icall), 1, ' ')
if (history_amwg) then
call add_default('QRL'//diag(icall), 1, ' ')
call add_default('FLNS'//diag(icall), 1, ' ')
call add_default('FLDS'//diag(icall), 1, ' ')
call add_default('FLNT'//diag(icall), 1, ' ')
call add_default('FLUT'//diag(icall), 1, ' ')
call add_default('FLUTC'//diag(icall), 1, ' ')
call add_default('FLNTC'//diag(icall), 1, ' ')
call add_default('FLNSC'//diag(icall), 1, ' ')
call add_default('LWCF'//diag(icall), 1, ' ')
endif ! history_amwg
end if
end do
! Add cloud-scale radiative quantities
call phys_getopts(use_MMF_out=use_MMF)
if (use_MMF) then
call addfld('CRM_QRAD', dims_crm_rad, 'A', 'K/s', &
'Radiative heating tendency', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('CRM_QRS ', dims_crm_rad, 'I', 'K/s', &
'CRM Shortwave radiative heating rate', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('CRM_QRSC', dims_crm_rad, 'I', 'K/s', &
'CRM clear-sky shortwave radiative heating rate', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('CRM_QRL ', dims_crm_rad, 'I', 'K/s', &
'CRM Longwave radiative heating rate', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('CRM_QRLC', dims_crm_rad, 'I', 'K/s', &
'CRM clear-sky longwave radiative heating rate', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld('CRM_CLD_RAD', dims_crm_rad, 'I', 'fraction', &
'CRM cloud fraction', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
end if
call addfld('EMIS', (/ 'lev' /), 'A', '1', 'Cloud longwave emissivity')
! Add default fields for single column mode
if (single_column.and.scm_crm_mode) then
call add_default ('FUL ', 1, ' ')
call add_default ('FULC ', 1, ' ')
call add_default ('FDL ', 1, ' ')
call add_default ('FDLC ', 1, ' ')
endif
! HIRS/MSU diagnostic brightness temperatures
if (dohirs) then
call addfld(hirsname(1),horiz_only,'A','K','HIRS CH2 infra-red brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(hirsname(2),horiz_only,'A','K','HIRS CH4 infra-red brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(hirsname(3),horiz_only,'A','K','HIRS CH6 infra-red brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(hirsname(4),horiz_only,'A','K','HIRS CH8 infra-red brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(hirsname(5),horiz_only,'A','K','HIRS CH10 infra-red brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(hirsname(6),horiz_only,'A','K','HIRS CH11 infra-red brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(hirsname(7),horiz_only,'A','K','HIRS CH12 infra-red brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(msuname(1),horiz_only,'A','K','MSU CH1 microwave brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(msuname(2),horiz_only,'A','K','MSU CH2 microwave brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(msuname(3),horiz_only,'A','K','MSU CH3 microwave brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
call addfld(msuname(4),horiz_only,'A','K','MSU CH4 microwave brightness temperature', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
! Add HIRS/MSU fields to default history files
call add_default (hirsname(1), 1, ' ')
call add_default (hirsname(2), 1, ' ')
call add_default (hirsname(3), 1, ' ')
call add_default (hirsname(4), 1, ' ')
call add_default (hirsname(5), 1, ' ')
call add_default (hirsname(6), 1, ' ')
call add_default (hirsname(7), 1, ' ')
call add_default (msuname(1), 1, ' ')
call add_default (msuname(2), 1, ' ')
call add_default (msuname(3), 1, ' ')
call add_default (msuname(4), 1, ' ')
end if
! Heating rate needed for d(theta)/dt computation
! TODO: why include this here? Can't this be calculated from QRS and QRL,
! which are already output?
call addfld('HR',(/ 'lev' /), 'A','K/s', &
'Heating rate needed for d(theta)/dt computation', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
if (history_budget .and. history_budget_histfile_num > 1) then
call add_default ('QRL ', history_budget_histfile_num, ' ')
call add_default ('QRS ', history_budget_histfile_num, ' ')
end if
if (history_vdiag) then
call add_default('FLUT', 2, ' ')
call add_default('FLUT', 3, ' ')
end if
cldfsnow_idx = 0
cldfsnow_idx = pbuf_get_index('CLDFSNOW',errcode=err)
if (cldfsnow_idx > 0) then
call addfld('CLDFSNOW',(/ 'lev' /),'I','1','CLDFSNOW',flag_xyfill=.true.)
call addfld('SNOW_ICLD_VISTAU', (/ 'lev' /), 'A', '1', &
'Snow in-cloud extinction visible sw optical depth', &
sampling_seq='rad_lwsw', flag_xyfill=.true.)
endif
#ifdef MMF_ML_TRAINING
ml_solin_idx = pbuf_get_index('SOLIN', errcode=err)
ml_coszrs_idx = pbuf_get_index('COSZRS',errcode=err)
#endif
end subroutine radiation_init
subroutine radiation_final()
call rrtmgp_finalize()
end subroutine radiation_final
subroutine perturbation_growth_init()
use cam_logfile, only: iulog
character(len=32) :: subname = 'perturbation_growth_init'
! Wrap modes in an ifdef for now since this is not implemented here, and I
! have some work to do to figure out what the heck this is meant to do.
#ifdef DO_PERGRO_MODS
!Modification needed by pergro_mods for generating random numbers
if (pergro_mods) then
max_chnks_in_blk = maxval(npchunks(:)) !maximum of the number for chunks in each procs
allocate(clm_rand_seed(pcols,kiss_seed_num,max_chnks_in_blk), stat=astat)
if (astat /= 0) then
write(iulog,*) 'radiation.F90(rrtmg)-radiation_init: failed to allocate clm_rand_seed; error = ',astat
call endrun
end if
allocate(tot_chnk_till_this_prc(0:npes-1), stat=astat)
if (astat /= 0) then
write(errstr,*) 'radiation.F90(rrtmg)-radiation_init: failed to allocate tot_chnk_till_this_prc variable; error = ',astat
call endrun(errstr)
end if
!BSINGH - Build lat lon relationship to chunk and column
!Compute maximum number of chunks each processor have
if (masterproc) then
tot_chnk_till_this_prc(0:npes-1) = huge(1)
do ipes = 0, npes - 1
tot_chnk_till_this_prc(ipes) = 0
do ipes_tmp = 0, ipes-1
tot_chnk_till_this_prc(ipes) = tot_chnk_till_this_prc(ipes) + npchunks(ipes_tmp)
enddo
enddo
endif
#ifdef SPMD
!BSINGH - Ideally we should use mpi_scatter but we are using this variable
!in "if(masterproc)" below in phys_run1, so broadcast is iused here
call mpibcast(tot_chnk_till_this_prc,npes, mpi_integer, 0, mpicom)
#endif
call get_block_bounds_d(firstblock,lastblock)
allocate(clm_id(pcols,max_chnks_in_blk), stat=astat)
if( astat /= 0 ) then
write(errstr,*) 'radiation.F90(rrtmg)-radiation_init: failed to allocate clm_id; error = ',astat
call endrun(errstr)
end if
allocate(clm_id_mstr(pcols,max_chnks_in_blk,npes), stat=astat)
if( astat /= 0 ) then
write(errstr,*) 'radiation.F90(rrtmg)-radiation_init: failed to allocate clm_id_mstr; error = ',astat
call endrun(errstr)
end if
!compute all clm ids on masterproc and then scatter it ....
if(masterproc) then
do igcol = 1, ngcols_p
imap = latlon_to_dyn_gcol_map(igcol)
chunkid = knuhcs(imap)%chunkid
icol = knuhcs(imap)%col
iown = chunks(chunkid)%owner
ilchnk = (chunks(chunkid)%lcid - lastblock) - tot_chnk_till_this_prc(iown)
clm_id_mstr(icol,ilchnk,iown+1) = igcol
enddo
endif
#ifdef SPMD
!Scatter
tot_cols = pcols*max_chnks_in_blk
call MPI_Scatter( clm_id_mstr, tot_cols, mpi_integer, &
clm_id, tot_cols, mpi_integer, 0, &
MPI_COMM_WORLD,ierr)
#else