error running my project

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

}
 
M

mlimber

Gary said:
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

}

You don't tell us which line generates the error, but I'll take a wild
guess that it's "gsl_matrix_fscanf (f, m);". Since the GSL is off-topic
here, you'll want to read the documentation for it, consult any user
lists that the authors might maintain, or check out the code for that
function directly (it's open source). My guess is that there's
something wrong with the file you're trying to read in.

Cheers! --M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,991
Messages
2,570,212
Members
46,800
Latest member
Tobi1987

Latest Threads

Top