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; }
00047
00048 ~hdf5_fstreambase () { close (); }
00049
00050 hdf5_fstreambase (const char *name, int mode, int = 0)
00051 {
00052 if (mode & std::ios::in)
00053 file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT);
00054 else if (mode & std::ios::out)
00055 {
00056 if (mode & std::ios::app && H5Fis_hdf5 (name) > 0)
00057 file_id = H5Fopen (name, H5F_ACC_RDWR, H5P_DEFAULT);
00058 else
00059 file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT,
00060 H5P_DEFAULT);
00061 }
00062 if (file_id < 0)
00063 std::ios::setstate (std::ios::badbit);
00064
00065 current_item = 0;
00066 }
00067
00068 void close ()
00069 {
00070 if (file_id >= 0)
00071 {
00072 if (H5Fclose (file_id) < 0)
00073 std::ios::setstate (std::ios::badbit);
00074 file_id = -1;
00075 }
00076 }
00077
00078 void open (const char *name, int mode, int)
00079 {
00080 clear ();
00081
00082 if (mode & std::ios::in)
00083 file_id = H5Fopen (name, H5F_ACC_RDONLY, H5P_DEFAULT);
00084 else if (mode & std::ios::out)
00085 {
00086 if (mode & std::ios::app && H5Fis_hdf5 (name) > 0)
00087 file_id = H5Fopen (name, H5F_ACC_RDWR, H5P_DEFAULT);
00088 else
00089 file_id = H5Fcreate (name, H5F_ACC_TRUNC, H5P_DEFAULT,
00090 H5P_DEFAULT);
00091 }
00092 if (file_id < 0)
00093 std::ios::setstate (std::ios::badbit);
00094
00095 current_item = 0;
00096 }
00097 };
00098
00099
00100
00101
00102 class hdf5_ifstream : public hdf5_fstreambase, public std::istream
00103 {
00104 public:
00105
00106 hdf5_ifstream () : hdf5_fstreambase (), std::istream (0) { }
00107
00108 hdf5_ifstream (const char *name, int mode = std::ios::in|std::ios::binary,
00109 int prot = 0)
00110 : hdf5_fstreambase (name, mode, prot), std::istream (0) { }
00111
00112 void open (const char *name, int mode = std::ios::in|std::ios::binary,
00113 int prot = 0)
00114 { hdf5_fstreambase::open (name, mode, prot); }
00115 };
00116
00117 class hdf5_ofstream : public hdf5_fstreambase, public std::ostream
00118 {
00119 public:
00120
00121 hdf5_ofstream () : hdf5_fstreambase (), std::ostream (0) { }
00122
00123 hdf5_ofstream (const char *name, int mode = std::ios::out|std::ios::binary,
00124 int prot = 0)
00125 : hdf5_fstreambase (name, mode, prot), std::ostream (0) { }
00126
00127 void open (const char *name, int mode = std::ios::out|std::ios::binary,
00128 int prot = 0)
00129 { hdf5_fstreambase::open (name, mode, prot); }
00130 };
00131
00132
00133
00134 struct
00135 hdf5_callback_data
00136 {
00137 hdf5_callback_data (void)
00138 : name (), global (false), tc (), doc () { }
00139
00140
00141
00142
00143 std::string name;
00144
00145
00146 bool global;
00147
00148
00149 octave_value tc;
00150
00151
00152 std::string doc;
00153 };
00154
00155 #if HAVE_HDF5_INT2FLOAT_CONVERSIONS
00156 extern OCTINTERP_API hid_t
00157 save_type_to_hdf5 (save_type st)
00158 #endif
00159
00160 extern OCTINTERP_API hid_t
00161 hdf5_make_complex_type (hid_t num_type);
00162
00163 extern OCTINTERP_API bool
00164 hdf5_types_compatible (hid_t t1, hid_t t2);
00165
00166 extern OCTINTERP_API herr_t
00167 hdf5_read_next_data (hid_t group_id, const char *name, void *dv);
00168
00169 extern OCTINTERP_API bool
00170 add_hdf5_data (hid_t loc_id, const octave_value& tc,
00171 const std::string& name, const std::string& doc,
00172 bool mark_as_global, bool save_as_floats);
00173
00174 extern OCTINTERP_API int
00175 save_hdf5_empty (hid_t loc_id, const char *name, const dim_vector d);
00176
00177 extern OCTINTERP_API int
00178 load_hdf5_empty (hid_t loc_id, const char *name, dim_vector &d);
00179
00180 extern OCTINTERP_API std::string
00181 read_hdf5_data (std::istream& is, const std::string& filename, bool& global,
00182 octave_value& tc, std::string& doc);
00183
00184 extern OCTINTERP_API bool
00185 save_hdf5_data (std::ostream& os, const octave_value& tc,
00186 const std::string& name, const std::string& doc,
00187 bool mark_as_global, bool save_as_floats);
00188
00189 #ifdef IDX_TYPE_LONG
00190 #define H5T_NATIVE_IDX H5T_NATIVE_LONG
00191 #else
00192 #define H5T_NATIVE_IDX H5T_NATIVE_INT
00193 #endif
00194
00195 #endif
00196
00197 #endif
00198
00199
00200
00201
00202
00203