From: <and...@us...> - 2008-05-29 21:11:07
|
Revision: 8441 http://plplot.svn.sourceforge.net/plplot/?rev=8441&view=rev Author: andrewross Date: 2008-05-29 14:11:04 -0700 (Thu, 29 May 2008) Log Message: ----------- Initial commit of the the ocaml bindings for plplot contributed by Hezekiah Carty. Cmake parts have been written Andrew Ross. This binding is disabled by default. To enable set ENABLE_ocaml to be ON. Modified Paths: -------------- trunk/bindings/CMakeLists.txt trunk/cmake/modules/instdirs.cmake trunk/cmake/modules/plplot.cmake trunk/cmake/modules/summary.cmake trunk/examples/CMakeLists.txt Added Paths: ----------- trunk/bindings/ocaml/ trunk/bindings/ocaml/CMakeLists.txt trunk/bindings/ocaml/META.cmake trunk/bindings/ocaml/README trunk/bindings/ocaml/extras.ml trunk/bindings/ocaml/libplplot_stubs.clib trunk/bindings/ocaml/myocamlbuild.ml.cmake trunk/bindings/ocaml/plplot.idl trunk/bindings/ocaml/plplot_h trunk/bindings/ocaml/plplot_h.inc trunk/bindings/ocaml/plplot_impl.c trunk/bindings/ocaml/touchup.ml trunk/cmake/modules/ocaml.cmake trunk/examples/ocaml/ trunk/examples/ocaml/CMakeLists.txt trunk/examples/ocaml/Makefile.examples.in trunk/examples/ocaml/x11.ml trunk/examples/ocaml/x19.ml Modified: trunk/bindings/CMakeLists.txt =================================================================== --- trunk/bindings/CMakeLists.txt 2008-05-29 14:06:00 UTC (rev 8440) +++ trunk/bindings/CMakeLists.txt 2008-05-29 21:11:04 UTC (rev 8441) @@ -32,6 +32,7 @@ add_subdirectory(wxwidgets) add_subdirectory(ada) add_subdirectory(d) +add_subdirectory(ocaml) set(index) if(ENABLE_tcl) Added: trunk/bindings/ocaml/CMakeLists.txt =================================================================== --- trunk/bindings/ocaml/CMakeLists.txt (rev 0) +++ trunk/bindings/ocaml/CMakeLists.txt 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,103 @@ +# bindings/ocaml/CMakeLists.txt +### Process this file with cmake to produce Makefile +### +# Copyright (C) 2008 Andrew Ross +# +# This file is part of PLplot. +# +# PLplot is free software; you can redistribute it and/or modify +# it under the terms of the GNU Library General Public License as published +# by the Free Software Foundation; version 2 of the License. +# +# PLplot is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with PLplot; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +if(ENABLE_ocaml) + + set(SOURCE_LIST + extras.ml + libplplot_stubs.clib + plplot_h + plplot_h.inc + plplot.idl + plplot_impl.c + touchup.ml + ) + set(GEN_SOURCE_LIST + ${CMAKE_CURRENT_BINARY_DIR}/myocamlbuild.ml + ) + + set(OCAML_INSTALL_FILES + plplot.cma + plplot.cmxa + plplot.a + plplot.cmi + libplplot_stubs.a + ) + + set(OCAML_FULL_INSTALL_FILES) + foreach(OCAML_FILE ${OCAML_INSTALL_FILES}) + set(OCAML_FULL_INSTALL_FILES ${OCAML_FULL_INSTALL_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${OCAML_BUILD_DIR}/${OCAML_FILE}) + endforeach(OCAML_FILE ${OCAML_INSTALL_FILES}) + + # Configure the META file + configure_file(META.cmake ${CMAKE_CURRENT_BINARY_DIR}/META) + + # Configure the file controlling the ocamlbuild process + configure_file(myocamlbuild.ml.cmake ${CMAKE_CURRENT_BINARY_DIR}/myocamlbuild.ml) + set(DEPENDS_LIST ${GEN_SOURCE_LIST}) + + # Copy all source into the build tree since the whole project must be in + # the same directory + foreach(SRC_FILE ${SOURCE_LIST}) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} + COMMAND ${CMAKE_COMMAND} + -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FILE} + ) + set(DEPENDS_LIST ${DEPENDS_LIST} ${CMAKE_CURRENT_BINARY_DIR}/${SRC_FILE}) + endforeach(SRC_FILE ${SOURCE_LIST}) + + # Note: ocamlbuild requires build-dir to be a relative path + # Also the build-dir must not be the project root - hence the + # new subdirectory + # Build bytecode version + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OCAML_BUILD_DIR}/plplot.cma + COMMAND ${OCAMLBUILD} -tag debug -classic-display -build-dir ${OCAML_BUILD_DIR} plplot.cma + DEPENDS ${DEPENDS_LIST} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + + # Build native version + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${OCAML_BUILD_DIR}/plplot.cmxa + ${CMAKE_CURRENT_BINARY_DIR}/${OCAML_BUILD_DIR}/plplot.a + COMMAND ocamlbuild -tag debug -build-dir ${OCAML_BUILD_DIR} plplot.cmxa + DEPENDS ${DEPENDS_LIST} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + + add_custom_target( + plplot_ocaml ALL + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${OCAML_BUILD_DIR}/plplot.cma ${CMAKE_CURRENT_BINARY_DIR}/${OCAML_BUILD_DIR}/plplot.cmxa ${CMAKE_CURRENT_BINARY_DIR}/${OCAML_BUILD_DIR}/plplot.a + ) + + # Most files go in the plplot subdirectory + install(FILES ${OCAML_FULL_INSTALL_FILES} ${CMAKE_CURRENT_BINARY_DIR}/META + DESTINATION ${OCAML_INSTALL_DIR}/plplot + ) + + # Shared library stubs go in stublibs + install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${OCAML_BUILD_DIR}/dllplplot_stubs.so + DESTINATION ${OCAML_INSTALL_DIR}/stublibs + ) + +endif(ENABLE_ocaml) Added: trunk/bindings/ocaml/META.cmake =================================================================== --- trunk/bindings/ocaml/META.cmake (rev 0) +++ trunk/bindings/ocaml/META.cmake 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,8 @@ +# findlib META file for ocaml-plplot +requires = "" +description = "PLplot library bindings" +version = "@VERSION@" +browse_interfaces = " Plplot " +archive(byte) = "plplot.cma" +archive(native) = "plplot.cmxa" + Added: trunk/bindings/ocaml/README =================================================================== --- trunk/bindings/ocaml/README (rev 0) +++ trunk/bindings/ocaml/README 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,42 @@ + +These notes are from the stand-alone version of the ocaml bindings and +are retained only for interest. + +This is an interface to PLplot (http://plplot.sourceforge.net/) for the +Objective Caml language. + +* REQUIREMENTS +- PLplot >5.9.0 +- OCaml 3.10.x + - ocamlbuild is used to compile ocaml-plplot. ocamlbuild is only included + in OCaml 3.10.0 and later. No other 3.10.x specific OCaml functionality + is used in ocaml-plplot. +- camlidl +- findlib +- GNU make + +* INSTALLATION +Modify INCDIRS and LIBDIRS in the Makefile to point to your PLplot installation +$ make (generates bytecode and native libs, plus a toplevel) +$ make libinstall (to install the library using findlib) + +* NOTES +ocaml-plplot has only been tested on OCaml 3.10.x, under 32bit Linux (Fedora, +Debian and CentOS). It should work on a 64bit system as well as older versions +of OCaml, but these are not tested. Any feedback regarding function or lack of +function on other platforms is welcome. + +This wrapper/interface is still in a fairly basic state. Most of the 2D and 3D +plotting routines are in place. For a 3D plotting example, see the file +examples/x11.ml - a direct port of the PLplot example 11. The function names +are the same as for the PLplot C API. Function parameters are largely the +same, with the exception that most arguments indicating array lengths are +deduced automatically by the camlidl generated interface (the "redacted form" +of the commands in the PLplot manual). + +The best reference is currently the PLplot web page shown at the top of this +README file. The documentation there for the C API holds for the most part here +as well. + +Hezekiah M. Carty +h...@at... Added: trunk/bindings/ocaml/extras.ml =================================================================== --- trunk/bindings/ocaml/extras.ml (rev 0) +++ trunk/bindings/ocaml/extras.ml 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,197 @@ +open Plplot + +let draw_legend x y names colors = + (* + let () = + if x < 0.0 || x > 1.0 || y < 0.0 || y > 1.0 then + failwith "Legend location must be between 0.0 and 1.0" + in + *) + + let character_width = 0.2 in + let character_height = 0.2 in + let x_buffer = 0.1 in + let y_buffer = 0.1 in + + let max_name_length = + List.fold_left ( + fun l n2 -> + max l (String.length n2) + ) 0 names + in + let width = + float_of_int max_name_length *. character_width +. 2.0 *. x_buffer + in + let height = + character_height *. float_of_int (List.length names) + in + + let tx = x +. 0.6 in + let ty = ref (y +. 0.2) in + + List.iter2 ( + fun n c -> + plcol0 c; + plline [|tx -. 0.4; tx -. 0.1|] [|!ty; !ty|]; + plptex tx !ty 0.0 0.0 0.0 n; + ty := !ty -. character_height -. 0.2; + () + ) names colors; + () + +(** [plshades0 a xmin xmax ymin ymax clevels base_color] acts in the same + manner as plshades, but uses color map 0 rather than color map 1. + [base_color] is the index of the color to use for the first shaded + interval. The next interval uses color index [base_color] + 1 and so on. + A separate call to {plcont} is +*) +let plshades0 a xmin xmax ymin ymax clevels base_color color_step = + (* Save the current color and pencil width values *) + let initial_color = plg_current_col0 () in + let initial_width = plgwid () in + + (* Use color map 0, and iterate through colors from base_color in increments + of 1. *) + let color_map = 0 in + Array.iteri ( + fun i c0 -> + let c1 = clevels.(i + 1) in + let color = float_of_int (base_color + i * color_step) in + plshade a xmin xmax ymin ymax c0 c1 color_map color 0 0 0 0 0 0; + ) (Array.sub clevels 0 (Array.length clevels - 1)); + + (* Restore the initial color and width values *) + plcol0 initial_color; + plwid initial_width; + () + +(** [color_bar ?tick_interval ?step contours] draws a vertical color bar on the + right side end of the plot canvas, using the information in [contours] to + decide which colors to draw. + If [step] is provided, then every [step] units there will + be a new color. If [step] is omitted, then the smallest difference + between two consecutive values in [contours] is used. + [tick_level] can be used to set the interval between axis numbers if + something other than [step] is desired. +*) +let color_bar ?(tick_interval) ?(step) contours = + (* Get the current character size to restore later *) + let (old_default, old_scale) = plgchr () in + + (* A wee, tiny little font for the color scale *) + plschr 0.0 0.50; + + (* Vertical bar on the right side of the plot canvas *) + plvpor 0.93 0.96 0.15 0.85; + + (* Minimum and maximum values *) + let cmin = Array.fold_left min infinity contours in + let cmax = Array.fold_left max neg_infinity contours in + + (* Find the smallest step between contours, if none is provided *) + let step = + match step with + Some s -> s + | None -> + let accum = ref 0.0 in + for i = 1 to Array.length contours - 1 do + let delta = contours.(i) -. contours.(i - 1) in + if delta > !accum then + accum := delta + else + () + done; + !accum + in + let tick_interval = + match tick_interval with + Some t -> t + | None -> step + in + + (* Setup the color bar shades according to the given step size *) + let shades = + Array.init + (int_of_float ((cmax -. cmin) /. step) + 1) + (fun i -> float_of_int i *. step) + in + (* Unit x-axis, y-axis scaled to contour values *) + plwind 0.0 1.0 cmin cmax; + (* Small ticks on the vertical axis *) + plsmaj 1.0 1.0; + (* Show each contour *) + plshades [| shades; shades |] 0.0 1.0 cmin cmax shades 0 0 0 0; + plcol0 15; + plbox "bc" 0.0 0 "bcmtv" tick_interval 0; + + (* Set the character size to the old values *) + plschr old_default old_scale; + () + +(** [color_bar0 ?tick_interval ?step contours base_color color_step] -- + See [color_bar]. This does the same thing, except that it uses color map 0 + for the colors. [base_color] is the first map 0 index to use, and + [color_step] is the index increment. So the colors used are: + cmap0.(base_color + n * color_step) for n in 0 .. (Array.length contours) +*) +let color_bar0 ?(tick_interval) ?(step) contours base_color color_step = + (* Save some plot parameters to restore at the end of the function *) + let (old_default, old_scaled) = plgchr () in + let old_col0 = plg_current_col0 () in + let (old_vxmin, old_vxmax, old_vymin, old_vymax) = plgvpd () in + let (old_wxmin, old_wxmax, old_wymin, old_wymax) = plgvpw () in + + (* A wee, tiny little font for the color scale *) + plschr 0.0 0.50; + + (* Vertical bar on the right side of the plot canvas *) + plvpor 0.93 0.96 0.15 0.85; + + (* Minimum and maximum values *) + let cmin = Array.fold_left min infinity contours in + let cmax = Array.fold_left max neg_infinity contours in + + (* Find the smallest step between contours, if none is provided *) + let step = + match step with + Some s -> s + | None -> + let accum = ref 0.0 in + for i = 1 to Array.length contours - 1 do + let delta = contours.(i) -. contours.(i - 1) in + if delta > !accum then + accum := delta + else + () + done; + !accum + in + let tick_interval = + match tick_interval with + Some t -> t + | None -> step + in + + (* Setup the color bar shades according to the given step size *) + let shades = + Array.init + ((int_of_float (cmax -. cmin) + 1) * int_of_float step) + (fun i -> float_of_int i *. step) + in + (* Unit x-axis, y-axis scaled to contour values *) + plwind 0.0 1.0 cmin cmax; + (* Small ticks on the vertical axis *) + plsmaj 0.0 0.5; + (* Show each contour *) + plshades0 [| contours; contours |] 0.0 1.0 cmin cmax contours base_color color_step; + plcol0 15; + plbox "bc" 0.0 0 "bcmtv" tick_interval 0; + + (* Set things back to their old/default values *) + plschr old_scaled 1.0; + plcol0 old_col0; + plsmaj 0.0 1.0; + plvpor old_vxmin old_vxmax old_vymin old_vymax; + plwind old_wxmin old_wxmax old_wymin old_wymax; + () + Added: trunk/bindings/ocaml/libplplot_stubs.clib =================================================================== --- trunk/bindings/ocaml/libplplot_stubs.clib (rev 0) +++ trunk/bindings/ocaml/libplplot_stubs.clib 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1 @@ +plplot_impl.o plplot_stubs.o Added: trunk/bindings/ocaml/myocamlbuild.ml.cmake =================================================================== --- trunk/bindings/ocaml/myocamlbuild.ml.cmake (rev 0) +++ trunk/bindings/ocaml/myocamlbuild.ml.cmake 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,83 @@ +open Ocamlbuild_plugin;; +open Command;; + +(* ocamlfind packages required for compilation *) +let packages = "";; + +(* Build an appropriate ocamlfind command line *) +let ocamlfind cmd = + S [A "ocamlfind"; A cmd; A "-package"; A packages];; + +(* Link packages in when needed. *) +flag ["ocaml"; "link"; "program"] (A "-linkpkg");; + +(* The camlidl command to use (default: first one found in $PATH) *) +let camlidl = S([A"camlidl"; A"-header"]);; + +(* Files included in the main idl descriptor *) +let idl_includes = ["plplot_h.inc"];; + +(* A simple function to check if a string is empty/whitespace *) +let is_all_whitespace s = + try + String.iter (fun c -> if c <> ' ' then raise Exit) s; + true + with Exit -> false + +let get_env_elem s = + let it = getenv s in + match is_all_whitespace it with + true -> N + | false -> A it + +;; + +dispatch begin function + | After_options -> + (* Redefine ocaml{c,opt,dep} to use the ocamlfind equivalents *) + Options.ocamlc := ocamlfind "c"; + Options.ocamlopt := ocamlfind "opt"; + Options.ocamldep := ocamlfind "dep"; + | After_rules -> + (* Handle *.idl files properly... I think *) + rule "camlidl processing" + ~prods:["%.mli"; "%.ml"; "%_stubs.c"] + ~deps:["%.idl"] + begin fun env _build -> + let idl = env "%.idl" in + let tags = tags_of_pathname idl++"compile"++"camlidl" in + let cmd = Cmd(S[camlidl; T tags; P idl]) in + Seq [cmd] + end; + + (* Include the plplot and camlidl compiler options for ocamlmklib *) + flag ["ocamlmklib"; "c"] + (S[A"-L@BUILD_DIR@/src"; A"-lplplot@LIB_TAG@"; A"-L@CAMLIDL_LIB_DIR@"; A"-lcamlidl"]); + + (* gcc needs to know where to find the needed #includes *) + flag ["c"; "compile"] + (S[A"-ccopt"; A"-I@SOURCE_DIR@/include"; + A"-ccopt"; A"-I@BUILD_DIR@/include"] ); + + (* Custom tag for OCaml bytecode *) + flag ["ocaml"; "link"; "byte"] + (A"-custom"); + + (* Use the proper extras when compiling the OCaml library *) + flag ["ocaml"; "link"; "library"; "byte"] + (S[A"-dllib"; A"-lplplot_stubs"; A"-cclib"; A"-lplplot_stubs"; + A"-cclib"; A"-lplplot@LIB_TAG@"; A"-cclib"; A"-lcamlidl"]); + + flag ["ocaml"; "link"; "library"; "native"] + (S[A"-cclib"; A"-lplplot_stubs"; + A"-cclib"; A"plplot@LIB_TAG@"; + A"-cclib"; A"-lcamlidl"]); + + (* Make sure the C pieces and built... *) + dep ["ocaml"; "compile"] ["libplplot_stubs.a"]; + + (* Any camlidl work must be updated if the camlidl inputs are changed *) + dep ["compile"; "camlidl"] idl_includes; + + | _ -> () +end Added: trunk/bindings/ocaml/plplot.idl =================================================================== --- trunk/bindings/ocaml/plplot.idl (rev 0) +++ trunk/bindings/ocaml/plplot.idl 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,132 @@ +/* +Copyright 2007 Hezekiah M. Carty + +This file is part of ocaml-plplot. + +ocaml-plplot is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Foobar is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with ocaml-plplot. If not, see <http://www.gnu.org/licenses/>. +*/ + +// This is a simplified and modified version of the plplot.h file. +#include "plplot_h.inc" + +// These functions require(d) some manual assistance to get them to work +// properly +#define PLINT int +#define PLFLT double +#define PLBOOL int + +[mlname(plcont)] void ml_plcont( + [size_is(nx,ny)] PLFLT **f, PLINT nx, PLINT ny, + PLINT kx, PLINT lx, PLINT ky, PLINT ly, + [size_is(nlevel)] PLFLT *clevel, PLINT nlevel); + +[mlname(plshade)] void ml_plshade( + [size_is(nx,ny)] PLFLT **a, PLINT nx, PLINT ny, + PLFLT left, PLFLT right, PLFLT bottom, PLFLT top, + PLFLT shade_min, PLFLT shade_max, + PLINT sh_cmap, PLFLT sh_color, PLINT sh_width, + PLINT min_color, PLINT min_width, + PLINT max_color, PLINT max_width, + PLBOOL rectangular); + +[mlname(plshades)] void ml_plshades( + [size_is(nx,ny)] PLFLT **a, PLINT nx, PLINT ny, + PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + [size_is(nlevel)] PLFLT *clevel, PLINT nlevel, PLINT fill_width, + PLINT cont_color, PLINT cont_width, + PLBOOL rectangular); + +[mlname(plimagefr)] void ml_plimagefr( + [size_is(nx, ny)] PLFLT **idata, PLINT nx, PLINT ny, + PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT zmin, PLFLT zmax, + PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax, + PLFLT valuemin, PLFLT valuemax); + +[mlname(plvect)] void ml_plvect( + [size_is(nx,ny)] PLFLT **u, [size_is(nx,ny)] PLFLT **v, + PLINT nx, PLINT ny, PLFLT scale); + +[mlname(plmap)] void ml_plmap( + [string] const char *type, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat); + +[mlname(plmeridians)] void ml_plmeridians( + PLFLT dlong, PLFLT dlat, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat); + +// XXX The following are non-standard functions which help retrieve some extra +// information from PLplot. +int plg_current_col0(void); +float plg_current_col1(void); +int plgwid(void); +float plgchrht(void); + +#define QUOTEME(x) #x +#define RAW_ML(x) quote(mlmli, QUOTEME(x)); + +// Setting the translation function for the contouring and plotting functions +quote(ml, + "let set_pltr (f : float -> float -> (float * float)) =\ + Callback.register \"caml_plplot_plotter\" f"); +quote(mli, "val set_pltr : (float -> float -> (float * float)) -> unit"); +quote(ml, "let unset_pltr () = Callback.register \"caml_plplot_plotter\" 0"); +quote(mli, "val unset_pltr : unit -> unit"); + +// Setting the translation function for the map drawing functions +quote(ml, + "let set_mapform (f : float -> float -> (float * float)) =\ + Callback.register \"caml_plplot_mapform\" f"); +quote(mli, "val set_mapform : (float -> float -> (float * float)) -> unit"); +quote(ml, + "let unset_mapform () = Callback.register \"caml_plplot_mapform\" 0"); +quote(mli, "val unset_mapform : unit -> unit"); + +// Setting the "defined" function for the shading functions +quote(ml, +"let set_defined (f : float -> float -> int) =\ + Callback.register \"caml_plplot_defined\" f"); +quote(mli, "val set_defined : (float -> float -> int) -> unit"); +quote(ml, + "let unset_defined () = Callback.register \"caml_plplot_defined\" 0"); +quote(mli, "val unset_defined : unit -> unit"); + +// plgriddata wrapper +// These #define lines were pulled from plplot.h, v5.8.0 +#define _GRID_CSA 1 /* Bivariate Cubic Spline approximation */ +#define _GRID_DTLI 2 /* Delaunay Triangulation Linear Interpolation */ +#define _GRID_NNI 3 /* Natural Neighbors Interpolation */ +#define _GRID_NNIDW 4 /* Nearest Neighbors Inverse Distance Weighted */ +#define _GRID_NNLI 5 /* Nearest Neighbors Linear Interpolation */ +#define _GRID_NNAIDW 6 /* Nearest Neighbors Around Inverse Distance Weighted */ + +typedef enum { + GRID_CSA = _GRID_CSA, + GRID_DTLI = _GRID_DTLI, + GRID_NNI = _GRID_NNI, + GRID_NNIDW = _GRID_NNIDW, + GRID_NNLI = _GRID_NNLI, + GRID_NNAIDW = _GRID_NNAIDW, +} plplot_grid_method_type; + +RAW_ML(external plgriddata : float array -> float array -> float array -> float array -> float array -> plplot_grid_method_type -> float -> float array array = "ml_plgriddata_bytecode" "ml_plgriddata") + +// Taken from the plplot.h 3D plot style definitions +// XXX TODO This is currently unused... +/* +enum plot_style_enum { DRAW_LINEX = 1, DRAW_LINEY = 2, DRAW_LINEXY = 3, MAG_COLOR = 4, + BASE_CONT = 8, TOP_CONT = 16, SURF_CONT = 32, DRAW_SIDES = 64, + FACETED = 128, MESH = 256 }; +typedef [set] enum plot_style_enum plot_style; +*/ Added: trunk/bindings/ocaml/plplot_h =================================================================== --- trunk/bindings/ocaml/plplot_h (rev 0) +++ trunk/bindings/ocaml/plplot_h 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,719 @@ +//typedef double PLFLT; +#define PLFLT double + +//typedef unsigned int PLUNICODE; +//typedef int PLINT; +#define PLUNICODE unsigned int +#define PLINT int + +//typedef PLINT PLBOOL; +#define PLBOOL int + + void +c_pl_setcontlabelformat(PLINT lexp, PLINT sigdig); + + void +c_pl_setcontlabelparam(PLFLT offset, PLFLT size, PLFLT spacing, PLINT active); + + void +c_pladv(PLINT page); + +/* + void +c_plarrows(PLFLT *u, PLFLT *v, PLFLT *x, PLFLT *y, PLINT n, + PLFLT scale, PLFLT dx, PLFLT dy) ; + + void +c_plvect(PLFLT **u, PLFLT **v, PLINT nx, PLINT ny, PLFLT scale, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); +*/ + + void +c_plsvect(PLFLT *arrowx, PLFLT *arrowy, PLINT npts, PLBOOL fill); + + void +c_plaxes(PLFLT x0, PLFLT y0, const char *xopt, PLFLT xtick, PLINT nxsub, + const char *yopt, PLFLT ytick, PLINT nysub); + + void +c_plbin(PLINT nbin, PLFLT *x, PLFLT *y, PLINT opt); + + void +c_plbop(void); + + void +c_plbox(const char *xopt, PLFLT xtick, PLINT nxsub, + const char *yopt, PLFLT ytick, PLINT nysub); + + void +c_plbox3(const char *xopt, const char *xlabel, PLFLT xtick, PLINT nsubx, + const char *yopt, const char *ylabel, PLFLT ytick, PLINT nsuby, + const char *zopt, const char *zlabel, PLFLT ztick, PLINT nsubz); + + void +c_plcalc_world(PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window); + + void +c_plclear(void); + + void +c_plcol0(PLINT icol0); + + void +c_plcol1(PLFLT col1); + +/* + void +c_plcont(PLFLT **f, PLINT nx, PLINT ny, PLINT kx, PLINT lx, + PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); + + void +plfcont(PLFLT (*f2eval) (PLINT, PLINT, PLPointer), + PLPointer f2eval_data, + PLINT nx, PLINT ny, PLINT kx, PLINT lx, + PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); +*/ + + void +c_plcpstrm(PLINT iplsr, PLBOOL flags); + +/* + void +pldid2pc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax); + + void +pldip2dc(PLFLT *xmin, PLFLT *ymin, PLFLT *xmax, PLFLT *ymax); +*/ + + void +c_plend(void); + + void +c_plend1(void); + + void +c_plenv(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLINT just, PLINT axis); + + void +c_plenv0(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLINT just, PLINT axis); + + void +c_pleop(void); + + void +c_plerrx(PLINT n, PLFLT *xmin, PLFLT *xmax, PLFLT *y); + + void +c_plerry(PLINT n, PLFLT *x, PLFLT *ymin, PLFLT *ymax); + + void +c_plfamadv(void); + + void +c_plfill(PLINT n, PLFLT *x, PLFLT *y); + + void +c_plfill3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z); + + void +c_plflush(void); + + void +c_plfont(PLINT ifont); + + void +c_plfontld(PLINT fnt); + + void +c_plgchr(PLFLT *p_def, PLFLT *p_ht); + + void +c_plgcol0(PLINT icol0, PLINT *r, PLINT *g, PLINT *b); + + void +c_plgcol0a(PLINT icol0, PLINT *r, PLINT *g, PLINT *b, PLFLT *a); + + void +c_plgcolbg(PLINT *r, PLINT *g, PLINT *b); + + void +c_plgcolbga(PLINT *r, PLINT *g, PLINT *b, PLFLT *a); + + void +c_plgcompression(PLINT *compression); + + void +c_plgdev(char *p_dev); + + void +c_plgdidev(PLFLT *p_mar, PLFLT *p_aspect, PLFLT *p_jx, PLFLT *p_jy); + + void +c_plgdiori(PLFLT *p_rot); + + void +c_plgdiplt(PLFLT *p_xmin, PLFLT *p_ymin, PLFLT *p_xmax, PLFLT *p_ymax); + + void +c_plgfci(PLUNICODE *pfci); + + void +c_plgfam(PLINT *p_fam, PLINT *p_num, PLINT *p_bmax); + + void +c_plgfnam(char *fnam); + + void +c_plglevel(PLINT *p_level); + + void +c_plgpage(PLFLT *p_xp, PLFLT *p_yp, + PLINT *p_xleng, PLINT *p_yleng, PLINT *p_xoff, PLINT *p_yoff); + + void +c_plgra(void); + +/* + void +c_plgriddata(PLFLT *x, PLFLT *y, PLFLT *z, PLINT npts, + PLFLT *xg, PLINT nptsx, PLFLT *yg, PLINT nptsy, + PLFLT **zg, PLINT type, PLFLT data); +*/ + + void +c_plgspa(PLFLT *xmin, PLFLT *xmax, PLFLT *ymin, PLFLT *ymax); + + void +c_plgstrm(PLINT *p_strm); + + void +c_plgver(char *p_ver); + + void +c_plgvpd(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax); + + void +c_plgvpw(PLFLT *p_xmin, PLFLT *p_xmax, PLFLT *p_ymin, PLFLT *p_ymax); + + void +c_plgxax(PLINT *p_digmax, PLINT *p_digits); + + void +c_plgyax(PLINT *p_digmax, PLINT *p_digits); + + void +c_plgzax(PLINT *p_digmax, PLINT *p_digits); + + void +c_plhist(PLINT n, PLFLT *data, PLFLT datmin, PLFLT datmax, + PLINT nbin, PLINT opt); + + void +c_plhls(PLFLT h, PLFLT l, PLFLT s); + + void +c_plhlsrgb(PLFLT h, PLFLT l, PLFLT s, PLFLT *p_r, PLFLT *p_g, PLFLT *p_b); + + void +c_plinit(void); + + void +c_pljoin(PLFLT x1, PLFLT y1, PLFLT x2, PLFLT y2); + + void +c_pllab(const char *xlabel, const char *ylabel, const char *tlabel); + + void +c_pllightsource(PLFLT x, PLFLT y, PLFLT z); + + void +c_plline(PLINT n, PLFLT *x, PLFLT *y); + + void +c_plline3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z); + + void +c_pllsty(PLINT lin); + +/* + void +c_plmap( void (*mapform)(PLINT, PLFLT *, PLFLT *), const char *type, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat ); + + void +c_plmeridians( void (*mapform)(PLINT, PLFLT *, PLFLT *), + PLFLT dlong, PLFLT dlat, + PLFLT minlong, PLFLT maxlong, PLFLT minlat, PLFLT maxlat ); +*/ + + void +c_plmesh(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt); + + void +c_plmeshc(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, PLINT opt, + PLFLT *clevel, PLINT nlevel); + + void +c_plmkstrm(PLINT *p_strm); + + void +c_plmtex(const char *side, PLFLT disp, PLFLT pos, PLFLT just, + const char *text); + + void +c_plmtex3(const char *side, PLFLT disp, PLFLT pos, PLFLT just, + const char *text); + + void +c_plot3d(PLFLT *x, PLFLT *y, PLFLT **z, + PLINT nx, PLINT ny, PLINT opt, PLBOOL side); + + void +c_plot3dc(PLFLT *x, PLFLT *y, PLFLT **z, + PLINT nx, PLINT ny, PLINT opt, + PLFLT *clevel, PLINT nlevel); + +/* + void +c_plot3dcl(PLFLT *x, PLFLT *y, PLFLT **z, + PLINT nx, PLINT ny, PLINT opt, + PLFLT *clevel, PLINT nlevel, + PLINT ixstart, PLINT ixn, PLINT *indexymin, PLINT*indexymax); +*/ + + void +c_plpat(PLINT nlin, PLINT *inc, PLINT *del); + + void +c_plpoin(PLINT n, PLFLT *x, PLFLT *y, PLINT code); + + void +c_plpoin3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z, PLINT code); + + void +c_plpoly3(PLINT n, PLFLT *x, PLFLT *y, PLFLT *z, PLBOOL *draw, PLBOOL ifcc); + + void +c_plprec(PLINT setp, PLINT prec); + + void +c_plpsty(PLINT patt); + + void +c_plptex(PLFLT x, PLFLT y, PLFLT dx, PLFLT dy, PLFLT just, const char *text); + + void +c_plptex3(PLFLT wx, PLFLT wy, PLFLT wz, PLFLT dx, PLFLT dy, PLFLT dz, + PLFLT sx, PLFLT sy, PLFLT sz, PLFLT just, const char *text); + + void +c_plreplot(void); + + void +c_plrgb(PLFLT r, PLFLT g, PLFLT b); + + void +c_plrgb1(PLINT r, PLINT g, PLINT b); + + void +c_plrgbhls(PLFLT r, PLFLT g, PLFLT b, PLFLT *p_h, PLFLT *p_l, PLFLT *p_s); + + void +c_plschr(PLFLT def, PLFLT scale); + + void +c_plscmap0(PLINT *r, PLINT *g, PLINT *b, PLINT ncol0); + + void +c_plscmap0a(PLINT *r, PLINT *g, PLINT *b, PLFLT *a, PLINT ncol0); + + void +c_plscmap0n(PLINT ncol0); + + void +c_plscmap1(PLINT *r, PLINT *g, PLINT *b, PLINT ncol1); + + void +c_plscmap1a(PLINT *r, PLINT *g, PLINT *b, PLFLT *a, PLINT ncol1); + + void +c_plscmap1l(PLBOOL itype, PLINT npts, PLFLT *intensity, + PLFLT *coord1, PLFLT *coord2, PLFLT *coord3, PLBOOL *rev); + + void +c_plscmap1la(PLBOOL itype, PLINT npts, PLFLT *intensity, + PLFLT *coord1, PLFLT *coord2, PLFLT *coord3, PLFLT *a, PLBOOL *rev); + + void +c_plscmap1n(PLINT ncol1); + + void +c_plscol0(PLINT icol0, PLINT r, PLINT g, PLINT b); + + void +c_plscol0a(PLINT icol0, PLINT r, PLINT g, PLINT b, PLFLT a); + + void +c_plscolbg(PLINT r, PLINT g, PLINT b); + + void +c_plscolbga(PLINT r, PLINT g, PLINT b, PLFLT a); + + void +c_plscolor(PLINT color); + + void +c_plscompression(PLINT compression); + + void +c_plsdev(const char *devname); + + void +c_plsdidev(PLFLT mar, PLFLT aspect, PLFLT jx, PLFLT jy); + + void +c_plsdimap(PLINT dimxmin, PLINT dimxmax, PLINT dimymin, PLINT dimymax, + PLFLT dimxpmm, PLFLT dimypmm); + + void +c_plsdiori(PLFLT rot); + + void +c_plsdiplt(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax); + + void +c_plsdiplz(PLFLT xmin, PLFLT ymin, PLFLT xmax, PLFLT ymax); + + void +c_plsesc(char esc); + + void +c_plsfam(PLINT fam, PLINT num, PLINT bmax); + + void +c_plsfci(PLUNICODE fci); + + void +c_plsfnam(const char *fnam); + +/* + void +c_plshade(PLFLT **a, PLINT nx, PLINT ny, PLINT (*defined) (PLFLT, PLFLT), + PLFLT left, PLFLT right, PLFLT bottom, PLFLT top, + PLFLT shade_min, PLFLT shade_max, + PLINT sh_cmap, PLFLT sh_color, PLINT sh_width, + PLINT min_color, PLINT min_width, + PLINT max_color, PLINT max_width, + void (*fill) (PLINT, PLFLT *, PLFLT *), PLBOOL rectangular, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); + + void +c_plshade1(PLFLT *a, PLINT nx, PLINT ny, PLINT (*defined) (PLFLT, PLFLT), + PLFLT left, PLFLT right, PLFLT bottom, PLFLT top, + PLFLT shade_min, PLFLT shade_max, + PLINT sh_cmap, PLFLT sh_color, PLINT sh_width, + PLINT min_color, PLINT min_width, + PLINT max_color, PLINT max_width, + void (*fill) (PLINT, PLFLT *, PLFLT *), PLBOOL rectangular, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); + + void +c_plshades( PLFLT **a, PLINT nx, PLINT ny, PLINT (*defined) (PLFLT, PLFLT), + PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, + PLFLT *clevel, PLINT nlevel, PLINT fill_width, + PLINT cont_color, PLINT cont_width, + void (*fill) (PLINT, PLFLT *, PLFLT *), PLBOOL rectangular, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); + + void +plfshade(PLFLT (*f2eval) (PLINT, PLINT, PLPointer), + PLPointer f2eval_data, + PLFLT (*c2eval) (PLINT, PLINT, PLPointer), + PLPointer c2eval_data, + PLINT nx, PLINT ny, + PLFLT left, PLFLT right, PLFLT bottom, PLFLT top, + PLFLT shade_min, PLFLT shade_max, + PLINT sh_cmap, PLFLT sh_color, PLINT sh_width, + PLINT min_color, PLINT min_width, + PLINT max_color, PLINT max_width, + void (*fill) (PLINT, PLFLT *, PLFLT *), PLBOOL rectangular, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); +*/ + + void +c_plsmaj(PLFLT def, PLFLT scale); + +/* + void +c_plsmem(PLINT maxx, PLINT maxy, void *plotmem); +*/ + + void +c_plsmin(PLFLT def, PLFLT scale); + + void +c_plsori(PLINT ori); + + void +c_plspage(PLFLT xp, PLFLT yp, PLINT xleng, PLINT yleng, + PLINT xoff, PLINT yoff); + + void +c_plspause(PLBOOL pause); + + void +c_plsstrm(PLINT strm); + + void +c_plssub(PLINT nx, PLINT ny); + + void +c_plssym(PLFLT def, PLFLT scale); + + void +c_plstar(PLINT nx, PLINT ny); + + void +c_plstart(const char *devname, PLINT nx, PLINT ny); + + void +c_plstripa(PLINT id, PLINT pen, PLFLT x, PLFLT y); + +/* + void +c_plstripc(PLINT *id, const char *xspec, const char *yspec, + PLFLT xmin, PLFLT xmax, PLFLT xjump, PLFLT ymin, PLFLT ymax, + PLFLT xlpos, PLFLT ylpos, + PLBOOL y_ascl, PLBOOL acc, + PLINT colbox, PLINT collab, + PLINT colline[], PLINT styline[], const char *legline[], + const char *labx, const char *laby, const char *labtop); +*/ + + void +c_plstripd(PLINT id); + +/* + void +c_plimagefr(PLFLT **idata, PLINT nx, PLINT ny, + PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax, + PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax, + PLFLT valuemin, PLFLT valuemax); +*/ + + void +c_plimage(PLFLT **idata, PLINT nx, PLINT ny, + PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax, + PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax); + + void +c_plstyl(PLINT nms, PLINT *mark, PLINT *space); + + void +c_plsurf3d(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, + PLINT opt, PLFLT *clevel, PLINT nlevel); + +/* + void +c_plsurf3dl(PLFLT *x, PLFLT *y, PLFLT **z, PLINT nx, PLINT ny, + PLINT opt, PLFLT *clevel, PLINT nlevel, + PLINT ixstart, PLINT ixn, PLINT *indexymin, PLINT*indexymax); +*/ + + void +c_plsvpa(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax); + + void +c_plsxax(PLINT digmax, PLINT digits); + + void +plsxwin(PLINT window_id); + + void +c_plsyax(PLINT digmax, PLINT digits); + + void +c_plsym(PLINT n, PLFLT *x, PLFLT *y, PLINT code); + + void +c_plszax(PLINT digmax, PLINT digits); + + void +c_pltext(void); + + void +c_pltimefmt(const char *fmt); + + void +c_plvasp(PLFLT aspect); + + void +c_plvpas(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT aspect); + + void +c_plvpor(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax); + + void +c_plvsta(void); + + void +c_plw3d(PLFLT basex, PLFLT basey, PLFLT height, PLFLT xmin0, + PLFLT xmax0, PLFLT ymin0, PLFLT ymax0, PLFLT zmin0, + PLFLT zmax0, PLFLT alt, PLFLT az); + + void +c_plwid(PLINT width); + + void +c_plwind(PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax); + + void +c_plxormod(PLBOOL mode, PLBOOL *status); + +/* + void +plgFileDevs(const char ***p_menustr, const char ***p_devname, int *p_ndev); + + void +plgDevs(const char ***p_menustr, const char ***p_devname, int *p_ndev); + + void +plsKeyEH(void (*KeyEH) (PLGraphicsIn *, void *, int *), void *KeyEH_data); + + void +plsButtonEH(void (*ButtonEH) (PLGraphicsIn *, void *, int *), + void *ButtonEH_data); + + void +plsbopH(void (*handler) (void *, int *), void *handler_data); + + void +plseopH(void (*handler) (void *, int *), void *handler_data); + + void +plsError(PLINT *errcode, char *errmsg); + + void +plsexit(int (*handler) (const char *)); + + void +plsabort(void (*handler) (const char *)); + + void +pltr0(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); + + void +pltr1(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); + + void +pltr2(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); + + void +pltr2p(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data); + + void +pltr0f(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data); + + void +pltr2f(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, void *pltr_data); + + PLFLT +plf2eval2(PLINT ix, PLINT iy, PLPointer plf2eval_data); + + PLFLT +plf2eval(PLINT ix, PLINT iy, PLPointer plf2eval_data); + + PLFLT +plf2evalr(PLINT ix, PLINT iy, PLPointer plf2eval_data); + + void +plClearOpts(void); + + void +plResetOpts(void); + + int +plMergeOpts(PLOptionTable *options, const char *name, const char **notes); + + void +plSetUsage(const char *program_string, const char *usage_string); + +*/ + + int +c_plsetopt(const char *opt, const char *optarg); + +/* + int +plSetOpt(const char *opt, const char *optarg); + + int +c_plparseopts(int *p_argc, const char **argv, PLINT mode); + + void +plOptUsage(void); + + void +plgfile(FILE **p_file); + + void +plsfile(FILE *file); + + void +plgesc(char *p_esc); + + void +pl_cmd(PLINT op, void *ptr); + + int +plFindName(char *p); + + char * +plFindCommand(const char *fn); + + void +plGetName(const char *dir, const char *subdir, const char *filename, char **filespec); + + PLINT +plGetInt(const char *s); + + PLFLT +plGetFlt(const char *s); + + void +plAlloc2dGrid(PLFLT ***f, PLINT nx, PLINT ny); + + void +plFree2dGrid(PLFLT **f, PLINT nx, PLINT ny); +*/ + + void +plMinMax2dGrid(PLFLT **f, PLINT nx, PLINT ny, PLFLT *fmax, PLFLT *fmin); + +/* + int +plGetCursor(PLGraphicsIn *gin); + + int +plTranslateCursor(PLGraphicsIn *gin); + + int +plParseOpts(int *p_argc, const char **argv, PLINT mode); +*/ + + void +plHLS_RGB(PLFLT h, PLFLT l, PLFLT s, PLFLT *p_r, PLFLT *p_g, PLFLT *p_b); + + void +plRGB_HLS(PLFLT r, PLFLT g, PLFLT b, PLFLT *p_h, PLFLT *p_l, PLFLT *p_s); Added: trunk/bindings/ocaml/plplot_h.inc =================================================================== --- trunk/bindings/ocaml/plplot_h.inc (rev 0) +++ trunk/bindings/ocaml/plplot_h.inc 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,140 @@ +void c_pl_setcontlabelformat(int lexp, int sigdig); +[mlname(pl_setcontlabelparam)] void c_pl_setcontlabelparam ( double offset, double size, double spacing, int active ); +[mlname(pladv)] void c_pladv ( int page ); +[mlname(plsvect)] void c_plsvect ( [in, size_is(npts)] double * arrowx, [in, size_is(npts)] double * arrowy, int npts, int fill ); +[mlname(plaxes)] void c_plaxes ( double x0, double y0, [string] const char * xopt, double xtick, int nxsub, [string] const char * yopt, double ytick, int nysub ); +[mlname(plbin)] void c_plbin ( int nbin, double * x, double * y, int opt ); +[mlname(plbop)] void c_plbop ( void ); +[mlname(plbox)] void c_plbox ( [string] const char * xopt, double xtick, int nxsub, [string] const char * yopt, double ytick, int nysub ); +[mlname(plbox3)] void c_plbox3 ( [string] const char * xopt, [string] const char * xlabel, double xtick, int nsubx, [string] const char * yopt, [string] const char * ylabel, double ytick, int nsuby, [string] const char * zopt, [string] const char * zlabel, double ztick, int nsubz ); +[mlname(plcalc_world)] void c_plcalc_world ( double rx, double ry, [out] double * wx, [out] double * wy, [out] int * window ); +[mlname(plclear)] void c_plclear ( void ); +[mlname(plcol0)] void c_plcol0 ( int icol0 ); +[mlname(plcol1)] void c_plcol1 ( double col1 ); +[mlname(plcpstrm)] void c_plcpstrm ( int iplsr, int flags ); +[mlname(plend)] void c_plend ( void ); +[mlname(plend1)] void c_plend1 ( void ); +[mlname(plenv)] void c_plenv ( double xmin, double xmax, double ymin, double ymax, int just, int axis ); +[mlname(plenv0)] void c_plenv0 ( double xmin, double xmax, double ymin, double ymax, int just, int axis ); +[mlname(pleop)] void c_pleop ( void ); +[mlname(plerrx)] void c_plerrx ( int n, [in, size_is(n)] double * xmin, [in, size_is(n)] double * xmax, [in, size_is(n)] double * y ); +[mlname(plerry)] void c_plerry ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * ymin, [in, size_is(n)] double * ymax ); +[mlname(plfamadv)] void c_plfamadv ( void ); +[mlname(plfill)] void c_plfill ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * y ); +[mlname(plfill3)] void c_plfill3 ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * y, [in, size_is(n)] double * z ); +[mlname(plflush)] void c_plflush ( void ); +[mlname(plfont)] void c_plfont ( int ifont ); +[mlname(plfontld)] void c_plfontld ( int fnt ); +[mlname(plgchr)] void c_plgchr ( [out] double * p_def, [out] double * p_ht ); +[mlname(plgcol0)] void c_plgcol0 ( int icol0, [out] int * r, [out] int * g, [out] int * b ); +[mlname(plgcol0a)] void c_plgcol0a ( int icol0, [out] int * r, [out] int * g, [out] int * b, [out] double * a ); +[mlname(plgcolbg)] void c_plgcolbg ( [out] int * r, [out] int * g, [out] int * b ); +[mlname(plgcolbga)] void c_plgcolbga ( [out] int * r, [out] int * g, [out] int * b, [out] double * a ); +[mlname(plgcompression)] void c_plgcompression ( [out] int * compression ); +[mlname(plgdev)] void c_plgdev ( [string, out, length_is(1024)] char * p_dev ); +[mlname(plgdidev)] void c_plgdidev ( [out] double * p_mar, [out] double * p_aspect, [out] double * p_jx, [out] double * p_jy ); +[mlname(plgdiori)] void c_plgdiori ( [out] double * p_rot ); +[mlname(plgdiplt)] void c_plgdiplt ( [out] double * p_xmin, [out] double * p_ymin, [out] double * p_xmax, [out] double * p_ymax ); +[mlname(plgfci)] void c_plgfci ( [out] unsigned int * pfci ); +[mlname(plgfam)] void c_plgfam ( [out] int * p_fam, [out] int * p_num, [out] int * p_bmax ); +[mlname(plgfnam)] void c_plgfnam ( [string, out, length_is(1024)] char * fnam ); +[mlname(plglevel)] void c_plglevel ( [out] int * p_level ); +[mlname(plgpage)] void c_plgpage ( [out] double * p_xp, [out] double * p_yp, [out] int * p_xleng, [out] int * p_yleng, [out] int * p_xoff, [out] int * p_yoff ); +[mlname(plgra)] void c_plgra ( void ); +[mlname(plgspa)] void c_plgspa ( [out] double * xmin, [out] double * xmax, [out] double * ymin, [out] double * ymax ); +[mlname(plgstrm)] void c_plgstrm ( [out] int * p_strm ); +[mlname(plgver)] void c_plgver ( [string, out, length_is(1024)] char * p_ver ); +[mlname(plgvpd)] void c_plgvpd ( [out] double * p_xmin, [out] double * p_xmax, [out] double * p_ymin, [out] double * p_ymax ); +[mlname(plgvpw)] void c_plgvpw ( [out] double * p_xmin, [out] double * p_xmax, [out] double * p_ymin, [out] double * p_ymax ); +[mlname(plgxax)] void c_plgxax ( [out] int * p_digmax, [out] int * p_digits ); +[mlname(plgyax)] void c_plgyax ( [out] int * p_digmax, [out] int * p_digits ); +[mlname(plgzax)] void c_plgzax ( [out] int * p_digmax, [out] int * p_digits ); +[mlname(plhist)] void c_plhist ( int n, [in, size_is(n), size_is(n)] double * data, double datmin, double datmax, int nbin, int opt ); +[mlname(plhls)] void c_plhls ( double h, double l, double s ); +[mlname(plhlsrgb)] void c_plhlsrgb ( double h, double l, double s, double * p_r, double * p_g, double * p_b ); +[mlname(plinit)] void c_plinit ( void ); +[mlname(pljoin)] void c_pljoin ( double x1, double y1, double x2, double y2 ); +[mlname(pllab)] void c_pllab ( [string] const char * xlabel, [string] const char * ylabel, [string] const char * tlabel ); +[mlname(pllightsource)] void c_pllightsource ( double x, double y, double z ); +[mlname(plline)] void c_plline ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * y ); +[mlname(plline3)] void c_plline3 ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * y, [in, size_is(n)] double * z ); +[mlname(pllsty)] void c_pllsty ( int lin ); +[mlname(plmesh)] void c_plmesh ( [size_is(nx), in] double * x, [size_is(ny), in] double * y, [size_is(nx, ny), in] double ** z, int nx, int ny, int opt ); +[mlname(plmeshc)] void c_plmeshc ( [size_is(nx), in] double * x, [size_is(ny), in] double * y, [size_is(nx, ny), in] double ** z, int nx, int ny, int opt, [size_is(nlevel), in] double * clevel, int nlevel ); +[mlname(plmkstrm)] void c_plmkstrm ( int * p_strm ); +[mlname(plmtex)] void c_plmtex ( [string] const char * side, double disp, double pos, double just, [string] const char * text ); +[mlname(plmtex3)] void c_plmtex3 ( [string] const char * side, double disp, double pos, double just, [string] const char * text ); +[mlname(plot3d)] void c_plot3d ( [size_is(nx), in] double * x, [size_is(ny), in] double * y, [size_is(nx, ny), in] double ** z, int nx, int ny, int opt, int side ); +[mlname(plot3dc)] void c_plot3dc ( [size_is(nx), in] double * x, [size_is(ny), in] double * y, [size_is(nx, ny), in] double ** z, int nx, int ny, int opt, [size_is(nlevel), in] double * clevel, int nlevel ); +[mlname(plpat)] void c_plpat ( int nlin, int * inc, int * del ); +[mlname(plpoin)] void c_plpoin ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * y, int code ); +[mlname(plpoin3)] void c_plpoin3 ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * y, [in, size_is(n)] double * z, int code ); +[mlname(plpoly3)] void c_plpoly3 ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * y, [in, size_is(n)] double * z, [in, size_is(n)] int * draw, int ifcc ); +[mlname(plprec)] void c_plprec ( int setp, int prec ); +[mlname(plpsty)] void c_plpsty ( int patt ); +[mlname(plptex)] void c_plptex ( double x, double y, double dx, double dy, double just, [string] const char * text ); +[mlname(plptex3)] void c_plptex3 ( double wx, double wy, double wz, double dx, double dy, double dz, double sx, double sy, double sz, double just, [string] const char * text ); +[mlname(plreplot)] void c_plreplot ( void ); +[mlname(plrgb)] void c_plrgb ( double r, double g, double b ); +[mlname(plrgb1)] void c_plrgb1 ( int r, int g, int b ); +[mlname(plrgbhls)] void c_plrgbhls ( double r, double g, double b, [out] double * p_h, [out] double * p_l, [out] double * p_s ); +[mlname(plschr)] void c_plschr ( double def, double scale ); +[mlname(plscmap0)] void c_plscmap0 ( [size_is(ncol0), in] int * r, [size_is(ncol0), in] int * g, [size_is(ncol0), in] int * b, int ncol0 ); +[mlname(plscmap0a)] void c_plscmap0a ( [size_is(ncol0), in] int * r, [size_is(ncol0), in] int * g, [size_is(ncol0), in] int * b, [size_is(ncol0), in] double * a, int ncol0 ); +[mlname(plscmap0n)] void c_plscmap0n ( int ncol0 ); +[mlname(plscmap1)] void c_plscmap1 ( [size_is(ncol1), in] int * r, [size_is(ncol1), in] int * g, [size_is(ncol1), in] int * b, int ncol1 ); +[mlname(plscmap1a)] void c_plscmap1a ( [size_is(ncol1), in] int * r, [size_is(ncol1), in] int * g, [size_is(ncol1), in] int * b, [size_is(ncol1), in] double * a, int ncol1 ); +[mlname(plscmap1l)] void c_plscmap1l ( int itype, int npts, [size_is(npts), in, size_is(npts)] double * intensity, [size_is(npts), in, size_is(npts)] double * coord1, [size_is(npts), in, size_is(npts)] double * coord2, [size_is(npts), in, size_is(npts)] double * coord3, [in, size_is(npts), in, size_is(npts), unique] int * rev ); +[mlname(plscmap1la)] void c_plscmap1la ( int itype, int npts, [size_is(npts), in, size_is(npts)] double * intensity, [size_is(npts), in, size_is(npts)] double * coord1, [size_is(npts), in, size_is(npts)] double * coord2, [size_is(npts), in, size_is(npts)] double * coord3, [size_is(npts), in, size_is(npts)] double * a, [in, size_is(npts)] int * rev ); +[mlname(plscmap1n)] void c_plscmap1n ( int ncol1 ); +[mlname(plscol0)] void c_plscol0 ( int icol0, int r, int g, int b ); +[mlname(plscol0a)] void c_plscol0a ( int icol0, int r, int g, int b, double a ); +[mlname(plscolbg)] void c_plscolbg ( int r, int g, int b ); +[mlname(plscolbga)] void c_plscolbga ( int r, int g, int b, double a ); +[mlname(plscolor)] void c_plscolor ( int color ); +[mlname(plscompression)] void c_plscompression ( int compression ); +[mlname(plsdev)] void c_plsdev ( [string] const char * devname ); +[mlname(plsdidev)] void c_plsdidev ( double mar, double aspect, double jx, double jy ); +[mlname(plsdimap)] void c_plsdimap ( int dimxmin, int dimxmax, int dimymin, int dimymax, double dimxpmm, double dimypmm ); +[mlname(plsdiori)] void c_plsdiori ( double rot ); +[mlname(plsdiplt)] void c_plsdiplt ( double xmin, double ymin, double xmax, double ymax ); +[mlname(plsdiplz)] void c_plsdiplz ( double xmin, double ymin, double xmax, double ymax ); +[mlname(plsesc)] void c_plsesc ( char esc ); +[mlname(plsfam)] void c_plsfam ( int fam, int num, int bmax ); +[mlname(plsfci)] void c_plsfci ( unsigned int fci ); +[mlname(plsfnam)] void c_plsfnam ( [string] const char * fnam ); +[mlname(plsmaj)] void c_plsmaj ( double def, double scale ); +[mlname(plsmin)] void c_plsmin ( double def, double scale ); +[mlname(plsori)] void c_plsori ( int ori ); +[mlname(plspage)] void c_plspage ( double xp, double yp, int xleng, int yleng, int xoff, int yoff ); +[mlname(plspause)] void c_plspause ( int pause ); +[mlname(plsstrm)] void c_plsstrm ( int strm ); +[mlname(plssub)] void c_plssub ( int nx, int ny ); +[mlname(plssym)] void c_plssym ( double def, double scale ); +[mlname(plstar)] void c_plstar ( int nx, int ny ); +[mlname(plstart)] void c_plstart ( [string] const char * devname, int nx, int ny ); +[mlname(plstripa)] void c_plstripa ( int id, int pen, double x, double y ); +[mlname(plstripd)] void c_plstripd ( int id ); +[mlname(plimage)] void c_plimage ( [in, size_is(nx, ny)] double ** idata, int nx, int ny, double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double Dxmin, double Dxmax, double Dymin, double Dymax ); +[mlname(plstyl)] void c_plstyl ( int nms, [size_is(nms)] int * mark, [size_is(nms)] int * space ); +[mlname(plsurf3d)] void c_plsurf3d ( [size_is(nx), in] double * x, [size_is(ny), in] double * y, [size_is(nx, ny), in] double ** z, int nx, int ny, int opt, [size_is(nlevel), in] double * clevel, int nlevel ); +[mlname(plsvpa)] void c_plsvpa ( double xmin, double xmax, double ymin, double ymax ); +[mlname(plsxax)] void c_plsxax ( int digmax, int digits ); +void plsxwin ( int window_id ); +[mlname(plsyax)] void c_plsyax ( int digmax, int digits ); +[mlname(plsym)] void c_plsym ( int n, [in, size_is(n)] double * x, [in, size_is(n)] double * y, int code ); +[mlname(plszax)] void c_plszax ( int digmax, int digits ); +[mlname(pltext)] void c_pltext ( void ); +[mlname(pltimefmt)] void c_pltimefmt ( [string] const char * fmt ); +[mlname(plvasp)] void c_plvasp ( double aspect ); +[mlname(plvpas)] void c_plvpas ( double xmin, double xmax, double ymin, double ymax, double aspect ); +[mlname(plvpor)] void c_plvpor ( double xmin, double xmax, double ymin, double ymax ); +[mlname(plvsta)] void c_plvsta ( void ); +[mlname(plw3d)] void c_plw3d ( double basex, double basey, double height, double xmin0, double xmax0, double ymin0, double ymax0, double zmin0, double zmax0, double alt, double az ); +[mlname(plwid)] void c_plwid ( int width ); +[mlname(plwind)] void c_plwind ( double xmin, double xmax, double ymin, double ymax ); +[mlname(plxormod)] void c_plxormod ( int mode, [out] int * status ); +[mlname(plsetopt)] int c_plsetopt ( [string] const char * opt, [string] const char * optarg ); +void plMinMax2dGrid ( [size_is(nx, ny)] double ** f, int nx, int ny, [out] double * fmax, [out] double * fmin ); +void plHLS_RGB ( double h, double l, double s, double * p_r, double * p_g, double * p_b ); +void plRGB_HLS ( double r, double g, double b, double * p_h, double * p_l, double * p_s ); Added: trunk/bindings/ocaml/plplot_impl.c =================================================================== --- trunk/bindings/ocaml/plplot_impl.c (rev 0) +++ trunk/bindings/ocaml/plplot_impl.c 2008-05-29 21:11:04 UTC (rev 8441) @@ -0,0 +1,426 @@ +/* +Copyright 2007 Hezekiah M. Carty + +This file is part of ocaml-plplot. + +ocaml-plplot is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +Foobar is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with ocaml-plplot. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <plplotP.h> + +/* The "usual" OCaml includes */ +#include <caml/alloc.h> +#include <caml/callback.h> +#include <caml/fail.h> +#include <caml/memory.h> +#include <caml/misc.h> +#include <caml/mlvalues.h> +#include <caml/bigarray.h> + +#include <plplot.h> + +#include <stdio.h> + +#define MAX_EXCEPTION_MESSAGE_LENGTH 1000 +#define CAML_PLPLOT_PLOTTER_FUNC_NAME "caml_plplot_plotter" +#define CAML_PLPLOT_MAPFORM_FUNC_NAME "caml_plplot_mapform" +#define CAML_PLPLOT_DEFINED_FUNC_NAME "caml_plplot_defined" + +typedef void(*ML_PLOTTER_FUNC)(PLFLT, PLFLT, PLFLT*, PLFLT*, PLPointer); +typedef PLINT(*ML_DEFINED_FUNC)(PLFLT, PLFLT); +typedef void(*ML_MAPFORM_FUNC)(PLINT, PLFLT*, PLFLT*); + +/* + + CALLBACK WRAPPERS + + */ + +// A simple routine to wrap a properly registered OCaml callback in a form +// usable by PLPlot routines. If an appropriate callback is not registered +// then the PLPlot built-in pltr0 function is used instead. +void ml_plotter(PLFLT x, PLFLT y, PLFLT *tx, PLFLT *ty, PLPointer pltr_data) { + CAMLparam0(); + CAMLlocal1(result); + + // Get the OCaml callback function (if there is one) + static value * pltr = NULL; + if (pltr == NULL) + pltr = caml_named_value(CAML_PLPLOT_PLOTTER_FUNC_NAME); + + // No check to see if a callback function has been designated yet, + // because that is checked before we get to this point. + result = + caml_callback2(*pltr, caml_copy_double(x), caml_copy_double(y)); + double new_x, new_y; + new_x = Double_val( Field(result, 0) ); + new_y = Double_val( Field(result, 1) ); + + *tx = new_x; + *ty = new_y; + + CAMLreturn0; +} + +// A simple routine to wrap a properly registered OCaml callback in a form +// usable by PLPlot routines. If an appropriate callback is not registered +// then the result is always 1 (the data point is defined). +// This function is used in the plshade* functions to determine if a given data +// point is valid/defined or not. +PLINT ml_defined(PLFLT x, PLFLT y) { + CAMLparam0(); + CAMLlocal1(result); + + // The result which will be returned to the user. + PLINT is_it_defined; + + // Get the OCaml callback function (if there is one) + static value * defined = NULL; + if (defined == NULL) + defined = caml_named_value(CAML_PLPLOT_DEFINED_FUNC_NAME); + + // No check to see if a callback function has been designated yet, + // because that is checked before we get to this point. + result = + caml_callback2(*defined, caml_copy_double(x), caml_copy_double(y)); + is_it_defined = Int_val(result); + + CAMLreturn(is_it_defined); +} + +// A simple routine to wrap a properly registered OCaml callback in a form +// usable by PLPlot routines. If an appropriate callback is not registered +// then nothing is done. +void ml_mapform(PLINT n, PLFLT *x, PLFLT *y) { + CAMLparam0(); + CAMLlocal1(result); + + // Get the OCaml callback function (if there is one) + static value * mapform = NULL; + if (mapform == NULL) + mapform = caml_named_value(CAML_PLPLOT_MAPFORM_FUNC_NAME); + + // No check to see if a callback function has been designated yet, + // because that is checked before we get to this point. + int i; + for (i = 0; i < n; i++) { + result = + caml_callback2(*mapform, + caml_copy_double(x[i]), caml_copy_double(y[i])); + + double new_x, new_y; + new_x = Double_val( Field(result, 0) ); + new_y = Double_val( Field(result, 1) ); + + x[i] = new_x; + y[i] = new_y; + } + + CAMLreturn0; +} + +// Check if the matching OCaml callback is defined. Return NULL if it is not, +// and the proper function pointer if it is. +ML_PLOTTER_FUNC get_ml_plotter_func() { + static value * pltr = NULL; + if (pltr == NULL) + pltr = caml_named_value(CAML_PLPLOT_PLOTTER_FUNC_NAME); + + if (pltr == NULL || Val_int(0) == *pltr) { + // No plotter defined + return NULL; + } + else { + // Plotter is defined + return ml_plotter; + } +} +ML_DEFINED_FUNC get_ml_defined_func() { + static value * defined = NULL; + if (defined == NULL) + defined = caml_named_value(CAML_PLPLOT_DEFINED_FUNC_NAME); + + if (defined == NULL || Val_int(0) == *defined) { + // No plotter defined + return NULL; + } + else { + // Plotter is defined + return ml_defined; + } +} +ML_MAPFORM_FUNC get_ml_mapform_func() { + static value * mapform = NULL; + if (mapform == NULL) + mapform = caml_named_value(CAML_PLPLOT_MAPFORM_FUNC_NAME); + + if (mapform == NULL || Val_int(0) == *mapform) { + // No plotter defined + return NULL; + } + else { + // Plotter is defined + return ml_mapform; + } +} + + +/* + + CONTOURING, SHADING and IMAGE FUNCTIONS + +*/ + +/* + void +c_plcont(PLFLT **f, PLINT nx, PLINT ny, PLINT kx, PLINT lx, + PLINT ky, PLINT ly, PLFLT *clevel, PLINT nlevel, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); +*/ +void ml_plcont(PLFLT **f, PLINT nx, PLINT ny, + PLINT kx, PLINT lx, PLINT ky, PLINT ly, + PLFLT *clevel, PLINT nlevel) { + if (get_ml_plotter_func() == NULL) { + // This is handled in PLplot, but the error is raised here to clarify + // what the user needs to do since the custom plotter is defined + // separately from the call to plcont. + caml_invalid_argument("A custom plotter must be defined \ + before calling plcont"); + } + else { + c_plcont(f, nx, ny, kx, lx, ky, ly, clevel, nlevel, + get_ml_plotter_func(), (void*)1); + } +} + +/* + void +c_plshade(PLFLT **a, PLINT nx, PLINT ny, PLINT (*defined) (PLFLT, PLFLT), + PLFLT left, PLFLT right, PLFLT bottom, PLFLT top, + PLFLT shade_min, PLFLT shade_max, + PLINT sh_cmap, PLFLT sh_color, PLINT sh_width, + PLINT min_color, PLINT min_width, + PLINT max_color, PLINT max_width, + void (*fill) (PLINT, PLFLT *, PLFLT *), PLBOOL rectangular, + void (*pltr) (PLFLT, PLFLT, PLFLT *, PLFLT *, PLPointer), + PLPointer pltr_data); +*/ +void ml_plshade(PLFLT **a, PLINT nx, PLINT ny, + PLFLT left, PLFLT right, PLFLT bottom, PLFLT top, + PLFLT shade_min, PLFLT shade_max, + PLINT sh_cmap, PLFLT sh_color, PLINT sh_width, + PLINT min_color, PLINT min_width, + PLINT max_color, PLINT max_width, + PLBOOL rectangular) { + c_plshade(a, nx, ny, + ge... [truncated message content] |