[SciPy-User] help! strange netCDF output

Ryan May rmay31@gmail....
Fri Nov 12 15:24:59 CST 2010

On Fri, Nov 12, 2010 at 2:31 PM, Neil Berg <nberg@atmos.ucla.edu> wrote:
>> 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.

'i' is short for 'int', but this normally has a size of 4. You were
probably thinking 'short int' when you thought of int, which has a
code of 'h'.


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

More information about the SciPy-User mailing list