Skip to content

Commit

Permalink
workaround for C lib bug discovered in issue #485
Browse files Browse the repository at this point in the history
  • Loading branch information
jswhit committed Nov 11, 2015
1 parent 6582642 commit b5e1f34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
version 1.2.2 (not yet released)
================================
* if trying to write a unicode attribute, check to see if it exists
first, and if so, delete it and recreate it. Workaround for C
lib bug discovered in issue #485.
* support for NETCDF3_64BIT_DATA format supported in netcdf-c 4.4.0.
Similar to NETCDF3_64BIT (now NETCDF3_64BIT_OFFSET), but includes
64 bit dimensions and sizes, plus unsigned and 64 bit integer
Expand Down
10 changes: 10 additions & 0 deletions netCDF4/_netCDF4.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,8 @@ cdef _get_full_format(int grpid):
cdef _set_att(grp, int varid, name, value, nc_type xtype=-99):
# Private function to set an attribute name/value pair
cdef int i, ierr, lenarr, n
cdef size_t att_len
cdef nc_type att_type
cdef char *attname
cdef char *datstring
cdef ndarray value_arr
Expand Down Expand Up @@ -1216,6 +1218,14 @@ cdef _set_att(grp, int varid, name, value, nc_type xtype=-99):
# write null byte
lenarr=1; datstring = '\x00'
if value_arr.dtype.char == 'U' and not is_netcdf3:
# check to see if attribute already
# exists, if so delete it and re-create it
# (workaround for issue #485).
ierr = nc_inq_att(grp._grpid, varid, attname, &att_type, &att_len)
if ierr == NC_NOERR:
ierr = nc_del_att(grp._grpid, varid, attname)
if ierr != NC_NOERR:
raise RuntimeError((<char *>nc_strerror(ierr)).decode('ascii'))
# a unicode string, use put_att_string (if NETCDF4 file).
ierr = nc_put_att_string(grp._grpid, varid, attname, 1, &datstring)
else:
Expand Down

0 comments on commit b5e1f34

Please sign in to comment.