| 1 | ;; Reading and writing histograms. |
|---|
| 2 | ;; Liam Healy 2008-02-17 17:11:23EST read-write.lisp |
|---|
| 3 | ;; Time-stamp: <2008-02-17 17:13:15EST read-write.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | (defmfun write-binary-1 (object stream) |
|---|
| 9 | "gsl_histogram_fwrite" |
|---|
| 10 | ((stream :pointer) ((pointer object) :pointer)) |
|---|
| 11 | :export nil |
|---|
| 12 | :index write-binary) |
|---|
| 13 | |
|---|
| 14 | (defmfun write-binary-2 (object stream) |
|---|
| 15 | "gsl_histogram2d_fwrite" |
|---|
| 16 | ((stream :pointer) ((pointer object) :pointer)) |
|---|
| 17 | :export nil |
|---|
| 18 | :index write-binary) |
|---|
| 19 | |
|---|
| 20 | (defmethod write-binary ((object histogram) stream) |
|---|
| 21 | (histo-1d2d object write-binary (stream))) |
|---|
| 22 | |
|---|
| 23 | (defmfun read-binary-1 (object stream) |
|---|
| 24 | "gsl_histogram_fread" |
|---|
| 25 | ((stream :pointer) ((pointer object) :pointer)) |
|---|
| 26 | :export nil |
|---|
| 27 | :index read-binary) |
|---|
| 28 | |
|---|
| 29 | (defmfun read-binary-2 (object stream) |
|---|
| 30 | "gsl_histogram2d_fread" |
|---|
| 31 | ((stream :pointer) ((pointer object) :pointer)) |
|---|
| 32 | :export nil |
|---|
| 33 | :index read-binary) |
|---|
| 34 | |
|---|
| 35 | (defmethod read-binary ((object histogram) stream) |
|---|
| 36 | (histo-1d2d object read-binary (stream))) |
|---|
| 37 | |
|---|
| 38 | (defmfun write-formatted-1 (object stream format) |
|---|
| 39 | "gsl_histogram_fprintf" |
|---|
| 40 | ((stream :pointer) ((pointer object) :pointer) |
|---|
| 41 | ((first format) :string) ((second format) :string)) |
|---|
| 42 | :export nil |
|---|
| 43 | :index write-formatted) |
|---|
| 44 | |
|---|
| 45 | (defmfun write-formatted-2 (object stream format) |
|---|
| 46 | "gsl_histogram2d_fprintf" |
|---|
| 47 | ((stream :pointer) ((pointer object) :pointer) |
|---|
| 48 | ((first format) :string) ((second format) :string)) |
|---|
| 49 | :export nil |
|---|
| 50 | :index write-formatted) |
|---|
| 51 | |
|---|
| 52 | (defmethod write-formatted ((object histogram) stream format) |
|---|
| 53 | ;; FDL |
|---|
| 54 | "This function writes the ranges and bins of the histogram |
|---|
| 55 | line-by-line to the stream using the format specifiers |
|---|
| 56 | (first format) for range format and (second format) for bin format. |
|---|
| 57 | These should be one of the %g, %e or %f C formats for floating point |
|---|
| 58 | numbers. The histogram output is formatted in three columns, |
|---|
| 59 | and the columns are separated by spaces, |
|---|
| 60 | like this, |
|---|
| 61 | range[0] range[1] bin[0] |
|---|
| 62 | range[1] range[2] bin[1] |
|---|
| 63 | range[2] range[3] bin[2] |
|---|
| 64 | .... |
|---|
| 65 | range[n-1] range[n] bin[n-1] |
|---|
| 66 | The values of the ranges are formatted using range format and the |
|---|
| 67 | value of the bins are formatted using bin format. Each line |
|---|
| 68 | contains the lower and upper limit of the range of the bins and the |
|---|
| 69 | value of the bin itself. Since the upper limit of one bin is the lower |
|---|
| 70 | limit of the next there is duplication of these values between lines but |
|---|
| 71 | this allows the histogram to be manipulated with line-oriented tools." |
|---|
| 72 | (histo-1d2d object write-formatted (stream format))) |
|---|
| 73 | |
|---|
| 74 | (defmfun read-formatted-1 (object stream format) |
|---|
| 75 | "gsl_histogram_fscanf" |
|---|
| 76 | ((stream :pointer) ((pointer object) :pointer)) |
|---|
| 77 | :export nil |
|---|
| 78 | :index read-formatted) |
|---|
| 79 | |
|---|
| 80 | (defmfun read-formatted-2 (object stream format) |
|---|
| 81 | "gsl_histogram2d_fscanf" |
|---|
| 82 | ((stream :pointer) ((pointer object) :pointer)) |
|---|
| 83 | :export nil |
|---|
| 84 | :index read-formatted) |
|---|
| 85 | |
|---|
| 86 | (defmethod read-formatted ((object histogram) stream format) |
|---|
| 87 | ;; FDL |
|---|
| 88 | "Read formatted data from the stream into the histogram. The |
|---|
| 89 | data is assumed to be in the three-column format used by |
|---|
| 90 | #'write-formatted. The histogram must be preallocated with |
|---|
| 91 | the correct length since the function uses the size of the |
|---|
| 92 | histogram to determine how many numbers to read. The |
|---|
| 93 | argument 'format is ignored." |
|---|
| 94 | (histo-1d2d object read-formatted (stream format))) |
|---|