我正在尝试使用我自己的 .csv 文件中的数据来创建使用 R 包“ncdf4”的 netCDF 文件。我的数据集由 3 列组成:经度、纬度和温度,有 2592 行。我一直在按照包中的建议将维度和变量添加到 netCDF 文件中。一切都很好,直到我想在我的文件上写入温度数据。我收到此错误:
Error in ncvar_put(nc = ncnew, varid = var_temp, data, start = c(1, 1, :
ncvar_put: error: you asked to write 65160 values, but the passed data
array only has 2592 entries!
Run Code Online (Sandbox Code Playgroud)
怎么了?
library(ncdf)
library(ncdf4)
TimeTable<-read.csv("time.csv",header=T,sep=",")
filename="time.nc"
xvals<-1:360
yvals<--90:90
nx<-length(xvals)
ny<-length(yvals)
lon1<-ncdim_def("longitude","degrees_east",xvals)
lat2<-ncdim_def("latitude", "degrees_north",yvals )
time<-ncdim_def("Time","months", 1:12, unlim=T )
mv <- -999 # missing value to use
var_temp<- ncvar_def("temperature", "celsius", list(lon1, lat2, time),longname="CRU_Global_1961-1990_Mean_Monthly_Surface_Temperature_Climatology",mv)
ncnew<-nc_create(filename,list(var_temp))
print(paste("The file has",ncnew$nvars,"variables"))#
print(paste("The …Run Code Online (Sandbox Code Playgroud)