0

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.

2
  • where is the write? Also what is with all the transposing? You would benefit from working carefully at each step to get rid of unneeded code. Just use [ to reorder by rows/columns Commented Sep 6, 2012 at 22:23
  • 1
    What mdsumner probably meant was something like y <- y[nrow(y):1,] to reverse the rows of matrix y. Commented Sep 7, 2012 at 11:43

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.