Skip to content

Commit d99116c

Browse files
Add computation and output of dominate category.
Fixes ufs-community#709.
1 parent 4adcb64 commit d99116c

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

sorc/sfc_climo_gen.fd/interp2.F90

+7-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ subroutine interp2(localpet, input_file)
3636
real(esmf_kind_r4), allocatable :: data_src_global(:,:)
3737
real(esmf_kind_r4), allocatable :: data_src_global2(:,:,:)
3838
real(esmf_kind_r4), allocatable :: data_mdl_one_tile(:,:,:)
39+
real(esmf_kind_r4), allocatable :: dom_cat_mdl_one_tile(:,:)
3940
real(esmf_kind_r4), allocatable :: lat_mdl_one_tile(:,:)
4041
real(esmf_kind_r4), allocatable :: sum_mdl_one_tile(:,:)
4142
real(esmf_kind_r4), allocatable :: lon_mdl_one_tile(:,:)
@@ -93,13 +94,15 @@ subroutine interp2(localpet, input_file)
9394
if (localpet == 0) then
9495
allocate(data_src_global2(i_src,j_src,num_categories))
9596
allocate(data_mdl_one_tile(i_mdl,j_mdl,num_categories))
97+
allocate(dom_cat_mdl_one_tile(i_mdl,j_mdl))
9698
allocate(mask_mdl_one_tile(i_mdl,j_mdl))
9799
allocate(lat_mdl_one_tile(i_mdl,j_mdl))
98100
allocate(sum_mdl_one_tile(i_mdl,j_mdl))
99101
allocate(lon_mdl_one_tile(i_mdl,j_mdl))
100102
else
101103
allocate(data_src_global2(0,0,0))
102104
allocate(data_mdl_one_tile(0,0,0))
105+
allocate(dom_cat_mdl_one_tile(0,0))
103106
allocate(mask_mdl_one_tile(0,0))
104107
allocate(lat_mdl_one_tile(0,0))
105108
allocate(sum_mdl_one_tile(0,0))
@@ -189,14 +192,16 @@ subroutine interp2(localpet, input_file)
189192
enddo
190193
call search2 (data_mdl_one_tile, mask_mdl_one_tile, i_mdl, j_mdl, num_categories, tile, field_names(1))
191194
print*,'after regrid ',data_mdl_one_tile(i_mdl/2,j_mdl/2,:)
192-
call output2 (data_mdl_one_tile, lat_mdl_one_tile, lon_mdl_one_tile, i_mdl, j_mdl, num_categories, tile)
195+
dom_cat_mdl_one_tile = 0.0
196+
dom_cat_mdl_one_tile = maxloc(data_mdl_one_tile,dim=3)
197+
call output2 (data_mdl_one_tile, dom_cat_mdl_one_tile, lat_mdl_one_tile, lon_mdl_one_tile, i_mdl, j_mdl, num_categories, tile)
193198
endif
194199

195200
enddo OUTPUT_LOOP
196201

197202
status=nf90_close(ncid)
198203

199-
deallocate(data_mdl_one_tile, mask_mdl_one_tile, data_src_global2)
204+
deallocate(data_mdl_one_tile, dom_cat_mdl_one_tile, mask_mdl_one_tile, data_src_global2)
200205
deallocate(lat_mdl_one_tile, lon_mdl_one_tile, sum_mdl_one_tile)
201206

202207
print*,"- CALL FieldRegridRelease."

sorc/sfc_climo_gen.fd/output2.f90

+44-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
!! @param[in] j_mdl j dimensions of tile.
1414
!! @param[in] tile Tile number.
1515
!! @author George Gayno @date 2018
16-
subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
16+
subroutine output2(data_one_tile, dom_cat_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
1717
num_categories, tile)
1818

1919
use mpi
@@ -30,16 +30,18 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
3030
integer, intent(in) :: i_mdl, j_mdl, tile, num_categories
3131

3232
real(esmf_kind_r4), intent(in) :: data_one_tile(i_mdl,j_mdl,num_categories)
33+
real(esmf_kind_r4), intent(in) :: dom_cat_one_tile(i_mdl,j_mdl)
3334
real(esmf_kind_r4) :: lat_one_tile(i_mdl,j_mdl)
3435
real(esmf_kind_r4), intent(in) :: lon_one_tile(i_mdl,j_mdl)
3536
real(esmf_kind_r4) :: sum_one_tile(i_mdl,j_mdl)
36-
37+
38+
character(len=200) :: field_names_pct
3739
character(len=200) :: out_file
3840
character(len=200) :: out_file_with_halo
3941

4042
integer :: error
4143
integer :: field_idx
42-
integer :: dim_x, dim_y, dim_z, id_data
44+
integer :: dim_x, dim_y, dim_z, id_data_pct, id_data_dom_cat
4345
integer :: dim_time, id_times, ierr
4446
integer :: header_buffer_val = 16384
4547
integer :: i_out, j_out, id_lat, id_lon, id_sum
@@ -113,14 +115,25 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
113115
error = nf90_put_att(ncid(tile), id_lon, "units", "degrees_east")
114116
call netcdf_err(error, 'DEFINING GEOLON UNIT ATTRIBUTE' )
115117

116-
error = nf90_def_var(ncid(tile), trim(field_names(1)), NF90_FLOAT, (/dim_x,dim_y,dim_z,dim_time/), id_data)
118+
field_names_pct = trim(field_names(1)) // "_pct"
119+
error = nf90_def_var(ncid(tile), trim(field_names_pct), NF90_FLOAT, (/dim_x,dim_y,dim_z,dim_time/), id_data_pct)
120+
call netcdf_err(error, 'DEFINING FIELD' )
121+
error = nf90_put_att(ncid(tile), id_data_pct, "units", "percent coverage each category")
122+
call netcdf_err(error, 'DEFINING FIELD ATTRIBUTE' )
123+
error = nf90_put_att(ncid(tile), id_data_pct, "missing_value", missing)
124+
call netcdf_err(error, 'DEFINING FIELD ATTRIBUTE' )
125+
error = nf90_put_att(ncid(tile), id_data_pct, "coordinates", "geolon geolat")
126+
call netcdf_err(error, 'DEFINING COORD ATTRIBUTE' )
127+
128+
error = nf90_def_var(ncid(tile), trim(field_names(1)), NF90_FLOAT, (/dim_x,dim_y,dim_time/), id_data_dom_cat)
117129
call netcdf_err(error, 'DEFINING FIELD' )
118-
error = nf90_put_att(ncid(tile), id_data, "units", "percent coverage each category")
130+
error = nf90_put_att(ncid(tile), id_data_dom_cat, "units", "dominate category")
119131
call netcdf_err(error, 'DEFINING FIELD ATTRIBUTE' )
120-
error = nf90_put_att(ncid(tile), id_data, "missing_value", missing)
132+
error = nf90_put_att(ncid(tile), id_data_dom_cat, "missing_value", missing)
121133
call netcdf_err(error, 'DEFINING FIELD ATTRIBUTE' )
122-
error = nf90_put_att(ncid(tile), id_data, "coordinates", "geolon geolat")
134+
error = nf90_put_att(ncid(tile), id_data_dom_cat, "coordinates", "geolon geolat")
123135
call netcdf_err(error, 'DEFINING COORD ATTRIBUTE' )
136+
124137
error = nf90_def_var(ncid(tile), 'sum', NF90_FLOAT, (/dim_x,dim_y,dim_time/), id_sum)
125138
call netcdf_err(error, 'DEFINING FIELD' )
126139

@@ -139,12 +152,14 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
139152
call netcdf_err(error, 'IN NF90_PUT_VAR FOR GEOLON' )
140153

141154
print*,'- WRITE DATA '
142-
error = nf90_inq_varid( ncid(tile), field_names(field_idx), id_data)
143-
call netcdf_err(error, 'IN NF90_INQ_VARID' )
144-
error = nf90_put_var( ncid(tile), id_data, data_one_tile(i_start:i_end,j_start:j_end,:), &
155+
error = nf90_put_var( ncid(tile), id_data_pct, data_one_tile(i_start:i_end,j_start:j_end,:), &
145156
start=(/1,1,1,1/), count=(/i_out,j_out,num_categories,1/))
146157
call netcdf_err(error, 'IN NF90_PUT_VAR' )
147158

159+
error = nf90_put_var( ncid(tile), id_data_dom_cat, dom_cat_one_tile(i_start:i_end,j_start:j_end), &
160+
start=(/1,1,1/), count=(/i_out,j_out,1/))
161+
call netcdf_err(error, 'IN NF90_PUT_VAR' )
162+
148163
! Temporary output of sum of %.
149164
sum_one_tile = sum(data_one_tile, dim=3)
150165
error = nf90_put_var( ncid(tile), id_sum, sum_one_tile(i_start:i_end,j_start:j_end), &
@@ -192,13 +207,22 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
192207
error = nf90_put_att(ncid_with_halo, id_lon, "units", "degrees_east")
193208
call netcdf_err(error, 'DEFINING GEOLON UNIT ATTRIBUTE' )
194209

195-
error = nf90_def_var(ncid_with_halo, field_names(1), NF90_FLOAT, (/dim_x,dim_y,dim_z,dim_time/), id_data)
210+
error = nf90_def_var(ncid_with_halo, field_names_pct, NF90_FLOAT, (/dim_x,dim_y,dim_z,dim_time/), id_data_pct)
196211
call netcdf_err(error, 'DEFINING FIELD VARIABLE' )
197-
error = nf90_put_att(ncid_with_halo, id_data, "units", "percent coverage each category")
212+
error = nf90_put_att(ncid_with_halo, id_data_pct, "units", "percent coverage each category")
198213
call netcdf_err(error, 'DEFINING FIELD ATTRIBUTE' )
199-
error = nf90_put_att(ncid_with_halo, id_data, "missing_value", missing)
214+
error = nf90_put_att(ncid_with_halo, id_data_pct, "missing_value", missing)
200215
call netcdf_err(error, 'DEFINING FIELD ATTRIBUTE' )
201-
error = nf90_put_att(ncid_with_halo, id_data, "coordinates", "geolon geolat")
216+
error = nf90_put_att(ncid_with_halo, id_data_pct, "coordinates", "geolon geolat")
217+
call netcdf_err(error, 'DEFINING COORD ATTRIBUTE' )
218+
219+
error = nf90_def_var(ncid(tile), trim(field_names(1)), NF90_FLOAT, (/dim_x,dim_y,dim_time/), id_data_dom_cat)
220+
call netcdf_err(error, 'DEFINING FIELD' )
221+
error = nf90_put_att(ncid(tile), id_data_dom_cat, "units", "dominate category")
222+
call netcdf_err(error, 'DEFINING FIELD ATTRIBUTE' )
223+
error = nf90_put_att(ncid(tile), id_data_dom_cat, "missing_value", missing)
224+
call netcdf_err(error, 'DEFINING FIELD ATTRIBUTE' )
225+
error = nf90_put_att(ncid(tile), id_data_dom_cat, "coordinates", "geolon geolat")
202226
call netcdf_err(error, 'DEFINING COORD ATTRIBUTE' )
203227

204228
error = nf90_enddef(ncid_with_halo, header_buffer_val,4,0,4)
@@ -216,13 +240,15 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
216240
call netcdf_err(error, 'IN NF90_PUT_VAR FOR GEOLON' )
217241

218242
print*,'- WRITE DATA'
219-
error = nf90_inq_varid(ncid_with_halo, field_names(field_idx), id_data)
220-
call netcdf_err(error, 'IN NF90_INQ_VARID' )
221243

222-
error = nf90_put_var(ncid_with_halo, id_data, data_one_tile, &
244+
error = nf90_put_var(ncid_with_halo, id_data_pct, data_one_tile, &
223245
start=(/1,1,1,1/), count=(/i_mdl,j_mdl,num_categories,1/))
224246
call netcdf_err(error, 'IN NF90_PUT_VAR' )
225-
247+
248+
error = nf90_put_var(ncid_with_halo, id_data_dom_cat, dom_cat_one_tile, &
249+
start=(/1,1,1/), count=(/i_mdl,j_mdl,1/))
250+
call netcdf_err(error, 'IN NF90_PUT_VAR' )
251+
226252
error = nf90_close(ncid_with_halo)
227253

228254
return

0 commit comments

Comments
 (0)