# by: hapt library(ncdf4) filename <-"TC_freq_2010_ERA" dt.lon <- read.table("lon.list",header=F) nlon <- nrow(dt.lon) slon <- dt.lon[1,1] elon <- dt.lon[nlon,1] cint_lon <- dt.lon[2,1]-dt.lon[1,1] dt.lat <- read.table("lat.list",header=F) nlat <-nrow(dt.lat) slat <- dt.lat[1,1] elat <- dt.lat[nlat,1] cint_lat <- dt.lat[2,1]-dt.lat[1,1] lon <- as.array(seq(slon,elon,cint_lon)) lat <- as.array(seq(slat,elat,cint_lat)) data <- read.table(paste(filename,".txt",sep=""),header=F) data <- as.matrix(data) # define dimensions londim <- ncdim_def("lon","degrees_east",as.double(lon)) latdim <- ncdim_def("lat","degrees_north",as.double(lat)) # define variables dlname <- "TC_frequency" var_out<- ncvar_def("tc_freq",units="",list(londim,latdim),-9999,dlname) # create netCDF file and put arrays ncfname <- paste(filename,".nc",sep="") ncid_out <- nc_create(file=ncfname,list(var_out)) ncvar_put(ncid_out,var_out,data) nc_close(ncid_out)