-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspcam_drivers.F90
2653 lines (2236 loc) · 116 KB
/
spcam_drivers.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
#define CBRAIN
module spcam_drivers
use camsrfexch, only: cam_out_t, cam_in_t
use ppgrid, only: pcols, pver
use camsrfexch , only: cam_export
use shr_kind_mod, only: r8 => shr_kind_r8
#ifdef CRM
use crmdims, only: crm_nx, crm_ny, crm_nz
#endif
use radiation, only: rad_out_t
use physics_buffer, only: physics_buffer_desc, pbuf_get_field, pbuf_get_index
use physics_types, only: physics_state, physics_state_copy, physics_ptend
use pkg_cldoptics, only: cldems, cldovrlap, cldefr
use phys_grid, only: get_rlat_all_p, get_rlon_all_p
use cam_history, only: outfld
use cam_history_support, only : fillvalue
#ifdef CBRAIN
use time_manager, only: is_first_step, is_first_restart_step, get_step_size
#endif
implicit none
save
private
type rad_avgdata_type_sam1mom
real(r8), allocatable :: solin_m(:) ! Solar incident flux
real(r8), allocatable :: fsntoa_m(:) ! Net solar flux at TOA
real(r8), allocatable :: fsutoa_m(:) ! upwelling solar flux at TOA
real(r8), allocatable :: fsntoac_m(:) ! Clear sky net solar flux at TOA
real(r8), allocatable :: fsnirt_m(:) ! Near-IR flux absorbed at toa
real(r8), allocatable :: fsnrtc_m(:) ! Clear sky near-IR flux absorbed at toa
real(r8), allocatable :: fsnirtsq_m(:) ! Near-IR flux absorbed at toa >= 0.7 microns
real(r8), allocatable :: fsntc_m(:) ! Clear sky total column abs solar flux
real(r8), allocatable :: fsnsc_m(:) ! Clear sky surface abs solar flux
real(r8), allocatable :: fsdsc_m(:) ! Clear sky surface downwelling solar flux
real(r8), allocatable :: flut_m(:) ! Upward flux at top of model
real(r8), allocatable :: flutc_m(:) ! Upward Clear Sky flux at top of model
real(r8), allocatable :: flntc_m(:) ! Clear sky lw flux at model top
real(r8), allocatable :: flnsc_m(:) ! Clear sky lw flux at srf (up-down)
real(r8), allocatable :: fldsc_m(:) ! Clear sky lw flux at srf (down)
real(r8), allocatable :: flwds_m(:) ! Down longwave flux at surface
real(r8), allocatable :: fsns_m(:) ! Surface solar absorbed flux
real(r8), allocatable :: fsnr_m(:)
real(r8), allocatable :: fsnt_m(:) ! Net column abs solar flux at model top
real(r8), allocatable :: flns_m(:) ! Srf longwave cooling (up-down) flux
real(r8), allocatable :: flnt_m(:) ! Net outgoing lw flux at model top
real(r8), allocatable :: flnr_m(:)
real(r8), allocatable :: fsds_m(:) ! Surface solar down flux
real(r8), allocatable :: fln200_m(:) ! net longwave flux interpolated to 200 mb
real(r8), allocatable :: fln200c_m(:) ! net clearsky longwave flux interpolated to 200 mb
real(r8), allocatable :: fsn200_m(:) ! fns interpolated to 200 mb
real(r8), allocatable :: fsn200c_m(:) ! fcns interpolated to 200 mb
real(r8), allocatable :: sols_m(:) ! Solar downward visible direct to surface
real(r8), allocatable :: soll_m(:) ! Solar downward near infrared direct to surface
real(r8), allocatable :: solsd_m(:) ! Solar downward visible diffuse to surface
real(r8), allocatable :: solld_m(:) ! Solar downward near infrared diffuse to surface
real(r8), allocatable :: qrs_m(:,:)
real(r8), allocatable :: qrl_m(:,:)
real(r8), allocatable :: qrsc_m(:,:)
real(r8), allocatable :: qrlc_m(:,:)
real(r8), allocatable :: rel_crm(:,:,:,:)
real(r8), allocatable :: rei_crm(:,:,:,:)
real(r8), allocatable :: qrl_crm(:,:,:,:)
real(r8), allocatable :: qrs_crm(:,:,:,:)
real(r8), allocatable :: fsdtoa_m(:) ! Solar input = Flux Solar Downward Top of Atmosphere
real(r8), allocatable :: flds_m(:) ! Down longwave flux at surface
real(r8), pointer :: t_rad (:,:,:,:) ! rad temperuture
real(r8), pointer :: qv_rad(:,:,:,:) ! rad vapor
real(r8), pointer :: qc_rad(:,:,:,:) ! rad cloud water
real(r8), pointer :: qi_rad(:,:,:,:) ! rad cloud ice
real(r8), pointer :: crm_qrad(:,:,:,:) ! rad heating
real(r8), allocatable :: tot_cld_vistau_m(:,:) ! gbx water+ice cloud optical depth (only during day, night = fillvalue)
real(r8), allocatable :: tot_icld_vistau_m(:,:) ! in-cld water+ice cloud optical depth (only during day, night = fillvalue)
real(r8), allocatable :: liq_icld_vistau_m(:,:) ! in-cld liq cloud optical depth (only during day, night = fillvalue)
real(r8), allocatable :: ice_icld_vistau_m(:,:) ! in-cld ice cloud optical depth (only during day, night = fillvalue)
real(r8), allocatable :: nct_tot_icld_vistau_m(:,:) ! the number of CRM columns that has in-cloud visible sw optical depth
real(r8), allocatable :: nct_liq_icld_vistau_m(:,:) ! the number of CRM column that has liq in-cloud visible sw optical depth
real(r8), allocatable :: nct_ice_icld_vistau_m(:,:) ! the number of CRM column that has ice in-cloud visible sw optical depth
! Just used in m2005 -- needed for compilation only
real(r8), allocatable :: snow_icld_vistau_m(:,:) ! snow in-cloud visible sw optical depth for output on history files
real(r8), allocatable :: nct_snow_icld_vistau_m(:,:) ! the number of CRM column that has snow in-cloud visible sw optical depth
real(r8), allocatable :: crm_aodvisz(:,:,:,:) ! layer aerosol optical depth at 550nm at CRM grids
real(r8), allocatable :: crm_aodvis(:,:,:) ! AOD at 550nm at CRM grids
real(r8), allocatable :: crm_aod400(:,:,:) ! AOD at 400nm at CRM grids
real(r8), allocatable :: crm_aod700(:,:,:) ! AOD at 700nm at CRM grids
real(r8), allocatable :: aod400(:) ! AOD at 400nm at CRM grids
real(r8), allocatable :: aod700(:) ! AOD at 700nm at CRM grids
real(r8), allocatable :: cld_tau_crm(:,:,:,:)
real(r8), allocatable :: crm_fsnt(:,:,:) ! net shortwave fluxes at TOA at CRM grids
real(r8), allocatable :: crm_fsntc(:,:,:) ! net clear-sky shortwave fluxes at TOA at CRM grids
real(r8), allocatable :: crm_fsns(:,:,:) ! net shortwave fluxes at surface at CRM grids
real(r8), allocatable :: crm_fsnsc(:,:,:) ! net clear-sky shortwave fluxes at surface at CRM grids
real(r8), allocatable :: crm_flnt(:,:,:) ! net longwave fluxes at TOA at CRM grids
real(r8), allocatable :: crm_flntc(:,:,:) ! net clear-sky longwave fluxes at TOA at CRM grids
real(r8), allocatable :: crm_flns(:,:,:) ! net longwave fluxes at surface at CRM grids
real(r8), allocatable :: crm_flnsc(:,:,:) ! net clear-sky longwave fluxes at surface at CRM grids
real(r8), allocatable :: crm_swcf(:,:,:) ! shortwave cloud forcing at CRM grids
end type rad_avgdata_type_sam1mom
type rad_avgdata_type_m2005
real(r8),allocatable :: solin_m(:) ! Solar incident flux
real(r8),allocatable :: fsntoa_m(:) ! Net solar flux at TOA
real(r8),allocatable :: fsutoa_m(:) ! upwelling solar flux at TOA
real(r8),allocatable :: fsntoac_m(:) ! Clear sky net solar flux at TOA
real(r8),allocatable :: fsnirt_m(:) ! Near-IR flux absorbed at toa
real(r8),allocatable :: fsnrtc_m(:) ! Clear sky near-IR flux absorbed at toa
real(r8),allocatable :: fsnirtsq_m(:) ! Near-IR flux absorbed at toa >= 0.7 microns
real(r8),allocatable :: fsntc_m(:) ! Clear sky total column abs solar flux
real(r8),allocatable :: fsnsc_m(:) ! Clear sky surface abs solar flux
real(r8),allocatable :: fsdsc_m(:) ! Clear sky surface downwelling solar flux
real(r8),allocatable :: flut_m(:) ! Upward flux at top of model
real(r8),allocatable :: flutc_m(:) ! Upward Clear Sky flux at top of model
real(r8),allocatable :: flntc_m(:) ! Clear sky lw flux at model top
real(r8),allocatable :: flnsc_m(:) ! Clear sky lw flux at srf (up-down)
real(r8),allocatable :: fldsc_m(:) ! Clear sky lw flux at srf (down)
real(r8),allocatable :: flwds_m(:) ! Down longwave flux at surface
real(r8),allocatable :: fsns_m(:) ! Surface solar absorbed flux
real(r8),allocatable :: fsnr_m(:)
real(r8),allocatable :: fsnt_m(:) ! Net column abs solar flux at model top
real(r8),allocatable :: flns_m(:) ! Srf longwave cooling (up-down) flux
real(r8),allocatable :: flnt_m(:) ! Net outgoing lw flux at model top
real(r8),allocatable :: flnr_m(:)
real(r8),allocatable :: fsds_m(:) ! Surface solar down flux
real(r8),allocatable :: fln200_m(:) ! net longwave flux interpolated to 200 mb
real(r8),allocatable :: fln200c_m(:) ! net clearsky longwave flux interpolated to 200 mb
real(r8),allocatable :: fsn200_m(:) ! fns interpolated to 200 mb
real(r8),allocatable :: fsn200c_m(:) ! fcns interpolated to 200 mb
real(r8),allocatable :: sols_m(:) ! Solar downward visible direct to surface
real(r8),allocatable :: soll_m(:) ! Solar downward near infrared direct to surface
real(r8),allocatable :: solsd_m(:) ! Solar downward visible diffuse to surface
real(r8),allocatable :: solld_m(:) ! Solar downward near infrared diffuse to surface
real(r8),allocatable :: qrs_m(:,:)
real(r8),allocatable :: qrl_m(:,:)
real(r8),allocatable :: qrsc_m(:,:)
real(r8),allocatable :: qrlc_m(:,:)
real(r8),allocatable :: su_m(:,:,:) ! shortwave spectral flux up
real(r8),allocatable :: sd_m(:,:,:) ! shortwave spectral flux down
real(r8),allocatable :: lu_m(:,:,:) ! longwave spectral flux up
real(r8),allocatable :: ld_m(:,:,:) ! longwave spectral flux down
real(r8),pointer :: su(:,:,:) ! shortwave spectral flux up
real(r8),pointer :: sd(:,:,:) ! shortwave spectral flux down
real(r8),pointer :: lu(:,:,:) ! longwave spectral flux up
real(r8),pointer :: ld(:,:,:) ! longwave spectral flux down
real(r8), allocatable :: dei_crm(:,:,:,:) ! cloud scale ice effective diameter for optics
real(r8), allocatable :: mu_crm(:,:,:,:) ! cloud scale gamma parameter for optics
real(r8), allocatable :: lambdac_crm(:,:,:,:) ! cloud scale slope of droplet distribution for optics
real(r8), allocatable :: des_crm(:,:,:,:) ! cloud scale snow crystal diameter (micro-meter)
real(r8), allocatable :: rel_crm(:,:,:,:)
real(r8), allocatable :: rei_crm(:,:,:,:)
real(r8), allocatable :: cld_tau_crm(:,:,:,:)
real(r8), allocatable :: qrl_crm(:,:,:,:)
real(r8), allocatable :: qrs_crm(:,:,:,:)
real(r8), allocatable :: crm_fsnt(:,:,:) ! net shortwave fluxes at TOA at CRM grids
real(r8), allocatable :: crm_fsntc(:,:,:) ! net clear-sky shortwave fluxes at TOA at CRM grids
real(r8), allocatable :: crm_fsns(:,:,:) ! net shortwave fluxes at surface at CRM grids
real(r8), allocatable :: crm_fsnsc(:,:,:) ! net clear-sky shortwave fluxes at surface at CRM grids
real(r8), allocatable :: crm_flnt(:,:,:) ! net longwave fluxes at TOA at CRM grids
real(r8), allocatable :: crm_flntc(:,:,:) ! net clear-sky longwave fluxes at TOA at CRM grids
real(r8), allocatable :: crm_flns(:,:,:) ! net longwave fluxes at surface at CRM grids
real(r8), allocatable :: crm_flnsc(:,:,:) ! net clear-sky longwave fluxes at surface at CRM grids
real(r8), allocatable :: crm_swcf(:,:,:) ! shortwave cloud forcing at CRM grids
real(r8), allocatable :: crm_aodvisz(:,:,:,:) ! layer aerosol optical depth at 550nm at CRM grids
real(r8), allocatable :: crm_aodvis(:,:,:) ! AOD at 550nm at CRM grids
real(r8), allocatable :: crm_aod400(:,:,:) ! AOD at 400nm at CRM grids
real(r8), allocatable :: crm_aod700(:,:,:) ! AOD at 700nm at CRM grids
real(r8), allocatable :: aod400(:) ! AOD at 400nm at CRM grids
real(r8), allocatable :: aod700(:) ! AOD at 700nm at CRM grids
real(r8), pointer :: t_rad (:,:,:) ! rad temperuture
real(r8), pointer :: qv_rad(:,:,:) ! rad vapor
real(r8), pointer :: qc_rad(:,:,:) ! rad cloud water
real(r8), pointer :: qi_rad(:,:,:) ! rad cloud ice
real(r8), pointer :: crm_qrad(:,:,:) ! rad heating
real(r8), allocatable :: tot_cld_vistau_m(:,:) ! gbx water+ice cloud optical depth (only during day, night = fillvalue)
real(r8), allocatable :: tot_icld_vistau_m(:,:) ! in-cld water+ice cloud optical depth (only during day, night = fillvalue)
real(r8), allocatable :: liq_icld_vistau_m(:,:) ! in-cld liq cloud optical depth (only during day, night = fillvalue)
real(r8), allocatable :: ice_icld_vistau_m(:,:) ! in-cld ice cloud optical depth (only during day, night = fillvalue)
real(r8), allocatable :: nct_tot_icld_vistau_m(:,:) ! the number of CRM columns that has in-cloud visible sw optical depth
real(r8), allocatable :: nct_liq_icld_vistau_m(:,:) ! the number of CRM column that has liq in-cloud visible sw optical depth
real(r8), allocatable :: nct_ice_icld_vistau_m(:,:) ! the number of CRM column that has ice in-cloud visible sw optical depth
! These do not need N_DIAG dimension
real(r8),allocatable :: snow_tau(:,:,:) ! snow extinction optical depth
real(r8),allocatable :: snow_lw_abs (:,:,:) ! snow absorption optics depth (LW)
! Just used in m2005
real(r8),allocatable :: snow_icld_vistau_m(:,:) ! snow in-cloud visible sw optical depth for output on history files
real(r8),allocatable :: nct_snow_icld_vistau_m(:,:) ! the number of CRM column that has snow in-cloud visible sw optical depth
end type rad_avgdata_type_m2005
public :: tphysbc_spcam, spcam_register, spcam_init
integer :: dei_idx = -1
integer :: mu_idx = -1
integer :: lambdac_idx = -1
integer :: des_idx = -1
integer :: dgnumwet_crm_idx = -1
integer :: qaerwat_crm_idx = -1
integer :: rel_idx = -1
integer :: rei_idx = -1
integer :: landm_idx = -1
integer :: iciwp_idx = -1
integer :: iclwp_idx = -1
integer :: icswp_idx = -1
integer :: cld_idx = -1
integer :: dgnumwet_idx = -1
integer :: qaerwat_idx = -1
integer :: crm_t_rad_idx = -1
integer :: crm_qc_rad_idx = -1
integer :: crm_qi_rad_idx = -1
integer :: crm_qv_rad_idx = -1
integer :: crm_qrad_idx = -1
integer :: crm_cld_rad_idx = -1
integer :: crm_nc_rad_idx = -1
integer :: crm_ni_rad_idx = -1
integer :: crm_qs_rad_idx = -1
integer :: crm_ns_rad_idx = -1
integer :: cicewp_idx = -1
integer :: cliqwp_idx = -1
integer :: cldemis_idx = -1
integer :: cldtau_idx = -1
integer :: pmxrgn_idx = -1
integer :: nmxrgn_idx = -1
integer :: qrs_idx = -1
integer :: qrl_idx = -1
integer :: fsns_idx = -1
integer :: fsnt_idx = -1
integer :: flns_idx = -1
integer :: flnt_idx = -1
integer :: fsds_idx = -1
integer :: cldfsnow_idx = -1
! Minghuai - todo -- CAC note
! These values will be "averaged" as appropriate and stored back in the pbuf
! They should no longer be "saved" -- Probably will want to put in rad_avgdata structure
! Email from Minghaui - 10/10/14 said to put on todo list as he did not have
! time to address it now
! real(r8),allocatable :: cicewp(:,:)
! real(r8),allocatable :: cliqwp(:,:)
! real(r8),allocatable :: rel(:,:)
! real(r8),allocatable :: rei(:,:)
! real(r8),allocatable :: dei(:,:)
! real(r8),allocatable :: mu(:,:)
! real(r8),allocatable :: lambdac(:,:)
! real(r8),allocatable :: des(:,:)
! real(r8),allocatable :: cld(:,:) ! cloud fraction
! real(r8),allocatable :: cldfsnow(:,:) ! cloud fraction of just "snow clouds- whatever they are"
! real(r8),allocatable :: csnowp(:,:)
! real(r8),allocatable :: dgnumwet(:,:,:) ! number mode diameter
! real(r8),allocatable :: qaerwat(:,:,:) ! aerosol water
integer :: nmodes
logical :: is_spcam_m2005, is_spcam_sam1mom
logical :: prog_modal_aero
#ifdef CBRAIN
integer :: nstep0
#endif
contains
subroutine tphysbc_spcam (ztodt, state, &
tend, pbuf, &
cam_out, cam_in )
!-----------------------------------------------------------------------
!
! Purpose:
! Evaluate and apply physical processes that are calculated BEFORE
! coupling to land, sea, and ice models.
!
! Processes currently included are:
!
! o Resetting Negative Tracers to Positive
! o Global Mean Total Energy Fixer
! o Dry Adjustment
! o Asymmetric Turbulence Scheme : Deep Convection & Shallow Convection
! o Stratiform Macro-Microphysics
! o Wet Scavenging of Aerosol
! o Radiation
!
! Method:
!
! Each parameterization should be implemented with this sequence of calls:
! 1) Call physics interface
! 2) Check energy
! 3) Call physics_update
! See Interface to Column Physics and Chemistry Packages
! http://www.ccsm.ucar.edu/models/atm-cam/docs/phys-interface/index.html
!
!-----------------------------------------------------------------------
use physics_buffer, only : pbuf_old_tim_idx, dyn_time_lvls
use physics_types, only: physics_state, physics_tend, physics_ptend, physics_update, &
physics_state_check
use dadadj_cam, only: dadadj_tend
use cam_diagnostics, only: diag_state_b4_coupling,diag_conv_tend_ini, diag_phys_writeout, diag_conv, diag_export,&
diag_state_b4_phys_write, diag_braindebug
use cam_history, only: outfld
use constituents, only: pcnst, qmin, cnst_get_ind
use time_manager, only: get_nstep
use check_energy, only: check_energy_chng, check_energy_fix
use check_energy, only: check_tracers_data, check_tracers_init
use dycore, only: dycore_is
use radiation, only: radiation_tend
use cloud_diagnostics, only: cloud_diagnostics_calc
use perf_mod
use tropopause, only: tropopause_output
use cam_abortutils, only: endrun
#ifdef CRM
use crm_physics, only: crm_physics_tend
use spmd_utils, only: masterproc
#ifdef CBRAIN
use cloudbrain, only : neural_net, init_neural_net, &
cb_partial_coupling, cb_partial_coupling_vars
use physconst, only: cpair, zvir, gravit, cpairv, rairv
use cam_logfile, only: iulog
#endif
#endif
#ifdef CBRAINDIAG
use geopotential, only: geopotential_t
use cam_history_support, only: pflds
#endif
use phys_control, only: phys_getopts
use sslt_rebin, only: sslt_rebin_adv
use qneg_module, only: qneg3
implicit none
!
! Arguments
!
real(r8), intent(in) :: ztodt ! 2 delta t (model time increment)
type(physics_state), intent(inout) :: state
type(physics_tend ), intent(inout) :: tend
type(physics_buffer_desc), pointer :: pbuf(:)
type(cam_out_t), intent(inout) :: cam_out
type(cam_in_t), intent(in) :: cam_in
#ifdef CRM
#ifdef CBRAIN
type(physics_state) :: state_save
type(physics_tend ) :: tend_save
real (r8) :: nn_solin(pcols)
real (r8) :: ftem3 (pcols,pver)
#endif
#ifdef CBRAINDIAG
type(physics_state) :: state_save_sp, state_save_nn
type(physics_tend ) :: tend_save_sp, tend_save_nn
type(cam_out_t) :: cam_out_save_sp, cam_out_save_nn
logical :: do_geopotential = .false.
real(r8) :: zvirv(state%psetcols,pver) ! Local zvir array pointer
#endif
!
!---------------------------Local workspace-----------------------------
!
type(physics_ptend) :: ptend ! indivdual parameterization tendencies
type(physics_state) :: state_loc
integer :: nstep ! current timestep number
real(r8) :: net_flx(pcols)
real(r8) cldn(pcols,pver)
integer lchnk ! chunk identifier
integer ncol ! number of atmospheric columns
integer i ! index
integer :: ixcldice, ixcldliq ! constituent indices for cloud liquid and ice water.
! physics buffer fields to compute tendencies for stratiform package
integer itim_old, ifld
real(r8), pointer, dimension(:,:) :: cld ! cloud fraction
! physics buffer fields for total energy and mass adjustment
real(r8), pointer, dimension(: ) :: teout
real(r8), pointer, dimension(:,:) :: qini
real(r8), pointer, dimension(:,:) :: cldliqini
real(r8), pointer, dimension(:,:) :: cldiceini
real(r8), pointer, dimension(:,:) :: dtcore
real(r8), pointer, dimension(:,:,:) :: fracis ! fraction of transported species that are insoluble
! energy checking variables
real(r8) :: zero(pcols) ! array of zeros
real(r8) :: flx_heat(pcols)
type(check_tracers_data):: tracerint ! energy integrals and cummulative boundary fluxes
logical :: state_debug_checks ! Debug physics_state.
type(rad_avgdata_type_sam1mom) :: rad_avgdata_sam1mom
type(rad_avgdata_type_m2005) :: rad_avgdata_m2005
type(rad_out_t) :: rd
integer :: teout_idx, qini_idx, cldliqini_idx, cldiceini_idx
integer :: ii, jj, k
integer :: nstep_NN
!-----------------------------------------------------------------------
call t_startf('bc_init')
zero = 0._r8
lchnk = state%lchnk
ncol = state%ncol
nstep = get_nstep()
teout_idx = pbuf_get_index('TEOUT')
qini_idx = pbuf_get_index('QINI')
cldliqini_idx = pbuf_get_index('CLDLIQINI')
cldiceini_idx = pbuf_get_index('CLDICEINI')
call phys_getopts(state_debug_checks_out=state_debug_checks)
! Associate pointers with physics buffer fields
itim_old = pbuf_old_tim_idx()
ifld = pbuf_get_index('CLD')
call pbuf_get_field(pbuf, ifld, cld, (/1,1,itim_old/),(/pcols,pver,1/))
call pbuf_get_field(pbuf, teout_idx, teout, (/1,itim_old/), (/pcols,1/))
call pbuf_get_field(pbuf, qini_idx, qini)
call pbuf_get_field(pbuf, cldliqini_idx, cldliqini)
call pbuf_get_field(pbuf, cldiceini_idx, cldiceini)
ifld = pbuf_get_index('DTCORE')
call pbuf_get_field(pbuf, ifld, dtcore, start=(/1,1,itim_old/), kount=(/pcols,pver,1/) )
ifld = pbuf_get_index('FRACIS')
call pbuf_get_field(pbuf, ifld, fracis, start=(/1,1,1/), kount=(/pcols, pver, pcnst/) )
fracis (:ncol,:,1:pcnst) = 1._r8
! Set physics tendencies to 0
tend %dTdt(:ncol,:pver) = 0._r8
tend %dudt(:ncol,:pver) = 0._r8
tend %dvdt(:ncol,:pver) = 0._r8
call qneg3('TPHYSBCb',lchnk ,ncol ,pcols ,pver , &
1, pcnst, qmin ,state%q )
! Validate state coming from the dynamics.
if (state_debug_checks) &
call physics_state_check(state, name="before tphysbc (dycore?)")
!
! Dump out "before physics" state
!
call diag_state_b4_phys_write (state)
#ifdef CBRAIN
state_save = state
tend_save = tend
#endif
#ifdef CBRAINDIAG
call diag_braindebug(state, cam_out, cam_in, 0) ! 0 for 'before physics'
#endif
! compute mass integrals of input tracers state
call check_tracers_init(state, tracerint)
call t_stopf('bc_init')
!===================================================
! Global mean total energy fixer
!===================================================
call t_startf('energy_fixer')
if (dycore_is('LR') .or. dycore_is('SE')) then
call check_energy_fix(state, ptend, nstep, flx_heat)
call physics_update(state, ptend, ztodt, tend)
call check_energy_chng(state, tend, "chkengyfix", nstep, ztodt, zero, zero, zero, flx_heat)
call outfld('EFIX', flx_heat, pcols,lchnk)
end if
! Save state for convective tendency calculations.
call diag_conv_tend_ini(state, pbuf)
call cnst_get_ind('CLDLIQ', ixcldliq)
call cnst_get_ind('CLDICE', ixcldice)
qini (:ncol,:pver) = state%q(:ncol,:pver, 1)
cldliqini(:ncol,:pver) = state%q(:ncol,:pver,ixcldliq)
cldiceini(:ncol,:pver) = state%q(:ncol,:pver,ixcldice)
call outfld('TEOUT', teout , pcols, lchnk )
call outfld('TEINP', state%te_ini, pcols, lchnk )
call outfld('TEFIX', state%te_cur, pcols, lchnk )
! T tendency due to dynamics
if( nstep > dyn_time_lvls-1 ) then
dtcore(:ncol,:pver) = (state%t(:ncol,:pver) - dtcore(:ncol,:pver))/(ztodt)
call outfld( 'DTCORE', dtcore, pcols, lchnk )
end if
call t_stopf('energy_fixer')
call sslt_rebin_adv(pbuf, state)
!
!===================================================
! Dry adjustment
! This code block is not a good example of interfacing a parameterization
!===================================================
call t_startf('dry_adjustment')
call dadadj_tend (ztodt, state, ptend)
call physics_update(state, ptend, ztodt, tend)
call t_stopf('dry_adjustment')
! -------------------------------------------------------------------------------
! Call cloud resolving model
! -------------------------------------------------------------------------------
call crm_physics_tend(ztodt, state, tend, ptend, pbuf, cam_in)
call physics_update(state, ptend, ztodt, tend)
!===================================================
! Moist physical parameteriztions complete:
! send dynamical variables, and derived variables to history file
!===================================================
call t_startf('bc_history_write')
call diag_phys_writeout(state, pbuf)
call diag_conv(state, ztodt, pbuf)
call t_stopf('bc_history_write')
!===================================================
! Write cloud diagnostics on history file
!===================================================
if (is_spcam_sam1mom) then
call spcam_radiation_setup_sam1mom(cam_in, cldn, state, pbuf, rad_avgdata_sam1mom, state_loc)
else if (is_spcam_m2005) then
call spcam_radiation_setup_m2005(state, pbuf, rad_avgdata_m2005, state_loc)
end if
call t_startf('bc_cld_diag_history_write')
call cloud_diagnostics_calc(state, pbuf)
call t_stopf('bc_cld_diag_history_write')
!===================================================
! Radiation computations
!===================================================
call t_startf('radiation')
if (is_spcam_sam1mom) then
do jj=1,crm_ny
do ii=1,crm_nx
call spcam_radiation_col_setup_sam1mom(ii, jj, state_loc, pbuf, rad_avgdata_sam1mom)
call radiation_tend(state_loc, ptend, pbuf, &
cam_out, cam_in, &
net_flx, rd)
call spcam_radiation_col_finalize_sam1mom(state, ii, jj, pbuf, rd, cam_out, rad_avgdata_sam1mom)
end do
end do
#ifdef CBRAIN
! Warning this is a hacky way to get SOLIN from interior to SP (pritch)
! When it comes time to bypass SP entirely for speedup we need a better way to get it.
call spcam_radiation_finalize_sam1mom(cam_in, state, pbuf, rad_avgdata_sam1mom, cam_out, cldn, net_flx, ptend,nn_solin)
#else
call spcam_radiation_finalize_sam1mom(cam_in, state, pbuf, rad_avgdata_sam1mom, cam_out, cldn, net_flx, ptend)
#endif
else if(is_spcam_m2005) then
do jj=1,crm_ny
do ii=1,crm_nx
call spcam_radiation_col_setup_m2005(ii, jj, ixcldice, ixcldliq, state_loc, pbuf, rad_avgdata_m2005)
call radiation_tend(state_loc, ptend, pbuf, &
cam_out, cam_in, &
net_flx, rd)
call spcam_radiation_col_finalize_m2005(state, ii, jj, pbuf, rd, cam_out, rad_avgdata_m2005)
end do
end do
call spcam_radiation_finalize_m2005(cam_in, state, pbuf, rad_avgdata_m2005, cam_out, net_flx, ptend)
end if
! Set net flux used by spectral dycores
do i=1,ncol
tend%flx_net(i) = net_flx(i)
end do
! don't add radiative tendency to GCM temperature in case of superparameterization
! as it was added above as part of crm tendency.
ptend%s = 0._r8
call physics_update(state, ptend, ztodt, tend)
call check_energy_chng(state, tend, "spradheat", nstep, ztodt, zero, zero, zero, zero)
call t_stopf('radiation')
! sungduk: the following dignostic call need to be moved after the NN call,
! so that the diagnostics are based on NN calculations, not SP.
!
! ! Diagnose the location of the tropopause and its location to the history file(s).
! call t_startf('tropopause')
! call tropopause_output(state)
! call t_stopf('tropopause')
! ! Save atmospheric fields to force surface models
! call t_startf('cam_export')
! call cam_export (state,cam_out,pbuf)
! call t_stopf('cam_export')
#ifdef CBRAINDIAG
! cam_export is called here for diag_braindebug
! so that cam_out%prec* variables are updated before diag_braindebug
call cam_export (state,cam_out,pbuf)
call diag_braindebug(state, cam_out, cam_in, 1) ! 1 for SP
call outfld('SOLIN0', nn_solin, pcols, lchnk)
! save SP calculation
state_save_sp = state
tend_save_sp = tend
cam_out_save_sp = cam_out ! save cam_out so that cam_export won't be called again
#endif
call diag_state_b4_coupling (state) ! pritch & beucler (contains SP tendency impacts).
!
! sungduk: why printing out b4c
! variables here? These rad cnsts are redisributed
! by SP. This potentially introduce
! inconsitency, since CRM is forced by
! qrl+qrs calculated from the previous
! time step.
! (is this just for saving variables for NN
! training?)
#ifdef CBRAIN
! =============================== NEURAL NETWORK SUBSUMES TPHYSBC HERE =========================
! restore state to before physics (in future we can just #ifndef everything between there and here to avoid doing SP)
if (is_first_step() .or. is_first_restart_step()) then
call init_neural_net() ! TODO isolate to first time step.
nstep0 = nstep
endif
nstep_NN = 86400 / get_step_size()
#ifdef CBRAIN_BASELINE
nstep_NN = 864000000 / get_step_size() ! for SP baseline
#endif
if (nstep-nstep0 .ge. nstep_NN) then ! allow coupling after 1 day
if (nstep-nstep0 .eq. nstep_NN) then
write (iulog,*) 'CLOUDBRAIN: NN is coupled at nstep = ', nstep
endif
! Save off control tendencies under standard SP before forgetting them:
ftem3(:ncol,:pver) = state%q(:ncol,:pver,1) - state_save%q(:ncol,:pver,1)
call outfld ('SP_BP2BC_DQ',ftem3,pcols,lchnk)
ftem3(:ncol,:pver) = (state%s(:ncol,:pver) - state_save%s(:ncol,:pver))/cpair
call outfld ('SP_BP2BC_DT',ftem3,pcols,lchnk)
ftem3(:ncol,:pver) = state%q(:ncol,:pver,ixcldliq) - state_save%q(:ncol,:pver,ixcldliq)
call outfld ('SP_BP2BC_DQC',ftem3,pcols,lchnk)
ftem3(:ncol,:pver) = state%q(:ncol,:pver,ixcldice) - state_save%q(:ncol,:pver,ixcldice)
call outfld ('SP_BP2BC_DQI',ftem3,pcols,lchnk)
! SY: calculate solin
! call cloudbrain_solin(state, nn_solin)
! Override what standard SP & explicit physics had done...
state = state_save
tend = tend_save
! ...Replace with the NN answer:
call neural_net (state,nn_solin,cam_in,ztodt,ptend,cam_out,pbuf) ! returns ptend and cam_out
call physics_update (state, ptend, ztodt, tend)
! Self-consistent NN increments for diagnosis vs. SP
ftem3(:ncol,:pver) = state%q(:ncol,:pver,1) - state_save%q(:ncol,:pver,1)
call outfld ('NN_BP2BC_DQ',ftem3,pcols,lchnk)
ftem3(:ncol,:pver) = (state%s(:ncol,:pver) - state_save%s(:ncol,:pver))/cpair
call outfld ('NN_BP2BC_DT',ftem3,pcols,lchnk)
ftem3(:ncol,:pver) = state%q(:ncol,:pver,ixcldliq) - state_save%q(:ncol,:pver,ixcldliq)
call outfld ('NN_BP2BC_DQC',ftem3,pcols,lchnk)
ftem3(:ncol,:pver) = state%q(:ncol,:pver,ixcldice) - state_save%q(:ncol,:pver,ixcldice)
call outfld ('NN_BP2BC_DQI',ftem3,pcols,lchnk)
endif
#endif
! Save atmospheric fields to force surface models
call t_startf('cam_export')
call cam_export (state,cam_out,pbuf)
call t_stopf('cam_export')
#ifdef CBRAINDIAG
call diag_braindebug(state, cam_out, cam_in, 2) ! 2 for NN
! save NN calculation for optional partial NN coupling
state_save_nn = state
tend_save_nn = tend
cam_out_save_nn = cam_out
! restore state, tend, cam_out to SP calculation
state = state_save_sp
tend = tend_save_sp
cam_out = cam_out_save_sp
! Partial coupling
! NN calculations are used for any variables included in 'cb_partial_coupling_vars'
! e.g., ['QBCTEND','TBCTEND','CLDLIQBCTEND','CLDICEBCTEND','PRECSC','PRECC','FLWDS','NETSW','SOLL','SOLLD','SOLS','SOLSD']
if (cb_partial_coupling) then
ii = 1
do while (ii < pflds .and. cb_partial_coupling_vars(ii) /= ' ')
if (trim(cb_partial_coupling_vars(ii)) == 'TBCTEND') then
state%t(:,:) = state_save_nn%t(:,:)
tend%dtdt(:,:) = tend_save_nn%dtdt(:,:)
do_geopotential = .true.
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'QBCTEND') then
state%q(:,:,1) = state_save_nn%q(:,:,1)
do_geopotential = .true.
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'CLDLIQBCTEND') then
state%q(:,:,ixcldliq) = state_save_nn%q(:,:,ixcldliq)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'CLDICEBCTEND') then
state%q(:,:,ixcldice) = state_save_nn%q(:,:,ixcldice)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'PRECSC') then
cam_out%precsc(:) = cam_out_save_nn%precsc(:)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'PRECC') then
cam_out%precc(:) = cam_out_save_nn%precc(:)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'FLWDS') then
cam_out%flwds(:) = cam_out_save_nn%flwds(:)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'NETSW') then
cam_out%netsw(:) = cam_out_save_nn%netsw(:)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'SOLL') then
cam_out%soll(:) = cam_out_save_nn%soll(:)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'SOLLD') then
cam_out%solld(:) = cam_out_save_nn%solld(:)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'SOLS') then
cam_out%sols(:) = cam_out_save_nn%sols(:)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else if (trim(cb_partial_coupling_vars(ii)) == 'SOLSD') then
cam_out%solsd(:) = cam_out_save_nn%solsd(:)
if (nstep-nstep0 .eq. nstep_NN .and. masterproc) then
write (iulog,*) 'CLOUDBRAIN partial coupling: ', trim(cb_partial_coupling_vars(ii))
endif
else
call endrun('[CLOUDBRAIN: cb_partial_coupling] Wrong variables are included in cb_partial_coupling_vars.')
end if
ii = ii+1
end do
if (do_geopotential) then
zvirv(:,:) = zvir
call geopotential_t ( &
state%lnpint, state%lnpmid, state%pint, state%pmid , state%pdel, state%rpdel, &
state%t , state%q(:,:,1), rairv(:,:,lchnk), gravit, zvirv, &
state%zi , state%zm , ncol)
! update dry static energy for use in next process
do k = ptend%top_level, ptend%bot_level
state%s(:ncol,k) = state%t(:ncol,k )*cpairv(:ncol,k,lchnk) &
+ gravit*state%zm(:ncol,k) + state%phis(:ncol)
end do
end if
call diag_braindebug(state, cam_out, cam_in, 3) ! 2 for partial coupling
end if
#endif
! Diagnose the location of the tropopause and its location to the history
! file(s).
call t_startf('tropopause')
call tropopause_output(state)
call t_stopf('tropopause')
! Write export state to history file
call t_startf('diag_export')
call diag_export(cam_out)
call t_stopf('diag_export')
#endif
end subroutine tphysbc_spcam
!===============================================================================
subroutine spcam_register()
use physics_buffer, only: pbuf_add_field, dtype_r8, dyn_time_lvls ! is dyn_time_lvls needed ???
use phys_control, only: cam_physpkg_is
#ifdef CRM
use crm_physics, only: crm_physics_register
use crmx_vars, only: naer, vaer, hgaer
use crmx_grid
#ifdef MODAL_AERO
use modal_aero_data, only: ntot_amode
allocate(naer(nzm, ntot_amode)) ! Aerosol number concentration [/m3]
allocate(vaer(nzm, ntot_amode)) ! aerosol volume concentration [m3/m3]
allocate(hgaer(nzm, ntot_amode)) ! hygroscopicity of aerosol mode
#endif
call crm_physics_register()
#endif
is_spcam_m2005 = cam_physpkg_is('spcam_m2005')
is_spcam_sam1mom = cam_physpkg_is('spcam_sam1mom')
if (is_spcam_m2005) then
call pbuf_add_field('ICSWP', 'physpkg',dtype_r8,(/pcols,pver/), icswp_idx)
call pbuf_add_field('CLDFSNOW', 'physpkg',dtype_r8,(/pcols,pver,dyn_time_lvls/), cldfsnow_idx)
endif
end subroutine spcam_register
!===============================================================================
subroutine spcam_init(pbuf2d)
use physics_buffer, only: pbuf_get_index
use phys_control, only: phys_getopts
#ifdef CRM
use crm_physics, only: crm_physics_init
#endif
use rad_constituents, only: rad_cnst_get_info
type(physics_buffer_desc), pointer :: pbuf2d(:,:)
#ifdef CRM
call phys_getopts(prog_modal_aero_out = prog_modal_aero)
call rad_cnst_get_info(0, nmodes=nmodes)
dei_idx = pbuf_get_index('DEI')
mu_idx = pbuf_get_index('MU')
lambdac_idx = pbuf_get_index('LAMBDAC')
des_idx = pbuf_get_index('DES')
rel_idx = pbuf_get_index('REL')
rei_idx = pbuf_get_index('REI')
landm_idx = pbuf_get_index('LANDM')
cld_idx = pbuf_get_index('CLD')
qrs_idx = pbuf_get_index('QRS')
qrl_idx = pbuf_get_index('QRL')
fsns_idx = pbuf_get_index('FSNS')
fsds_idx = pbuf_get_index('FSDS')
fsnt_idx = pbuf_get_index('FSNT')
flnt_idx = pbuf_get_index('FLNT')
flns_idx = pbuf_get_index('FLNS')
crm_t_rad_idx = pbuf_get_index('CRM_T_RAD')
crm_qc_rad_idx = pbuf_get_index('CRM_QC_RAD')
crm_qi_rad_idx = pbuf_get_index('CRM_QI_RAD')
crm_qv_rad_idx = pbuf_get_index('CRM_QV_RAD')
crm_qrad_idx = pbuf_get_index('CRM_QRAD')
crm_cld_rad_idx = pbuf_get_index('CRM_CLD_RAD')
if (is_spcam_sam1mom) then
cldemis_idx = pbuf_get_index('CLDEMIS')
cldtau_idx = pbuf_get_index('CLDTAU')
cicewp_idx = pbuf_get_index('CICEWP')
cliqwp_idx = pbuf_get_index('CLIQWP')
pmxrgn_idx = pbuf_get_index('PMXRGN')
nmxrgn_idx = pbuf_get_index('NMXRGN')
else if (is_spcam_m2005) then
iciwp_idx = pbuf_get_index('ICIWP')
iclwp_idx = pbuf_get_index('ICLWP')
crm_nc_rad_idx = pbuf_get_index('CRM_NC_RAD')
crm_ni_rad_idx = pbuf_get_index('CRM_NI_RAD')
crm_qs_rad_idx = pbuf_get_index('CRM_QS_RAD')
crm_ns_rad_idx = pbuf_get_index('CRM_NS_RAD')
end if
if (prog_modal_aero) then
dgnumwet_idx = pbuf_get_index('DGNUMWET')
qaerwat_idx = pbuf_get_index('QAERWAT')
dgnumwet_crm_idx = pbuf_get_index('CRM_DGNUMWET')
qaerwat_crm_idx = pbuf_get_index('CRM_QAERWAT')
end if
! Initialize the crm_physics layer
call crm_physics_init(pbuf2d)
#endif
end subroutine spcam_init
!===============================================================================
subroutine spcam_radiation_setup_m2005(state, pbuf, rad_avgdata, state_loc)
use physics_buffer, only: physics_buffer_desc, pbuf_get_field
use physics_buffer, only: pbuf_old_tim_idx
type(physics_state), intent(in) :: state
type(physics_buffer_desc), intent(inout), pointer :: pbuf(:)
type(rad_avgdata_type_m2005), intent(out) :: rad_avgdata
type(physics_state), intent(out) :: state_loc
#ifdef m2005
real(r8), pointer, dimension(:, :) :: cicewp
real(r8), pointer, dimension(:, :) :: cliqwp
real(r8), pointer, dimension(:, :) :: csnowp
real(r8), pointer, dimension(:,:) :: rel ! liquid effective drop radius (microns)
real(r8), pointer, dimension(:,:) :: rei ! ice effective drop size (microns)
real(r8), pointer, dimension(:,:) :: cld ! cloud fraction
real(r8), pointer, dimension(:,:) :: cldfsnow ! cloud fraction of just "snow clouds- whatever they are"
real(r8), pointer, dimension(:, :) :: dei ! ice effective diameter for optics (radiation)
real(r8), pointer, dimension(:, :) :: mu ! gamma parameter for optics (radiation)
real(r8), pointer, dimension(:, :) :: lambdac ! slope of droplet distribution for optics (radiation)
real(r8), pointer, dimension(:, :) :: des ! snow crystatl diameter for optics (mirometer, radiation)
integer :: ncol ! number of atmospheric columns
integer :: itim_old
ncol = state%ncol
call physics_state_copy(state, state_loc)
allocate(rad_avgdata%solin_m (pcols))
allocate(rad_avgdata%fsntoa_m (pcols))
allocate(rad_avgdata%fsutoa_m (pcols))
allocate(rad_avgdata%fsntoac_m (pcols))
allocate(rad_avgdata%fsnirt_m (pcols))
allocate(rad_avgdata%fsnrtc_m (pcols))
allocate(rad_avgdata%fsnirtsq_m (pcols))
allocate(rad_avgdata%fsntc_m (pcols))
allocate(rad_avgdata%fsnsc_m (pcols))
allocate(rad_avgdata%fsdsc_m (pcols))
allocate(rad_avgdata%flut_m (pcols))
allocate(rad_avgdata%flutc_m (pcols))
allocate(rad_avgdata%flntc_m (pcols))
allocate(rad_avgdata%flnsc_m (pcols))
allocate(rad_avgdata%fldsc_m (pcols))
allocate(rad_avgdata%flwds_m (pcols))
allocate(rad_avgdata%fsns_m (pcols))
allocate(rad_avgdata%fsnr_m (pcols))
allocate(rad_avgdata%fsnt_m (pcols))
allocate(rad_avgdata%flns_m (pcols))
allocate(rad_avgdata%flnt_m (pcols))
allocate(rad_avgdata%flnr_m (pcols))
allocate(rad_avgdata%fsds_m (pcols))
allocate(rad_avgdata%fln200_m (pcols))
allocate(rad_avgdata%fln200c_m (pcols))
allocate(rad_avgdata%fsn200_m (pcols))
allocate(rad_avgdata%fsn200c_m (pcols))
allocate(rad_avgdata%sols_m (pcols))
allocate(rad_avgdata%soll_m (pcols))
allocate(rad_avgdata%solsd_m (pcols))
allocate(rad_avgdata%solld_m (pcols))
allocate(rad_avgdata%qrs_m (pcols,pver))
allocate(rad_avgdata%qrl_m (pcols,pver))
allocate(rad_avgdata%qrsc_m (pcols,pver))
allocate(rad_avgdata%qrlc_m (pcols,pver))