comparison src/ls-mat5.cc @ 12396:6ba430a75553

Fix for legends with location southeastoutside and soutwestoutside. Pad legend position
author David Bateman <dbateman@free.fr>
date Sun, 06 Feb 2011 23:25:31 +0100
parents 4ced6b90fffb
children c60eaf7dac31
comparison
equal deleted inserted replaced
12395:4d30b4136a3e 12396:6ba430a75553
523 // wouldn't be needed. 523 // wouldn't be needed.
524 524
525 OCTAVE_LOCAL_BUFFER (char, inbuf, element_length); 525 OCTAVE_LOCAL_BUFFER (char, inbuf, element_length);
526 is.read (inbuf, element_length); 526 is.read (inbuf, element_length);
527 527
528 std::cerr << "len: " << element_length << "\n";
529
528 // We uncompress the first 8 bytes of the header to get the buffer length 530 // We uncompress the first 8 bytes of the header to get the buffer length
529 // This will fail with an error Z_MEM_ERROR 531 // This will fail with an error Z_MEM_ERROR
530 uLongf destLen = 8; 532 uLongf destLen = 8;
531 OCTAVE_LOCAL_BUFFER (unsigned int, tmp, 2); 533 OCTAVE_LOCAL_BUFFER (unsigned int, tmp, 2);
532 if (uncompress (reinterpret_cast<Bytef *> (tmp), &destLen, 534 if (uncompress (reinterpret_cast<Bytef *> (tmp), &destLen,
535 { 537 {
536 // Why should I have to initialize outbuf as I'll just overwrite!! 538 // Why should I have to initialize outbuf as I'll just overwrite!!
537 if (swap) 539 if (swap)
538 swap_bytes<4> (tmp, 2); 540 swap_bytes<4> (tmp, 2);
539 541
540 destLen = tmp[1] + 8; 542 destLen = tmp[1] + 32;
541 std::string outbuf (destLen, ' '); 543 std::string outbuf (destLen, ' ');
542 544
543 // FIXME -- find a way to avoid casting away const here! 545 // Try reading the compressed file with 8 different lengthes
544 546 // to account for the zero padding that are added to matlab
545 int err = uncompress (reinterpret_cast<Bytef *> (const_cast<char *> (outbuf.c_str ())), 547 // files
546 &destLen, reinterpret_cast<Bytef *> (inbuf), 548 for (int k = 0; k < 8; k++)
547 element_length);
548
549 if (err != Z_OK)
550 { 549 {
551 std::string msg; 550 // FIXME -- find a way to avoid casting away const here!
552 switch (err) 551 int err = uncompress (reinterpret_cast<Bytef *>
552 (const_cast<char *> (outbuf.c_str ())),
553 &destLen, reinterpret_cast<Bytef *> (inbuf),
554 element_length - k);
555
556 if (err != Z_OK)
553 { 557 {
554 case Z_STREAM_END: 558 std::string msg;
555 msg = "stream end"; 559 switch (err)
556 break; 560 {
557 561 case Z_STREAM_END:
558 case Z_NEED_DICT: 562 msg = "stream end";
559 msg = "need dict"; 563 break;
560 break; 564
561 565 case Z_NEED_DICT:
562 case Z_ERRNO: 566 msg = "need dict";
563 msg = "errno case"; 567 break;
564 break; 568
565 569 case Z_ERRNO:
566 case Z_STREAM_ERROR: 570 msg = "errno case";
567 msg = "stream error"; 571 break;
568 break; 572
569 573 case Z_STREAM_ERROR:
570 case Z_DATA_ERROR: 574 msg = "stream error";
571 msg = "data error"; 575 break;
572 break; 576
573 577 case Z_DATA_ERROR:
574 case Z_MEM_ERROR: 578 if (k != 7)
575 msg = "mem error"; 579 {
576 break; 580 std::cerr << "k = " << k << "\n";
577 581 continue;
578 case Z_BUF_ERROR: 582 }
579 msg = "buf error"; 583 else
580 break; 584 msg = "data error";
581 585 break;
582 case Z_VERSION_ERROR: 586
583 msg = "version error"; 587 case Z_MEM_ERROR:
588 msg = "mem error";
589 break;
590
591 case Z_BUF_ERROR:
592 msg = "buf error";
593 break;
594
595 case Z_VERSION_ERROR:
596 msg = "version error";
597 break;
598 }
599
600 error ("load: error uncompressing data element (%s from zlib)",
601 msg.c_str ());
584 break; 602 break;
585 } 603 }
586 604 else
587 error ("load: error uncompressing data element (%s from zlib)", 605 {
588 msg.c_str ()); 606 std::istringstream gz_is (outbuf);
589 } 607 retval = read_mat5_binary_element (gz_is, filename,
590 else
591 {
592 std::istringstream gz_is (outbuf);
593 retval = read_mat5_binary_element (gz_is, filename,
594 swap, global, tc); 608 swap, global, tc);
609 break;
610 }
595 } 611 }
596 } 612 }
597 else 613 else
598 error ("load: error probing size of compressed data element"); 614 error ("load: error probing size of compressed data element");
599 615