I would like to write a binary file from a netcdf file
library(ncdf)
download.file("http://gswp/Fixed/SoilDepth.nc", destfile="SoilDepth.nc")
soil <- open.ncdf("SoilDepth.nc")
soil$var[[3]] -> var3
get.var.ncdf(soil, var3) -> SoilDepth
download.file("http://gswp/Fixed/landmask_gswp.nc", destfile="landmask.nc")
landmask <- open.ncdf("landmask.nc")
landmask$var[[3]] -> varland
get.var.ncdf(landmask, varland) -> land
land = t(land)
land[land==1] <- SoilDepth
land[land==0] <- NA
land = t(land)
image(land)
the result of This code will look like:![map of soil][1]
Now I want to write it to a binary file:
The result is an image upside down.
You requested a reverse orientation yourself, by specifying
ylim=c(1,0). Simply change that last line toand you’ll be fine, as the double transpose does nothing except eat resources.
Further information: The only difference between the original and the re-read data is the fact that the latter has
NaN(i.e. Not a Number) in the places where the former hadNA(Not Available). Undoing this modification yields completely identical data:After this,
ybecomes indistinguishable fromland.