1+ module cable_output_definitions_mod
2+ use iso_fortran_env, only: real32
3+
4+ use cable_abort_module, only: cable_abort
5+
6+ use cable_def_types_mod, only: canopy_type
7+
8+ use cable_io_vars_module, only: metGrid
9+
10+ use cable_netcdf_mod, only: CABLE_NETCDF_FLOAT
11+
12+ use aggregator_mod, only: new_aggregator
13+ use aggregator_mod, only: aggregator_real32_1d_t
14+
15+ use cable_netcdf_mod, only: MAX_LEN_DIM = > CABLE_NETCDF_MAX_STR_LEN_DIM
16+
17+ use cable_output_prototype_v2_mod, only: requires_x_y_output_grid
18+ use cable_output_prototype_v2_mod, only: requires_land_output_grid
19+ use cable_output_prototype_v2_mod, only: cable_output_add_variable
20+ use cable_output_prototype_v2_mod, only: cable_output_aggregator_t
21+ use cable_output_prototype_v2_mod, only: cable_output_add_aggregator
22+ use cable_output_prototype_v2_mod, only: output_options, patchout_options
23+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE
24+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_SOIL
25+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_SNOW
26+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_RAD
27+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_PLANTCARBON
28+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_SOILCARBON
29+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_PATCH
30+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_PATCH_SOIL
31+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_PATCH_SNOW
32+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_PATCH_RAD
33+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_PATCH_PLANTCARBON
34+ use cable_output_prototype_v2_mod, only: CABLE_OUTPUT_SHAPE_TYPE_BASE_PATCH_SOILCARBON
35+
36+ use cable_checks_module, only: ranges ! TODO(Sean): pass ranges via an argument rather than use module
37+
38+ implicit none
39+ private
40+
41+ public :: cable_output_definitions_set
42+
43+ contains
44+
45+ subroutine cable_output_definitions_set (canopy )
46+ type (canopy_type), intent (inout ) :: canopy
47+
48+ character (len= MAX_LEN_DIM), allocatable :: base_dims(:)
49+
50+ if (requires_x_y_output_grid(output_options% grid, metGrid)) then
51+ base_dims = [" x" , " y" ]
52+ else if (requires_land_output_grid(output_options% grid, metGrid)) then
53+ base_dims = [" land" ]
54+ else
55+ call cable_abort(" Error: Unable to determine output grid type" , __FILE__, __LINE__)
56+ end if
57+
58+ call cable_output_add_variable( &
59+ name= " Qh" , &
60+ dims= [base_dims, " patch" , " time" ], &
61+ var_type= CABLE_NETCDF_FLOAT, &
62+ units= " W/m^2" , &
63+ long_name= " Surface sensible heat flux" , &
64+ range= ranges% Qh, &
65+ active= output_options% Qh .and. (output_options% patch .OR. patchout_options% Qh), &
66+ grid_cell_averaging= .false. , &
67+ shape_type= CABLE_OUTPUT_SHAPE_TYPE_BASE_PATCH, &
68+ accumulation_frequency= " all" , &
69+ aggregation_frequency= output_options% averaging, &
70+ aggregator= new_aggregator( &
71+ source_data= canopy% fh, &
72+ method= " mean" &
73+ ) &
74+ )
75+
76+ call cable_output_add_variable( &
77+ name= " Qh" , &
78+ dims= [base_dims, " time" ], &
79+ var_type= CABLE_NETCDF_FLOAT, &
80+ units= " W/m^2" , &
81+ long_name= " Surface sensible heat flux" , &
82+ range= ranges% Qh, &
83+ active= output_options% Qh .and. .not. (output_options% patch .OR. patchout_options% Qh), &
84+ grid_cell_averaging= .true. , &
85+ shape_type= CABLE_OUTPUT_SHAPE_TYPE_BASE, &
86+ accumulation_frequency= " all" , &
87+ aggregation_frequency= output_options% averaging, &
88+ aggregator= new_aggregator( &
89+ source_data= canopy% fh, &
90+ method= " mean" &
91+ ) &
92+ )
93+
94+ add_variable_Tmx: block
95+ real (kind= real32), pointer :: tdaymx(:)
96+ type (cable_output_aggregator_t), target :: tdaymx_intermediate_aggregator
97+
98+ if (output_options% Tex .and. output_options% averaging == " monthly" ) then
99+ ! Create an intermmediate aggregator to compute daily maximum T
100+ call cable_output_add_aggregator( &
101+ aggregator= new_aggregator( &
102+ source_data= canopy% tscrn, &
103+ method= " max" &
104+ ), &
105+ accumulation_frequency= " all" , &
106+ aggregation_frequency= " daily" , &
107+ output_aggregator= tdaymx_intermediate_aggregator &
108+ )
109+ select type (aggregator = > tdaymx_intermediate_aggregator% aggregator_handle% aggregator)
110+ type is (aggregator_real32_1d_t)
111+ ! This is required to ensure that the storage for tdaymx is allocated.
112+ call aggregator% init()
113+ tdaymx = > aggregator% storage
114+ end select
115+ else
116+ tdaymx = > canopy% tscrn ! dummy assignment when Tmx is not needed
117+ end if
118+
119+ call cable_output_add_variable( &
120+ name= " Tmx" , &
121+ dims= [base_dims, " time" ], &
122+ var_type= CABLE_NETCDF_FLOAT, &
123+ units= " oC" , &
124+ long_name= " averaged daily maximum screen-level T" , &
125+ active= ( &
126+ output_options% Tex .and. &
127+ output_options% averaging == " monthly" .and. &
128+ .not. (output_options% patch .OR. patchout_options% Tex) &
129+ ), &
130+ grid_cell_averaging= .true. , &
131+ shape_type= CABLE_OUTPUT_SHAPE_TYPE_BASE, &
132+ range= ranges% Tscrn, &
133+ accumulation_frequency= " daily" , &
134+ aggregation_frequency= output_options% averaging, &
135+ aggregator= new_aggregator( &
136+ source_data= tdaymx, &
137+ method= " mean" &
138+ ) &
139+ )
140+
141+ call cable_output_add_variable( &
142+ name= " Tmx" , &
143+ dims= [base_dims, " patch" , " time" ], &
144+ var_type= CABLE_NETCDF_FLOAT, &
145+ units= " oC" , &
146+ long_name= " averaged daily maximum screen-level T" , &
147+ active= ( &
148+ output_options% Tex .and. &
149+ output_options% averaging == " monthly" .and. &
150+ (output_options% patch .OR. patchout_options% Tex) &
151+ ), &
152+ grid_cell_averaging= .false. , &
153+ shape_type= CABLE_OUTPUT_SHAPE_TYPE_BASE_PATCH, &
154+ range= ranges% Tscrn, &
155+ accumulation_frequency= " daily" , &
156+ aggregation_frequency= output_options% averaging, &
157+ aggregator= new_aggregator( &
158+ source_data= tdaymx, &
159+ method= " mean" &
160+ ) &
161+ )
162+
163+ end block add_variable_Tmx
164+
165+ end subroutine cable_output_definitions_set
166+
167+ end module
0 commit comments