Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi! thanks for your answer, but unfortunately I cannot make it to work. Here is the beggining of my data:

1 3 25 1 5 1 3 1 2 2 3 3 3 25 1 1 5 2 4500 1 1 1 1 5 5 8000 1 1 5 500 1 1 1 5 2 1 1 1000 1000 1000 1000 5000 1 25 6000 500 25 25 9000 1 1 5 1000 6000 25 10 5 5 5 5 1000 9540 1000 5 1 5 500 2500 2 5 5 5 ...

Is just a sequence of integers, stored in a plain text file called "data".

Now, this is my code:

my $fi = gsl_fopen('data', 'r'); my $fo = gsl_fopen('hist', 'w'); my $h = gsl_histogram_alloc(6); my $range = [ 1.0, 10.0, 100.0, 1000.0, 10000.0, 100000.0 ]; gsl_histogram_fread($fi, $h); gsl_histogram_set_ranges($h,$range,7); gsl_histogram_fprintf($fo, $h, "%3.1f", "%3.1f"); gsl_fclose($fo); gsl_fclose($fi);

What I need is to produce a histogram with 6 logarithmic bins (see the $range variable in the code). When I run this code I get no errors, and the result is:

1.0 10.0 0.0
10.0 100.0 0.0
100.0 1000.0 0.0
1000.0 10000.0 0.0
10000.0 100000.0 0.0
100000.0 0.0 0.0


So, either no data is read or something of what I have no idea is going on. In the documentation one finds:

gsl_histogram_fread($stream, $h) - This function reads into the histogram $h from the open stream $stream, which has been opened by the gsl_fopen function from the Math::GSL module, in binary format. The histogram $h must be preallocated with the correct size since the function uses the number of bins in $h to determine how many bytes to read. The return value is 0 for success and $GSL_EFAILED if there was a problem reading from the file. The data is assumed to have been written in the native binary format on the same architecture.

But I find it a bit complicated to understand if a text file can be read or not. Oh wise monks! any hint will be appreciated!

In reply to Re^2: How does Math::GSL accept data? by hda
in thread How does Math::GSL accept data? by hda

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-06-12 17:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.