I am trying to use the data on my own .csv file to create a netCDF file using the R package "ncdf4". My dataset is composed by 3 columns: longitude, latitude and temperature and it has 2592 rows. I have been following the suggestions in the package to add the dimension and the variables to the netCDF file. Everything is fin until I want to write the temperature data on my file. I got this error:
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!
What's wrong?
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 file has",ncnew$ndim,"dimensions"))#
data<-array(TimeTable$tem_1)
ncvar_put( nc=ncnew, varid=var_temp,data,start=c(1,1,1),count=c(nx,ny,1))
Could you please suggest me something? Many thanks