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
On Mon, Sep 12, 2011 at 1:32 PM, Claudia Stocker <cstocker at climate.unibe.ch> wrote:> 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(): > >[...code omitted...]> 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..Hi Claudia, could you put the following code in right before the put.var.ncdf call and see what it prints: print(paste('num of NAs in time:", sum(is.na(dim.time)) )) print(paste("length of time:", length(dim.time) )) print(paste("num of NAs in spi24.me:", sum(is.na(spi24.me)) )) print(paste("length of spi24.me:", length(spi24.me) )) If that doesn't show anything wrong, you can email me the data and your code and I can give it a try. Or, you can try the newest version of the ncdf/ncdf4 packages, which you can download from: http://cirrus.ucsd.edu/~pierce/ncdf/ it may be a bug that I've already fixed. Regards, --Dave -- David W. Pierce Division of Climate, Atmospheric Science, and Physical Oceanography Scripps Institution of Oceanography (858) 534-8276 (voice) ?/ ?(858) 534-8561 (fax) ? ?dpierce at ucsd.edu