Revision: 9220
http://plplot.svn.sourceforge.net/plplot/?rev=9220&view=rev
Author: airwin
Date: 2008-12-23 22:34:51 +0000 (Tue, 23 Dec 2008)
Log Message:
-----------
AWI for Hezekiah M. Carty. Update OCaml examples 15, 29 and 31 to match up
with the current state of the C examples so that clean ctest compare results
are produced.
Modified Paths:
--------------
trunk/examples/ocaml/x15.ml
trunk/examples/ocaml/x29.ml
trunk/examples/ocaml/x31.ml
Modified: trunk/examples/ocaml/x15.ml
===================================================================
--- trunk/examples/ocaml/x15.ml 2008-12-23 16:44:41 UTC (rev 9219)
+++ trunk/examples/ocaml/x15.ml 2008-12-23 22:34:51 UTC (rev 9220)
@@ -91,6 +91,22 @@
let max_width = 0 in
let sh_width = 2 in
+ let inc =
+ [|
+ [|450|]; [|-450|]; [|0|]; [|900|];
+ [|300|]; [|450;-450|]; [|0; 900|]; [|0; 450|];
+ [|450; -450|]; [|0; 900|];
+ |]
+ in
+ let del =
+ [|
+ [|2000|]; [|2000|]; [|2000|];
+ [|2000|]; [|2000|]; [|2000; 2000|];
+ [|2000; 2000|]; [|2000; 2000|]; [|4000; 4000|];
+ [|4000; 2000|];
+ |]
+ in
+
pladv 0;
plvpor 0.1 0.9 0.1 0.9;
plwind (-1.0) 1.0 (-1.0) 1.0;
@@ -100,7 +116,7 @@
let shade_min = zmin +. (zmax -. zmin) *. float_of_int i /. 10.0 in
let shade_max = zmin +. (zmax -. zmin) *. float_of_int (i + 1) /. 10.0 in
let sh_color = float_of_int (i + 6) in
- plpsty ((i + 2) mod 8 + 1);
+ plpat inc.(i) del.(i);
plshade
z (-1.0) 1.0 (-1.0) 1.0
@@ -116,6 +132,54 @@
()
(*--------------------------------------------------------------------------*\
+ * plot3
+ *
+ * Illustrates shaded regions in 3d, using a different fill pattern for
+ * each region.
+\*--------------------------------------------------------------------------*)
+
+let plot3 () =
+ let xx =
+ [|
+ [|-1.0; 1.0; 1.0; -1.0; -1.0|];
+ [|-1.0; 1.0; 1.0; -1.0; -1.0|];
+ |]
+ in
+ let yy =
+ [|
+ [|1.0; 1.0; 0.0; 0.0; 1.0|];
+ [|-1.0; -1.0; 0.0; 0.0; -1.0|];
+ |]
+ in
+ let zz =
+ [|
+ [|0.0; 0.0; 1.0; 1.0; 0.0|];
+ [|0.0; 0.0; 1.0; 1.0; 0.0|];
+ |]
+ in
+
+ pladv 0;
+ plvpor 0.1 0.9 0.1 0.9;
+ plwind (-1.0) 1.0 (-1.0) 1.0;
+ plw3d 1.0 1.0 1.0 (-1.0) 1.0 (-1.0) 1.0 0.0 1.5 30.0 (-40.0);
+
+ (* Plot using identity transform *)
+ plcol0 1;
+ plbox3 "bntu" "X" 0.0 0 "bntu" "Y" 0.0 0 "bcdfntu" "Z" 0.5 0;
+ plcol0 2;
+ pllab "" "" "3-d polygon filling";
+
+ plcol0 3;
+ plpsty 1;
+ plline3 xx.(0) yy.(0) zz.(0);
+ let sub a = Array.sub a 0 4 in
+ plfill3 (sub xx.(0)) (sub yy.(0)) (sub zz.(0));
+ plpsty 2;
+ plline3 xx.(1) yy.(1) zz.(1);
+ plfill3 (sub xx.(1)) (sub yy.(1)) (sub zz.(1));
+ ()
+
+(*--------------------------------------------------------------------------*\
* Does a variety of shade plots.
\*--------------------------------------------------------------------------*)
let () =
@@ -144,6 +208,7 @@
plot1 z zmin zmax;
plot2 z zmin zmax;
+ plot3 ();
plend ();
()
Modified: trunk/examples/ocaml/x29.ml
===================================================================
--- trunk/examples/ocaml/x29.ml 2008-12-23 16:44:41 UTC (rev 9219)
+++ trunk/examples/ocaml/x29.ml 2008-12-23 22:34:51 UTC (rev 9220)
@@ -30,7 +30,7 @@
(* Plot a model diurnal cycle of temperature *)
let plot1 () =
(* Data points every 10 minutes for 1 day *)
- let npts = 145 in
+ let npts = 73 in
let xmin = 0.0 in
let xmax = 60.0 *. 60.0 *. 24.0 in (* Number of seconds in a day *)
@@ -46,8 +46,21 @@
15.0 -. 5.0 *. cos (2.0 *. pi *. (float_of_int i /. float_of_int npts))
)
in
+
+ (* Set x error bars to +/- 5 minute *)
+ let xerr1 = Array.map (fun xi -> xi -. 60.0 *. 5.0) x in
+ let xerr2 = Array.map (fun xi -> xi +. 60.0 *. 5.0) x in
+ (* Set y error bars to +/- 0.1 deg C *)
+ let yerr1 = Array.map (fun yi -> yi -. 0.1) y in
+ let yerr2 = Array.map (fun yi -> yi +. 0.1) y in
+
pladv 0;
+ (* Rescale major ticks marks by 0.5 *)
+ plsmaj 0.0 0.5;
+ (* Rescale minor ticks and error bar marks by 0.5 *)
+ plsmin 0.0 0.5;
+
plvsta ();
plwind xmin xmax ymin ymax;
@@ -63,6 +76,15 @@
plcol0 4;
plline x y;
+
+ plcol0 2;
+ plerrx xerr1 xerr2 y;
+ plcol0 3;
+ plerry x yerr1 yerr2;
+
+ (* Rescale major / minor tick marks back to default *)
+ plsmin 0.0 1.0;
+ plsmaj 0.0 1.0;
()
(* Plot the number of hours of daylight as a function of day for a year *)
@@ -101,6 +123,7 @@
plcol0 1;
(* Set time format to be abbreviated month name followed by day of month *)
pltimefmt "%b %d";
+ plprec 1 1;
plenv xmin xmax ymin ymax 0 40;
@@ -110,6 +133,8 @@
plcol0 4;
plline x y;
+
+ plprec 0 0;
()
let plot3 () =
@@ -152,6 +177,8 @@
plcol0 4;
+ (* Rescale symbol size (used by plpoin) by 0.5 *)
+ plssym 0.0 0.5;
plpoin x y 2;
plline x y;
()
Modified: trunk/examples/ocaml/x31.ml
===================================================================
--- trunk/examples/ocaml/x31.ml 2008-12-23 16:44:41 UTC (rev 9219)
+++ trunk/examples/ocaml/x31.ml 2008-12-23 22:34:51 UTC (rev 9220)
@@ -1,169 +1,222 @@
(* $Id$
- set/get tester
+ Copyright (C) 2008 Alan W. Irwin
+ Copyright (C) 2008 Andrew Ross
+ Copyright (C) 2008 Hezekiah M. Carty
+
+ set/get tester
+
+ This file is part of PLplot.
+
+ PLplot is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Library Public License as published
+ by the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ 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
+
*)
+open Printf
open Plplot
-open Printf
-(*--------------------------------------------------------------------------*\
- * Demonstrates absolute positioning of graphs on a page.
- \*--------------------------------------------------------------------------*)
-
-let main () =
+let () =
let r1 = [|0; 255|] in
let g1 = [|255; 0|] in
let b1 = [|0; 0|] in
let a1 = [|1.0; 1.0|] in
+ let status = ref 0 in
+ let failed_if t s =
+ if t then (
+ eprintf s;
+ status := 1;
+ );
+ in
+
(* Parse and process command line arguments *)
ignore (plparseopts Sys.argv [PL_PARSE_FULL]);
- (* Test setting / getting page size *)
- let xp, yp, xleng, yleng, xoff, yoff = plgpage () in
- let xp2 = xp *. 0.9 in
- let yp2 = yp *. 0.9 in
- let xleng2 = int_of_float (float_of_int xleng *. 0.9) in
- let yleng2 = int_of_float (float_of_int yleng *. 0.9) in
- plspage xp2 yp2 xleng2 yleng2 xoff yoff;
- let xp, yp, xleng, yleng, xoff, yoff = plgpage () in
- if xp <> xp2 || yp <> yp2 || xleng <> xleng2 || yleng <> yleng2 then (
- failwith "plgpage test failed\n";
- );
+ (* Test setting / getting compression parameter across plinit. *)
+ let compression1 = 95 in
+ plscompression compression1;
- plscompression 1;
- let compression = plgcompression () in
- if (compression <> 1) then (
- failwith "plgcompression test failed\n"
- );
+ (* Test setting / getting familying parameters across plinit *)
+ let fam1 = 0 in
+ let num1 = 10 in
+ let bmax1 = 1000 in
+ plsfam fam1 num1 bmax1;
- let fam, num, bmax = plgfam () in
- plsfam 1 1 100000;
- let fam1, num1, bmax1 = plgfam () in
- if fam1 <> 1 || num1 <> 1 || bmax1 <> 100000 then (
- failwith "plgfam test failed\n";
- );
- plsfam fam num bmax;
+ (* Test setting / getting page parameters across plinit *)
+ let xp1 = 200. in
+ let yp1 = 200. in
+ let xleng1 = 400 in
+ let yleng1 = 200 in
+ let xoff1 = 10 in
+ let yoff1 = 20 in
+ plspage xp1 yp1 xleng1 yleng1 xoff1 yoff1;
(* Initialize plplot *)
plinit ();
+ (* Test if device initialization screwed around with the preset
+ compression parameter. *)
+ let compression2 = plgcompression () in
+ printf "Output various PLplot parameters\n";
+ printf "compression parameter = %d\n" compression2;
+ failed_if
+ (compression2 <> compression1)
+ "plgcompression test failed\n";
+
+ (* Test if device initialization screwed around with any of the
+ preset familying values. *)
+ let fam2, num2, bmax2 = plgfam () in
+ printf "family parameters: fam, num, bmax = %d %d %d\n" fam2 num2 bmax2;
+ failed_if
+ (fam2 <> fam1 || num2 <> num1 || bmax2 <> bmax1)
+ "plgfam test failed\n";
+
+ (* Test if device initialization screwed around with any of the
+ preset page values. *)
+ let xp2, yp2, xleng2, yleng2, xoff2, yoff2 = plgpage () in
+ printf
+ "page parameters: xp, yp, xleng, yleng, xoff, yoff = %f %f %d %d %d %d\n"
+ xp2 yp2 xleng2 yleng2 xoff2 yoff2;
+ failed_if
+ (xp2 <> xp1 || yp2 <> yp1 || xleng2 <> xleng1 || yleng2 <> yleng1 ||
+ xoff2 <> xoff1 || yoff2 <> yoff1)
+ "plgpage test failed\n";
+
+
+ (* Exercise plscolor, plscol0, plscmap1, and plscmap1a to make sure
+ they work without any obvious error messages. *)
plscolor 1;
-
plscol0 1 255 0 0;
-
plscmap1 r1 g1 b1;
plscmap1a r1 g1 b1 a1;
- let level = plglevel () in
- if level <> 1 then (
- let err =
- sprintf "plglevel test failed. Level is %d, but 1 expected.\n" level
- in
- failwith err;
- );
+ let level2 = plglevel () in
+ printf "level parameter = %d\n" level2;
+ failed_if (level2 != 1) "plglevel test failed.\n";
pladv 0;
- plvpor 0.0 1.0 0.0 1.0;
+ plvpor 0.01 0.99 0.02 0.49;
+ let xmin, xmax, ymin, ymax = plgvpd () in
+ printf
+ "plvpor: xmin, xmax, ymin, ymax = %f %f %f %f\n"
+ xmin xmax ymin ymax;
+ failed_if
+ (xmin <> 0.01 || xmax <> 0.99 || ymin <> 0.02 || ymax <> 0.49)
+ "plgvpd test failed\n";
+ let xmid = 0.5 *. (xmin +. xmax) in
+ let ymid = 0.5 *. (ymin +. ymax) in
+
plwind 0.2 0.3 0.4 0.5;
let xmin, xmax, ymin, ymax = plgvpw () in
- if xmin <> 0.2 || xmax <> 0.3 || ymin <> 0.4 || ymax <> 0.5 then (
- failwith "plgvpw test failed\n";
- );
+ printf
+ "plwind: xmin, xmax, ymin, ymax = %f %f %f %f\n"
+ xmin xmax ymin ymax;
+ failed_if
+ (xmin <> 0.2 || xmax <> 0.3 || ymin <> 0.4 || ymax <> 0.5)
+ "plgvpw test failed\n";
- let xmin, xmax, ymin, ymax = plgvpd () in
- if xmin <> 0.0 || xmax <> 1.0 || ymin <> 0.0 || ymax <> 1.0 then (
- failwith "plgvpd test failed\n";
- );
+ (* Get world coordinates for middle of viewport *)
+ let wx, wy, win = plcalc_world xmid ymid in
+ printf "world parameters: wx, wy, win = %f %f %d\n" wx wy win;
+ failed_if
+ (
+ abs_float (wx -. 0.5 *. (xmin +. xmax)) > 1.0E-5 ||
+ abs_float (wy -. 0.5 *. (ymin +. ymax)) > 1.0E-5
+ )
+ "plcalc_world test failed\n";
- (* Get world coordinates for 0.5,0.5 which is in the middle of
- the window *)
- let wx, wy, win = plcalc_world 0.5 0.5 in
- if abs_float (wx -. 0.25) > 1.0E-5 || abs_float (wy -. 0.45) > 1.0E-5 then (
- failwith "plcalc_world test failed\n";
- );
-
- (* Retrieve and print the name of the output file (if any) *)
+ (* Retrieve and print the name of the output file (if any).
+ This goes to stderr not stdout since it will vary between tests and
+ we want stdout to be identical for compare test. *)
let fnam = plgfnam () in
- printf "Output file name is %s\n" fnam;
+ if String.length fnam = 0 then
+ printf "No output file name is set\n"
+ else
+ printf"Output file name read\n";
+ eprintf "Output file name is %s\n" fnam;
(* Set and get the number of digits used to display axis labels *)
(* Note digits is currently ignored in pls[xyz]ax and
therefore it does not make sense to test the returned
value *)
plsxax 3 0;
- let digmax, _ = plgxax () in
- if digmax <> 3 then (
- failwith "plgxax test failed\n";
- );
+ let digmax, digits = plgxax () in
+ printf "x axis parameters: digmax, digits = %d %d\n" digmax digits;
+ failed_if (digmax <> 3) "plgxax test failed\n";
- plsyax 3 0;
- let digmax, _ = plgyax () in
- if digmax <> 3 then (
- failwith "plgyax test failed\n";
- );
+ plsyax 4 0;
+ let digmax, digits = plgyax () in
+ printf "y axis parameters: digmax, digits = %d %d\n" digmax digits;
+ failed_if (digmax <> 4) "plgyax test failed\n";
- plszax 3 0;
- let digmax, _ = plgzax () in
- if digmax <> 3 then (
- failwith "plgzax test failed\n";
- );
+ plszax 5 0;
+ let digmax, digits = plgzax () in
+ printf "z axis parameters: digmax, digits = %d %d\n" digmax digits;
+ failed_if (digmax <> 5) "plgzax test failed\n";
- (* TODO: Add PL_NOTSET definition to the OCaml bindings? *)
- plsdidev 0.05 (-42.0) 0.0 0.0;
+ plsdidev 0.05 (-42.0) 0.1 0.2;
let mar, aspect, jx, jy = plgdidev () in
- if mar <> 0.05 || jx <> 0.0 || jy <> 0.0 then (
- failwith "plgdidev test failed\n";
- );
+ printf
+ "device-space window parameters: mar, aspect, jx, jy = %f %f %f %f\n"
+ mar aspect jx jy;
+ failed_if
+ (mar <> 0.05 || jx <> 0.1 || jy <> 0.2)
+ "plgdidev test failed\n";
plsdiori 1.0;
let ori = plgdiori () in
- if ori <> 1.0 then (
- failwith "plgdiori test failed\n";
- );
+ printf "ori parameter = %f\n" ori;
+ failed_if (ori <> 1.0) "plgdiori test failed\n";
- plsdiplt 0.1 0.1 0.9 0.9;
+ plsdiplt 0.1 0.2 0.9 0.8;
let xmin, ymin, xmax, ymax = plgdiplt () in
- if xmin <> 0.1 || xmax <> 0.9 || ymin <> 0.1 || ymax <> 0.9 then (
- failwith "plgdiplt test failed\n";
- );
+ printf
+ "plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n"
+ xmin ymin xmax ymax;
+ failed_if
+ (xmin <> 0.1 || xmax <> 0.9 || ymin <> 0.2 || ymax <> 0.8)
+ "plgdiplt test failed\n";
plsdiplz 0.1 0.1 0.9 0.9;
- let xmin, ymin, xmax, ymax = plgdiplt () in
- if
- xmin <> 0.1 +. 0.8 *. 0.1 ||
- xmax <> 0.1 +. 0.8 *. 0.9 ||
- ymin <> 0.1 +. 0.8 *. 0.1 ||
- ymax <> 0.1 +. 0.8 *. 0.9
- then (
- failwith "plsdiplz test failed\n";
- );
+ let zxmin, zymin, zxmax, zymax = plgdiplt () in
+ printf
+ "zoomed plot-space window parameters: xmin, ymin, xmax, ymax = %f %f %f %f\n"
+ zxmin zymin zxmax zymax;
+ failed_if (
+ abs_float (zxmin -. (xmin +. (xmax -. xmin) *. 0.1)) > 1.0E-5 ||
+ abs_float (zxmax -. (xmin +. (xmax -. xmin) *. 0.9)) > 1.0E-5 ||
+ abs_float (zymin -. (ymin +. (ymax -. ymin) *. 0.1)) > 1.0E-5 ||
+ abs_float (zymax -. (ymin +. (ymax -. ymin) *. 0.9)) > 1.0E-5
+ ) "plsdiplz test failed\n";
- plscolbg 0 0 0;
+ plscolbg 10 20 30;
let r, g, b = plgcolbg () in
- if r <> 0 || g <> 0 || b <> 0 then (
- failwith "plgcolbg test failed\n";
- );
+ printf "background colour parameters: r, g, b = %d %d %d\n" r g b;
+ failed_if (r <> 10 || g <> 20 || b <> 30) "plgcolbg test failed\n";
- plscolbga 0 0 0 1.0;
+ plscolbga 20 30 40 0.5;
let r, g, b, a = plgcolbga () in
- if r <> 0 || g <> 0 || b <> 0 || a <> 1.0 then (
- failwith "plgcolbga test failed\n";
- );
+ printf
+ "background/transparency colour parameters: r, g, b, a = %d %d %d %f\n"
+ r g b a;
+ failed_if
+ (r <> 20 || g <> 30 || b <> 40 || a <> 0.5)
+ "plgcolbga test failed\n";
- ()
+ plend ();
-let () =
- let () =
- try
- main ()
- with
- | Failure err ->
- prerr_string err;
- plend ();
- exit 1;
- ()
- in
- plend ();
+ exit !status;
()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|