comparison src/ls-mat4.cc @ 5275:23b37da9fd5b

[project @ 2005-04-08 16:07:35 by jwe]
author jwe
date Fri, 08 Apr 2005 16:07:37 +0000
parents 44046bbaa52c
children bd32f770c09a
comparison
equal deleted inserted replaced
5274:eae7b40388e9 5275:23b37da9fd5b
330 if (dlen < 0) 330 if (dlen < 0)
331 goto data_read_error; 331 goto data_read_error;
332 332
333 if (order) 333 if (order)
334 { 334 {
335 int tmp = nr; 335 octave_idx_type tmp = nr;
336 nr = nc; 336 nr = nc;
337 nc = tmp; 337 nc = tmp;
338 } 338 }
339 339
340 re.resize (nr, nc); 340 re.resize (nr, nc);
360 goto data_read_error; 360 goto data_read_error;
361 } 361 }
362 362
363 ComplexMatrix ctmp (nr, nc); 363 ComplexMatrix ctmp (nr, nc);
364 364
365 for (int j = 0; j < nc; j++) 365 for (octave_idx_type j = 0; j < nc; j++)
366 for (int i = 0; i < nr; i++) 366 for (octave_idx_type i = 0; i < nr; i++)
367 ctmp (i, j) = Complex (re (i, j), im (i, j)); 367 ctmp (i, j) = Complex (re (i, j), im (i, j));
368 368
369 tc = order ? ctmp.transpose () : ctmp; 369 tc = order ? ctmp.transpose () : ctmp;
370 } 370 }
371 else 371 else
404 os.write (X_CAST (char *, &nr), 4); 404 os.write (X_CAST (char *, &nr), 4);
405 405
406 FOUR_BYTE_INT nc = tc.columns (); 406 FOUR_BYTE_INT nc = tc.columns ();
407 os.write (X_CAST (char *, &nc), 4); 407 os.write (X_CAST (char *, &nc), 4);
408 408
409 int len = nr * nc; 409 octave_idx_type len = nr * nc;
410 410
411 FOUR_BYTE_INT imag = tc.is_complex_type () ? 1 : 0; 411 FOUR_BYTE_INT imag = tc.is_complex_type () ? 1 : 0;
412 os.write (X_CAST (char *, &imag), 4); 412 os.write (X_CAST (char *, &imag), 4);
413 413
414 // LEN includes the terminating character, and the file is also 414 // LEN includes the terminating character, and the file is also
423 { 423 {
424 unwind_protect::begin_frame ("save_mat_binary_data"); 424 unwind_protect::begin_frame ("save_mat_binary_data");
425 425
426 charMatrix chm = tc.char_matrix_value (); 426 charMatrix chm = tc.char_matrix_value ();
427 427
428 int nrow = chm.rows (); 428 octave_idx_type nrow = chm.rows ();
429 int ncol = chm.cols (); 429 octave_idx_type ncol = chm.cols ();
430 430
431 OCTAVE_LOCAL_BUFFER (double, buf, ncol*nrow); 431 OCTAVE_LOCAL_BUFFER (double, buf, ncol*nrow);
432 432
433 for (int i = 0; i < nrow; i++) 433 for (octave_idx_type i = 0; i < nrow; i++)
434 { 434 {
435 std::string tstr = chm.row_as_string (i); 435 std::string tstr = chm.row_as_string (i);
436 const char *s = tstr.data (); 436 const char *s = tstr.data ();
437 437
438 for (int j = 0; j < ncol; j++) 438 for (octave_idx_type j = 0; j < ncol; j++)
439 buf[j*nrow+i] = static_cast<double> (*s++ & 0x00FF); 439 buf[j*nrow+i] = static_cast<double> (*s++ & 0x00FF);
440 } 440 }
441 os.write ((char *)buf, nrow*ncol*sizeof(double)); 441 os.write ((char *)buf, nrow*ncol*sizeof(double));
442 442
443 unwind_protect::run_frame ("save_mat_binary_data"); 443 unwind_protect::run_frame ("save_mat_binary_data");
445 else if (tc.is_range ()) 445 else if (tc.is_range ())
446 { 446 {
447 Range r = tc.range_value (); 447 Range r = tc.range_value ();
448 double base = r.base (); 448 double base = r.base ();
449 double inc = r.inc (); 449 double inc = r.inc ();
450 int nel = r.nelem (); 450 octave_idx_type nel = r.nelem ();
451 for (int i = 0; i < nel; i++) 451 for (octave_idx_type i = 0; i < nel; i++)
452 { 452 {
453 double x = base + i * inc; 453 double x = base + i * inc;
454 os.write (X_CAST (char *, &x), 8); 454 os.write (X_CAST (char *, &x), 8);
455 } 455 }
456 } 456 }