[R] Problem with creation of netcdf file

Claudio Stefanini stefac88 at gmail.com
Fri Oct 28 13:14:50 CEST 2016

Hello everyone!
I have a weird problem with the netcdf format: I want to save part of 
the lon-lat matrix "radar_ok_final" as .nc file, so I select the first 
271 columns (corrensponding to the first 271 values in the longitude 
vector "Longvector") and I get this plot from the netcdf file that I create:


But if I select only the first 270 columns (and of course I modify 
"Longvector" in Longvector = lon_new_mosaico[c(1:270)]) I get this 
strange plot, translated and distorted, instead of the same plot above 
without the last column of data. Why?


here is my code: # data
radar_ok_final <- radarok_mosaico[,c(1:271)] # then I change to c(1:270)
# write the ncdf files
Longvector = lon_new_mosaico[c(1:271)] # then I change to c(1:270)
Latvector = lat_new_mosaico
# Define the dimensions
dimX = ncdim_def("Long", "degreesE", Longvector)
dimY = ncdim_def("Lat", "degreesN", Latvector)
# Define missing value
mv = NA
# Define the data
var2d = ncvar_def("dBZ", "units", list(dimX,dimY), mv, prec="double", 
# Create the NetCDF file
# If you want a NetCDF4 file, explicitly add force_v4=T
nc = nc_create(paste("/home/radarmeteo.com/data_archive/",year, month, 
day,"/Mosaico/Radar_mosaico_",year, month, day,"_",hour, minutes1,".nc", 
sep=""), list(var2d), force_v4=T)
# Write data to the NetCDF file
ncvar_put(nc, var2d, matrix(radar_ok_final, nrow=length(Latvector), 
# Close your new file to finish writing

Thank you very much for the help!

More information about the R-help mailing list