[Nexus] 2D character arrays in python binding?

Akeroyd, FA (Freddie) freddie.akeroyd at stfc.ac.uk
Thu Jan 29 15:44:33 GMT 2009


Carlos,

The 4.2 release candidate of the NeXus API supports two dimensional
character arrays for HDF4 and HDF5 - XML might suffer problems if there
are embedded newlines etc. The API is expecting a square array of
characters i.e. it will not pad short strings with spaces. I got the
python API to work by using:

{{{
filenames=['bar1      ','longerbar2','bar3      ']
...
f.makedata('filenames','char',[3,10])
f.opendata('filenames')
f.putdata(''.join(filenames))
...
}}}  

However it should be possible for us to get the python API to spot a
string list and do the necessary space padding and joining for you
automatically.

Regards,

Freddie

> -----Original Message-----
> From: nexus-bounces at nexusformat.org [mailto:nexus-
> bounces at nexusformat.org] On Behalf Of Carlos Pascual Izarra
> Sent: 28 January 2009 10:16
> To: nexus at nexusformat.org
> Subject: [Nexus] 2D character arrays in python binding?
> 
> Hello,
> After reading the lists and the python binding source code I am still
> not
> sure: is it possible to write 2D character arrays with the python
> binding?
> (other than manually converting the array to "uint8" and back when
> reading)
> 
> I've tried doing:
> 
> {{{
> filenames=['bar1','longerbar2','bar3']
> ...
> f.makedata('filenames','char',[3,32])
> f.opendata('filenames')
> f.putdata(filenames)
> ...
> }}}
> 
> but I get:
> {{{
> ValueError: Expected character data: foo.h5(entry/data/filenames)
> }}}
> 
> 
> I also tried putting the data row by row with putslab, replacing the
> putdata
> line with:
> {{{
> for i in range(3): f.putslab(filenames[i],[i,0],[1,32])
> }}}
> 
> In which case it does not raise an exception, but:
> a) it stores the data using dtype=uint8
> b) It stores garbage from contiguous memory (i.e. it does not pad the
> strings
> to fill the given shape)
> 
> Cheers,
> 
> Carlos Pascual
> 
> _______________________________________________
> NeXus mailing list
> NeXus at nexusformat.org
> http://lists.nexusformat.org/mailman/listinfo/nexus
-- 
Scanned by iCritical.



More information about the NeXus mailing list