10 integer,
dimension(:,:),
allocatable :: lcdata
22 character(len=255),
intent(in) :: lc_file
24 character(len=255) :: sds_name
25 integer :: sd_id, sds_id, sds_index
26 integer,
dimension(2) :: start2, stride2, dims2
27 integer,
dimension(32):: dimids
28 integer :: rank,
dtype, nattrs
35 character(len=255) :: dset_name
36 character(len=255) :: attr_name
37 character(len=255) :: group_name
38 character(len=255) :: err_msg
40 status = nf90_open(lc_file, nf90_nowrite, nc_id)
41 if (status /= nf90_noerr)
then
42 print *,
"ERROR: Failed to open deepblue lut_nc4 file: ", status
46 group_name =
'LANDCOVER'
47 status = nf90_inq_ncid(nc_id, group_name, grp_id)
48 if (status /= nf90_noerr)
then
49 print *,
"ERROR: Failed to get ID of group "//
trim(group_name)//
": ", status
53 dset_name =
'VEGETATION'
54 status = nf90_inq_varid(grp_id, dset_name, dset_id)
55 if (status /= nf90_noerr)
then
56 print *,
"ERROR: Failed to get ID of dataset "//
trim(dset_name)//
": ", status
59 status = nf90_inquire_variable(grp_id, dset_id, dimids=dimids)
60 status = nf90_inquire_dimension(grp_id, dimids(1), len = dims2(1))
61 status = nf90_inquire_dimension(grp_id, dimids(2), len = dims2(2))
62 allocate(lcdata(dims2(1), dims2(2)), stat=status)
64 print *,
"ERROR: Unable to allocate lcdata array: ", status
70 status = nf90_get_var(grp_id, dset_id, lcdata, start=start2, &
71 stride=stride2, count=dims2)
72 err_msg = nf90_strerror(status)
73 if (status /= nf90_noerr)
then
74 print *,
"ERROR: Failed to read dataset "//
trim(dset_name)//
": ", status
78 status = nf90_close(nc_id)
79 if (status /= nf90_noerr)
then
80 print *,
"ERROR: Failed to close lut_nc4 file: ", status
89 integer,
intent(inout) :: status
91 deallocate(lcdata, stat=status)
93 print *,
"ERROR: Unable to deallocate land cover array: ", status
102 real,
intent(in) :: lat
103 real,
intent(in) :: lon
104 integer,
intent(inout) :: status
110 ilat = floor(lat * 20.0) + 1800 + 1
111 ilon = floor(lon * 20.0) + 3600 + 1
112 if (lon == 180.0 .AND. ilon == 3601) ilon = 1
113 if (ilat >
size(lcdata,1) .OR. ilon >
size(lcdata,2))
then
114 print *,
"ERROR: Indices out of bounds for land cover array: ", ilat, ilon
118 lc = lcdata(ilat,ilon)