[R] Problem in put.var.ncdf
Claudia Stocker
cstocker at climate.unibe.ch
Mon Sep 12 22:32:24 CEST 2011
Dear all,
I have a problem in writing a variable to a NetCDF-File.
My code works pretty well until the step put.var.ncdf():
# Get variables
#---------------------
data1 <- open.ncdf("PREC_me_03-1500.nc")
prec1 <- get.var.ncdf(data1,"PRECT")
dim.time <- get.var.ncdf(data1,"time2")
close.ncdf(data1)
# Calculation
#---------------------
spi24.me <- spi.func(prec1)
--> spi24.me is a vector with 437270 values, ranging from -4 to 4 with 10
decimal places.
# Save as NetCDF
#---------------------
dim.time.spi <- dim.def.ncdf("time", "days since 1499-01-01 00:00:00",
dim.time)
var.spi.24.03.me <- var.def.ncdf("spi03_24_me", "unitless", dim.time.spi,
0, longname="SPI tr_1500_03 24mt MA", prec="float")
spi <- create.ncdf("spi_regions_03.nc", var.spi.24.03.me)
put.var.ncdf(spi, var.spi.24.03.me, spi24.me)
close.ncdf(spi)
R prints the following error:
#---------------------
Error in put.var.ncdf(spi, var.spi.24.03.me, spi24.me) : NA/NaN/Inf in
foreign function call (arg 5)
I can exclude an error in length (dim.time.spi and spi24.me have the same
length) or NA (there are no NA in the spi24.me vector). Where is the
error?? The code seems so simple..
I found a similar post of Sashi Challa on Thu, 04 Nov 2010 22:09:23 -0700,
but there was unfortunately no answer.
Thanks your help!
claudia
More information about the R-help
mailing list