56 use netcdf,
only: nf90_char, nf90_global, nf90_int, nf90_netcdf4, nf90_real,&
57 nf90_unlimited, nf90_def_dim, nf90_put_att, nf90_put_var, &
58 nf90_create, nf90_def_var, nf90_enddef
65 INTEGER,
INTENT(in) :: nspc
67 INTEGER,
dimension(:) :: dimYeSpXY(4), dimLimits(3)
68 INTEGER :: dimId_year, dimId_speciesLength,dimId_species, dimId_x, dimId_y, dimId_hc, dimId_lc
69 INTEGER :: varId_year,varId_species, varId_x, varId_y, varId_crs, varId_hc, varId_lc
74 INTEGER :: years(numyrs)
75 INTEGER :: species(nspc+1)
76 INTEGER :: hc(maxhc+1)
79 INTEGER :: i, numReportYears, actualYear, rpti
81 character*6:: yearChar
86 character*25 :: dateTimeString
96 call date_and_time(zone=zone,
values= date_time)
97 write(datetimestring,
'(I4.4,"-",2(I2.2,"-"),"T",2(I2.2,":"),I2.2,A5)') date_time(1),date_time(2),&
98 date_time(3), date_time(5), date_time(6), date_time(7), zone
100 call m_check(nf90_put_att(
nc_file_id, nf90_global ,
"title",
"TreeMig model output"), __line__,__file__)
102 "Swiss Federal Institute for Forest, Snow and Landscape Research WSL"), __line__,__file__)
104 call m_check(nf90_put_att(
nc_file_id, nf90_global ,
"institute_id",
"WSL"), __line__,__file__)
106 call m_check(nf90_put_att(
nc_file_id, nf90_global ,
"model_id",
"TreeMig"), __line__,__file__)
107 call m_check(nf90_put_att(
nc_file_id, nf90_global ,
"contact",
"maintainer_treemig@wsl.ch"),&
110 call m_check(nf90_put_att(
nc_file_id, nf90_global ,
"reference",
"TreeMig model described by Lischke et al., "&
111 "2006 (https://www.dora.lib4ri.ch/wsl/islandora/object/wsl%3A6049)"), __line__,__file__)
112 call m_check(nf90_put_att(
nc_file_id, nf90_global ,
"treeMig_version",
"0.0.1"), __line__,__file__)
113 call m_check(nf90_put_att(
nc_file_id, nf90_global ,
"conventions",
"CF-1.10"), __line__,__file__)
114 call m_check(nf90_put_att(
nc_file_id, nf90_global ,
"creation_date", datetimestring),&
120 call m_check(nf90_def_dim(
nc_file_id,
"time", nf90_unlimited, dimid_year), __line__,__file__)
123 call m_check(nf90_def_dim(
nc_file_id,
"species", nspc+1, dimid_species), __line__,__file__)
128 call m_check(nf90_def_dim(
nc_file_id,
"string80", 80, dimid_specieslength), __line__,__file__)
131 call m_check(nf90_def_var(
nc_file_id,
"time", nf90_int, dimid_year,varid_year), __line__,__file__)
135 call m_check(nf90_put_att(
nc_file_id, varid_year,
"axis",
"T"), __line__,__file__)
136 call m_check(nf90_put_att(
nc_file_id, varid_year,
"long_name",
"time"), __line__,__file__)
137 call m_check(nf90_put_att(
nc_file_id, varid_year,
"standard_name",
"time"), __line__,__file__)
139 call m_check(nf90_put_att(
nc_file_id, varid_year,
"units",
"years since "//trim(yearchar)//
"-1-1 0:0:0"),&
144 (/ dimid_specieslength, dimid_species /), varid_species),&
147 call m_check(nf90_def_var(
nc_file_id,
"x", nf90_real, dimid_x, varid_x), __line__,__file__)
148 call m_check(nf90_put_att(
nc_file_id, varid_x,
"standard_name",
"projection_x_coordinate"),&
150 call m_check(nf90_put_att(
nc_file_id, varid_x,
"long_name",
"x coordinate of projection"),&
155 call m_check(nf90_def_var(
nc_file_id,
"y", nf90_real, dimid_y, varid_y),__line__,__file__)
156 call m_check(nf90_put_att(
nc_file_id, varid_y,
"standard_name",
"projection_y_coordinate"),&
158 call m_check(nf90_put_att(
nc_file_id, varid_y,
"long_name",
"y coordinate of projection"),&
163 call m_check(nf90_def_var(
nc_file_id,
"crs", nf90_int, [
INTEGER::], varId_crs),__LINE__,__FILE__)
167 dimyespxy(1:4) = (/ dimid_year,dimid_species, dimid_x, dimid_y /)
173 dimlimits(1:3) = (/nspc+1,maxlon, maxlat/)
199 call m_check(nf90_def_dim(
nc_file_id,
"hc", maxhc+1, dimid_hc),__line__,__file__)
214 call initncvar(
light_nc, 4, (/ dimid_year,dimid_hc, dimid_lc, dimid_x, dimid_y /),&
215 (/maxhc+1,maxlc,maxlon, maxlat/))
241 years(numreportyears+1) = actualyear
242 numreportyears = numreportyears+1
256 call m_check( nf90_put_var(
nc_file_id, varid_year, years(1:numreportyears)), __line__,__file__)
291 use,
intrinsic :: iso_fortran_env
292 use,
intrinsic :: ieee_arithmetic
298 TYPE(
ncvar),
INTENT(inout) :: var
299 INTEGER,
dimension(:),
INTENT(in) :: NCDims
300 INTEGER,
INTENT(in) :: numDims
301 INTEGER,
dimension(:),
INTENT(in) :: limits
305 character (len=500) :: errormsg
306 fillval = ieee_value(fillval, ieee_quiet_nan)
308 call m_check(nf90_def_var(
nc_file_id, var%name, nf90_real, ncdims, var%varId, deflate_level = 4),&
311 call m_check(nf90_put_att(
nc_file_id, var%varId,
"_FillValue", fillval), __line__,__file__)
314 call m_check(nf90_put_att(
nc_file_id, var%varId,
"units", var%attr_unit), __line__,__file__)
318 select case (numdims)
320 allocate (var%values4D(1:limits(1), 1:limits(2), 1:limits(3), 1:limits(4)), stat=alloc_st, errmsg=errormsg)
321 var%values4D = fillval
323 allocate (var%values3D(1:limits(1), 1:limits(2), 1:limits(3)), stat=alloc_st, errmsg=errormsg)
324 var%values3D = fillval
326 allocate (var%values2D(1:limits(1), 1:limits(2)), stat=alloc_st, errmsg=errormsg)
327 var%values2D = fillval
329 call logerror(
"Invalid number of NETCDF dimensions")
333 call checkalloc(alloc_st, errormsg, var%name//
" Output")