1## Copyright (C) 1998, 1999, 2000 Joao Cardoso 2## Copyright (C) 2004 Rafael Laboissiere 3## 4## This program is free software; you can redistribute it and/or modify it 5## under the terms of the GNU General Public License as published by the 6## Free Software Foundation; either version 2 of the License, or (at your 7## option) any later version. 8## 9## This program is distributed in the hope that it will be useful, but 10## WITHOUT ANY WARRANTY; without even the implied warranty of 11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12## General Public License for more details. 13## 14## This file is part of plplot_octave. 15## It is based on the corresponding demo function of PLplot. 16## Does a series of 3-d plots for a given data set, with different 17## viewing options in each plot. 18 191; 20 21function cmap1_init(g) 22 i = [0; 1]; # left boundary, right boundary 23 if (g) 24 h = [0; 0]; # hue -- low: red (arbitrary if s=0) -- high: red (arbitrary if s=0) 25 l = [0.5; 1]; # lightness -- low: half-dark -- high: light 26 s = [0; 0]; # minimum saturation 27 else 28 h = [240; 0]; # blue -> green -> yellow -> red 29 l = [0.6; 0.6]; 30 s = [0.8; 0.8]; 31 endif 32 33 plscmap1n(256); 34 plscmap1l(0, i, h, l, s, zeros(2,1)); 35endfunction 36 37 function ix08c 38 39 global MAG_COLOR BASE_CONT SURF_CONT FACETED 40 41 42 # These values must be odd, for the middle 43 # of the index range to be an integer, and thus 44 # to correspond to the exact floating point centre 45 # of the sombrero. 46 47 XPTS=35; ## Data points in x 48 YPTS=45; ## Datat points in y 49 50 alt=[60.0, 40.0]; 51 az =[30.0, -30.0]; 52 53 title=["#frPLplot Example 8 - Alt=60, Az=30"; 54 "#frPLplot Example 8 - Alt=40, Az=-30"]; 55 56 ## Parse and process command line arguments 57 58 ## (void) plparseopts(&argc, argv, PL_PARSE_FULL); 59 60 ## Initialize plplot 61 plinit(); 62 63 rosen = 0; 64 65 dx = 2. / ( XPTS - 1 ); 66 dy = 2. / ( YPTS - 1 ); 67 x = -1. + dx*(0:XPTS-1); 68 y = -1. + dy*(0:YPTS-1); 69 if (rosen) 70 x = x * 1.5; 71 y = y + 0.5; 72 endif 73 [xx, yy] = meshgrid(x,y); 74 75 if (rosen) 76 z = (1 - xx) .^ 2 + 100 .* (yy - xx .^ 2) .^ 2; 77 if exist ("do_fortran_indexing") 78 of = do_fortran_indexing; 79 do_fortran_indexing = 1; 80 endif 81 z(z <= 0) = exp(-5); # make sure the minimum after applying log() is -5 82 if exist ("do_fortran_indexing") 83 do_fortran_indexing = of; 84 endif 85 z = log(z); 86 else 87 r = sqrt(xx .* xx + yy .* yy); 88 z = exp(-r .* r) .* cos(2.0 * pi .* r); 89 endif 90 91 pllightsource(1.,1.,1.); 92 93 n_col = 100; 94 plscmap1n(n_col); 95 96 # Set up data and arrays for plsurf3dl call below. 97 indexxmin = 0; 98 indexxmax = XPTS; 99 # Must be same shape as z, and a row of z. 100 # Parameters of ellipse that limits the data. 101 x0 = 0.5*(XPTS - 1); 102 a = 0.9*x0; 103 y0 = 0.5*(YPTS - 1); 104 b = 0.7*y0; 105 106 for i=indexxmin+1: indexxmax 107 square_root = sqrt(1. - min(1., (((i-1) - x0)/a)^2)); 108 # Add 0.5 to find nearest integer and therefore preserve symmetry 109 # with regard to lower and upper bound of y range. 110 indexymin(i) = max(0, floor(0.5 + y0 - b*square_root)); 111 # indexymax calculated with the convention that it is 1 112 # greater than highest valid index. 113 indexymax(i) = min(YPTS, 1 + floor(0.5 + y0 + b*square_root)); 114 zlimited(indexymin(i)+1:indexymax(i),i) = z(indexymin(i)+1:indexymax(i),i); 115 endfor 116 # Force zlimited to be the correct size so that the plsurf3dl call below passes 117 # all dimension consistency checks. This index is outside the elliptical 118 # limits above so should be ignored at the C level. 119 zlimited(YPTS, XPTS) = 1.e300; 120 121 nlevel = 10; 122 zmax = max(max(z)); 123 zmin = min(min(z)); 124 step = (zmax-zmin)/(nlevel+1); 125 clevel = linspace(zmin+step, zmax-step, nlevel)'; 126 127 for k=1:2 128 for ifshade=0:4 129 130 pladv(0); 131 plvpor(0.0, 1.0, 0.0, 0.9); 132 plwind(-1.0, 1.0, -0.9, 1.1); 133 plcol0(3); 134 plmtex("t", 1.0, 0.5, 0.5, deblank(title(k,:))); 135 plcol0(1); 136 if (rosen) 137 plw3d(1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax, alt(k), az(k)); 138 else 139 plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax, alt(k), az(k)); 140 endif 141 142 plbox3("bnstu", "x axis", 0.0, 0, 143 "bnstu", "y axis", 0.0, 0, 144 "bcdmnstuv", "z axis", 0.0, 0); 145 plcol0(2); 146 147 switch(ifshade) 148 case 0 149 cmap1_init(1); 150 plsurf3d(x', y', z', 0, 0); 151 case 1 152 cmap1_init(0); 153 plsurf3d(x', y', z', MAG_COLOR, 0); 154 case 2 155 plsurf3d(x', y', z', MAG_COLOR + FACETED, 0); 156 case 3 157 plsurf3d(x', y', z', MAG_COLOR + SURF_CONT + BASE_CONT, clevel); 158 case 4 159 plsurf3dl(x', y', z', MAG_COLOR + SURF_CONT + BASE_CONT, clevel, indexxmin, indexymin', indexymax'); 160 endswitch 161 endfor 162 endfor 163 plend1(); 164 endfunction 165 166ix08c 167