changeset 20351:d8992a16643c

doc: Clean up m-files which generate images for Manual. * geometryimages.m, interpimages.m, plotimages.m, sparseimages.m, splineimages.m: Use the same style throughout the mi-files. Obey Octave coding conventions.
author Rik <rik@octave.org>
date Thu, 09 Jul 2015 21:38:57 -0700
parents b9d4ccf4291c
children fc3056b9fac0
files doc/interpreter/geometryimages.m doc/interpreter/interpimages.m doc/interpreter/plotimages.m doc/interpreter/sparseimages.m doc/interpreter/splineimages.m
diffstat 5 files changed, 66 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/doc/interpreter/geometryimages.m	Tue Jul 07 21:25:31 2015 +0100
+++ b/doc/interpreter/geometryimages.m	Thu Jul 09 21:38:57 2015 -0700
@@ -20,7 +20,7 @@
   graphics_toolkit ("gnuplot");
   set_print_size ();
   hide_output ();
-  outfile = fullfile (d, strcat (nm, ".", typ));
+  outfile = fullfile (d, [nm "." typ]);
   if (strcmp (typ, "png"))
     set (0, "defaulttextfontname", "*");
   endif
@@ -50,7 +50,7 @@
     xc = r * sin (pi*pc) + c(1);
     yc = r * cos (pi*pc) + c(2);
     plot (xc, yc, "g-", "LineWidth", 3);
-    axis([0, 1, 0, 1]);
+    axis ([0, 1, 0, 1]);
     legend ("Delaunay Triangulation", "Voronoi Diagram");
     print (outfile, d_typ);
   elseif (strcmp (nm, "triplot"))
@@ -113,6 +113,28 @@
   r = sqrt ((xc - x(1)).^2 + (yc - y(1)).^2);
 endfunction
 
+function sombreroimage (nm, typ, d_typ)
+  if (strcmp (typ, "txt"))
+    fid = fopen ([nm ".txt"], "wt");
+    fputs (fid, "+-----------------------------+\n");
+    fputs (fid, "| Image unavailable because   |\n");
+    fputs (fid, "| of a missing QHULL library. |\n");
+    fputs (fid, "+-----------------------------+\n");
+    fclose (fid);
+    return;
+  else
+    hide_output ();
+    [x, y, z] = sombrero ();
+    unwind_protect
+      mesh (x, y, z);
+      title ("Sorry, graphics not available because Octave was\\ncompiled without the QHULL library.");
+    unwind_protect_cleanup
+      print (outfile, d_typ);
+      hide_output ();
+    end_unwind_protect
+  endif
+endfunction
+
 function set_print_size ()
   image_size = [5.0, 3.5]; # in inches, 16:9 format
   border = 0;              # For postscript use 50/72
@@ -126,37 +148,13 @@
 ## print since print() resets output to stdout (unfortunately, gnpulot
 ## can't pop output as it can the terminal type).
 function hide_output ()
-  f = figure (1);
-  set (f, "visible", "off");
-endfunction
-
-function sombreroimage (nm, typ, d_typ)
-  if (strcmp (typ, "txt"))
-    fid = fopen (sprintf ("%s.txt", nm), "wt");
-    fputs (fid, "+-----------------------------+\n");
-    fputs (fid, "| Image unavailable because   |\n");
-    fputs (fid, "| of a missing QHULL library. |\n");
-    fputs (fid, "+-----------------------------+\n");
-    fclose (fid);
-    return;
-  else ## if (!strcmp (typ, "txt"))
-
-    hide_output ();
-
-    [x, y, z] = sombrero ();
-    unwind_protect
-      mesh (x, y, z);
-      title ("Sorry, graphics not available because octave was\\ncompiled without the QHULL library.");
-    unwind_protect_cleanup
-      print (outfile, d_typ);
-      hide_output ();
-    end_unwind_protect
-  endif
+  hf = figure (1);
+  set (hf, "visible", "off");
 endfunction
 
 ## generate something for the texinfo @image command to process
 function image_as_txt (d, nm)
-  fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt");
+  fid = fopen (fullfile (d, [nm ".txt"]), "wt");
   fputs (fid, "\n");
   fputs (fid, "+---------------------------------+\n");
   fputs (fid, "| Image unavailable in text mode. |\n");
--- a/doc/interpreter/interpimages.m	Tue Jul 07 21:25:31 2015 +0100
+++ b/doc/interpreter/interpimages.m	Thu Jul 09 21:38:57 2015 -0700
@@ -20,7 +20,7 @@
   graphics_toolkit ("gnuplot");
   set_print_size ();
   hide_output ();
-  outfile = fullfile (d, strcat (nm, ".", typ));
+  outfile = fullfile (d, [nm "." typ]);
   if (strcmp (typ, "png"))
     set (0, "defaulttextfontname", "*");
   endif
@@ -91,13 +91,13 @@
 ## print since print() resets output to stdout (unfortunately, gnpulot
 ## can't pop output as it can the terminal type).
 function hide_output ()
-  f = figure (1);
-  set (f, "visible", "off");
+  hf = figure (1);
+  set (hf, "visible", "off");
 endfunction
 
 ## generate something for the texinfo @image command to process
-function image_as_txt(d, nm)
-  fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt");
+function image_as_txt (d, nm)
+  fid = fopen (fullfile (d, [nm ".txt"]), "wt");
   fputs (fid, "\n");
   fputs (fid, "+---------------------------------+\n");
   fputs (fid, "| Image unavailable in text mode. |\n");
--- a/doc/interpreter/plotimages.m	Tue Jul 07 21:25:31 2015 +0100
+++ b/doc/interpreter/plotimages.m	Thu Jul 09 21:38:57 2015 -0700
@@ -20,7 +20,7 @@
   graphics_toolkit ("qt");
   set_print_size ();
   hide_output ();
-  outfile = fullfile (d, strcat (nm, ".", typ));
+  outfile = fullfile (d, [nm "." typ]);
   if (strcmp (typ, "png"))
     set (0, "defaulttextfontname", "*");
   endif
@@ -30,7 +30,7 @@
     d_typ = ["-d", typ];
   endif
 
-  if (strcmp(typ , "txt"))
+  if (strcmp (typ , "txt"))
     image_as_txt (d, nm);
   elseif (strcmp (nm, "plot"))
     x = -10:0.1:10;
@@ -78,7 +78,7 @@
     t = 0:0.1:10*pi;
     r = linspace (0, 1, numel (t));
     z = linspace (0, 1, numel (t));
-    plot3 (r.*sin(t), r.*cos(t), z);
+    plot3 (r.*sin (t), r.*cos (t), z);
     xlabel ("r.*sin (t)");
     ylabel ("r.*cos (t)");
     zlabel ("z");
@@ -126,16 +126,17 @@
 ## print since print() resets output to stdout (unfortunately, gnuplot
 ## can't pop output as it can the terminal type).
 function hide_output ()
-  f = figure (1);
-  set (f, "visible", "off");
+  hf = figure (1);
+  set (hf, "visible", "off");
 endfunction
 
 ## generate something for the texinfo @image command to process
 function image_as_txt (d, nm)
-  fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt");
+  fid = fopen (fullfile (d, [nm ".txt"]), "wt");
   fputs (fid, "\n");
   fputs (fid, "+---------------------------------+\n");
   fputs (fid, "| Image unavailable in text mode. |\n");
   fputs (fid, "+---------------------------------+\n");
   fclose (fid);
 endfunction
+
--- a/doc/interpreter/sparseimages.m	Tue Jul 07 21:25:31 2015 +0100
+++ b/doc/interpreter/sparseimages.m	Thu Jul 09 21:38:57 2015 -0700
@@ -43,20 +43,6 @@
   endif
 endfunction
 
-function set_print_size ()
-  image_size = [5.0, 3.5]; # in inches, 16:9 format
-  border = 0;              # For postscript use 50/72
-  set (0, "defaultfigurepapertype", "<custom>");
-  set (0, "defaultfigurepaperorientation", "landscape");
-  set (0, "defaultfigurepapersize", image_size + 2*border);
-  set (0, "defaultfigurepaperposition", [border, border, image_size]);
-endfunction
-
-function hide_output ()
-  f = figure (1);
-  set (f, "visible", "off");
-endfunction
-
 function gplotimages (d, nm, typ)
   hide_output ();
   outfile = fullfile (d, strcat (nm, ".", typ));
@@ -94,7 +80,7 @@
         printsparse (r1, outfile);
       elseif (strcmp (nm, "spcholperm"))
         [r2,p2,q2] = chol (a);
-        printsparse(r2, outfile);
+        printsparse (r2, outfile);
       endif
       ## printf("Text NNZ: Matrix %d, Chol %d, PermChol %d\n",nnz(a),nnz(r1),nnz(r2));
     endif
@@ -110,7 +96,7 @@
     d_typ = ["-d" typ];
   endif
 
-  a = 10*speye (n) + sparse (1:n,ceil([1:n]/2),1,n,n) + ...
+  a = 10*speye (n) + sparse (1:n,ceil ([1:n]/2),1,n,n) + ...
       sparse (ceil ([1:n]/2),1:n,1,n,n);
   if (strcmp (nm, "spmatrix"))
     spy (a);
@@ -267,7 +253,7 @@
 ## sorry about that.
 function sombreroimage (d, nm, typ)
   if (strcmp (typ, "txt"))
-    fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt");
+    fid = fopen (fullfile (d, [nm ".txt"]), "wt");
     fputs (fid, "\n");
     fputs (fid, "+---------------------------------------+\n");
     fputs (fid, "| Image unavailable because of a        |\n");
@@ -275,8 +261,7 @@
     fputs (fid, "+---------------------------------------+\n");
     fclose (fid);
     return;
-  else ## if (!strcmp (typ, "txt"))
-
+  else
     hide_output ();
     if (strcmp (typ, "eps"))
       d_typ = "-depsc2";
@@ -295,3 +280,20 @@
   endif
 endfunction
 
+function set_print_size ()
+  image_size = [5.0, 3.5]; # in inches, 16:9 format
+  border = 0;              # For postscript use 50/72
+  set (0, "defaultfigurepapertype", "<custom>");
+  set (0, "defaultfigurepaperorientation", "landscape");
+  set (0, "defaultfigurepapersize", image_size + 2*border);
+  set (0, "defaultfigurepaperposition", [border, border, image_size]);
+endfunction
+
+## Use this function before plotting commands and after every call to
+## print since print() resets output to stdout (unfortunately, gnpulot
+## can't pop output as it can the terminal type).
+function hide_output ()
+  hf = figure (1);
+  set (hf, "visible", "off");
+endfunction
+
--- a/doc/interpreter/splineimages.m	Tue Jul 07 21:25:31 2015 +0100
+++ b/doc/interpreter/splineimages.m	Thu Jul 09 21:38:57 2015 -0700
@@ -20,7 +20,7 @@
   graphics_toolkit ("gnuplot");
   set_print_size ();
   hide_output ();
-  outfile = fullfile (d, strcat (nm, ".", typ));
+  outfile = fullfile (d, [nm "." typ]);
   if (strcmp (typ, "png"))
     set (0, "defaulttextfontname", "*");
   endif
@@ -109,7 +109,7 @@
     plot (x, y, ".", xx, [y1; y2]);
     axis tight;
     ylim ([-1.5 1.5]);
-    legend({"data", "clamped", "hinged periodic"});
+    legend ({"data", "clamped", "hinged periodic"});
     print (outfile, d_typ);
   elseif (strcmp (nm, "splinefit5"))
     ## Truncated data
@@ -172,13 +172,13 @@
 ## print since print() resets output to stdout (unfortunately, gnpulot
 ## can't pop output as it can the terminal type).
 function hide_output ()
-  f = figure (1);
-  set (f, "visible", "off");
+  hf = figure (1);
+  set (hf, "visible", "off");
 endfunction
 
 ## generate something for the texinfo @image command to process
-function image_as_txt(d, nm)
-  fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt");
+function image_as_txt (d, nm)
+  fid = fopen (fullfile (d, [nm ".txt"]), "wt");
   fputs (fid, "\n");
   fputs (fid, "+---------------------------------+\n");
   fputs (fid, "| Image unavailable in text mode. |\n");