31 subroutine output_driver(data_one_tile, dom_cat_one_tile, lat_one_tile, lon_one_tile, &
32 i_mdl, j_mdl, num_categories, tile)
42 integer,
intent(in) :: i_mdl, j_mdl, tile, num_categories
44 real(esmf_kind_r4),
intent(in) :: data_one_tile(i_mdl,j_mdl,num_categories)
45 real(esmf_kind_r4),
intent(in) :: dom_cat_one_tile(i_mdl,j_mdl)
46 real(esmf_kind_r4),
intent(in) :: lat_one_tile(i_mdl,j_mdl)
47 real(esmf_kind_r4),
intent(in) :: lon_one_tile(i_mdl,j_mdl)
49 character(len=200) :: out_file
50 character(len=200) :: out_file_with_halo
54 integer :: i_out, j_out
55 integer :: i_start, i_end, j_start, j_end
61 out_file =
"./soil_type." //
grid_tiles(tile) //
".nc" 62 out_file_with_halo =
"./soil_type." //
grid_tiles(tile) //
".halo.nc" 63 case (
'vegetation_type')
64 out_file =
"./vegetation_type." //
grid_tiles(tile) //
".nc" 65 out_file_with_halo =
"./vegetation_type." //
grid_tiles(tile) //
".halo.nc" 67 print*,
'- FATAL ERROR IN ROUTINE OUTPUT. UNIDENTIFIED FIELD : ',
field_names(field_idx)
68 call mpi_abort(mpi_comm_world, 67, ierr)
77 print*,
"- WILL WRITE WITHOUT HALO REGION OF ",
halo,
" ROWS/COLS." 82 i_out = i_end - i_start + 1
83 j_out = j_end - j_start + 1
84 call writeit(out_file, i_out, j_out, num_categories, &
85 lat_one_tile(i_start:i_end,j_start:j_end), &
86 lon_one_tile(i_start:i_end,j_start:j_end), &
87 data_one_tile(i_start:i_end,j_start:j_end,:), &
88 dom_cat_one_tile(i_start:i_end,j_start:j_end) )
89 print*,
"- WILL WRITE FULL DOMAIN INCLUDING HALO." 90 call writeit(out_file_with_halo, i_mdl, j_mdl, num_categories, &
91 lat_one_tile, lon_one_tile, data_one_tile, dom_cat_one_tile)
93 print*,
"- WILL WRITE DATA." 94 call writeit(out_file, i_mdl, j_mdl, num_categories, &
95 lat_one_tile, lon_one_tile, data_one_tile, dom_cat_one_tile)
112 subroutine writeit(out_file, iout, jout, num_categories, &
113 latitude, longitude, data_pct, dominant_cat)
122 character(len=*),
intent(in) :: out_file
124 integer,
intent(in) :: iout, jout, num_categories
126 real(esmf_kind_r4),
intent(in) :: latitude(iout,jout)
127 real(esmf_kind_r4),
intent(in) :: longitude(iout,jout)
128 real(esmf_kind_r4),
intent(in) :: data_pct(iout,jout,num_categories)
129 real(esmf_kind_r4),
intent(in) :: dominant_cat(iout,jout)
131 character(len=200) :: field_names_pct
132 integer :: header_buffer_val = 16384
133 integer :: ncid, dim_x, dim_y, dim_z, dim_time
134 integer :: id_times, id_lat, id_lon, id_data_pct
135 integer :: id_data_dom_cat
141 print*,
"- OPEN AND WRITE: ",trim(out_file)
142 error = nf90_create(out_file, nf90_netcdf4, ncid)
143 call netcdf_err(error,
'ERROR IN NF90_CREATE' )
144 error = nf90_def_dim(ncid,
'nx', iout, dim_x)
145 call netcdf_err(error,
'DEFINING NX DIMENSION' )
146 error = nf90_def_dim(ncid,
'ny', jout, dim_y)
147 call netcdf_err(error,
'DEFINING NY DIMENSION' )
148 error = nf90_def_dim(ncid,
'num_categories', num_categories, dim_z)
149 call netcdf_err(error,
'DEFINING NZ DIMENSION' )
151 call netcdf_err(error,
'DEFINING TIME DIMENSION' )
153 error = nf90_def_var(ncid,
'time', nf90_float, dim_time, id_times)
154 call netcdf_err(error,
'DEFINING TIME VARIABLE' )
155 error = nf90_put_att(ncid, id_times,
"units",
"days since 2015-1-1")
156 call netcdf_err(error,
'DEFINING TIME ATTRIBUTE' )
157 if (len_trim(
source) > 0)
then 158 error = nf90_put_att(ncid, nf90_global,
'source',
source)
159 call netcdf_err(error,
'DEFINING GLOBAL SOURCE ATTRIBUTE' )
162 error = nf90_def_var(ncid,
'geolat', nf90_float, (/dim_x,dim_y/), id_lat)
163 call netcdf_err(error,
'DEFINING GEOLAT FIELD' )
164 error = nf90_put_att(ncid, id_lat,
"long_name",
"Latitude")
165 call netcdf_err(error,
'DEFINING GEOLAT NAME ATTRIBUTE' )
166 error = nf90_put_att(ncid, id_lat,
"units",
"degrees_north")
167 call netcdf_err(error,
'DEFINING GEOLAT UNIT ATTRIBUTE' )
168 error = nf90_def_var(ncid,
'geolon', nf90_float, (/dim_x,dim_y/), id_lon)
169 call netcdf_err(error,
'DEFINING GEOLON FIELD' )
170 error = nf90_put_att(ncid, id_lon,
"long_name",
"Longitude")
171 call netcdf_err(error,
'DEFINING GEOLON NAME ATTRIBUTE' )
172 error = nf90_put_att(ncid, id_lon,
"units",
"degrees_east")
173 call netcdf_err(error,
'DEFINING GEOLON UNIT ATTRIBUTE' )
176 error = nf90_def_var(ncid, trim(field_names_pct), nf90_float, (/dim_x,dim_y,dim_z,dim_time/), id_data_pct)
178 error = nf90_put_att(ncid, id_data_pct,
"units",
"percent coverage each category")
179 call netcdf_err(error,
'DEFINING FIELD ATTRIBUTE' )
180 error = nf90_put_att(ncid, id_data_pct,
"coordinates",
"geolon geolat")
181 call netcdf_err(error,
'DEFINING COORD ATTRIBUTE' )
183 error = nf90_def_var(ncid, trim(
field_names(1)), nf90_float, (/dim_x,dim_y,dim_time/), id_data_dom_cat)
185 error = nf90_put_att(ncid, id_data_dom_cat,
"units",
"dominant category")
186 call netcdf_err(error,
'DEFINING FIELD ATTRIBUTE' )
187 error = nf90_put_att(ncid, id_data_dom_cat,
"coordinates",
"geolon geolat")
188 call netcdf_err(error,
'DEFINING COORD ATTRIBUTE' )
193 error = nf90_enddef(ncid, header_buffer_val,4,0,4)
195 error = nf90_put_var( ncid, id_times,
day_of_rec)
198 error = nf90_put_var( ncid, id_lat, latitude)
199 call netcdf_err(error,
'IN NF90_PUT_VAR FOR GEOLAT' )
201 error = nf90_put_var( ncid, id_lon, longitude)
202 call netcdf_err(error,
'IN NF90_PUT_VAR FOR GEOLON' )
204 error = nf90_put_var( ncid, id_data_pct, data_pct)
207 error = nf90_put_var( ncid, id_data_dom_cat, dominant_cat)
214 error = nf90_close(ncid)
Set up program execution.
character(len=5), dimension(:), allocatable, public grid_tiles
Array of model grid tile names.
character(len=50), dimension(:), allocatable, public field_names
Names of fields to be processed.
This module defines the model grid.
Read grid specs, date information and land/sea mask for the source data that will be interpolated to ...
integer, public num_time_recs
Number of time records.
integer, public halo
Number of row/cols defining the lateral boundary halo.
integer, dimension(:), allocatable, public day_of_rec
Day of each time record with respect to Jan 1.
subroutine writeit(out_file, iout, jout, num_categories, latitude, longitude, data_pct, dominant_cat)
Write data to a netcdf file.
Output categorical data such as vegetation type.
subroutine, public output_driver(data_one_tile, dom_cat_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, num_categories, tile)
Driver routine to output model categorical data.
subroutine, public netcdf_err(err, string)
Handle netCDF error codes.
character(len=75), public source
Original source of the data.