| 1 | ;; N-tuples |
|---|
| 2 | ;; Liam Healy Sat Feb 3 2007 - 12:53 |
|---|
| 3 | ;; Time-stamp: <2008-02-17 18:39:48EST ntuple.lisp> |
|---|
| 4 | ;; $Id$ |
|---|
| 5 | |
|---|
| 6 | (in-package :gsl) |
|---|
| 7 | |
|---|
| 8 | ;;; The basic definitions are here, but a smooth interface to CL |
|---|
| 9 | ;;; has not been created, and it has not been tested. |
|---|
| 10 | |
|---|
| 11 | ;;; Writing a file |
|---|
| 12 | (defmfun create-ntuple (filename data size) |
|---|
| 13 | "gsl_ntuple_create" |
|---|
| 14 | ((filename :string) (data :pointer) (size size)) |
|---|
| 15 | :c-return :pointer |
|---|
| 16 | :documentation ; FDL |
|---|
| 17 | "Create a new write-only ntuple file filename for |
|---|
| 18 | ntuples of size and return a pointer to the newly created |
|---|
| 19 | ntuple struct. Any existing file with the same name is truncated to |
|---|
| 20 | zero length and overwritten. A pointer to memory for the current ntuple |
|---|
| 21 | row data must be supplied---this is used to copy ntuples |
|---|
| 22 | in and out of the file.") |
|---|
| 23 | |
|---|
| 24 | ;;; Reading a file |
|---|
| 25 | (defmfun open-ntuple (filename data size) |
|---|
| 26 | "gsl_ntuple_create" |
|---|
| 27 | ((filename :string) (data :pointer) (size size)) |
|---|
| 28 | :c-return :pointer |
|---|
| 29 | :documentation ; FDL |
|---|
| 30 | "Open an existing ntuple file filename for reading |
|---|
| 31 | and return a pointer to a corresponding ntuple struct. The ntuples in |
|---|
| 32 | the file must have size size. A pointer to memory for the current |
|---|
| 33 | ntuple row data must be supplied---this is used to copy |
|---|
| 34 | ntuples in and out of the file.") |
|---|
| 35 | |
|---|
| 36 | ;;; Writing ntuples |
|---|
| 37 | (defmfun write-ntuple (ntuple) |
|---|
| 38 | "gsl_ntuple_write" |
|---|
| 39 | ((ntuple :pointer)) |
|---|
| 40 | :documentation ; FDL |
|---|
| 41 | "Write the current ntuple ntuple->ntuple_data of |
|---|
| 42 | size ntuple->size to the corresponding file.") |
|---|
| 43 | |
|---|
| 44 | (defmfun bookdata-ntuple (ntuple) |
|---|
| 45 | "gsl_ntuple_bookdata" |
|---|
| 46 | ((ntuple :pointer)) |
|---|
| 47 | :documentation ; FDL |
|---|
| 48 | "A synonym for #'write-ntuple}.") |
|---|
| 49 | |
|---|
| 50 | ;;; Reading ntuples |
|---|
| 51 | (defmfun read-ntuple (ntuple) |
|---|
| 52 | "gsl_ntuple_read" |
|---|
| 53 | ((ntuple :pointer)) |
|---|
| 54 | :documentation ; FDL |
|---|
| 55 | "Read the current row of the ntuple file and stores the value.") |
|---|
| 56 | |
|---|
| 57 | ;;; Closing file |
|---|
| 58 | (defmfun close-ntuple (ntuple) |
|---|
| 59 | "gsl_ntuple_close" |
|---|
| 60 | ((ntuple :pointer)) |
|---|
| 61 | :documentation ; FDL |
|---|
| 62 | "Closes the ntuple file ntupe and frees its |
|---|
| 63 | associated allocated memory.") |
|---|
| 64 | |
|---|
| 65 | ;;; Histogramming ntuple values |
|---|
| 66 | (defmfun project-ntuple (histogram ntuple value-function select-function) |
|---|
| 67 | "gsl_ntuple_project" |
|---|
| 68 | ((histogram :pointer) (ntuple :pointer) |
|---|
| 69 | (value-function :pointer) (select-function :pointer)) |
|---|
| 70 | :documentation ; FDL |
|---|
| 71 | "Update the histogram the ntuple |
|---|
| 72 | using the functions value-function and select-function. For each |
|---|
| 73 | ntuple row where the selection function select-function is non-zero the |
|---|
| 74 | corresponding value of that row is computed using the function |
|---|
| 75 | value-function and added to the histogram. Those ntuple rows where |
|---|
| 76 | select-function returns zero are ignored. New entries are added to |
|---|
| 77 | the histogram, so subsequent calls can be used to accumulate further |
|---|
| 78 | data in the same histogram.") |
|---|
| 79 | |
|---|
| 80 | ;;; Callback definitions |
|---|
| 81 | |
|---|
| 82 | (export '(def-ntuple-select-function def-ntuple-value-function)) |
|---|
| 83 | |
|---|
| 84 | (defmacro def-ntuple-select-function (name arg) |
|---|
| 85 | ;; FDL |
|---|
| 86 | "The selection function determines which ntuple rows are selected |
|---|
| 87 | for histogramming. The struct component function should return a |
|---|
| 88 | non-zero value for each ntuple row that is to be included in the |
|---|
| 89 | histogram. " |
|---|
| 90 | `(def-single-function ,name ,arg :int :pointer)) |
|---|
| 91 | |
|---|
| 92 | (defmacro def-ntuple-value-function (name arg) |
|---|
| 93 | ;; FDL |
|---|
| 94 | "The value function computes scalar values for those ntuple rows |
|---|
| 95 | selected by the selection function which should return the value |
|---|
| 96 | to be added to the histogram." |
|---|
| 97 | `(def-single-function ,name ,arg :double :pointer)) |
|---|