The simple answer is that you need first to run
my $stream = Math::GSL::gsl_fopen $file, $mode;
The complicated answer is that gsl_fopen is defined in Math::GSL, which uses the fopen function from Math::GSL::Vector (for some reason), which is an alias of Math::GSL::Vectorc::fopen, whose definition I can't find—so I can't tell you anything but the obvious about $file, and nothing at all about $mode, except that it can end in +b.
For future reference, it would have been perfectly OK to continue our discussion in the Chatterbox. | [reply] [d/l] [select] |
Thanks for your help JadeNB. Hmm, I added that but I get a unhandled win32 exception.
Here is the code that I have.
use Math::GSL::Histogram qw/:all/;
use Math::GSL;
$file = "blah.txt";
$mode = 1;
$h = gsl_histogram_alloc(3);
gsl_histogram_set_ranges($h, [0, 41, 61, 100], 4);
gsl_histogram_increment ($h, 0);
gsl_histogram_increment ($h, 41);
gsl_histogram_increment ($h, 61);
gsl_histogram_increment ($h, 100);
$stream = Math::GSL::gsl_fopen $file, $mode;
gsl_histogram_fscanf($stream, $h);
How am I doing this wrong? | [reply] [d/l] |
I'm not really up to speed with this, but I think you might want something like:
use Math::GSL::Histogram qw/:all/;
use Math::GSL qw/:all/;
$file = "blah.txt";
$mode = 'w';
$h = gsl_histogram_alloc(3);
gsl_histogram_set_ranges($h, [0, 41, 61, 100], 4);
gsl_histogram_increment ($h, 0);
gsl_histogram_increment ($h, 41);
gsl_histogram_increment ($h, 61);
gsl_histogram_increment ($h, 100);
$stream = gsl_fopen $file, $mode;
gsl_histogram_fprintf($stream, $h, '%f', '%f');
At least that runs without error. On my Windows Vista box, I need to view 'blah.txt' in something like wordpad. For me, notepad ignores the newlines.
It might be worth your while to download the Math::GSL source from CPAN, as the test files (in the 't' folder) provide useful examples of correct usage.
Cheers, Rob | [reply] [d/l] |