inputpath <- 'data/cru_ts4.05.1901.2020.tmp.dat.nc'
library(ncdf4) # package for netcdf manipulation
library(raster) # package for raster manipulation
library(rgdal) # package for geospatial analysis
library(ggplot2) # package for plotting
nc_data <- nc_open(inputpath)
#print(nc_data)
# Save the print(nc) dump to a text file
#{
#sink('ncdata.txt')
#print(nc_data)
#sink()
#}
lon <- ncvar_get(nc_data, "lon")
lat <- ncvar_get(nc_data, "lat", verbose = F)
t <- ncvar_get(nc_data, "time")
ticount <- length(t)
head(lon) # look at the first few entries in the longitude vector
###裁剪数据
#boundary = c(72,108,25,43) #TP bondary
lon_scope= which(lon == 99.75)
lat_scope = which(lat == 30.75)
start = c(lon_scope,lat_scope,1)
count = c(1,1,ticount)
stride1 = c(1,1,1)
ndvi.array <- ncvar_get(nc_data,"tmp",start,count) # store the data in a 3-dimensional array
dim(ndvi.array)