00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if !defined (octave_ls_hdf5_h)
00024 #define octave_ls_hdf5_h 1
00025
00026 #if defined (HAVE_HDF5)
00027
00028 #include "oct-hdf5.h"
00029
00030
00031
00032
00033
00034
00035
00036 class hdf5_fstreambase : virtual public std::ios
00037 {
00038 public:
00039
00040
00041 hid_t file_id;
00042
00043
00044 int current_item;
00045
00046 hdf5_fstreambase () : file_id (-1), current_item () { }
00047
00048 ~hdf5_fstreambase () { close (); }
00049
00050 hdf5_fstreambase (const char *name, int mode, int = 0)
00051 : file_id (-1), current_item (-1)
00052 {
00053 if (mode & std::ios::in)
00054 file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT);
00055 else if (mode & std::ios::out)
00056 {
00057 if (mode & std::ios::app && H5Fis_hdf5 (name) > 0)
00058 file_id = H5Fopen (name, H5F_ACC_RDWR, H5P_DEFAULT);
00059 else
00060 file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT,
00061 H5P_DEFAULT);
00062 }
00063 if (file_id < 0)
00064 std::ios::setstate (std::ios::badbit);
00065
00066 current_item = 0;
00067 }
00068
00069 void close ()
00070 {
00071 if (file_id >= 0)
00072 {
00073 if (H5Fclose (file_id) < 0)
00074 std::ios::setstate (std::ios::badbit);
00075 file_id = -1;
00076 }
00077 }
00078
00079 void open (const char *name, int mode, int)
00080 {
00081 clear ();
00082
00083 if (mode & std::ios::in)
00084 file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT);
00085 else if (mode & std::ios::out)
00086 {
00087 if (mode & std::ios::app && H5Fis_hdf5 (name) > 0)
00088 file_id = H5Fopen (name, H5F_ACC_RDWR, H5P_DEFAULT);
00089 else
00090 file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT,
00091 H5P_DEFAULT);
00092 }
00093 if (file_id < 0)
00094 std::ios::setstate (std::ios::badbit);
00095
00096 current_item = 0;
00097 }
00098 };
00099
00100
00101
00102
00103 class hdf5_ifstream : public hdf5_fstreambase, public std::istream
00104 {
00105 public:
00106
00107 hdf5_ifstream () : hdf5_fstreambase (), std::istream (0) { }
00108
00109 hdf5_ifstream (const char *name, int mode = std::ios::in|std::ios::binary,
00110 int prot = 0)
00111 : hdf5_fstreambase (name, mode, prot), std::istream (0) { }
00112
00113 void open (const char *name, int mode = std::ios::in|std::ios::binary,
00114 int prot = 0)
00115 { hdf5_fstreambase::open (name, mode, prot); }
00116 };
00117
00118 class hdf5_ofstream : public hdf5_fstreambase, public std::ostream
00119 {
00120 public:
00121
00122 hdf5_ofstream () : hdf5_fstreambase (), std::ostream (0) { }
00123
00124 hdf5_ofstream (const char *name, int mode = std::ios::out|std::ios::binary,
00125 int prot = 0)
00126 : hdf5_fstreambase (name, mode, prot), std::ostream (0) { }
00127
00128 void open (const char *name, int mode = std::ios::out|std::ios::binary,
00129 int prot = 0)
00130 { hdf5_fstreambase::open (name, mode, prot); }
00131 };
00132
00133
00134
00135 struct
00136 hdf5_callback_data
00137 {
00138 hdf5_callback_data (void)
00139 : name (), global (false), tc (), doc () { }
00140
00141
00142
00143
00144 std::string name;
00145
00146
00147 bool global;
00148
00149
00150 octave_value tc;
00151
00152
00153 std::string doc;
00154 };
00155
00156 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS
00157 extern OCTINTERP_API hid_t
00158 save_type_to_hdf5 (save_type st)
00159 #endif
00160
00161 extern OCTINTERP_API hid_t
00162 hdf5_make_complex_type (hid_t num_type);
00163
00164 extern OCTINTERP_API bool
00165 hdf5_types_compatible (hid_t t1, hid_t t2);
00166
00167 extern OCTINTERP_API herr_t
00168 hdf5_read_next_data (hid_t group_id, const char *name, void *dv);
00169
00170 extern OCTINTERP_API bool
00171 add_hdf5_data (hid_t loc_id, const octave_value& tc,
00172 const std::string& name, const std::string& doc,
00173 bool mark_as_global, bool save_as_floats);
00174
00175 extern OCTINTERP_API int
00176 save_hdf5_empty (hid_t loc_id, const char *name, const dim_vector d);
00177
00178 extern OCTINTERP_API int
00179 load_hdf5_empty (hid_t loc_id, const char *name, dim_vector &d);
00180
00181 extern OCTINTERP_API std::string
00182 read_hdf5_data (std::istream& is, const std::string& filename, bool& global,
00183 octave_value& tc, std::string& doc);
00184
00185 extern OCTINTERP_API bool
00186 save_hdf5_data (std::ostream& os, const octave_value& tc,
00187 const std::string& name, const std::string& doc,
00188 bool mark_as_global, bool save_as_floats);
00189
00190 extern OCTINTERP_API bool
00191 hdf5_check_attr (hid_t loc_id, const char *attr_name);
00192
00193 extern OCTINTERP_API bool
00194 hdf5_get_scalar_attr (hid_t loc_id, hid_t type_id, const char *attr_name,
00195 void *buf);
00196
00197 extern OCTINTERP_API herr_t
00198 hdf5_add_attr (hid_t loc_id, const char *attr_name);
00199
00200
00201 extern OCTINTERP_API herr_t
00202 hdf5_add_scalar_attr (hid_t loc_id, hid_t type_id,
00203 const char *attr_name, void *buf);
00204
00205 #ifdef IDX_TYPE_LONG
00206 #define H5T_NATIVE_IDX H5T_NATIVE_LONG
00207 #else
00208 #define H5T_NATIVE_IDX H5T_NATIVE_INT
00209 #endif
00210
00211 #endif
00212
00213 #endif