Mercurial > hg > octave-lojdl
changeset 4814:495e9df75836
[project @ 2004-03-03 23:46:38 by jwe]
author | jwe |
---|---|
date | Wed, 03 Mar 2004 23:46:38 +0000 |
parents | fba5c6e96e0f |
children | 2eb844b27953 |
files | src/ChangeLog src/ov-cell.cc |
diffstat | 2 files changed, 56 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-03-03 David Bateman <dbateman@free.fr> + + * ov-cell.cc (octave_cell::save_hdf5, octave_cell::load_hdf5): + Make N-d aware. + 2004-03-03 John W. Eaton <jwe@bevo.che.wisc.edu> * parse.y: Delete spaces surrounding = in %name-prefix directive.
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -690,21 +690,29 @@ bool octave_cell::save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats) { - hsize_t dimens[3]; + dim_vector dv = dims (); + hsize_t rank = dv.length(); hid_t space_hid = -1, data_hid = -1, size_hid = -1; data_hid = H5Gcreate (loc_id, name, 0); if (data_hid < 0) return false; - // Have to save rows/columns since can't have a dataset of groups.... - space_hid = H5Screate_simple (0, dimens, (hsize_t*) 0); + // Have to save cell array shape, since can't have a + // dataset of groups.... + space_hid = H5Screate_simple (1, &rank, (hsize_t*) 0); if (space_hid < 0) { H5Gclose (data_hid); return false; } - size_hid = H5Dcreate (data_hid, "rows", H5T_NATIVE_INT, space_hid, + OCTAVE_LOCAL_BUFFER (int, hdims, rank); + + // Octave uses column-major, while HDF5 uses row-major ordering + for (int i = 0; i < (int)rank; i++) + hdims[i] = dv (rank-i-1); + + size_hid = H5Dcreate (data_hid, "dims", H5T_NATIVE_INT, space_hid, H5P_DEFAULT); if (size_hid < 0) { @@ -713,29 +721,8 @@ return false; } - int rc = rows(); if (! H5Dwrite (size_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, (void*) &rc) < 0) - { - H5Dclose (size_hid); - H5Sclose (space_hid); - H5Gclose (data_hid); - return false; - } - H5Dclose (size_hid); - - size_hid = H5Dcreate (data_hid, "columns", H5T_NATIVE_INT, space_hid, - H5P_DEFAULT); - if (size_hid < 0) - { - H5Sclose (space_hid); - H5Gclose (data_hid); - return false; - } - - rc = columns(); - if (! H5Dwrite (size_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, (void*) &rc) < 0) + H5P_DEFAULT, (void*) hdims) < 0) { H5Dclose (size_hid); H5Sclose (space_hid); @@ -748,19 +735,16 @@ // recursively add each element of the cell to this group Cell tmp = cell_value (); - for (int j = 0; j < tmp.cols (); j++) + for (int i = 0; i < dv.numel (); i++) { - for (int i = 0; i < tmp.rows (); i++) - { - char s[20]; - sprintf (s, "_%d", (i + j * tmp.rows ())); + char s[20]; + sprintf (s, "_%d", i); - if (! add_hdf5_data(data_hid, tmp.elem (i, j), s, "", false, - save_as_floats)) - { - H5Gclose (data_hid); - return false; - } + if (! add_hdf5_data(data_hid, tmp.elem (i), s, "", false, + save_as_floats)) + { + H5Gclose (data_hid); + return false; } } @@ -778,39 +762,27 @@ if (group_id < 0) return false; - hid_t data_hid = H5Dopen (group_id, "rows"); + hid_t data_hid = H5Dopen (group_id, "dims"); hid_t space_hid = H5Dget_space (data_hid); hsize_t rank = H5Sget_simple_extent_ndims (space_hid); - if (rank != 0) + if (rank != 1) { H5Dclose(data_hid); H5Gclose(group_id); return false; } - int nr; - if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, (void *) &nr) < 0) - { - H5Dclose(data_hid); - H5Gclose(group_id); - return false; - } - H5Dclose (data_hid); + OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); + OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); + H5Sget_simple_extent_dims (space_hid, hdims, maxdims); - data_hid = H5Dopen (group_id, "columns"); - space_hid = H5Dget_space (data_hid); - rank = H5Sget_simple_extent_ndims (space_hid); - if (rank != 0) - { - H5Dclose(data_hid); - H5Gclose(group_id); - return false; - } - - int nc; + // Octave uses column-major, while HDF5 uses row-major ordering + dim_vector dv; + dv.resize (hdims[0]); + OCTAVE_LOCAL_BUFFER (int, tmp, hdims[0]); + if (H5Dread (data_hid, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, (void *) &nc) < 0) + H5P_DEFAULT, (void *) tmp) < 0) { H5Dclose(data_hid); H5Gclose(group_id); @@ -819,44 +791,42 @@ H5Dclose (data_hid); H5Gclose (group_id); + for (int i = 0, j = hdims[0] - 1; i < (int)hdims[0]; i++, j--) + dv(j) = tmp[i]; + hdf5_callback_data dsub; herr_t retval2 = -1; - Cell m (nr, nc); + Cell m (dv); int current_item = 0; if (have_h5giterate_bug) - current_item = 2; // Skip row/columns items in group + current_item = 1; // Skip dims items in group #ifdef HAVE_H5GGET_NUM_OBJS hsize_t num_obj = 0; H5Gget_num_objs (loc_id, &num_obj); #endif - for (int j = 0; j < nc; j++) + for (int i = 0; i < dv.numel (); i++) { - for (int i = 0; i < nr; i++) - { #ifdef HAVE_H5GGET_NUM_OBJS - if (current_item >= static_cast<int> (num_obj)) - retval2 = -1; - else + if (current_item >= static_cast<int> (num_obj)) + retval2 = -1; + else #endif - retval2 = H5Giterate (loc_id, name, ¤t_item, - hdf5_read_next_data, &dsub); - - if (retval2 <= 0) - break; - - octave_value ov = dsub.tc; - m.elem (i, j) = ov; - - if (have_h5giterate_bug) - current_item++; // H5Giterate returned the last index processed - - } + retval2 = H5Giterate (loc_id, name, ¤t_item, + hdf5_read_next_data, &dsub); + if (retval2 <= 0) break; + + octave_value ov = dsub.tc; + m.elem (i) = ov; + + if (have_h5giterate_bug) + current_item++; // H5Giterate returned the last index processed + } if (retval2 >= 0)