comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Reopen HDF5 file to add more data?
items: Re: Reopen HDF5 file to add more data?

Reopen HDF5 file to add more data?
type: item
description: Dear Folks, It appears not to be possible to add more data to an HDF5 file once the file has been closed, at least not in the IDL implementation. Is that correct? Here's a minimal example of what I'm trying to do. This triggers the error that inspires my question. Is there a way to reopen an file for writing, or do I have to read in the old archive and recopy everything to a new archive? Many thanks, David ;--- cut here for minimal example --- filename = 'testfile.h5' group = 'group' name = 'testdata' ;;; Create and close an HDF5 archive with one group and no data fid = h5f_create(filename) gid = h5g_create(fid, group) h5g_close, gid h5f_close, fid ;;; Reopen the HDF5 archive to add some data to the group fid = h5f_open(filename) gid = h5g_open(fid, group) ;;; attempt to write some data a = bindgen(640, 480) tid = h5t_idl_create(a) sid = h5s_create_simple(a.dim) did = h5d_create(gid, name, tid, sid) ;;; <-- this fails h5d_write, did, a ;;; close the file h5d_close, did h5s_close, sid h5t_close, tid h5g_close, gid h5f_close, fid
creator: dg86
date: 2015-02-09T16:25:55-00:00

Re: Reopen HDF5 file to add more data?
type: item
description: On Monday, February 9, 2015 at 5:25:56 PM UTC+1, David Grier wrote: > Dear Folks, > > It appears not to be possible to add more data to an HDF5 file once > the file has been closed, at least not in the IDL implementation. > Is that correct? > > Here's a minimal example of what I'm trying to do. This triggers > the error that inspires my question. > > Is there a way to reopen an file for writing, or do I have to read in the > old archive and recopy everything to a new archive? > > Many thanks, > > David > > ;--- cut here for minimal example --- > filename = 'testfile.h5' > group = 'group' > name = 'testdata' > > ;;; Create and close an HDF5 archive with one group and no data > fid = h5f_create(filename) > gid = h5g_create(fid, group) > h5g_close, gid > h5f_close, fid > > ;;; Reopen the HDF5 archive to add some data to the group > fid = h5f_open(filename) > gid = h5g_open(fid, group) > > ;;; attempt to write some data > a = bindgen(640, 480) > tid = h5t_idl_create(a) > sid = h5s_create_simple(a.dim) > did = h5d_create(gid, name, tid, sid) ;;; <-- this fails > h5d_write, did, a > > ;;; close the file > h5d_close, did > h5s_close, sid > h5t_close, tid > h5g_close, gid > h5f_close, fid hi David, You need to use H5D_EXTEND to increase the size of your dataset before you can append additional data. best Mark
creator: markb77
date: 2015-02-10T08:17:37-00:00

Re: Reopen HDF5 file to add more data?
type: item
description: On Tuesday, February 10, 2015 at 3:17:39 AM UTC-5, superchromix wrote: > On Monday, February 9, 2015 at 5:25:56 PM UTC+1, David Grier wrote: >> Dear Folks, >> >> It appears not to be possible to add more data to an HDF5 file once >> the file has been closed, at least not in the IDL implementation. >> Is that correct? >> >> Here's a minimal example of what I'm trying to do. This triggers >> the error that inspires my question. >> >> Is there a way to reopen an file for writing, or do I have to read in the >> old archive and recopy everything to a new archive? >> >> Many thanks, >> >> David >> >> ;--- cut here for minimal example --- >> filename = 'testfile.h5' >> group = 'group' >> name = 'testdata' >> >> ;;; Create and close an HDF5 archive with one group and no data >> fid = h5f_create(filename) >> gid = h5g_create(fid, group) >> h5g_close, gid >> h5f_close, fid >> >> ;;; Reopen the HDF5 archive to add some data to the group >> fid = h5f_open(filename) >> gid = h5g_open(fid, group) >> >> ;;; attempt to write some data >> a = bindgen(640, 480) >> tid = h5t_idl_create(a) >> sid = h5s_create_simple(a.dim) >> did = h5d_create(gid, name, tid, sid) ;;; <-- this fails >> h5d_write, did, a >> >> ;;; close the file >> h5d_close, did >> h5s_close, sid >> h5t_close, tid >> h5g_close, gid >> h5f_close, fid > > > hi David, > > You need to use H5D_EXTEND to increase the size of your dataset before you can append additional data. > > best > Mark It turns out the answer is even simpler than that. H5F_OPEN opens a file read-only by default. The /WRITE switch opens it read-write. Everything is working now! TTFN, David
creator: dg86
date: 2015-02-10T17:25:49-00:00