[SciPy-User] help! strange netCDF output

Neil Berg nberg@atmos.ucla....
Fri Nov 12 14:31:29 CST 2010

> This is a bug I hit awhile back in pupynere (on which scipy's netcdf
> support is based). Basically, the python netcdf library maps the 'l'
> type to NC_INT. However, at least on 64-bit machines, this is a
> problem:

Good to know.  I am running a 64-bit macbook pro.

> So if you use a dtype of 'l', it's creating int64's. However, NetCDF
> only supports NC_INT, which always has a size of 4. Somewhere in
> there, your array is cast to 8-byte integers. When the netcdf library
> goes to write them out, it does (effectively) a basic pointer cast, so
> that each of those int64's becomes 2 int32's. Since your original data
> were in the range of int32's, the extra byte created in moving to an
> int64 just contains 0's, which get written out.
> You could probably use a typecode of 'i', which gives you regular
> int32's. This would be more space efficient than using a double for a
> value with only 4 digits.

Yes, using the typecode 'i' also cured the output issue.  I thought that 'i' was simply short for 'int', which is why I didn't try this in the first place.  Anyways, I'll stick with 'i' and appreciate the help. 


More information about the SciPy-User mailing list