我想读取两个 netcdf 文件(两年的气候数据)并将一个网格(lon [15] 和 lat[15])的数据组合到一个数组(名为 prec_year),脚本如下。
我收到一个错误:
"Error in R_nc_get_vara_double: NetCDF: Index exceeds dimension bound
Var: precip Ndims: 3 Start: 0,4294967284,59Count: 366,1,1Error in get.var.ncdf (ex.nc, "precip", start = c(lon[1], lat[15], 1), :
C 函数 R_nc_get_vara_double 返回错误"
但是当我不指定 lat[],例如说“start = c(lon[1], 1,1)”时,它工作得很好。请帮助(1)为什么我得到这个错误,以及(2)如何解决它?
非常感谢!--------------------
setwd ("D://Historic Climate data/Aphrodyte/Prec_025/join 2 years")
Prec_origin <- c(1:2)
filenames <- list.files(pattern = NULL, all.files = FALSE)
for(i in filenames){
filepath <- file.path("D://Historic Climate data/Aphrodyte/Prec_025/join 2 years/",paste (i,sep=""))
ex.nc = open.ncdf (filepath, readunlim=FALSE)
lon = get.var.ncdf( ex.nc, "longitude") # coordinate variable
lat = get.var.ncdf( ex.nc, "latitude") # coordinate variable
day = get.var.ncdf( ex.nc, "time") # time variable
#change lon[x] and lat[y] to select different files/locations for comparison
prec_year = get.var.ncdf(ex.nc, "precip", start = c(lon[1],lat[15],1), count = c(1,1,-1))
Prec_origin <- c(Prec_origin, prec_year) #combine all data into one array
close.ncdf (ex.nc)
}
Prec_origin <- Prec_origin[-(1:2)] # delete first two rows-
--------------
[1] "file D://Historic Climate data/Aphrodyte/Prec_025/join 2 years//APHRO_MA_025deg_V1003R1.1952.nc has 3 dimensions:"
[1] "time Size: 366"
[1] "longitude Size: 360"
[1] "latitude Size: 280"
[1] "------------------------"
[1] "file D://Historic Climate data/Aphrodyte/Prec_025/join 2 years//APHRO_MA_025deg_V1003R1.1952.nc has 2 variables:"
[1] "float precip[longitude,latitude,time] Longname:daily precipitation analysis interpolated onto 0.25deg grids [mm/day] Missval:-99.9000015258789"
[1] "float rstn[longitude,latitude,time] Longname:ratio of 0.05deg-grids with station [%] Missval:-99.9000015258789"