16
16
! ! @param[in] time Time period to be output.
17
17
! ! @author George Gayno @date 2018
18
18
subroutine output2 (data_one_tile , lat_one_tile , lon_one_tile , i_mdl , j_mdl , &
19
- tile , record , time , field_idx )
19
+ num_categories , tile , record , time , field_idx )
20
20
21
21
use mpi
22
22
use esmf
@@ -29,46 +29,29 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
29
29
30
30
implicit none
31
31
32
- integer , intent (in ) :: i_mdl, j_mdl, tile
32
+ integer , intent (in ) :: i_mdl, j_mdl, tile, num_categories
33
33
integer , intent (in ) :: record, time, field_idx
34
34
35
- real (esmf_kind_r4 ), intent (in ) :: data_one_tile(i_mdl,j_mdl,20 )
35
+ real (esmf_kind_r4 ), intent (in ) :: data_one_tile(i_mdl,j_mdl,num_categories )
36
36
real (esmf_kind_r4 ) :: lat_one_tile(i_mdl,j_mdl)
37
37
real (esmf_kind_r4 ), intent (in ) :: lon_one_tile(i_mdl,j_mdl)
38
38
39
39
character (len= 200 ) :: out_file
40
40
character (len= 200 ) :: out_file_with_halo
41
41
42
- integer :: initialsiz, fsize, error, j
42
+ integer :: error, j
43
43
integer :: dim_x, dim_y, dim_z, id_data
44
44
integer :: dim_time, id_times, ierr
45
45
integer :: header_buffer_val = 16384
46
46
integer :: i_out, j_out, id_lat, id_lon, id_sum
47
47
integer :: i_start, i_end, j_start, j_end
48
48
integer , save :: ncid(6 ), ncid_with_halo
49
49
50
+ print * ,' num_time_recs/num_records/day_of_reo ' ,num_time_recs,num_records,day_of_rec
51
+ print * ,' record time ' ,record, time
52
+ print * ,' num fields ' , num_fields
53
+
50
54
select case (field_names(field_idx))
51
- case (' substrate_temperature' )
52
- out_file = " ./substrate_temperature." // grid_tiles(tile) // " .nc"
53
- out_file_with_halo = " ./substrate_temperature." // grid_tiles(tile) // " .halo.nc"
54
- case (' vegetation_greenness' )
55
- out_file = " ./vegetation_greenness." // grid_tiles(tile) // " .nc"
56
- out_file_with_halo = " ./vegetation_greenness." // grid_tiles(tile) // " .halo.nc"
57
- case (' maximum_snow_albedo' )
58
- out_file = " ./maximum_snow_albedo." // grid_tiles(tile) // " .nc"
59
- out_file_with_halo = " ./maximum_snow_albedo." // grid_tiles(tile) // " .halo.nc"
60
- case (' leaf_area_index' )
61
- out_file = " ./leaf_area_index." // grid_tiles(tile) // " .nc"
62
- out_file_with_halo = " ./leaf_area_index." // grid_tiles(tile) // " .halo.nc"
63
- case (' visible_black_sky_albedo' , ' visible_white_sky_albedo' , ' near_IR_black_sky_albedo' , ' near_IR_white_sky_albedo' )
64
- out_file = " ./snowfree_albedo." // grid_tiles(tile) // " .nc"
65
- out_file_with_halo = " ./snowfree_albedo." // grid_tiles(tile) // " .halo.nc"
66
- case (' facsf' )
67
- out_file = " ./facsf." // grid_tiles(tile) // " .nc"
68
- out_file_with_halo = " ./facsf." // grid_tiles(tile) // " .halo.nc"
69
- case (' slope_type' )
70
- out_file = " ./slope_type." // grid_tiles(tile) // " .nc"
71
- out_file_with_halo = " ./slope_type." // grid_tiles(tile) // " .halo.nc"
72
55
case (' soil_type' )
73
56
out_file = " ./soil_type." // grid_tiles(tile) // " .nc"
74
57
out_file_with_halo = " ./soil_type." // grid_tiles(tile) // " .halo.nc"
@@ -101,85 +84,77 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
101
84
i_out = i_end - i_start + 1
102
85
j_out = j_end - j_start + 1
103
86
104
- if (record == 1 ) then
105
-
106
- initialsiz = 0
107
- fsize = 65536
108
- error = nf90_create(out_file, IOR (NF90_NETCDF4,NF90_CLASSIC_MODEL), &
109
- ncid(tile), initialsize= initialsiz, chunksize= fsize)
110
- call netcdf_err(error, ' ERROR IN NF90_CREATE' )
111
- error = nf90_def_dim(ncid(tile), ' nx' , i_out, dim_x)
112
- call netcdf_err(error, ' DEFINING NX DIMENSION' )
113
- error = nf90_def_dim(ncid(tile), ' ny' , j_out, dim_y)
114
- call netcdf_err(error, ' DEFINING NY DIMENSION' )
115
- error = nf90_def_dim(ncid(tile), ' nz' , 20 , dim_z)
116
- call netcdf_err(error, ' DEFINING NZ DIMENSION' )
117
- error = nf90_def_dim(ncid(tile), ' time' , num_time_recs, dim_time)
118
- call netcdf_err(error, ' DEFINING TIME DIMENSION' )
119
- error = nf90_def_var(ncid(tile), ' time' , NF90_FLOAT, dim_time, id_times)
120
- call netcdf_err(error, ' DEFINING TIME VARIABLE' )
121
- error = nf90_put_att(ncid(tile), id_times, " units" , " days since 2015-1-1" )
122
- call netcdf_err(error, ' DEFINING TIME ATTRIBUTE' )
123
- if (len_trim (source) > 0 ) then
124
- error = nf90_put_att(ncid(tile), nf90_global, ' source' , source)
125
- call netcdf_err(error, ' DEFINING GLOBAL SOURCE ATTRIBUTE' )
126
- endif
127
-
128
- error = nf90_def_var(ncid(tile), ' geolat' , NF90_FLOAT, (/ dim_x,dim_y/ ), id_lat)
129
- call netcdf_err(error, ' DEFINING GEOLAT FIELD' )
130
- error = nf90_put_att(ncid(tile), id_lat, " long_name" , " Latitude" )
131
- call netcdf_err(error, ' DEFINING GEOLAT NAME ATTRIBUTE' )
132
- error = nf90_put_att(ncid(tile), id_lat, " units" , " degrees_north" )
133
- call netcdf_err(error, ' DEFINING GEOLAT UNIT ATTRIBUTE' )
134
- error = nf90_def_var(ncid(tile), ' geolon' , NF90_FLOAT, (/ dim_x,dim_y/ ), id_lon)
135
- call netcdf_err(error, ' DEFINING GEOLON FIELD' )
136
- error = nf90_put_att(ncid(tile), id_lon, " long_name" , " Longitude" )
137
- call netcdf_err(error, ' DEFINING GEOLON NAME ATTRIBUTE' )
138
- error = nf90_put_att(ncid(tile), id_lon, " units" , " degrees_east" )
139
- call netcdf_err(error, ' DEFINING GEOLON UNIT ATTRIBUTE' )
140
-
141
- do j = 1 , num_fields
142
- error = nf90_def_var(ncid(tile), trim (field_names(j)), NF90_FLOAT, (/ dim_x,dim_y,dim_z,dim_time/ ), id_data)
143
- call netcdf_err(error, ' DEFINING FIELD' )
144
- error = nf90_put_att(ncid(tile), id_data, " missing_value" , missing)
145
- call netcdf_err(error, ' DEFINING FIELD ATTRIBUTE' )
146
- error = nf90_put_att(ncid(tile), id_data, " coordinates" , " geolon geolat" )
147
- call netcdf_err(error, ' DEFINING COORD ATTRIBUTE' )
148
- error = nf90_def_var(ncid(tile), ' sum' , NF90_FLOAT, (/ dim_x,dim_y,dim_time/ ), id_sum)
149
- call netcdf_err(error, ' DEFINING FIELD' )
150
- enddo
151
-
152
- error = nf90_enddef(ncid(tile), header_buffer_val,4 ,0 ,4 )
153
- call netcdf_err(error, ' IN NF90_ENDDEF' )
154
-
155
- error = nf90_put_var( ncid(tile), id_times, day_of_rec)
156
- call netcdf_err(error, ' WRITING TIME FIELD' )
87
+ error = nf90_create(out_file, NF90_NETCDF4, ncid(tile))
88
+ call netcdf_err(error, ' ERROR IN NF90_CREATE' )
89
+ error = nf90_def_dim(ncid(tile), ' nx' , i_out, dim_x)
90
+ call netcdf_err(error, ' DEFINING NX DIMENSION' )
91
+ error = nf90_def_dim(ncid(tile), ' ny' , j_out, dim_y)
92
+ call netcdf_err(error, ' DEFINING NY DIMENSION' )
93
+ error = nf90_def_dim(ncid(tile), ' num_categories' , num_categories, dim_z)
94
+ call netcdf_err(error, ' DEFINING NZ DIMENSION' )
95
+ error = nf90_def_dim(ncid(tile), ' time' , num_time_recs, dim_time)
96
+ call netcdf_err(error, ' DEFINING TIME DIMENSION' )
97
+ error = nf90_def_var(ncid(tile), ' time' , NF90_FLOAT, dim_time, id_times)
98
+ call netcdf_err(error, ' DEFINING TIME VARIABLE' )
99
+ error = nf90_put_att(ncid(tile), id_times, " units" , " days since 2015-1-1" )
100
+ call netcdf_err(error, ' DEFINING TIME ATTRIBUTE' )
101
+ if (len_trim (source) > 0 ) then
102
+ error = nf90_put_att(ncid(tile), nf90_global, ' source' , source)
103
+ call netcdf_err(error, ' DEFINING GLOBAL SOURCE ATTRIBUTE' )
104
+ endif
157
105
158
- error = nf90_put_var( ncid(tile), id_lat, lat_one_tile(i_start:i_end,j_start:j_end), &
106
+ error = nf90_def_var(ncid(tile), ' geolat' , NF90_FLOAT, (/ dim_x,dim_y/ ), id_lat)
107
+ call netcdf_err(error, ' DEFINING GEOLAT FIELD' )
108
+ error = nf90_put_att(ncid(tile), id_lat, " long_name" , " Latitude" )
109
+ call netcdf_err(error, ' DEFINING GEOLAT NAME ATTRIBUTE' )
110
+ error = nf90_put_att(ncid(tile), id_lat, " units" , " degrees_north" )
111
+ call netcdf_err(error, ' DEFINING GEOLAT UNIT ATTRIBUTE' )
112
+ error = nf90_def_var(ncid(tile), ' geolon' , NF90_FLOAT, (/ dim_x,dim_y/ ), id_lon)
113
+ call netcdf_err(error, ' DEFINING GEOLON FIELD' )
114
+ error = nf90_put_att(ncid(tile), id_lon, " long_name" , " Longitude" )
115
+ call netcdf_err(error, ' DEFINING GEOLON NAME ATTRIBUTE' )
116
+ error = nf90_put_att(ncid(tile), id_lon, " units" , " degrees_east" )
117
+ call netcdf_err(error, ' DEFINING GEOLON UNIT ATTRIBUTE' )
118
+
119
+ error = nf90_def_var(ncid(tile), trim (field_names(1 )), NF90_FLOAT, (/ dim_x,dim_y,dim_z,dim_time/ ), id_data)
120
+ call netcdf_err(error, ' DEFINING FIELD' )
121
+ error = nf90_put_att(ncid(tile), id_data, " units" , " percent coverage each category" )
122
+ call netcdf_err(error, ' DEFINING FIELD ATTRIBUTE' )
123
+ error = nf90_put_att(ncid(tile), id_data, " missing_value" , missing)
124
+ call netcdf_err(error, ' DEFINING FIELD ATTRIBUTE' )
125
+ error = nf90_put_att(ncid(tile), id_data, " coordinates" , " geolon geolat" )
126
+ call netcdf_err(error, ' DEFINING COORD ATTRIBUTE' )
127
+ error = nf90_def_var(ncid(tile), ' sum' , NF90_FLOAT, (/ dim_x,dim_y,dim_time/ ), id_sum)
128
+ call netcdf_err(error, ' DEFINING FIELD' )
129
+
130
+ error = nf90_enddef(ncid(tile), header_buffer_val,4 ,0 ,4 )
131
+ call netcdf_err(error, ' IN NF90_ENDDEF' )
132
+
133
+ error = nf90_put_var( ncid(tile), id_times, day_of_rec)
134
+ call netcdf_err(error, ' WRITING TIME FIELD' )
135
+
136
+ error = nf90_put_var( ncid(tile), id_lat, lat_one_tile(i_start:i_end,j_start:j_end), &
159
137
start= (/ 1 ,1 / ), count= (/ i_out,j_out/ ))
160
- call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLAT' )
138
+ call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLAT' )
161
139
162
- error = nf90_put_var( ncid(tile), id_lon, lon_one_tile(i_start:i_end,j_start:j_end), &
140
+ error = nf90_put_var( ncid(tile), id_lon, lon_one_tile(i_start:i_end,j_start:j_end), &
163
141
start= (/ 1 ,1 / ), count= (/ i_out,j_out/ ))
164
- call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLON' )
165
-
166
- endif
142
+ call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLON' )
167
143
168
144
print * ,' - WRITE DATA FOR RECORD: ' ,record
169
145
error = nf90_inq_varid( ncid(tile), field_names(field_idx), id_data)
170
146
call netcdf_err(error, ' IN NF90_INQ_VARID' )
171
147
error = nf90_put_var( ncid(tile), id_data, data_one_tile(i_start:i_end,j_start:j_end,:), &
172
- start= (/ 1 ,1 ,1 ,time/ ), count= (/ i_out,j_out,20 ,1 / ))
148
+ start= (/ 1 ,1 ,1 ,time/ ), count= (/ i_out,j_out,num_categories ,1 / ))
173
149
call netcdf_err(error, ' IN NF90_PUT_VAR' )
174
150
175
- ! reuse lat
151
+ ! Temporary output of sum of %.
152
+ ! reuse latitude array.
176
153
lat_one_tile = sum (data_one_tile, dim= 3 )
177
154
error = nf90_put_var( ncid(tile), id_sum, lat_one_tile(i_start:i_end,j_start:j_end), &
178
155
start= (/ 1 ,1 ,time/ ), count= (/ i_out,j_out,1 / ))
179
156
180
- if (record == num_records) then
181
- error = nf90_close(ncid(tile))
182
- endif
157
+ error = nf90_close(ncid(tile))
183
158
184
159
print * ,' after write'
185
160
stop
@@ -194,10 +169,7 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
194
169
195
170
if (record == 1 ) then
196
171
197
- initialsiz = 0
198
- fsize = 65536
199
- error = nf90_create(out_file_with_halo, IOR (NF90_NETCDF4,NF90_CLASSIC_MODEL), &
200
- ncid_with_halo, initialsize= initialsiz, chunksize= fsize)
172
+ error = nf90_create(out_file_with_halo, NF90_NETCDF4, ncid_with_halo)
201
173
call netcdf_err(error, ' IN NF90_CREATE' )
202
174
error = nf90_def_dim(ncid_with_halo, ' nx' , i_mdl, dim_x)
203
175
call netcdf_err(error, ' DEFINING NX DIMENSION' )
0 commit comments