Mercurial > octave-nkf
comparison src/load-save.cc @ 5760:8d7162924bd3
[project @ 2006-04-14 04:01:37 by jwe]
author | jwe |
---|---|
date | Fri, 14 Apr 2006 04:01:40 +0000 |
parents | a9ac02e9fda5 |
children | 7ba9ad1fec11 |
comparison
equal
deleted
inserted
replaced
5759:ce79d238f142 | 5760:8d7162924bd3 |
---|---|
284 read_binary_file_header (std::istream& is, bool& swap, | 284 read_binary_file_header (std::istream& is, bool& swap, |
285 oct_mach_info::float_format& flt_fmt, bool quiet) | 285 oct_mach_info::float_format& flt_fmt, bool quiet) |
286 { | 286 { |
287 const int magic_len = 10; | 287 const int magic_len = 10; |
288 char magic[magic_len+1]; | 288 char magic[magic_len+1]; |
289 is.read (X_CAST (char *, magic), magic_len); | 289 is.read (magic, magic_len); |
290 magic[magic_len] = '\0'; | 290 magic[magic_len] = '\0'; |
291 | 291 |
292 if (strncmp (magic, "Octave-1-L", magic_len) == 0) | 292 if (strncmp (magic, "Octave-1-L", magic_len) == 0) |
293 swap = oct_mach_info::words_big_endian (); | 293 swap = oct_mach_info::words_big_endian (); |
294 else if (strncmp (magic, "Octave-1-B", magic_len) == 0) | 294 else if (strncmp (magic, "Octave-1-B", magic_len) == 0) |
299 error ("load: unable to read read binary file"); | 299 error ("load: unable to read read binary file"); |
300 return -1; | 300 return -1; |
301 } | 301 } |
302 | 302 |
303 char tmp = 0; | 303 char tmp = 0; |
304 is.read (X_CAST (char *, &tmp), 1); | 304 is.read (&tmp, 1); |
305 | 305 |
306 flt_fmt = mopt_digit_to_float_format (tmp); | 306 flt_fmt = mopt_digit_to_float_format (tmp); |
307 | 307 |
308 if (flt_fmt == oct_mach_info::flt_fmt_unknown) | 308 if (flt_fmt == oct_mach_info::flt_fmt_unknown) |
309 { | 309 { |
322 { | 322 { |
323 bool retval = false; | 323 bool retval = false; |
324 std::ifstream file (fname.c_str ()); | 324 std::ifstream file (fname.c_str ()); |
325 OCTAVE_LOCAL_BUFFER (unsigned char, magic, 2); | 325 OCTAVE_LOCAL_BUFFER (unsigned char, magic, 2); |
326 | 326 |
327 if (file.read (X_CAST (char *, magic), 2) && magic[0] == 0x1f && | 327 if (file.read (reinterpret_cast<char *> (magic), 2) && magic[0] == 0x1f && |
328 magic[1] == 0x8b) | 328 magic[1] == 0x8b) |
329 retval = true; | 329 retval = true; |
330 | 330 |
331 file.close (); | 331 file.close (); |
332 return retval; | 332 return retval; |
1210 ? "Octave-1-B" : "Octave-1-L"); | 1210 ? "Octave-1-B" : "Octave-1-L"); |
1211 | 1211 |
1212 oct_mach_info::float_format flt_fmt = | 1212 oct_mach_info::float_format flt_fmt = |
1213 oct_mach_info::native_float_format (); | 1213 oct_mach_info::native_float_format (); |
1214 | 1214 |
1215 char tmp = (char) float_format_to_mopt_digit (flt_fmt); | 1215 char tmp = static_cast<char> (float_format_to_mopt_digit (flt_fmt)); |
1216 | 1216 |
1217 os.write (X_CAST (char *, &tmp), 1); | 1217 os.write (&tmp, 1); |
1218 } | 1218 } |
1219 break; | 1219 break; |
1220 | 1220 |
1221 case LS_MAT5_BINARY: | 1221 case LS_MAT5_BINARY: |
1222 case LS_MAT7_BINARY: | 1222 case LS_MAT7_BINARY: |
1230 time (&now); | 1230 time (&now); |
1231 bdt = *gmtime (&now); | 1231 bdt = *gmtime (&now); |
1232 memset (headertext, ' ', 124); | 1232 memset (headertext, ' ', 124); |
1233 // ISO 8601 format date | 1233 // ISO 8601 format date |
1234 strftime (headertext, 124, "MATLAB 5.0 MAT-file, written by Octave " | 1234 strftime (headertext, 124, "MATLAB 5.0 MAT-file, written by Octave " |
1235 OCTAVE_VERSION ", %Y-%m-%d %T UTC", &bdt); | 1235 OCTAVE_VERSION ", %Y-%m-%d %T UTC", &bdt); |
1236 | 1236 |
1237 // The first pair of bytes give the version of the MAT file | 1237 // The first pair of bytes give the version of the MAT file |
1238 // format. The second pair of bytes form a magic number which | 1238 // format. The second pair of bytes form a magic number which |
1239 // signals a MAT file. MAT file data are always written in | 1239 // signals a MAT file. MAT file data are always written in |
1240 // native byte order. The order of the bytes in the second | 1240 // native byte order. The order of the bytes in the second |
1264 if (! comment_string.empty ()) | 1264 if (! comment_string.empty ()) |
1265 { | 1265 { |
1266 #ifdef HAVE_HDF5 | 1266 #ifdef HAVE_HDF5 |
1267 if (format == LS_HDF5) | 1267 if (format == LS_HDF5) |
1268 { | 1268 { |
1269 hdf5_ofstream& hs = (hdf5_ofstream&) os; | 1269 hdf5_ofstream& hs = dynamic_cast<hdf5_ofstream&> (os); |
1270 H5Gset_comment (hs.file_id, "/", comment_string.c_str ()); | 1270 H5Gset_comment (hs.file_id, "/", comment_string.c_str ()); |
1271 } | 1271 } |
1272 else | 1272 else |
1273 #endif /* HAVE_HDF5 */ | 1273 #endif /* HAVE_HDF5 */ |
1274 os << comment_string << "\n"; | 1274 os << comment_string << "\n"; |