From: <ai...@us...> - 2008-07-28 23:37:10
|
Revision: 8597 http://plplot.svn.sourceforge.net/plplot/?rev=8597&view=rev Author: airwin Date: 2008-07-28 23:37:18 +0000 (Mon, 28 Jul 2008) Log Message: ----------- AWI for Hezekiah M. Carty. Implement ocaml examples 4-8. Modified Paths: -------------- trunk/examples/ocaml/CMakeLists.txt trunk/examples/ocaml/Makefile.examples.in trunk/plplot_test/test_ocaml.sh.in Added Paths: ----------- trunk/examples/ocaml/x04.ml trunk/examples/ocaml/x05.ml trunk/examples/ocaml/x06.ml trunk/examples/ocaml/x07.ml trunk/examples/ocaml/x08.ml Modified: trunk/examples/ocaml/CMakeLists.txt =================================================================== --- trunk/examples/ocaml/CMakeLists.txt 2008-07-26 19:30:28 UTC (rev 8596) +++ trunk/examples/ocaml/CMakeLists.txt 2008-07-28 23:37:18 UTC (rev 8597) @@ -24,6 +24,11 @@ "01" "02" "03" + "04" + "05" + "06" + "07" + "08" "11" "19" ) Modified: trunk/examples/ocaml/Makefile.examples.in =================================================================== --- trunk/examples/ocaml/Makefile.examples.in 2008-07-26 19:30:28 UTC (rev 8596) +++ trunk/examples/ocaml/Makefile.examples.in 2008-07-28 23:37:18 UTC (rev 8597) @@ -31,6 +31,11 @@ x01$(EXEEXT) \ x02$(EXEEXT) \ x03$(EXEEXT) \ + x04$(EXEEXT) \ + x05$(EXEEXT) \ + x06$(EXEEXT) \ + x07$(EXEEXT) \ + x08$(EXEEXT) \ x11$(EXEEXT) \ x19$(EXEEXT) \ Added: trunk/examples/ocaml/x04.ml =================================================================== --- trunk/examples/ocaml/x04.ml (rev 0) +++ trunk/examples/ocaml/x04.ml 2008-07-28 23:37:18 UTC (rev 8597) @@ -0,0 +1,96 @@ +(* $Id$ + + Log plot demo. +*) + +open Plplot + +let pi = atan 1.0 *. 4.0 + +(*--------------------------------------------------------------------------*\ + * plot1 + * + * Log-linear plot. +\*--------------------------------------------------------------------------*) + +let plot1 plot_type = + (* + int i; + static PLFLT freql[101], ampl[101], phase[101]; + PLFLT f0, freq; + *) + pladv 0; + + (* Set up data for log plot *) + let f0 = 1.0 in + let freql = Array.init 101 (fun i -> -2.0 +. float_of_int i /. 20.0) in + let freq = Array.map (fun x -> 10.0**x) freql in + let ampl = + Array.map ( + fun x -> 20.0 *. log10 (1.0 /. sqrt (1.0 +. (x /. f0)**2.0)) + ) freq + in + let phase = + Array.map (fun x -> -.(180.0 /. pi) *. atan (x /. f0)) freq + in + + plvpor 0.15 0.85 0.1 0.9; + plwind (-2.0) 3.0 (-80.0) 0.0; + + (* Try different axis and labelling styles. *) + plcol0 1; + let () = + match plot_type with + 0 -> + plbox "bclnst" 0.0 0 "bnstv" 0.0 0; + | 1 -> + plbox "bcfghlnst" 0.0 0 "bcghnstv" 0.0 0; + | _ -> failwith "Bad plot type specified" + in + + (* Plot ampl vs freq *) + plcol0 2; + plline freql ampl; + plcol0 1; + plptex 1.6 (-30.0) 1.0 (-20.0) 0.5 "-20 dB/decade"; + + (* Put labels on *) + plcol0 1; + plmtex "b" 3.2 0.5 0.5 "Frequency"; + plmtex "t" 2.0 0.5 0.5 "Single Pole Low-Pass Filter"; + plcol0 2; + plmtex "l" 5.0 0.5 0.5 "Amplitude (dB)"; + + (* For the gridless case, put phase vs freq on same plot *) + if plot_type = 0 then ( + plcol0 1; + plwind (-2.0) 3.0 (-100.0) 0.0; + plbox "" 0.0 0 "cmstv" 30.0 3; + plcol0 3; + plline freql phase; + plcol0 3; + plmtex "r" 5.0 0.5 0.5 "Phase shift (degrees)"; + () + ) + else + () + +(*--------------------------------------------------------------------------*\ + * Illustration of logarithmic axes, and redefinition of window. +\*--------------------------------------------------------------------------*) + +let () = + (* Parse and process command line arguments *) + ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]); + + (* Initialize plplot *) + plinit(); + plfont 2; + + (* Make log plots using two different styles. *) + plot1 0; + plot1 1; + + plend (); + () + Property changes on: trunk/examples/ocaml/x04.ml ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/examples/ocaml/x05.ml =================================================================== --- trunk/examples/ocaml/x05.ml (rev 0) +++ trunk/examples/ocaml/x05.ml 2008-07-28 23:37:18 UTC (rev 8597) @@ -0,0 +1,36 @@ +(* $Id$ + + Histogram demo. +*) + +open Plplot + +let pi = atan 1.0 *. 4.0 + +let npts = 2047 + +(*--------------------------------------------------------------------------*\ + * Draws a histogram from sample data. +\*--------------------------------------------------------------------------*) + +let () = + (* Parse and process command line arguments *) + ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]); + + (* Initialize plplot *) + plinit (); + + (* Fill up data points *) + + let delta = 2.0 *. pi /. float_of_int npts in + let data = Array.init npts (fun i -> sin (float_of_int i *. delta)) in + + plcol0 1; + plhist data (-1.1) 1.1 44 0; + plcol0 2; + pllab "#frValue" "#frFrequency" + "#frPLplot Example 5 - Probability function of Oscillator"; + + plend (); + () + Property changes on: trunk/examples/ocaml/x05.ml ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/examples/ocaml/x06.ml =================================================================== --- trunk/examples/ocaml/x06.ml (rev 0) +++ trunk/examples/ocaml/x06.ml 2008-07-28 23:37:18 UTC (rev 8597) @@ -0,0 +1,56 @@ +(* $Id$ + + Font demo. +*) + +open Printf +open Plplot + +(*--------------------------------------------------------------------------*\ + * Displays the entire "plpoin" symbol (font) set. +\*--------------------------------------------------------------------------*) +let () = + (* Parse and process command line arguments *) + ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]); + + (* Initialize plplot *) + plinit (); + pladv 0; + + (* Set up viewport and window *) + plcol0 2; + plvpor 0.1 1.0 0.1 0.9; + plwind 0.0 1.0 0.0 1.3; + + (* Draw the grid using plbox *) + plbox "bcg" 0.1 0 "bcg" 0.1 0; + + (* Write the digits below the frame *) + plcol0 15; + for i = 0 to 9 do + plmtex "b" 1.5 (0.1 *. float_of_int i +. 0.05) 0.5 (string_of_int i); + done; + + let k = ref 0 in + for i = 0 to 12 do + (* Write the digits to the left of the frame *) + plmtex "lv" 1.0 (1.0 -. (2.0 *. float_of_int i +. 1.0) /. 26.0) 1.0 + (string_of_int (10 * i)); + for j = 0 to 9 do + let x = 0.1 *. float_of_int j +. 0.05 in + let y = 1.25 -. 0.1 *. float_of_int i in + + (* Display the symbols *) + let () = + if (!k < 128) then + plpoin [|x|] [|y|] !k + else + () + in + incr k; + done + done; + + plmtex "t" 1.5 0.5 0.5 "PLplot Example 6 - plpoin symbols"; + plend (); + () Property changes on: trunk/examples/ocaml/x06.ml ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/examples/ocaml/x07.ml =================================================================== --- trunk/examples/ocaml/x07.ml (rev 0) +++ trunk/examples/ocaml/x07.ml 2008-07-28 23:37:18 UTC (rev 8597) @@ -0,0 +1,60 @@ +(* $Id$ + + Font demo. +*) + +open Plplot + +let base = + [|0; 200; 500; 600; 700; 800; 900; + 2000; 2100; 2200; 2300; 2400; 2500; 2600; 2700; 2800; 2900|] + +(*--------------------------------------------------------------------------*\ + * Displays the entire "plsym" symbol (font) set. +\*--------------------------------------------------------------------------*) + +let () = + (* Parse and process command line arguments *) + ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]); + + (* Initialize plplot *) + plinit (); + + plfontld 1; + for l = 0 to 16 do + pladv 0; + + (* Set up viewport and window *) + plcol0 2; + plvpor 0.15 0.95 0.1 0.9; + plwind 0.0 1.0 0.0 1.0; + + (* Draw the grid using plbox *) + plbox "bcg" 0.1 0 "bcg" 0.1 0; + + (* Write the digits below the frame *) + plcol0 15; + for i = 0 to 9 do + plmtex "b" 1.5 (0.1 *. float_of_int i +. 0.05) 0.5 (string_of_int i); + done; + + let k = ref 0 in + for i = 0 to 9 do + (* Write the digits to the left of the frame *) + plmtex "lv" 1.0 (0.95 -. 0.1 *. float_of_int i) 1.0 + (string_of_int (base.(l) + 10 * i)); + for j = 0 to 9 do + let x = 0.1 *. float_of_int j +. 0.05 in + let y = 0.95 -. 0.1 *. float_of_int i in + + (* Display the symbols *) + plsym [|x|] [|y|] (base.(l) + !k); + incr k; + done; + done; + + plmtex "t" 1.5 0.5 0.5 "PLplot Example 7 - PLSYM symbols"; + done; + plend (); + () + Property changes on: trunk/examples/ocaml/x07.ml ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/examples/ocaml/x08.ml =================================================================== --- trunk/examples/ocaml/x08.ml (rev 0) +++ trunk/examples/ocaml/x08.ml 2008-07-28 23:37:18 UTC (rev 8597) @@ -0,0 +1,185 @@ +(* $Id$ + + 3-d plot demo. + + Copyright (C) 2004 Alan W. Irwin + Copyright (C) 2004 Rafael Laboissiere + Copyright (C) 2008 Hezekiah M. Carty + + 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 Plplot + +let pi = atan 1.0 *. 4.0 + +let xpts = 35 (* Data points in x *) +let ypts = 46 (* Data points in y *) + +let alt = [|60.0; 20.0|] +let az = [|30.0; 60.0|] + +let title = + [| + "#frPLplot Example 8 - Alt=60, Az=30"; + "#frPLplot Example 8 - Alt=20, Az=60"; + |] + +(*--------------------------------------------------------------------------*\ + * cmap1_init1 + * + * Initializes color map 1 in HLS space. + * Basic grayscale variation from half-dark (which makes more interesting + * looking plot compared to dark) to light. + * An interesting variation on this: + * s[1] = 1.0 +\*--------------------------------------------------------------------------*) + +let cmap1_init gray = + let i = [|0.0; 1.0|] in (* left and right boundaries *) + + let h, l, s = + if gray then ( + [|0.0; 0.0|], (* hue -- low: red (arbitrary if s=0) *) + (* hue -- high: red (arbitrary if s=0) *) + [|0.5; 1.0|], (* lightness -- low: half-dark *) + (* lightness -- high: light *) + [|0.0; 0.0|] (* minimum saturation *) + (* minimum saturation *) + ) + else ( + [|240.0; 0.0|], (* blue -> green -> yellow -> *) + (* -> red *) + [|0.6; 0.6|], + [|0.8; 0.8|] + ) + in + + plscmap1n 256; + plscmap1l 0 i h l s None; + () + +let levels = 10 + +(*--------------------------------------------------------------------------*\ + * Does a series of 3-d plots for a given data set, with different + * viewing options in each plot. +\*--------------------------------------------------------------------------*) +let () = + let nlevel = levels in + let rosen = true in + + (* Parse and process command line arguments *) + ignore (plparseopts Sys.argv [|PL_PARSE_FULL|]); + + (* Initialize plplot *) + plinit (); + + (* Allocate data structures *) + let z = Array.make_matrix xpts ypts 0.0 in + + let x = + Array.init xpts ( + fun i -> + (float_of_int (i - (xpts / 2)) /. float_of_int (xpts / 2)) *. + if rosen then + 1.5 + else + 1.0 + ) + in + + let y = + Array.init ypts ( + fun i -> + float_of_int (i - (ypts / 2)) /. float_of_int (ypts / 2) +. + if rosen then + 0.5 + else + 0.0 + ) + in + + for i = 0 to xpts - 1 do + let xx = x.(i) in + for j = 0 to ypts - 1 do + let yy = y.(j) in + if rosen then ( + z.(i).(j) <- (1.0 -. xx)**2. +. 100. *. (yy -. xx**2.)**2.0; + (* The log argument may be zero for just the right grid. *) + if z.(i).(j) > 0.0 then + z.(i).(j) <- log z.(i).(j) + else + z.(i).(j) <- -5. (* -MAXFLOAT would mess-up up the scale *) + ) + else ( + let r = sqrt (xx *. xx +. yy *. yy) in + z.(i).(j) <- exp (-.r *. r) *. cos (2.0 *. pi *. r) + ) + done + done; + + let zmax, zmin = plMinMax2dGrid z in + let step = (zmax -. zmin) /. float_of_int (nlevel + 1) in + let clevel = + Array.init nlevel (fun i -> zmin +. step +. step *. float_of_int i) + in + + pllightsource 1.0 1.0 1.0; + + for k = 0 to 1 do + for ifshade = 0 to 3 do + pladv 0; + plvpor 0.0 1.0 0.0 0.9; + plwind (-1.0) 1.0 (-0.9) 1.1; + plcol0 3; + plmtex "t" 1.0 0.5 0.5 title.(k); + plcol0 1; + if rosen then + plw3d 1.0 1.0 1.0 (-1.5) 1.5 (-0.5) 1.5 zmin zmax alt.(k) az.(k) + else + plw3d 1.0 1.0 1.0 (-1.0) 1.0 (-1.0) 1.0 zmin zmax alt.(k) az.(k); + + plbox3 "bnstu" "x axis" 0.0 0 + "bnstu" "y axis" 0.0 0 + "bcdmnstuv" "z axis" 0.0 0; + plcol0 2; + + (* NOTE: As of now, the named variables for the opt parameter options + have not been defined in the OCaml interface. *) + match ifshade with + 0 -> (* diffuse light surface plot *) + cmap1_init true; + plsurf3d x y z 0 [||]; + | 1 -> (* magnitude colored plot *) + cmap1_init false; + plsurf3d x y z 4 [||]; + | 2 -> (* magnitude colored plot with faceted + squares *) + cmap1_init false; + plsurf3d x y z (4 + 128) [||]; + | _ -> (* magnitude colored plot with contours *) + cmap1_init false; + plsurf3d x y z (4 + 32 + 8) clevel; + done + done; + + (* Clean up *) + plend (); + () + Property changes on: trunk/examples/ocaml/x08.ml ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/plplot_test/test_ocaml.sh.in =================================================================== --- trunk/plplot_test/test_ocaml.sh.in 2008-07-26 19:30:28 UTC (rev 8596) +++ trunk/plplot_test/test_ocaml.sh.in 2008-07-28 23:37:18 UTC (rev 8597) @@ -23,8 +23,7 @@ # and $options defined. # Do the standard non-interactive examples. -# Currently only 11 and 19 are implemented -for index in 01 02 03 11 19; do +for index in 01 02 03 04 05 06 07 08 11 19; do $ocamldir/x${index}ocaml -dev $device -o ${OUTPUT_DIR}/x${index}ocaml.$dsuffix \ $options 2> test.error # Look for any status codes (segfaults, plexit) from the examples themselves. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |