comparison scripts/plot/print.m @ 5363:37f62a7778c2

[project @ 2005-05-23 19:52:15 by jwe]
author jwe
date Mon, 23 May 2005 19:52:15 +0000
parents ef053d682e42
children c9c773d8333f
comparison
equal deleted inserted replaced
5362:ef053d682e42 5363:37f62a7778c2
97 97
98 ## PKG_ADD: mark_as_command print 98 ## PKG_ADD: mark_as_command print
99 99
100 function print (varargin) 100 function print (varargin)
101 101
102 ## take care of the settings we had before 102 orientation = "landscape"; ## orient;
103 origterm = gget ("terminal");
104 origout = gget ("output");
105 ## End of line trmination for __gnuplot_raw__ command strings.
106 endl = ";\n";
107 _automatic_replot = automatic_replot;
108
109 ## take care of the default terminal settings to restore them.
110 terminal_default = "";
111
112 orientation = orient;
113 use_color = 0; # 0=default, -1=mono, +1=color 103 use_color = 0; # 0=default, -1=mono, +1=color
114 force_solid = 0; # 0=default, -1=dashed, +1=solid 104 force_solid = 0; # 0=default, -1=dashed, +1=solid
115 fontsize = font = name = devopt = printer = ""; 105 fontsize = "";
116 106 font = "";
117 va_arg_cnt = 1; 107 name = "";
108 devopt = "";
109 printer = "";
118 110
119 for i = 1:nargin 111 for i = 1:nargin
120 arg = nth (varargin, va_arg_cnt++); 112 arg = varargin{i};
121 if (isstr (arg)) 113 if (isstr (arg))
122 if (strcmp (arg, "-color")) 114 if (strcmp (arg, "-color"))
123 use_color = 1; 115 use_color = 1;
124 elseif (strcmp (arg, "-mono")) 116 elseif (strcmp (arg, "-mono"))
125 use_color = -1; 117 use_color = -1;
154 endfor 146 endfor
155 147
156 doprint = isempty (name); 148 doprint = isempty (name);
157 if (doprint) 149 if (doprint)
158 if (isempty (devopt)) 150 if (isempty (devopt))
159 printname = [ tmpnam, ".ps" ]; 151 printname = strcat (tmpnam, ".ps");
160 else 152 else
161 printname = [ tmpnam, ".", devopt ]; 153 printname = strcat (tmpnam, ".", devopt);
162 endif 154 endif
163 name = printname; 155 name = printname;
164 endif 156 endif
165 157
166 if (isempty (devopt)) 158 if (isempty (devopt))
167 dot = rindex (name, "."); 159 dot = rindex (name, ".");
168 if (dot == 0) 160 if (dot == 0)
169 error ("print: no format specified"); 161 error ("print: no format specified");
170 else 162 else
171 dev = tolower (name(dot+1:end)); 163 dev = tolower (name(dot+1:end));
172 endif 164 endif
173 else 165 else
179 elseif (strcmp (dev, "cdr")) 171 elseif (strcmp (dev, "cdr"))
180 dev = "corel"; 172 dev = "corel";
181 endif 173 endif
182 174
183 ## check if we have to use convert 175 ## check if we have to use convert
184 dev_list = [" aifm corel fig png pbm dxf mf hpgl", ... 176 dev_list = {"aifm" "corel" "fig" "png" "pbm" "dxf" "mf" "hpgl", ...
185 " ps ps2 psc psc2 eps eps2 epsc epsc2 " ]; 177 "ps" "ps2" "psc" "psc2" "eps" "eps2" "epsc" "epsc2"};
186 convertname = ""; 178 convertname = "";
187 if (isempty (findstr (dev_list , [ " ", dev, " " ])) 179 idx = cellidx (dev_list, dev);
180 if (! idx)
188 if (! isempty (devopt)) 181 if (! isempty (devopt))
189 convertname = [ devopt ":" name ]; 182 convertname = strcat (devopt, ":", name);
190 else 183 else
191 convertname = name; 184 convertname = name;
192 endif 185 endif
193 dev = "epsc"; 186 dev = "epsc";
194 name = [ tmpnam, ".eps" ]; 187 name = strcat (tmpnam, ".eps");
195 endif 188 endif
196 189
197 unwind_protect 190 unwind_protect
198 automatic_replot = 0;
199 191
200 if (strcmp (dev, "ps") || strcmp (dev, "ps2") ... 192 if (strcmp (dev, "ps") || strcmp (dev, "ps2") ...
201 || strcmp (dev, "psc") || strcmp (dev, "psc2") 193 || strcmp (dev, "psc") || strcmp (dev, "psc2")
202 || strcmp (dev, "epsc") || strcmp (dev, "epsc2") 194 || strcmp (dev, "epsc") || strcmp (dev, "epsc2")
203 || strcmp (dev, "eps") || strcmp (dev, "eps2")) 195 || strcmp (dev, "eps") || strcmp (dev, "eps2"))
204 ## Various postscript options 196 ## Various postscript options
205 ## XXX FIXME XXX -- Do we need this? DAS
206 ##__gnuplot_set__ term postscript
207 terminal_default = gget ("terminal");
208
209 if (dev(1) == "e") 197 if (dev(1) == "e")
210 options = "eps "; 198 options = "eps ";
211 else 199 else
212 options = [ orientation, " " ]; 200 options = strcat (orientation, " ");
213 endif 201 endif
214 options = [ options, "enhanced " ]; 202 options = strcat (options, "enhanced ");
215 203
216 if (any (dev == "c") || use_color > 0) 204 if (any (dev == "c") || use_color > 0)
217 if (force_solid < 0) 205 if (force_solid < 0)
218 options = [ options, "color dashed " ]; 206 options = strcat (options, "color dashed ");
219 else 207 else
220 options = [ options, "color solid " ]; 208 options = strcat (options, "color solid ");
221 endif 209 endif
222 else 210 else
223 if (force_solid > 0) 211 if (force_solid > 0)
224 options = [ options, "mono solid " ]; 212 options = strcat (options, "mono solid ");
225 else 213 else
226 options = [ options, "mono dashed " ]; 214 options = strcat (options, "mono dashed ");
227 endif 215 endif
228 endif 216 endif
229 217
230 if (! isempty (font)) 218 if (! isempty (font))
231 options = [ options, "\"", font, "\" " ]; 219 options = strcat (options, "\"", font, "\" ");
232 endif 220 endif
233 if (! isempty (fontsize)) 221 if (! isempty (fontsize))
234 options = [ options, " ", fontsize ]; 222 options = strcat (options, " ", fontsize);
235 endif 223 endif
236 224
237 __gnuplot_raw__ (["set term postscript ", options, endl]); 225 __gnuplot_raw__ (sprintf ("set terminal postscript %s;\n", options));
238 226
239 227
240 elseif (strcmp (dev, "aifm") || strcmp (dev, "corel")) 228 elseif (strcmp (dev, "aifm") || strcmp (dev, "corel"))
241 ## Adobe Illustrator, CorelDraw 229 ## Adobe Illustrator, CorelDraw
242 ## FIXME: Do we need it? DAS
243 ## eval(sprintf ("__gnuplot_set__ term %s", dev));
244 terminal_default = gget ("terminal");
245 if (use_color >= 0) 230 if (use_color >= 0)
246 options = " color"; 231 options = " color";
247 else 232 else
248 options = " mono"; 233 options = " mono";
249 endif 234 endif
250 if (! isempty (font)) 235 if (! isempty (font))
251 options = [ options, " \"" , font, "\"" ]; 236 options = strcat (options, " \"", font, "\"");
252 endif 237 endif
253 if (! isempty (fontsize)) 238 if (! isempty (fontsize))
254 options = [ options, " ", fontsize ]; 239 options = strcat (options, " ", fontsize);
255 endif 240 endif
256 241
257 __gnuplot_raw__ (["set term ", dev, " ", options, endl]); 242 __gnuplot_raw__ (sprintf ("set terminal %s %s;\n", dev, options));
258 243
259 elseif (strcmp (dev, "fig")) 244 elseif (strcmp (dev, "fig"))
260 ## XFig 245 ## XFig
261 ## FIXME: Do we need it? DAS
262 ## __gnuplot_set__ term fig
263 terminal_default = gget ("terminal");
264 options = orientation; 246 options = orientation;
265 if (use_color >= 0) 247 if (use_color >= 0)
266 options = " color"; 248 options = " color";
267 else 249 else
268 options = " mono"; 250 options = " mono";
269 endif 251 endif
270 if (! isempty (fontsize)) 252 if (! isempty (fontsize))
271 options = [ options, " fontsize ", fontsize ]; 253 options = strcat (options, " fontsize ", fontsize);
272 endif 254 endif
273 __gnuplot_raw__ (["set term fig ", options, endl]); 255 __gnuplot_raw__ (sprintf ("set terminal fig %s;\n", options));
274 256
275 elseif (strcmp (dev, "png") || strcmp (dev, "pbm")) 257 elseif (strcmp (dev, "png") || strcmp (dev, "pbm"))
276 ## Portable network graphics, PBMplus 258 ## Portable network graphics, PBMplus
277 ## FIXME: Do we need it? DAS
278 ## eval(sprintf ("__gnuplot_set__ term %s", dev));
279 terminal_default = gget ("terminal");
280 259
281 ## XXX FIXME XXX -- New PNG interface takes color as "xRRGGBB" 260 ## XXX FIXME XXX -- New PNG interface takes color as "xRRGGBB"
282 ## where x is the literal character 'x' and 'RRGGBB' are the red, 261 ## where x is the literal character 'x' and 'RRGGBB' are the red,
283 ## green and blue components in hex. For now we just ignore it 262 ## green and blue components in hex. For now we just ignore it
284 ## and use default. The png terminal now is so rich with options, 263 ## and use default. The png terminal now is so rich with options,
288 ## if (use_color >= 0) 267 ## if (use_color >= 0)
289 ## eval (sprintf ("__gnuplot_set__ term %s color medium", dev)); 268 ## eval (sprintf ("__gnuplot_set__ term %s color medium", dev));
290 ##else 269 ##else
291 ##eval (sprintf ("__gnuplot_set__ term %s mono medium", dev)); 270 ##eval (sprintf ("__gnuplot_set__ term %s mono medium", dev));
292 ##endif 271 ##endif
293 272
294 __gnuplot_raw__ ("set term png large;\n") 273 __gnuplot_raw__ ("set terminal png large;\n")
295 274
296 elseif (strcmp (dev, "dxf") || strcmp (dev, "mf") || strcmp (dev, "hpgl")) 275 elseif (strcmp (dev, "dxf") || strcmp (dev, "mf") || strcmp (dev, "hpgl"))
297 ## AutoCad DXF, METAFONT, HPGL 276 ## AutoCad DXF, METAFONT, HPGL
298 __gnuplot_raw__ (["set terminal ", dev, endl]); 277 __gnuplot_raw__ (sprintf ("set terminal %s;\n", dev));
299 endif 278 endif
300 279
301 ## Gnuplot expects " around output file name 280 ## Gnuplot expects " around output file name
302 281
303 __gnuplot_raw__ (["set output \"", name, "\"", endl]); 282 __gnuplot_raw__ (sprintf ("set output \"%s\";\n", name));
304 __gnuplot_replot__ 283 __gnuplot_replot__
305 284
306 unwind_protect_cleanup 285 unwind_protect_cleanup
307 286
308 ## Restore init state 287 ## Restore init state
309 if (! isempty (terminal_default)) 288 __gnuplot_raw__ ("set terminal pop;\n");
310 __gnuplot_raw__ (["set terminal ", terminal_default, endl]); 289 __gnuplot_raw__ ("set output;\n")
311 endif
312 __gnuplot_raw__ (["set terminal ", origterm, endl]);
313 if (isempty (origout))
314 __gnuplot_raw__ ("set output;\n")
315 else
316 ## Gnuplot expects " around output file name
317 __gnuplot_raw__ (["set output \"", origout, "\"", endl]);
318 end
319 __gnuplot_replot__ 290 __gnuplot_replot__
320
321 automatic_replot = _automatic_replot ;
322 291
323 end_unwind_protect 292 end_unwind_protect
324 293
325 if (! isempty (convertname)) 294 if (! isempty (convertname))
326 command = [ "convert '", name, "' '", convertname, "'" ]; 295 command = sprintf ("convert '%s' '%s'", name, convertname);
327 [output, errcode] = system (command); 296 [output, errcode] = system (command);
328 unlink (name); 297 unlink (name);
329 if (errcode) 298 if (errcode)
330 error ("print: could not convert"); 299 error ("print: could not convert");
331 endif 300 endif
335 ## DAS 304 ## DAS
336 if (doprint) 305 if (doprint)
337 system (sprintf ("lpr %s '%s'", printer, printname)); 306 system (sprintf ("lpr %s '%s'", printer, printname));
338 unlink (printname); 307 unlink (printname);
339 endif 308 endif
340 309
341 endfunction 310 endfunction