11
11
! ! @param[in] field_idx Index of field within field name array.
12
12
! ! @param[in] i_mdl i dimensions of tile.
13
13
! ! @param[in] j_mdl j dimensions of tile.
14
- ! ! @param[in] record Record number to be output.
15
14
! ! @param[in] tile Tile number.
16
15
! ! @param[in] time Time period to be output.
17
16
! ! @author George Gayno @date 2018
18
17
subroutine output2 (data_one_tile , lat_one_tile , lon_one_tile , i_mdl , j_mdl , &
19
- num_categories , tile , record , time , field_idx )
18
+ num_categories , tile , time , field_idx )
20
19
21
20
use mpi
22
21
use esmf
23
22
use netcdf
24
23
use utils
25
- use source_grid, only : field_names, source, num_fields, &
26
- num_time_recs, num_records, day_of_rec
24
+ use source_grid, only : field_names, source, &
25
+ num_time_recs, day_of_rec
27
26
use model_grid, only : missing, grid_tiles
28
27
use program_setup, only : halo
29
28
30
29
implicit none
31
30
32
31
integer , intent (in ) :: i_mdl, j_mdl, tile, num_categories
33
- integer , intent (in ) :: record, time, field_idx
32
+ integer , intent (in ) :: time, field_idx
34
33
35
34
real (esmf_kind_r4 ), intent (in ) :: data_one_tile(i_mdl,j_mdl,num_categories)
36
35
real (esmf_kind_r4 ) :: lat_one_tile(i_mdl,j_mdl)
37
36
real (esmf_kind_r4 ), intent (in ) :: lon_one_tile(i_mdl,j_mdl)
37
+ real (esmf_kind_r4 ) :: sum_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 :: error, j
42
+ integer :: error
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
-
54
50
select case (field_names(field_idx))
55
51
case (' soil_type' )
56
52
out_file = " ./soil_type." // grid_tiles(tile) // " .nc"
@@ -141,24 +137,20 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
141
137
start= (/ 1 ,1 / ), count= (/ i_out,j_out/ ))
142
138
call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLON' )
143
139
144
- print * ,' - WRITE DATA FOR RECORD: ' ,record
140
+ print * ,' - WRITE DATA '
145
141
error = nf90_inq_varid( ncid(tile), field_names(field_idx), id_data)
146
142
call netcdf_err(error, ' IN NF90_INQ_VARID' )
147
143
error = nf90_put_var( ncid(tile), id_data, data_one_tile(i_start:i_end,j_start:j_end,:), &
148
144
start= (/ 1 ,1 ,1 ,time/ ), count= (/ i_out,j_out,num_categories,1 / ))
149
145
call netcdf_err(error, ' IN NF90_PUT_VAR' )
150
146
151
147
! Temporary output of sum of %.
152
- ! reuse latitude array.
153
- lat_one_tile = sum (data_one_tile, dim= 3 )
154
- error = nf90_put_var( ncid(tile), id_sum, lat_one_tile(i_start:i_end,j_start:j_end), &
148
+ sum_one_tile = sum (data_one_tile, dim= 3 )
149
+ error = nf90_put_var( ncid(tile), id_sum, sum_one_tile(i_start:i_end,j_start:j_end), &
155
150
start= (/ 1 ,1 ,time/ ), count= (/ i_out,j_out,1 / ))
156
151
157
152
error = nf90_close(ncid(tile))
158
153
159
- print * ,' after write'
160
- stop
161
-
162
154
!- ---------------------------------------------------------------------
163
155
! For regional nests, also output files including the halo
164
156
!- ---------------------------------------------------------------------
@@ -167,74 +159,73 @@ subroutine output2(data_one_tile, lat_one_tile, lon_one_tile, i_mdl, j_mdl, &
167
159
168
160
print * ," - WRITE OUT FILES THAT INCLUDE HALO REGION."
169
161
170
- if (record == 1 ) then
171
-
172
- error = nf90_create(out_file_with_halo, NF90_NETCDF4, ncid_with_halo)
173
- call netcdf_err(error, ' IN NF90_CREATE' )
174
- error = nf90_def_dim(ncid_with_halo, ' nx' , i_mdl, dim_x)
175
- call netcdf_err(error, ' DEFINING NX DIMENSION' )
176
- error = nf90_def_dim(ncid_with_halo, ' ny' , j_mdl, dim_y)
177
- call netcdf_err(error, ' DEFINING NY DIMENSION' )
178
- error = nf90_def_dim(ncid_with_halo, ' time' , num_time_recs, dim_time)
179
- call netcdf_err(error, ' DEFINING TIME DIMENSION' )
180
- error = nf90_def_var(ncid_with_halo, ' time' , NF90_FLOAT, dim_time, id_times)
181
- call netcdf_err(error, ' DEFINING TIME VARIABLE' )
182
- error = nf90_put_att(ncid_with_halo, id_times, " units" , " days since 2015-1-1" )
183
- call netcdf_err(error, ' DEFINING TIME ATTRIBUTE' )
184
- if (len_trim (source) > 0 ) then
185
- error = nf90_put_att(ncid_with_halo, nf90_global, ' source' , source)
186
- call netcdf_err(error, ' DEFINING GLOBAL SOURCE ATTRIBUTE' )
187
- endif
188
-
189
- error = nf90_def_var(ncid_with_halo, ' geolat' , NF90_FLOAT, (/ dim_x,dim_y/ ), id_lat)
190
- call netcdf_err(error, ' DEFINING GEOLAT FIELD' )
191
- error = nf90_put_att(ncid_with_halo, id_lat, " long_name" , " Latitude" )
192
- call netcdf_err(error, ' DEFINING GEOLAT NAME ATTRIBUTE' )
193
- error = nf90_put_att(ncid_with_halo, id_lat, " units" , " degrees_north" )
194
- call netcdf_err(error, ' DEFINING GEOLAT UNIT ATTRIBUTE' )
195
- error = nf90_def_var(ncid_with_halo, ' geolon' , NF90_FLOAT, (/ dim_x,dim_y/ ), id_lon)
196
- call netcdf_err(error, ' DEFINING GEOLON FIELD' )
197
- error = nf90_put_att(ncid_with_halo, id_lon, " long_name" , " Longitude" )
198
- call netcdf_err(error, ' DEFINING GEOLON NAME ATTRIBUTE' )
199
- error = nf90_put_att(ncid_with_halo, id_lon, " units" , " degrees_east" )
200
- call netcdf_err(error, ' DEFINING GEOLON UNIT ATTRIBUTE' )
201
-
202
- do j = 1 , num_fields
203
- error = nf90_def_var(ncid_with_halo, field_names(j), NF90_FLOAT, (/ dim_x,dim_y,dim_time/ ), id_data)
204
- call netcdf_err(error, ' DEFINING FIELD VARIABLE' )
205
- error = nf90_put_att(ncid_with_halo, id_data, " missing_value" , missing)
206
- call netcdf_err(error, ' DEFINING FIELD ATTRIBUTE' )
207
- error = nf90_put_att(ncid_with_halo, id_data, " coordinates" , " geolon geolat" )
208
- call netcdf_err(error, ' DEFINING COORD ATTRIBUTE' )
209
- enddo
210
-
211
- error = nf90_enddef(ncid_with_halo, header_buffer_val,4 ,0 ,4 )
212
- call netcdf_err(error, ' WRITING HEADER ENDDEF' )
213
-
214
- error = nf90_put_var(ncid_with_halo, id_times, day_of_rec)
215
- call netcdf_err(error, ' WRITING TIME VARIABLE' )
216
-
217
- error = nf90_put_var( ncid_with_halo, id_lat, lat_one_tile, &
218
- start= (/ 1 ,1 / ), count= (/ i_mdl,j_mdl/ ))
219
- call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLAT' )
162
+ error = nf90_create(out_file_with_halo, NF90_NETCDF4, ncid_with_halo)
163
+ call netcdf_err(error, ' IN NF90_CREATE' )
164
+ error = nf90_def_dim(ncid_with_halo, ' nx' , i_mdl, dim_x)
165
+ call netcdf_err(error, ' DEFINING NX DIMENSION' )
166
+ error = nf90_def_dim(ncid_with_halo, ' ny' , j_mdl, dim_y)
167
+ call netcdf_err(error, ' DEFINING NY DIMENSION' )
168
+ error = nf90_def_dim(ncid(tile), ' num_categories' , num_categories, dim_z)
169
+ call netcdf_err(error, ' DEFINING NZ DIMENSION' )
170
+ error = nf90_def_dim(ncid_with_halo, ' time' , num_time_recs, dim_time)
171
+ call netcdf_err(error, ' DEFINING TIME DIMENSION' )
172
+ error = nf90_def_var(ncid_with_halo, ' time' , NF90_FLOAT, dim_time, id_times)
173
+ call netcdf_err(error, ' DEFINING TIME VARIABLE' )
174
+ error = nf90_put_att(ncid_with_halo, id_times, " units" , " days since 2015-1-1" )
175
+ call netcdf_err(error, ' DEFINING TIME ATTRIBUTE' )
176
+ if (len_trim (source) > 0 ) then
177
+ error = nf90_put_att(ncid_with_halo, nf90_global, ' source' , source)
178
+ call netcdf_err(error, ' DEFINING GLOBAL SOURCE ATTRIBUTE' )
179
+ endif
220
180
221
- error = nf90_put_var( ncid_with_halo, id_lon, lon_one_tile, &
222
- start= (/ 1 ,1 / ), count= (/ i_mdl,j_mdl/ ))
223
- call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLON' )
181
+ error = nf90_def_var(ncid_with_halo, ' geolat' , NF90_FLOAT, (/ dim_x,dim_y/ ), id_lat)
182
+ call netcdf_err(error, ' DEFINING GEOLAT FIELD' )
183
+ error = nf90_put_att(ncid_with_halo, id_lat, " long_name" , " Latitude" )
184
+ call netcdf_err(error, ' DEFINING GEOLAT NAME ATTRIBUTE' )
185
+ error = nf90_put_att(ncid_with_halo, id_lat, " units" , " degrees_north" )
186
+ call netcdf_err(error, ' DEFINING GEOLAT UNIT ATTRIBUTE' )
187
+ error = nf90_def_var(ncid_with_halo, ' geolon' , NF90_FLOAT, (/ dim_x,dim_y/ ), id_lon)
188
+ call netcdf_err(error, ' DEFINING GEOLON FIELD' )
189
+ error = nf90_put_att(ncid_with_halo, id_lon, " long_name" , " Longitude" )
190
+ call netcdf_err(error, ' DEFINING GEOLON NAME ATTRIBUTE' )
191
+ error = nf90_put_att(ncid_with_halo, id_lon, " units" , " degrees_east" )
192
+ call netcdf_err(error, ' DEFINING GEOLON UNIT ATTRIBUTE' )
224
193
225
- endif
194
+ error = nf90_def_var(ncid_with_halo, field_names(1 ), NF90_FLOAT, (/ dim_x,dim_y,dim_z,dim_time/ ), id_data)
195
+ call netcdf_err(error, ' DEFINING FIELD VARIABLE' )
196
+ error = nf90_put_att(ncid_with_halo, id_data, " units" , " percent coverage each category" )
197
+ call netcdf_err(error, ' DEFINING FIELD ATTRIBUTE' )
198
+ error = nf90_put_att(ncid_with_halo, id_data, " missing_value" , missing)
199
+ call netcdf_err(error, ' DEFINING FIELD ATTRIBUTE' )
200
+ error = nf90_put_att(ncid_with_halo, id_data, " coordinates" , " geolon geolat" )
201
+ call netcdf_err(error, ' DEFINING COORD ATTRIBUTE' )
202
+
203
+ error = nf90_enddef(ncid_with_halo, header_buffer_val,4 ,0 ,4 )
204
+ call netcdf_err(error, ' WRITING HEADER ENDDEF' )
205
+
206
+ error = nf90_put_var(ncid_with_halo, id_times, day_of_rec)
207
+ call netcdf_err(error, ' WRITING TIME VARIABLE' )
226
208
227
- print * ,' - WRITE DATA FOR RECORD: ' ,record
209
+ error = nf90_put_var( ncid_with_halo, id_lat, lat_one_tile, &
210
+ start= (/ 1 ,1 / ), count= (/ i_mdl,j_mdl/ ))
211
+ call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLAT' )
212
+
213
+ error = nf90_put_var( ncid_with_halo, id_lon, lon_one_tile, &
214
+ start= (/ 1 ,1 / ), count= (/ i_mdl,j_mdl/ ))
215
+ call netcdf_err(error, ' IN NF90_PUT_VAR FOR GEOLON' )
216
+
217
+ print * ,' - WRITE DATA'
228
218
error = nf90_inq_varid(ncid_with_halo, field_names(field_idx), id_data)
229
219
call netcdf_err(error, ' IN NF90_INQ_VARID' )
230
220
231
221
error = nf90_put_var(ncid_with_halo, id_data, data_one_tile, &
232
- start= (/ 1 ,1 ,time/ ), count= (/ i_mdl,j_mdl,1 / ))
222
+ start= (/ 1 ,1 ,1 , time/ ), count= (/ i_mdl,j_mdl,num_categories ,1 / ))
233
223
call netcdf_err(error, ' IN NF90_PUT_VAR' )
234
224
235
- if (record == num_records) then
236
- error = nf90_close(ncid_with_halo)
237
- endif
225
+ error = nf90_close(ncid_with_halo)
226
+
227
+ call mpi_barrier(mpi_comm_world, error)
228
+ stop
238
229
239
230
return
240
231
0 commit comments