Tony Hill kindly reported a bug in the handling of NC_CHAR arrays under numpy. This patch fixes this. The following code now works as expected :
from pycdf import pycdf
output = CDF('file.nc',NC.WRITE|NC.CREATE|NC.TRUNC)
output.automode()
tdim = output.def_dim('testdim1',4)
tvar = output.def_var('testvar1',NC.CHAR,[tdim])
tvar.put('Test')
v = ''.join(tvar[:].tolist())
assert v == 'Test'
tvar[:] = '1234'
v = ''.join(tvar[:].tolist())
assert v == '1234'
To apply the patch, get the pycdf-0.6-3b.tar.gz distribution and the pycdf-0.6-3c.patch file, then execute :
tar xfz pycdf-0.6-3b.tar.gz
cd pycdf-0.6-3b
patch -p1 < ../pycdf-0.6-3c.patch
Enjoy!
patch file to correct bad handling of NC_CHAR arrays under numpy