sacvf
sacvf

Reputation: 2533

How to write a binary filefrom a netcdf file?

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.

Upvotes: 0

Views: 786

Answers (1)

MvG
MvG

Reputation: 60868

You requested a reverse orientation yourself, by specifying ylim=c(1,0). Simply change that last line to

image(y)

and 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 had NA (Not Available). Undoing this modification yields completely identical data:

y[is.nan(y)] <- NA

After this, y becomes indistinguishable from land.

Upvotes: 1

Related Questions