Skip to content

Commit

Permalink
Merge pull request hbristow#4 from headupinclouds/pr.byte_swap.fix
Browse files Browse the repository at this point in the history
Initialize MatlabIO::byte_swap=false
  • Loading branch information
headupinclouds authored Aug 21, 2016
2 parents 046060a + 37f2a12 commit 15009c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions include/MatlabIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class MatlabIO {
char subsys_[SUBSYS_LENGTH+1];
char endian_[ENDIAN_LENGTH+1];
int16_t version_;
bool byte_swap_;
int bytes_read_;
bool byte_swap_ = false;
int bytes_read_ = 0;
std::string filename_;

std::fstream fid_;
Expand Down
18 changes: 11 additions & 7 deletions src/MatlabIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
#include <cstring>
#include <iostream>
#include <exception>
#include <iomanip>
#include <zlib.h>

using namespace std;
using namespace cv;

Expand Down Expand Up @@ -164,11 +166,13 @@ vector<T2> convertPrimitiveType(const vector<char>& in) {
* needs reversal, this is automatically handled by esfstream.
*/
void MatlabIO::getHeader(void) {

// get the header information from the Mat file
for (unsigned int n = 0; n < HEADER_LENGTH+1; ++n) header_[n] = '\0';
for (unsigned int n = 0; n < SUBSYS_LENGTH+1; ++n) subsys_[n] = '\0';
for (unsigned int n = 0; n < ENDIAN_LENGTH+1; ++n) endian_[n] = '\0';

byte_swap_ = false;
read(header_, sizeof(char)*HEADER_LENGTH);
read(subsys_, sizeof(char)*SUBSYS_LENGTH);
read((char *)&version_, sizeof(int16_t));
Expand Down Expand Up @@ -737,13 +741,13 @@ void MatlabIO::whos(vector<MatlabIOContainer> variables) const {
if(variables[n].name().length() > flmax)
flmax = variables[n].name().length();

printf("-------------------------\n");
printf("File: %s\n", filename_.c_str());
printf("%s\n", header_);
printf("Variables:\n");
std::cout << "-------------------------\n";
std::cout << "File: " << filename_ << "\n";
std::cout << header_;
std::cout << "Variables: ";
for (unsigned int n = 0; n < variables.size(); ++n) {
printf("%*s: %s\n", int(flmax), variables[n].name().c_str(), variables[n].type().c_str());
std::cout << std::setw(flmax) << variables[n].name() << " " << variables[n].type() << "\n";
}
printf("-------------------------\n");
fflush(stdout);
std::cout << "-------------------------\n";
std::cout.flush();
}

0 comments on commit 15009c3

Please sign in to comment.