comparison doc/interpreter/sparseimages.m @ 6040:2bcb2fa24bbf

[project @ 2006-10-09 15:13:29 by jwe]
author jwe
date Mon, 09 Oct 2006 15:13:29 +0000
parents 7f8e4f5e2eb7
children c0011bf8f815
comparison
equal deleted inserted replaced
6039:2c9b89b6b919 6040:2bcb2fa24bbf
1 function sparseimages(nm,typ) 1 function sparseimages(nm,typ)
2 if (! isempty (findstr (octave_config_info ("DEFS"), "HAVE_COLAMD"))
3 && ! isempty (findstr (octave_config_info ("DEFS"), "HAVE_CHOLMOD"))
4 && ! isempty (findstr (octave_config_info ("DEFS"), "HAVE_UMFPACK")))
2 if (strcmp(typ,"txt")) 5 if (strcmp(typ,"txt"))
3 txtimages(nm,15,typ); 6 txtimages (nm, 15, typ);
4 else 7 else
5 if (strcmp (nm, "gplot")) 8 if (strcmp (nm, "gplot"))
6 gplotimages("gplot",typ); 9 gplotimages ("gplot", typ);
7 elseif (strcmp (nm, "grid")) 10 elseif (strcmp (nm, "grid"))
8 femimages("grid",typ); 11 femimages ("grid", typ);
9 else 12 else
10 otherimages(nm,200,typ); 13 otherimages (nm, 200, typ);
11 endif 14 endif
12 endif 15 endif
13 ## Kluge to give gnuplot enough time to process last figure before we 16 ## Kluge to give gnuplot enough time to process last figure before we
14 ## exit. Otherwise, Octave will delete the temporary data files when 17 ## exit. Otherwise, Octave will delete the temporary data files when
15 ## it exits and gnuplot will fail... 18 ## it exits and gnuplot will fail...
16 sleep (1); 19 sleep (1);
20 else ## There is no sparse matrix implementation available because
21 ## of missing libraries, plot sombreros instead
22 sombreroimage (nm, typ);
23 endif
17 endfunction 24 endfunction
18 25
19 ## Use this function before plotting commands and after every call to 26 ## Use this function before plotting commands and after every call to
20 ## print since print() resets output to stdout (unfortunately, gnpulot 27 ## print since print() resets output to stdout (unfortunately, gnpulot
21 ## can't pop output as it can the terminal type). 28 ## can't pop output as it can the terminal type).
22 function bury_output () 29 function bury_output ()
23 automatic_replot(0); 30 automatic_replot (0);
24 __gnuplot_set__ term dumb 31 __gnuplot_set__ term dumb
25 [status, dummy] = fileattrib("/dev/null"); 32 [status, dummy] = fileattrib ("/dev/null");
26 if (status) 33 if (status)
27 __gnuplot_raw__ ("set output \"/dev/null\"\n"); 34 __gnuplot_raw__ ("set output \"/dev/null\"\n");
28 endif 35 endif
29 endfunction 36 endfunction
30 37
31 function gplotimages(nm,typ) 38 function gplotimages (nm, typ)
32 bury_output (); 39 bury_output ();
33 A = sparse([2,6,1,3,2,4,3,5,4,6,1,5], 40 A = sparse ([2,6,1,3,2,4,3,5,4,6,1,5],
34 [1,1,2,2,3,3,4,4,5,5,6,6],1,6,6); 41 [1,1,2,2,3,3,4,4,5,5,6,6], 1, 6, 6);
35 xy = [0,4,8,6,4,2;5,0,5,7,5,7]'; 42 xy = [0,4,8,6,4,2;5,0,5,7,5,7]';
36 gplot(A,xy) 43 gplot (A, xy)
37 print(strcat(nm,".",typ),strcat("-d",typ)) 44 print (strcat (nm, ".", typ), strcat ("-d", typ))
38 bury_output (); 45 bury_output ();
39 endfunction 46 endfunction
40 47
41 function txtimages(nm,n,typ) 48 function txtimages(nm,n,typ)
42 a = 10*speye(n) + sparse(1:n,ceil([1:n]/2),1,n,n) + ... 49 a = 10*speye(n) + sparse(1:n,ceil([1:n]/2),1,n,n) + ...
217 unwind_protect_cleanup 224 unwind_protect_cleanup
218 __gnuplot_set__ noparametric; 225 __gnuplot_set__ noparametric;
219 end_unwind_protect 226 end_unwind_protect
220 endif 227 endif
221 endfunction 228 endfunction
229
230 ## There is no sparse matrix implementation available because of missing
231 ## libraries, plot sombreros instead. Also plot a nice title that we are
232 ## sorry about that.
233 function sombreroimage (nm, typ)
234 if (strcmp (typ, "txt"))
235 fid = fopen (sprintf ("%s.txt", nm), "wt");
236 fputs (fid, "+---------------------------------------+\n");
237 fputs (fid, "| Image unavailable because of a |\n");
238 fputs (fid, "| missing sparse matrix implementation. |\n");
239 fputs (fid, "+---------------------------------------+\n");
240 fclose (fid);
241 return;
242 else ## if (!strcmp (typ, "txt"))
243
244 bury_output ();
245
246 x = y = linspace (-8, 8, 41)';
247 [xx, yy] = meshgrid (x, y);
248 r = sqrt (xx .^ 2 + yy .^ 2) + eps;
249 z = sin (r) ./ r;
250 xlen = length (x);
251 ylen = length (y);
252 len = 3 * xlen;
253 zz = zeros (ylen, len);
254 k = 1;
255 for i = 1:3:len
256 zz(:,i) = x(k) * ones (ylen, 1);
257 zz(:,i+1) = y;
258 zz(:,i+2) = z(:,k);
259 k++;
260 endfor
261 unwind_protect
262 __gnuplot_raw__ ("set hidden3d;\n");
263 __gnuplot_raw__ ("set data style lines;\n");
264 __gnuplot_raw__ ("set surface;\n");
265 __gnuplot_raw__ ("set nocontour;\n");
266 __gnuplot_raw__ ("set nologscale;\n");
267 __gnuplot_set__ parametric;
268 __gnuplot_raw__ ("set view 60, 30, 1, 1;\n");
269 __gnuplot_raw__ ("set nokey;\n");
270 __gnuplot_raw__ ("set nocolorbox;\n");
271 msg = strcat ("");
272 __gnuplot_raw__ ("set title \"Sorry, graphics not available because octave was\\ncompiled without the sparse matrix implementation.\";\n");
273 __plt3__ (zz, "", "");
274 unwind_protect_cleanup
275 __gnuplot_set__ noparametric;
276 print (strcat (nm, ".", typ), strcat ("-d", typ));
277 bury_output ();
278 end_unwind_protect
279 endif
280 endfunction