Line data Source code
1 : !--------------------------------------------------------------------------------
2 : ! CARMA diagnostics data object
3 : !--------------------------------------------------------------------------------
4 : module carma_diags_mod
5 : use shr_kind_mod, only: r8 => shr_kind_r8
6 : use constituents, only: pcnst
7 : use ppgrid, only: pcols
8 : use carma_intr, only: MAXCLDAERDIAG, carma_calculate_cloudborne_diagnostics, carma_output_budget_diagnostics, &
9 : carma_output_cloudborne_diagnostics
10 : use carma_flags_mod, only: carma_do_package_diags
11 :
12 : use camsrfexch, only: cam_in_t
13 : use physics_types, only: physics_state, physics_ptend
14 : use physics_buffer, only: physics_buffer_desc
15 :
16 : implicit none
17 :
18 : private
19 :
20 : public :: carma_diags_t
21 :
22 : !------------------------------------------------------------------------------
23 : ! CARMA diags object
24 : !------------------------------------------------------------------------------
25 : type :: carma_diags_t
26 : private
27 :
28 : ! CARMA diagnostics
29 : real(r8), allocatable :: aerclddiag(:,:) ! the cloudborne aerosol diags snapshot
30 : real(r8), allocatable :: old_cflux(:,:) ! cam_in%clfux from before the timestep_tend
31 :
32 : contains
33 :
34 : procedure :: update
35 : procedure :: output
36 :
37 : final :: destructor
38 : end type carma_diags_t
39 :
40 : interface carma_diags_t
41 : procedure :: constructor
42 : end interface carma_diags_t
43 :
44 :
45 : contains
46 :
47 : !------------------------------------------------------------------------------
48 : ! object constructor allocates memory
49 : !------------------------------------------------------------------------------
50 153600 : function constructor() result(newobj)
51 :
52 : type(carma_diags_t), pointer :: newobj
53 :
54 : integer :: ierr
55 :
56 153600 : allocate(newobj,stat=ierr)
57 153600 : if( ierr /= 0 ) then
58 153600 : nullify(newobj)
59 : return
60 : end if
61 :
62 153600 : if (.not.carma_do_package_diags) return
63 :
64 0 : allocate(newobj%aerclddiag(pcols,MAXCLDAERDIAG),stat=ierr)
65 0 : if( ierr /= 0 ) then
66 0 : nullify(newobj)
67 0 : return
68 : end if
69 0 : allocate(newobj%old_cflux(pcols,pcnst),stat=ierr)
70 0 : if( ierr /= 0 ) then
71 0 : nullify(newobj)
72 0 : return
73 : end if
74 :
75 : end function constructor
76 :
77 : !------------------------------------------------------------------------------
78 : ! update the arrays
79 : !------------------------------------------------------------------------------
80 687360 : subroutine update(self, cam_in, state, pbuf)
81 : class(carma_diags_t), intent(inout) :: self
82 :
83 : type(cam_in_t), intent(in) :: cam_in
84 : type(physics_state), intent(in) :: state
85 : type(physics_buffer_desc), pointer :: pbuf(:)
86 :
87 687360 : if (.not.carma_do_package_diags) return
88 :
89 0 : self%old_cflux = cam_in%cflx
90 0 : call carma_calculate_cloudborne_diagnostics(state, pbuf, self%aerclddiag)
91 :
92 : end subroutine update
93 :
94 : !------------------------------------------------------------------------------
95 : ! output the carma bugdets to cam history
96 : !------------------------------------------------------------------------------
97 687360 : subroutine output(self, state, ptend, cam_in, label, dt, pbuf)
98 : class(carma_diags_t), intent(in) :: self
99 :
100 : type(physics_state), intent(in) :: state
101 : type(physics_ptend), intent(in) :: ptend
102 : type(cam_in_t), intent(in) :: cam_in
103 : character(len=*), intent(in) :: label
104 : real(r8), intent(in) :: dt
105 : type(physics_buffer_desc), pointer :: pbuf(:)
106 :
107 687360 : if (.not.carma_do_package_diags) return
108 :
109 0 : call carma_output_budget_diagnostics(state, ptend, self%old_cflux, cam_in%cflx, dt, label)
110 0 : call carma_output_cloudborne_diagnostics(state, pbuf, label, dt, self%aerclddiag)
111 :
112 : end subroutine output
113 :
114 : !------------------------------------------------------------------------------
115 : ! free up memory
116 : !------------------------------------------------------------------------------
117 153600 : subroutine destructor(self)
118 : type(carma_diags_t), intent(inout) :: self
119 :
120 153600 : if (allocated(self%aerclddiag)) then
121 0 : deallocate(self%aerclddiag)
122 : end if
123 153600 : if (allocated(self%old_cflux)) then
124 0 : deallocate(self%old_cflux)
125 : end if
126 :
127 153600 : end subroutine destructor
128 :
129 460800 : end module carma_diags_mod
|