G
Gary Wessle
Hi
I need help in finding out why the error below, I am writing a through
away program in C++ using debian/testing machine.
thanks
**************** error ****************
fred@debian:~/myPrograms/common$ make clean; make; ./proj
rm -rf *.o proj
g++ -Wall -g -c -o read_data.o read_data.cpp
g++ -Wall -g -c -o read_data_test.o read_data_test.cpp
g++ -g -o proj read_data.o read_data_test.o -lgsl -lgslcblas -lm
gsl: fprintf_source.c:164: ERROR: fscanf failed
Default GSL error handler invoked.
Aborted
fred@debian:~/myPrograms/common$
**************** read_data.h ****************
#ifndef READ_DATA_H
#define READ_DATA_H
#include <string>
#include <cstdio>
#include <gsl/gsl_matrix.h>
class read_data
{
int nRows, nCol;
std::string file_name;
void set_No_of_Rows_Cols();
gsl_matrix * m; // from gsl_matrix.h
void matrix_the_file();
public:
read_data(std::string const& fileName);
~read_data();
};
#endif
**************** read_data.cpp ****************
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <gsl/gsl_matrix.h>
#include "read_data.h"
using namespace std;
read_data::read_data( string const& fileName )
: file_name( fileName ){
nCol = 0;
nRows = 1;
set_No_of_Rows_Cols();
matrix_the_file();
}
void read_data::set_No_of_Rows_Cols() {
ifstream in(file_name.c_str());
string line;
getline(in, line);
stringstream input( line.c_str() );
string word;
while(input >> word)
nCol++; // init'd by constructor
while (getline(in, line))
nRows++; // init'd by constructor
}
void read_data::matrix_the_file(){
// allocate memory for the matrix
// needs to be freed later using
// void gsl_matrix_free (gsl_matrix * m)
m = gsl_matrix_alloc (nRows, nCol);
FILE * f = fopen(file_name.c_str(), "rb");
gsl_matrix_fscanf (f, m);
fclose(f);
cout << "data read" << endl;
}
read_data::~read_data() {}
/*
std::string command = "wc -l";
std::system( ( command + " " + file_name ).c_str() );
}
*/
**************** read_data_test.cpp ****************
#include <fstream>
#include <iostream>
#include <string>
#include "read_data.h"
using namespace std;
int main() {
string f = "../../data/ZB/Jun06/20060405";
read_data data1( f ); // space delimited
}
I need help in finding out why the error below, I am writing a through
away program in C++ using debian/testing machine.
thanks
**************** error ****************
fred@debian:~/myPrograms/common$ make clean; make; ./proj
rm -rf *.o proj
g++ -Wall -g -c -o read_data.o read_data.cpp
g++ -Wall -g -c -o read_data_test.o read_data_test.cpp
g++ -g -o proj read_data.o read_data_test.o -lgsl -lgslcblas -lm
gsl: fprintf_source.c:164: ERROR: fscanf failed
Default GSL error handler invoked.
Aborted
fred@debian:~/myPrograms/common$
**************** read_data.h ****************
#ifndef READ_DATA_H
#define READ_DATA_H
#include <string>
#include <cstdio>
#include <gsl/gsl_matrix.h>
class read_data
{
int nRows, nCol;
std::string file_name;
void set_No_of_Rows_Cols();
gsl_matrix * m; // from gsl_matrix.h
void matrix_the_file();
public:
read_data(std::string const& fileName);
~read_data();
};
#endif
**************** read_data.cpp ****************
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <gsl/gsl_matrix.h>
#include "read_data.h"
using namespace std;
read_data::read_data( string const& fileName )
: file_name( fileName ){
nCol = 0;
nRows = 1;
set_No_of_Rows_Cols();
matrix_the_file();
}
void read_data::set_No_of_Rows_Cols() {
ifstream in(file_name.c_str());
string line;
getline(in, line);
stringstream input( line.c_str() );
string word;
while(input >> word)
nCol++; // init'd by constructor
while (getline(in, line))
nRows++; // init'd by constructor
}
void read_data::matrix_the_file(){
// allocate memory for the matrix
// needs to be freed later using
// void gsl_matrix_free (gsl_matrix * m)
m = gsl_matrix_alloc (nRows, nCol);
FILE * f = fopen(file_name.c_str(), "rb");
gsl_matrix_fscanf (f, m);
fclose(f);
cout << "data read" << endl;
}
read_data::~read_data() {}
/*
std::string command = "wc -l";
std::system( ( command + " " + file_name ).c_str() );
}
*/
**************** read_data_test.cpp ****************
#include <fstream>
#include <iostream>
#include <string>
#include "read_data.h"
using namespace std;
int main() {
string f = "../../data/ZB/Jun06/20060405";
read_data data1( f ); // space delimited
}