189 function newoutputdataset( iDomain, level, file_name, double_precision, outputs_frequence, time_reference )
result(out)
192 integer(i4),
intent(in) :: idomain
193 type(
grid),
dimension(:),
allocatable,
target,
intent(in) :: level
194 character(*),
intent(in) :: file_name
195 logical,
intent(in) :: double_precision
196 integer(i4),
intent(in) :: outputs_frequence
197 integer(i4),
intent(in) :: time_reference
201 out%nc =
createoutputfile(idomain, level, file_name, double_precision, outputs_frequence, time_reference)
202 out%iDomain = idomain
205 if ( (outputs_frequence > 0) &
206 .and. (mod(
timestep * outputs_frequence, 2) == 1) &
207 .and. (time_reference == 1) &
209 out%time_unit_factor = 60
211 out%time_unit_factor = 1
213 out%outputs_frequence = outputs_frequence
214 out%time_reference = time_reference
215 out%double_precision = double_precision
216 out%previous_time = 0
234 integer(i4),
intent(in) :: current_time_step
238 type(ncvariable) :: tvar
240 self%counter = self%counter + 1
243 tvar = self%nc%getVariable(
"time")
244 select case( self%time_reference )
246 call tvar%setData(self%previous_time * self%time_unit_factor, (/self%counter/))
248 call tvar%setData((self%previous_time + current_time_step) * self%time_unit_factor / 2, (/self%counter/))
250 call tvar%setData(current_time_step * self%time_unit_factor, (/self%counter/))
253 tvar = self%nc%getVariable(
"time_bnds")
254 call tvar%setData(self%previous_time * self%time_unit_factor, (/1, self%counter/))
255 call tvar%setData(current_time_step * self%time_unit_factor, (/2, self%counter/))
256 self%previous_time = current_time_step
258 do ii = 1,
size(self%vars)
259 call self%vars(ii)%writeVariableTimestep(self%counter)
301 function createoutputfile(iDomain, level, file_name, double_precision, outputs_frequence, time_reference)
result(nc)
305 use mo_julian,
only : dec2date
310 integer(i4),
intent(in) :: idomain
311 type(
grid),
dimension(:),
allocatable,
intent(in) :: level
312 character(*),
intent(in) :: file_name
313 logical,
intent(in) :: double_precision
314 integer(i4),
intent(in) :: outputs_frequence
315 integer(i4),
intent(in) :: time_reference
317 type(ncdataset) :: nc
318 type(ncdimension),
dimension(4) :: dimids1
319 type(ncvariable) :: var
320 integer(i4) :: day, month, year
321 character(1028) :: fname
322 character(128) :: unit, date, time, datetime
323 real(dp),
allocatable,
dimension(:) :: easting, northing
324 real(dp),
allocatable,
dimension(:, :) :: x_bnds, y_bnds
325 real(dp) :: half_step
326 real(dp),
allocatable,
dimension(:) :: lat1d, lon1d
327 real(dp),
allocatable,
dimension(:, :) :: lat2d, lon2d
329 character(3) :: dtype
334 half_step = level(idomain)%cellsize / 2.0_dp
336 fname = trim(
dirout(idomain)) // trim(file_name)
339 nc = ncdataset(trim(fname),
"w")
347 allocate(x_bnds(2,
size(easting)))
348 allocate(y_bnds(2,
size(northing)))
349 x_bnds(1, :) = easting - half_step
350 x_bnds(2, :) = easting + half_step
351 y_bnds(1, :) = northing - half_step
352 y_bnds(2, :) = northing + half_step
355 nc%setDimension(
"easting",
size(easting)), &
356 nc%setDimension(
"northing",
size(northing)), &
357 nc%setDimension(
"time", 0), &
358 nc%setDimension(
"bnds", 2) &
361 var = nc%setVariable(
"easting", dtype, (/ dimids1(1) /))
362 call set_attributes(var,
"x-coordinate in the given coordinate system", &
363 unit=
"m", standard_name=
"projection_x_coordinate", add_coords=.false., axis=
"X", bounds=
"easting_bnds")
364 call var%setData(easting)
365 var = nc%setVariable(
"easting_bnds", dtype, (/ dimids1(4), dimids1(1) /))
366 call var%setData(x_bnds)
368 var = nc%setVariable(
"northing", dtype, (/ dimids1(2) /))
369 call set_attributes(var,
"y-coordinate in the given coordinate system", &
370 unit=
"m", standard_name=
"projection_y_coordinate", add_coords=.false., axis=
"Y", bounds=
"northing_bnds")
371 call var%setData(northing)
372 var = nc%setVariable(
"northing_bnds", dtype, (/ dimids1(4), dimids1(2) /))
373 call var%setData(y_bnds)
375 var = nc%setVariable(
"lon", dtype, dimids1(1 : 2))
377 double_precision=double_precision, add_coords=.false., standard_name=
"longitude")
378 call var%setData(lon2d)
380 var = nc%setVariable(
"lat", dtype, dimids1(1 : 2))
382 double_precision=double_precision, add_coords=.false., standard_name=
"latitude")
383 call var%setData(lat2d)
391 allocate(x_bnds(2,
size(lon1d)))
392 allocate(y_bnds(2,
size(lat1d)))
394 x_bnds(1, :) = lon1d - half_step
395 x_bnds(2, :) = lon1d + half_step
396 y_bnds(1, :) = lat1d - half_step
397 y_bnds(2, :) = lat1d + half_step
400 nc%setDimension(
"lon",
size(lon1d)), &
401 nc%setDimension(
"lat",
size(lat1d)), &
402 nc%setDimension(
"time", 0), &
403 nc%setDimension(
"bnds", 2) &
406 var = nc%setVariable(
"lon", dtype, (/ dimids1(1) /))
408 add_coords=.false., standard_name=
"longitude", axis=
"X", bounds=
"lon_bnds")
409 call var%setData(lon1d)
410 var = nc%setVariable(
"lon_bnds", dtype, (/ dimids1(4), dimids1(1) /))
411 call var%setData(x_bnds)
413 var = nc%setVariable(
"lat", dtype, (/ dimids1(2) /))
415 add_coords=.false., standard_name=
"latitude", axis=
"Y", bounds=
"lat_bnds")
416 call var%setData(lat1d)
417 var = nc%setVariable(
"lat_bnds", dtype, (/ dimids1(4), dimids1(2) /))
418 call var%setData(y_bnds)
424 call dec2date(real(
evalper(idomain)%julStart, dp), dd = day, mm = month, yy = year)
427 if ( (outputs_frequence > 0) &
428 .and. (mod(
timestep * outputs_frequence, 2) == 1) &
429 .and. (time_reference == 1) &
431 write(unit,
"('minutes since ', i4, '-' ,i2.2, '-', i2.2, 1x, '00:00:00')") year, month, day
433 write(unit,
"('hours since ', i4, '-' ,i2.2, '-', i2.2, 1x, '00:00:00')") year, month, day
437 var = nc%setVariable(
"time",
"i32", (/ dimids1(3) /))
438 call set_attributes(var,
"time", unit=unit, add_coords=.false., standard_name=
"time", axis=
"T", bounds=
"time_bnds")
439 var = nc%setVariable(
"time_bnds",
"i32", (/ dimids1(4), dimids1(3) /))
442 call date_and_time(date = date, time = time)
443 write(datetime,
"(a4,'-',a2,'-',a2,1x,a2,':',a2,':',a2)") date(1 : 4), &
444 date(5 : 6), date(7 : 8), time(1 : 2), time(3 : 4), time(5 : 6)
450 call nc%setAttribute(
"contact",
contact)
451 call nc%setAttribute(
"mHM_details", trim(
mhm_details) //
", release mHMv" // trim(
version))
452 call nc%setAttribute(
"history", trim(datetime) //
", " //
history)
454 call nc%setAttribute(
"creation_date", datetime)