[R-SIG-Mac] Problem with netcdf4 library provided with ncdf4 for R on osx

Roy Mendelssohn - NOAA Federal roy.mendelssohn at noaa.gov
Sat Feb 28 01:24:32 CET 2015

Hi All:

We stumbled on a problem with the netcdf4 library provided with the package ncdf4 on the Mac.  Here is why we feel it is due to the netcdf4 library included with the package.

First, if you install the existing package from CRAN, and try the following (this is using the OPeNDAP part):

myURL <- 'http://oceanmodeling.pmc.ucsc.edu:8080/thredds/dodsC/wc12.0_ccsra31_01/posterior/wc12_ccsra31_his_20101221_20101229.nc'

# this works, in fact works for any 2 or 3D variable
vbar<-ncvar_get(junk,”vbar", start=start, count=count)

#this segfaults and in fact will for any other of the 4D variables on that thredds server
salt<-ncvar_get(junk,"salt",start=start, count=count)

Here is where the detective work came in.  I emailed David Pierce who develops the ncdf4 package,  According to David, the library that comes with the package is generated from the CRAN computer that does the Mac packages.  When he tried the code above on his Linux machine, it worked just fine, while the code produced a segfault on two different OS machines with different versions of mac OSX.

I then built my own version of ncdf4 which linked into the netcdf4 libraries provided by the Fink project.  Same computer, same R code as above, worked just fine.

If I use the verbose option in the ncvar_get, here is the end of the output showing the segfault:

> $hasScaleFact
> [1] FALSE
> attr(,"class")
> [1] "ncvar4"
> [1] "ncvar_get: ncid2use= 65536 varid2use= 141 missval= 1e+37"
> [1] "ncvar_get_inner: entering with (C-STYLE INTEGER ONLY) ncid= 65536 varid= 141"
> [1] "ndims: 4"
> [1] "ncvar_get: varsize:"
> [1] 186 181  42  33
> [1] "ncvar_get: start:"
> [1] 1 1 1 1
> [1] "ncvar_get: count:"
> [1] 2 2 2 2
> [1] "ncvar_get: totvarsize: 16"
> [1] "ncvar_get_inner: getting var of type double id= 4"
> *** caught segfault ***
> address 0x8, cause 'memory not mapped'
> Traceback:
> 1: .Call("Rsx_nc4_get_vara_double", as.integer(ncid), as.integer(varid),     as.integer(c.start), as.integer(c.count), fixmiss, imvstate,     as.double(passed_missval), PACKAGE = "ncdf4")
> 2: ncvar_get_inner(ncid2use, varid2use, nc$var[[li]]$missval, addOffset,     scaleFact, start = start, count = count, verbose = verbose,     signedbyte = signedbyte, collapse_degen = collapse_degen)
> 3: ncvar_get(junk, "salt", start = start, count = count, verbose = TRUE)

-Roy M.

"The contents of this message do not reflect any position of the U.S. Government or NOAA."
Roy Mendelssohn
Supervisory Operations Research Analyst
Environmental Research Division
Southwest Fisheries Science Center
***Note new address and phone***
110 Shaffer Road
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: Roy.Mendelssohn at noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

More information about the R-SIG-Mac mailing list