On Thu, Jul 17, 2008 at 9:20 PM, Alan W. Irwin
<[EMAIL PROTECTED]> wrote:
> Hez, how far are you from getting command-line parsing to work for ocaml?
> That would be a huge step forward.
The attached patch updates the OCaml bindings to support plparseopts
and updates the existing OCaml example (01, 02, 03, 11, 19) to use
plparseopts. It also includes a cleanup for the plgriddata wrapper
internals.
With this, I was able to run
export LD_LIBRARY_PATH=`pwd`/build/bindings/ocaml/_build
ctest --verbose -R ocaml
and it completed successfully. It did not work as-is without the
LD_LIBRARY_PATH export. This is with patches that I do not think have
been applied yet to PLplot svn, so the LD_LIBRARY_PATH export may not
be required with the current PLplot svn. It should be once the
appropriate patch is applied.
Hez
--
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science
diff --git a/bindings/ocaml/plplot.idl b/bindings/ocaml/plplot.idl
index e820cba..09262fd 100644
--- a/bindings/ocaml/plplot.idl
+++ b/bindings/ocaml/plplot.idl
@@ -101,25 +101,29 @@ 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;
+// Hand-translated GRID_* flags for use with plgriddata
+quote(mlmli, "type plplot_grid_method_type = \
+ GRID_CSA | \
+ GRID_DTLI | \
+ GRID_NNI | \
+ GRID_NNIDW | \
+ GRID_NNLI | \
+ GRID_NNAIDW");
+
+// Hand-translated PL_PARSE_* flags for use with plparseopts
+quote(mlmli, "type plplot_parse_method_type = \
+ PL_PARSE_PARTIAL | \
+ PL_PARSE_FULL | \
+ PL_PARSE_QUIET | \
+ PL_PARSE_NODELETE | \
+ PL_PARSE_SHOWALL | \
+ PL_PARSE_OVERRIDE | \
+ PL_PARSE_NOPROGRAM | \
+ PL_PARSE_NODASH | \
+ PL_PARSE_SKIP");
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")
+RAW_ML(external plparseopts : string array -> plplot_parse_method_type array -> int = "ml_plparseopts")
// Taken from the plplot.h 3D plot style definitions
// XXX TODO This is currently unused...
diff --git a/bindings/ocaml/plplot_impl.c b/bindings/ocaml/plplot_impl.c
index 37ed58d..093dc43 100644
--- a/bindings/ocaml/plplot_impl.c
+++ b/bindings/ocaml/plplot_impl.c
@@ -395,6 +395,50 @@ value ml_plgriddata_bytecode(value* argv, int argn) {
argv[5], argv[6]);
}
+/* Translate the integer version of the OCaml variant to the appropriate
+ PLplot constant. */
+int translate_parse_option(int parse_option) {
+ int translated_option;
+ switch (parse_option) {
+ case 0: translated_option = PL_PARSE_PARTIAL; break;
+ case 1: translated_option = PL_PARSE_FULL; break;
+ case 2: translated_option = PL_PARSE_QUIET; break;
+ case 3: translated_option = PL_PARSE_NODELETE; break;
+ case 4: translated_option = PL_PARSE_SHOWALL; break;
+ case 5: translated_option = PL_PARSE_OVERRIDE; break;
+ case 6: translated_option = PL_PARSE_NOPROGRAM; break;
+ case 7: translated_option = PL_PARSE_NODASH; break;
+ case 8: translated_option = PL_PARSE_SKIP; break;
+ default: translated_option = -1;
+ }
+ return translated_option;
+}
+
+value ml_plparseopts(value argv, value parse_method) {
+ CAMLparam2(argv, parse_method);
+ int i;
+ int result;
+ int argv_length;
+ int parse_method_length;
+ int combined_parse_method;
+ argv_length = Wosize_val(argv);
+ parse_method_length = Wosize_val(parse_method);
+ // Make a copy of the command line argument strings
+ const char* argv_copy[argv_length];
+ for (i = 0; i < argv_length; i++) {
+ argv_copy[i] = String_val( Field(argv, i) );
+ }
+ // OR the elements of the parse_method array together
+ combined_parse_method = Int_val(Field(parse_method, 0));
+ for (i = 1; i < parse_method_length; i++) {
+ combined_parse_method =
+ combined_parse_method |
+ translate_parse_option(Int_val(Field(parse_method, i)));
+ }
+ result = plparseopts(&argv_length, argv_copy, combined_parse_method);
+ CAMLreturn( Val_int(result) );
+}
+
/* XXX Non-core functions follow XXX */
diff --git a/examples/ocaml/x01.ml b/examples/ocaml/x01.ml
index 84bb184..c932ea1 100644
--- a/examples/ocaml/x01.ml
+++ b/examples/ocaml/x01.ml
@@ -244,8 +244,8 @@ let main fontset =
(* NOT IMPLEMENTED YET
(* Parse and process command line arguments *)
plMergeOpts(options, "x01c options", notes);
- plparseopts(&argc, argv, PL_PARSE_FULL);
*)
+ ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]);
(* Get version number, just for kicks *)
let plplot_version = plgver () in
diff --git a/examples/ocaml/x02.ml b/examples/ocaml/x02.ml
index bed264d..8665388 100644
--- a/examples/ocaml/x02.ml
+++ b/examples/ocaml/x02.ml
@@ -128,10 +128,8 @@ let demo2 () =
\*--------------------------------------------------------------------------*)
let main () =
- (* NOT IMPLEMENTED
(* Parse and process command line arguments *)
- (void) plparseopts(&argc, argv, PL_PARSE_FULL);
- *)
+ ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]);
(* Initialize plplot *)
plinit ();
diff --git a/examples/ocaml/x03.ml b/examples/ocaml/x03.ml
index 1fc33c0..74711a2 100644
--- a/examples/ocaml/x03.ml
+++ b/examples/ocaml/x03.ml
@@ -35,10 +35,8 @@ let main () =
let x0 = Array.init 361 (fun i -> cos (dtr *. float_of_int i)) in
let y0 = Array.init 361 (fun i -> sin (dtr *. float_of_int i)) in
- (* NOT SUPPORTED YET
(* Parse and process command line arguments *)
- (void) plparseopts(&argc, argv, PL_PARSE_FULL);
- *)
+ ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]);
(* Initialize plplot *)
plinit ();
diff --git a/examples/ocaml/x11.ml b/examples/ocaml/x11.ml
index 45414a9..d98e8bc 100644
--- a/examples/ocaml/x11.ml
+++ b/examples/ocaml/x11.ml
@@ -48,6 +48,9 @@ let cmap1_init () =
\*--------------------------------------------------------------------------*)
let () =
+ (* Parse and process command line arguments *)
+ ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]);
+
(* Initialize plplot *)
plinit ();
diff --git a/examples/ocaml/x19.ml b/examples/ocaml/x19.ml
index 8eb7c6a..1a15a65 100644
--- a/examples/ocaml/x19.ml
+++ b/examples/ocaml/x19.ml
@@ -54,6 +54,9 @@ let () =
let miny = -70.0 in
let maxy = 80.0 in
+ (* Parse and process command line arguments *)
+ ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]);
+
plinit();
(* Cartesian plots *)
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel