Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/gnuplot.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % GNUPLOT a gnuplot interface for AOs. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: IPLOT provides an intelligent plotting tool for LTPDA. | |
5 % | |
6 % CALL: filenames = gnuplot(a,pl) | |
7 % | |
8 % INPUTS: pl - a parameter list | |
9 % a - input analysis objects | |
10 % | |
11 % OUTPUTS: filenames - if gnuplot is configured to output files, then | |
12 % the filenames are returned here. | |
13 % | |
14 % | |
15 % NOTE: this method requires gnuplot to be installed on the system. The | |
16 % path to the gnuplot binary can be set in the input plist with the key | |
17 % 'GNUPLOT'. | |
18 % | |
19 % gnuplot: http://www.gnuplot.info/ | |
20 % | |
21 % AO Plot Info | |
22 % ------------ | |
23 % | |
24 % If an input AO has a filled plotinfo plist, then the options contained in | |
25 % therein will overide any other options. The recognised keys are: | |
26 % | |
27 % 'linestyle', 'linewidth', 'color', 'marker', 'legend_on' | |
28 % | |
29 % The possible values are all those accepted by plot. | |
30 % | |
31 % | |
32 % EXAMPLES: | |
33 % | |
34 % 1) Plot two time-series AOs on the same plot and output to a PDF file | |
35 % | |
36 % gnuplot(a1, a2, plist('terminal', 'pdf enhanced', ... | |
37 % 'output', outfile, ... | |
38 % 'preamble', {'set title "my nice plot"', 'set key outside top right'}, ... | |
39 % 'markerscale', 3)) | |
40 % | |
41 % 2) Plot two time-series AOs in subplots. If the AOs have markers set in | |
42 % the plotinfo, they will be scaled in size x3 from default. | |
43 % | |
44 % gnuplot(a1, a2, plist('arrangement', 'subplots', 'terminal', 'pdf enhanced', ... | |
45 % 'output', outfile, ... | |
46 % 'preamble', {'set title "my nice plot"', 'set key outside top right'}, ... | |
47 % 'markerscale', 3)) | |
48 % | |
49 % 3) Plot two time-series AOs, each to its own output pdf file. | |
50 % | |
51 % gnuplot(a1, a2, plist('arrangement', 'single', 'terminal', 'pdf enhanced', ... | |
52 % 'output', outfile, 'outdir', '.', ... | |
53 % 'preamble', {'set title "my nice plot"', 'set key outside top right'}, ... | |
54 % 'markerscale', 3)) | |
55 % | |
56 % | |
57 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'gnuplot')">Parameters Description</a> | |
58 % | |
59 % VERSION: $Id: gnuplot.m,v 1.12 2011/04/13 04:51:36 mauro Exp $ | |
60 % | |
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
62 | |
63 | |
64 function varargout = gnuplot(varargin) | |
65 | |
66 | |
67 % Check if this is a call for parameters | |
68 if utils.helper.isinfocall(varargin{:}) | |
69 varargout{1} = getInfo(varargin{3}); | |
70 return | |
71 end | |
72 | |
73 import utils.const.* | |
74 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
75 | |
76 % Collect input variable names | |
77 in_names = cell(size(varargin)); | |
78 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
79 | |
80 % Collect all AOs | |
81 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
82 | |
83 % Apply defaults to plist | |
84 usepl = applyDefaults(getDefaultPlist, varargin{:}); | |
85 | |
86 % Loop over input AOs and collect the different types | |
87 [timeAOs, freqAOs, yAOs, xyAOs] = collectAOs(as); | |
88 | |
89 fnames = {}; | |
90 % Do time-series | |
91 if ~isempty(timeAOs) | |
92 fnames = [fnames plot_ao_set(timeAOs, usepl)]; | |
93 end | |
94 % Do freq-series | |
95 if ~isempty(freqAOs) | |
96 fnames = [fnames plot_ao_set(freqAOs, usepl)]; | |
97 end | |
98 | |
99 if ~isempty(xyAOs) | |
100 error('Plotting xy-data objects is not yet supported.'); | |
101 end | |
102 | |
103 if ~isempty(yAOs) | |
104 error('Plotting c-data objects is not yet supported.'); | |
105 end | |
106 | |
107 if nargout == 1 | |
108 varargout{1} = fnames; | |
109 end | |
110 | |
111 | |
112 end | |
113 | |
114 function fnames = plot_ao_set(as,pl) | |
115 | |
116 fnames = {}; | |
117 | |
118 Na = numel(as); | |
119 | |
120 % Parameters | |
121 odir = pl.find('OutputDir'); | |
122 output = pl.find('output'); | |
123 terminal = pl.find('terminal'); | |
124 terminalOpts = pl.find('terminal options'); | |
125 gnuplotBin = pl.find('gnuplot'); | |
126 | |
127 if isempty(terminal) | |
128 runcmd(gnuplotBin, ' -e "help terminal"'); | |
129 return; | |
130 end | |
131 | |
132 if isempty(output) | |
133 output = tempname; | |
134 else | |
135 output = fullfile(odir, output); | |
136 end | |
137 | |
138 %---------------- | |
139 % Make filenames | |
140 %---------------- | |
141 aTmpFile = tempname; | |
142 % One data file per AO | |
143 tmpData = {}; | |
144 for kk = 1:Na | |
145 tmpData = [tmpData {sprintf('%s_%d.dat', aTmpFile, kk)}]; | |
146 end | |
147 % One gnu file | |
148 tmpGnu = [aTmpFile '.gnu']; | |
149 % Output file | |
150 [path,name,ext] = fileparts(output); | |
151 if isempty(ext) | |
152 output = [output '.' terminal]; | |
153 end | |
154 | |
155 utils.helper.msg(utils.const.msg.PROC1, 'Output file: %s', output); | |
156 utils.helper.msg(utils.const.msg.PROC1, 'Plotting %d time-series AOs...', numel(as)); | |
157 | |
158 switch class(as(1).data) | |
159 case 'tsdata' | |
160 fnames = [fnames ts_plot(output, terminal, terminalOpts, tmpGnu, tmpData, as, pl)]; | |
161 case 'fsdata' | |
162 fnames = [fnames fs_plot(output, terminal, terminalOpts, tmpGnu, tmpData, as, pl)]; | |
163 case 'xydata' | |
164 case 'ydata' | |
165 otherwise | |
166 end | |
167 | |
168 % Clean up tmp files | |
169 for kk = 1:numel(tmpData) | |
170 delete(tmpData{kk}); | |
171 end | |
172 delete(tmpGnu); | |
173 | |
174 | |
175 end | |
176 | |
177 %-------------------------------------------------------------------------- | |
178 % Make freq-series plot | |
179 % | |
180 | |
181 function fnames = fs_plot(output, terminal, terminalOpts, tmpGnu, tmpData, as, pl) | |
182 | |
183 switch pl.find('arrangement') | |
184 case 'single' | |
185 fnames = write_single_freqseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl); | |
186 case 'stacked' | |
187 fnames = write_stacked_freqseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl); | |
188 case 'subplots' | |
189 error('subplots arrangement for frequency-series is not currently supported'); | |
190 otherwise | |
191 fnames = {}; | |
192 end | |
193 | |
194 end | |
195 | |
196 %-------------------------------------------------------------------------- | |
197 % Plots all the freq-series AOs on individual plots. | |
198 % | |
199 function fnames = write_single_freqseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl); | |
200 | |
201 fnames = {}; | |
202 gnuplotBin = pl.find('gnuplot'); | |
203 Na = numel(as); | |
204 | |
205 % Export data | |
206 for kk=1:Na | |
207 export(as(kk), tmpData{kk}, plist('complex format', 'absdeg')); | |
208 end | |
209 | |
210 % Process each AO | |
211 for kk=1:Na | |
212 | |
213 % Are we processing complex data? | |
214 complexData = false; | |
215 if ~isreal(as(kk).y) | |
216 complexData = true; | |
217 end | |
218 | |
219 [path,name,ext] = fileparts(output); | |
220 ofile = fullfile(path,sprintf('%s_%02d%s',name,kk,ext)); | |
221 fnames = [fnames {ofile}]; | |
222 | |
223 % Open and write gnu file | |
224 fd = fopen(tmpGnu, 'w+'); | |
225 writeHeader(fd, terminal, terminalOpts, ofile); | |
226 | |
227 % Need two plots for complex data | |
228 if complexData | |
229 fprintf(fd, 'set multiplot layout 2,1\n'); | |
230 end | |
231 | |
232 | |
233 % Line style | |
234 [color, lwidth, style, pointType, pointScale] = lineStyle(kk, as(kk), pl); | |
235 | |
236 % Axis labels | |
237 fprintf(fd, 'set xlabel "Frequency %s"\n', as(kk).xunits.char); | |
238 fprintf(fd, 'set ylabel "Amplitude %s"\n', fixUnits(as(kk).yunits.char)); | |
239 | |
240 % Axis scales | |
241 fprintf(fd, 'set lmargin at screen 0.15\n'); | |
242 fprintf(fd, 'unset logscale xy\n'); | |
243 fprintf(fd, 'set logscale x\n'); | |
244 fprintf(fd, 'set logscale y\n'); | |
245 | |
246 % Preamble | |
247 preamble = pl.find('preamble'); | |
248 writePreamble(fd, preamble); | |
249 | |
250 % Write the plot line | |
251 fprintf(fd, 'plot "%s" using 1:2 with %s lt %s lw %d %s %s title "%s"\n', ... | |
252 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
253 if complexData | |
254 fprintf(fd, 'set ylabel "Phase [deg]"\n'); | |
255 fprintf(fd, 'unset logscale xy\n'); | |
256 fprintf(fd, 'set logscale x\n'); | |
257 fprintf(fd, 'plot "%s" using 1:3 with %s lt %s lw %d %s %s title "%s"\n', ... | |
258 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
259 end | |
260 fclose(fd); | |
261 % Run gnuplot | |
262 runcmd(gnuplotBin, tmpGnu); | |
263 end | |
264 | |
265 end | |
266 | |
267 %-------------------------------------------------------------------------- | |
268 % Plots all the freq-series AOs on individual plots. | |
269 % | |
270 function fnames = write_stacked_freqseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl); | |
271 | |
272 fnames = {output}; | |
273 | |
274 gnuplotBin = pl.find('gnuplot'); | |
275 Na = numel(as); | |
276 | |
277 % Check the yunits | |
278 xlbl = as(1).xunits.char; | |
279 ylbl = as(1).yunits.char; | |
280 ylbl = fixUnits(ylbl); | |
281 for kk=2:Na | |
282 if ~strcmp(ylbl,fixUnits(as(kk).yunits.char)) | |
283 ylbl = '[mixed]'; | |
284 break; | |
285 end | |
286 end | |
287 | |
288 % Export data | |
289 allReal = true; | |
290 for kk=1:Na | |
291 export(as(kk), tmpData{kk}, plist('complex format', 'absdeg')); | |
292 if ~isreal(as(kk).y) | |
293 allReal = false; | |
294 end | |
295 end | |
296 | |
297 % Open and write gnu file | |
298 fd = fopen(tmpGnu, 'w+'); | |
299 | |
300 writeHeader(fd, terminal, terminalOpts, output); | |
301 | |
302 fprintf(fd, 'set lmargin at screen 0.15\n'); | |
303 % Axis labels | |
304 fprintf(fd, 'set xlabel "Frequency %s"\n', xlbl); | |
305 fprintf(fd, 'set ylabel "Amplitude %s"\n', ylbl); | |
306 | |
307 | |
308 % Need two plots for complex data | |
309 if ~allReal | |
310 fprintf(fd, 'set multiplot\n'); | |
311 fprintf(fd, 'set size 0.9,0.45\n'); | |
312 fprintf(fd, 'set origin 0.05,0.5\n'); | |
313 end | |
314 | |
315 fprintf(fd, 'unset logscale xy\n'); | |
316 fprintf(fd, 'set logscale x\n'); | |
317 fprintf(fd, 'set logscale y\n'); | |
318 | |
319 % Preamble | |
320 preamble = pl.find('preamble'); | |
321 writePreamble(fd, preamble); | |
322 | |
323 % Process real part of each AO | |
324 fprintf(fd, 'plot\\\n'); | |
325 for kk=1:Na | |
326 | |
327 hasErrors = ~isempty(as(kk).dy); | |
328 | |
329 % Line style | |
330 [color, lwidth, style, pointType, pointScale] = lineStyle(kk, as(kk), pl); | |
331 % Write the plot line | |
332 if hasErrors | |
333 fprintf(fd, ' "%s" using 1:2:4 with %s lt %s lw %d %s %s title "%s"', ... | |
334 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
335 else | |
336 fprintf(fd, ' "%s" using 1:2 with %s lt %s lw %d %s %s title "%s"', ... | |
337 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
338 end | |
339 if kk<Na | |
340 fprintf(fd, ',\\\n'); | |
341 end | |
342 end | |
343 | |
344 fprintf(fd, '\n\n'); | |
345 | |
346 % Need two plots for complex data | |
347 if ~allReal | |
348 hasErrors = ~isempty(as(kk).dy); | |
349 fprintf(fd, 'set ylabel "Phase [deg]"\n'); | |
350 fprintf(fd, 'set size 0.9,0.45\n'); | |
351 fprintf(fd, 'set origin 0.05,0.1\n'); | |
352 | |
353 fprintf(fd, 'unset logscale xy\n'); | |
354 fprintf(fd, 'set logscale x\n'); | |
355 | |
356 % Preamble | |
357 preamble = pl.find('preamble'); | |
358 writePreamble(fd, preamble); | |
359 | |
360 % Process real part of each AO | |
361 fprintf(fd, 'plot\\\n'); | |
362 for kk=1:Na | |
363 if ~isreal(as(kk).y) | |
364 % Line style | |
365 [color, lwidth, style, pointType, pointScale] = lineStyle(kk, as(kk), pl); | |
366 % Write the plot line | |
367 if hasErrors | |
368 fprintf(fd, ' "%s" using 1:3:4 with %s lt %s lw %d %s %s title "%s"', ... | |
369 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
370 else | |
371 fprintf(fd, ' "%s" using 1:3 with %s lt %s lw %d %s %s title "%s"', ... | |
372 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
373 end | |
374 if kk<Na | |
375 fprintf(fd, ',\\\n'); | |
376 end | |
377 end | |
378 end | |
379 | |
380 end | |
381 | |
382 fclose(fd); | |
383 | |
384 % Run gnuplot | |
385 runcmd(gnuplotBin, tmpGnu); | |
386 | |
387 end | |
388 | |
389 | |
390 %-------------------------------------------------------------------------- | |
391 % Make time-series plot | |
392 | |
393 function fnames = ts_plot(output, terminal, terminalOpts, tmpGnu, tmpData, as, pl) | |
394 | |
395 switch pl.find('arrangement') | |
396 case 'single' | |
397 fnames = write_single_timeseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl); | |
398 case 'stacked' | |
399 fnames = write_stacked_timeseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl); | |
400 case 'subplots' | |
401 fnames = write_subplot_timeseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl); | |
402 otherwise | |
403 fnames = {}; | |
404 end | |
405 | |
406 end | |
407 | |
408 | |
409 %-------------------------------------------------------------------------- | |
410 % Plots all time-series AOs on a single x-y plot. If the AOs have different | |
411 % yunits, then the label is set to [mixed]. | |
412 function fnames = write_stacked_timeseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl) | |
413 | |
414 fnames = {output}; | |
415 | |
416 gnuplotBin = pl.find('gnuplot'); | |
417 Na = numel(as); | |
418 | |
419 % Check the yunits | |
420 xlbl = as(1).xunits.char; | |
421 ylbl = as(1).yunits.char; | |
422 ylbl = fixUnits(ylbl); | |
423 for kk=2:Na | |
424 if ~strcmp(ylbl,fixUnits(as(kk).yunits.char)) | |
425 ylbl = '[mixed]'; | |
426 break; | |
427 end | |
428 end | |
429 | |
430 % Export data | |
431 for kk=1:Na | |
432 export(as(kk), tmpData{kk}, plist('complex format', 'absdeg')); | |
433 end | |
434 | |
435 % Open and write gnu file | |
436 fd = fopen(tmpGnu, 'w+'); | |
437 | |
438 writeHeader(fd, terminal, terminalOpts, output); | |
439 | |
440 % Axis labels | |
441 fprintf(fd, 'set xlabel "Time %s"\n', xlbl); | |
442 fprintf(fd, 'set ylabel "Amplitude %s"\n', ylbl); | |
443 | |
444 % Preamble | |
445 preamble = pl.find('preamble'); | |
446 writePreamble(fd, preamble); | |
447 | |
448 % Process each AO | |
449 fprintf(fd, 'plot\\\n'); | |
450 for kk=1:Na | |
451 % Line style | |
452 [color, lwidth, style, pointType, pointScale] = lineStyle(kk, as(kk), pl); | |
453 % Write the plot line | |
454 fprintf(fd, ' "%s" using 1:2 with %s lt %s lw %d %s %s title "%s"', ... | |
455 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
456 if kk<Na | |
457 fprintf(fd, ',\\\n'); | |
458 end | |
459 end | |
460 fclose(fd); | |
461 | |
462 % Run gnuplot | |
463 runcmd(gnuplotBin, tmpGnu); | |
464 end | |
465 | |
466 | |
467 %-------------------------------------------------------------------------- | |
468 % Plots all time-series AOs on a single x-y plot. If the AOs have different | |
469 % yunits, then the label is set to [mixed]. | |
470 function fnames = write_subplot_timeseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl) | |
471 | |
472 fnames = {output}; | |
473 gnuplotBin = pl.find('gnuplot'); | |
474 Na = numel(as); | |
475 | |
476 | |
477 % Export data | |
478 for kk=1:Na | |
479 export(as(kk), tmpData{kk}, plist('complex format', 'absdeg')); | |
480 end | |
481 | |
482 % Open and write gnu file | |
483 fd = fopen(tmpGnu, 'w+'); | |
484 | |
485 writeHeader(fd, terminal, terminalOpts, output); | |
486 | |
487 fprintf(fd, 'set multiplot layout %d,1\n', Na); | |
488 | |
489 | |
490 | |
491 % Process each AO | |
492 for kk=1:Na | |
493 % Line style | |
494 [color, lwidth, style, pointType, pointScale] = lineStyle(kk, as(kk), pl); | |
495 % Axis labels | |
496 fprintf(fd, 'set xlabel "Time %s"\n', as(kk).xunits.char); | |
497 fprintf(fd, 'set ylabel "Amplitude %s"\n', fixUnits(as(kk).yunits.char)); | |
498 % Preamble | |
499 preamble = pl.find('preamble'); | |
500 writePreamble(fd, preamble); | |
501 % Write the plot line | |
502 fprintf(fd, 'plot "%s" using 1:2 with %s lt %s lw %d %s %s title "%s"\n', ... | |
503 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
504 end | |
505 fclose(fd); | |
506 | |
507 % Run gnuplot | |
508 runcmd(gnuplotBin, tmpGnu); | |
509 end | |
510 | |
511 %-------------------------------------------------------------------------- | |
512 % Plots all time-series AOs on a single x-y plot. If the AOs have different | |
513 % yunits, then the label is set to [mixed]. | |
514 function fnames = write_single_timeseries_plot(terminal, terminalOpts, output, tmpGnu, tmpData, as, pl) | |
515 | |
516 fnames = {}; | |
517 gnuplotBin = pl.find('gnuplot'); | |
518 Na = numel(as); | |
519 | |
520 % Export data | |
521 for kk=1:Na | |
522 export(as(kk), tmpData{kk}, plist('complex format', 'absdeg')); | |
523 end | |
524 | |
525 % Process each AO | |
526 for kk=1:Na | |
527 | |
528 [path,name,ext] = fileparts(output); | |
529 ofile = fullfile(path,sprintf('%s_%02d%s',name,kk,ext)); | |
530 fnames = [fnames {ofile}]; | |
531 | |
532 % Open and write gnu file | |
533 fd = fopen(tmpGnu, 'w+'); | |
534 writeHeader(fd, terminal, terminalOpts, ofile); | |
535 | |
536 | |
537 % Line style | |
538 [color, lwidth, style, pointType, pointScale] = lineStyle(kk, as(kk), pl); | |
539 | |
540 % Axis labels | |
541 fprintf(fd, 'set xlabel "Time %s"\n', as(kk).xunits.char); | |
542 fprintf(fd, 'set ylabel "Amplitude %s"\n', fixUnits(as(kk).yunits.char)); | |
543 | |
544 % Preamble | |
545 preamble = pl.find('preamble'); | |
546 writePreamble(fd, preamble); | |
547 | |
548 % Write the plot line | |
549 fprintf(fd, 'plot "%s" using 1:2 with %s lt %s lw %d %s %s title "%s"\n', ... | |
550 tmpData{kk}, style, color, lwidth, pointType, pointScale, as(kk).name); | |
551 fclose(fd); | |
552 % Run gnuplot | |
553 runcmd(gnuplotBin, tmpGnu); | |
554 end | |
555 | |
556 end | |
557 | |
558 | |
559 %-------------------------------------------------------------------------- | |
560 % Functions for writing the GNUPLOT file. | |
561 % | |
562 | |
563 function writeHeader(fd, terminal, terminalOpts, output) | |
564 fprintf(fd, 'set terminal %s %s \n', terminal, terminalOpts); | |
565 if ~isempty(output) | |
566 fprintf(fd, 'set output "%s"\n', output); | |
567 end | |
568 fprintf(fd, 'set key outside\n'); | |
569 fprintf(fd, 'set grid xtics ytics\n'); | |
570 fprintf(fd, 'set key invert box\n'); | |
571 | |
572 end | |
573 | |
574 function writePreamble(fd, preamble) | |
575 | |
576 if ischar(preamble) | |
577 preamble = {preamble}; | |
578 end | |
579 for kk=1:numel(preamble) | |
580 fprintf(fd, '%s\n', preamble{kk}); | |
581 end | |
582 | |
583 end | |
584 | |
585 | |
586 function [color, lwidth, style, pointType, pointScale] = lineStyle(kk, as, pl) | |
587 | |
588 info = as.plotinfo; | |
589 if ~isempty(info) | |
590 color = info.find('color'); | |
591 lwidth = info.find('linewidth'); | |
592 marker = info.find('marker'); | |
593 else | |
594 color = []; | |
595 lwidth = []; | |
596 marker = []; | |
597 end | |
598 | |
599 % Color for this ao | |
600 color = mcol2gcol(kk, color); | |
601 | |
602 % line width | |
603 if isempty(lwidth) | |
604 lwidth = 2; | |
605 end | |
606 | |
607 % Marker | |
608 [style, pointType] = getMarker(marker, isempty(as.dy)); | |
609 pointScale = getPointScale(pl.find('markerscale'), pointType); | |
610 end | |
611 | |
612 function [style, pointType] = getMarker(marker, noErrors) | |
613 if noErrors | |
614 if isempty(marker) | |
615 style = 'l'; | |
616 pointType = ''; | |
617 else | |
618 style = 'lp'; | |
619 pointType = sprintf('pt %d', mmarkerTogmarker(marker)); | |
620 end | |
621 else | |
622 if isempty(marker) | |
623 style = 'errorlines'; | |
624 pointType = ''; | |
625 else | |
626 style = 'errorlines'; | |
627 pointType = sprintf('pt %d', mmarkerTogmarker(marker)); | |
628 end | |
629 end | |
630 | |
631 end | |
632 | |
633 function pointScale = getPointScale(size, pointType) | |
634 | |
635 pointScale = ''; | |
636 if pointType > 0 | |
637 if ~isempty(size) | |
638 pointScale = sprintf('ps %d', size); | |
639 end | |
640 end | |
641 | |
642 end | |
643 | |
644 | |
645 % Return a gnuplot point type based on the matlab marker. | |
646 % This is terminal dependent and so only works in some cases. | |
647 function pt = mmarkerTogmarker(mm) | |
648 | |
649 switch mm | |
650 case '+' | |
651 pt = 1; | |
652 case 'x' | |
653 pt = 2; | |
654 case 's' | |
655 pt = 4; | |
656 case 'd' | |
657 pt = 5; | |
658 case '^' | |
659 pt = 6; | |
660 otherwise | |
661 pt = 0; | |
662 end | |
663 | |
664 end | |
665 | |
666 % Prepare units for gnuplot | |
667 function str = fixUnits(str) | |
668 | |
669 str = strrep(strrep(str, '(', '{'), ')', '}'); | |
670 | |
671 end | |
672 | |
673 | |
674 % Returns an RGB color from a MATLAB string color | |
675 function col = mcol2gcol(kk, mcol) | |
676 | |
677 if isempty(mcol) | |
678 col = num2str(kk); | |
679 return | |
680 end | |
681 | |
682 if ischar(mcol) | |
683 str = mcol; | |
684 switch str | |
685 case 'r' | |
686 col = 'red'; | |
687 case 'g' | |
688 col = 'blue'; | |
689 case 'b' | |
690 col = 'blue'; | |
691 case 'c' | |
692 col = 'cyan'; | |
693 case 'm' | |
694 col = 'magenta'; | |
695 case 'y' | |
696 col = 'yellow'; | |
697 case 'k' | |
698 col = 'black'; | |
699 case 'w' | |
700 col = 'white'; | |
701 otherwise | |
702 col = str; | |
703 end | |
704 else | |
705 | |
706 % If we have a matlab rgb vector, we need to conver to a hex for | |
707 % gnuplot | |
708 | |
709 r = dec2hex(round(255*mcol(1))); | |
710 g = dec2hex(round(255*mcol(2))); | |
711 b = dec2hex(round(255*mcol(3))); | |
712 | |
713 col = ['#' r g b]; | |
714 | |
715 end | |
716 | |
717 col = sprintf('rgb "%s"', col); | |
718 | |
719 end | |
720 | |
721 | |
722 | |
723 %--------------------------------------------------------------------- | |
724 % This will run a shell command from within MATLAB using the given | |
725 % arguments. | |
726 % | |
727 % usage: runcmd(varargin) | |
728 % | |
729 % varargin - a series of strings to be concatenated together. | |
730 % | |
731 % | |
732 % e.g. >> runcmd('ls', '-l', dir); | |
733 % | |
734 % M Hewitson 16-07-04 | |
735 % | |
736 % $Id: gnuplot.m,v 1.12 2011/04/13 04:51:36 mauro Exp $ | |
737 % | |
738 function runcmd(varargin) | |
739 | |
740 fid = fopen('tmpcmd', 'w+'); | |
741 fprintf(fid, '#!/bin/bash\n'); | |
742 fprintf(fid, 'export PATH=$PATH:${HOME}/bin\n'); | |
743 for jj = 1:nargin | |
744 fprintf(fid, '%s ', varargin{jj}); | |
745 end | |
746 fprintf(fid, '\n'); | |
747 fclose(fid); | |
748 | |
749 !chmod +x tmpcmd | |
750 !./tmpcmd | |
751 !rm tmpcmd | |
752 end | |
753 | |
754 %-------------------------------------------------------------------------- | |
755 % Collect the AOs together by data class | |
756 % | |
757 function [timeAOs, freqAOs, yAOs, xyAOs] = collectAOs(as) | |
758 | |
759 timeAOs = []; | |
760 freqAOs = []; | |
761 yAOs = []; | |
762 xyAOs = []; | |
763 | |
764 for jj = 1:numel(as) | |
765 | |
766 switch class(as(jj).data) | |
767 case 'tsdata' | |
768 | |
769 timeAOs = [timeAOs as(jj)]; | |
770 | |
771 case 'fsdata' | |
772 | |
773 freqAOs = [freqAOs as(jj)]; | |
774 | |
775 case 'xydata' | |
776 | |
777 yAOs = [yAOs as(jj)]; | |
778 | |
779 case 'cdata' | |
780 | |
781 xyAOs = [xyAOs as(jj)]; | |
782 | |
783 otherwise | |
784 utils.helper.warn('Unsupported AO data type [%s]; skipping', class(as(jj).data)); | |
785 end % End switch on data type | |
786 end % End loop over AOs | |
787 | |
788 end | |
789 | |
790 | |
791 %-------------------------------------------------------------------------- | |
792 % Get Info Object | |
793 %-------------------------------------------------------------------------- | |
794 function ii = getInfo(varargin) | |
795 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
796 sets = {}; | |
797 pl = []; | |
798 else | |
799 sets = {'Default'}; | |
800 pl = getDefaultPlist(); | |
801 end | |
802 % Build info object | |
803 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.output, '$Id: gnuplot.m,v 1.12 2011/04/13 04:51:36 mauro Exp $', sets, pl); | |
804 end | |
805 | |
806 %-------------------------------------------------------------------------- | |
807 % Get Default Plist | |
808 %-------------------------------------------------------------------------- | |
809 function plout = getDefaultPlist() | |
810 persistent pl; | |
811 if ~exist('pl', 'var') || isempty(pl) | |
812 pl = buildplist(); | |
813 end | |
814 plout = pl; | |
815 end | |
816 | |
817 function pl = buildplist() | |
818 | |
819 % General plist for Welch-based, linearly spaced spectral estimators | |
820 pl = plist(); | |
821 | |
822 % Binary | |
823 p = param({'gnuplot', ['The path to the gnuplot binary.']},... | |
824 paramValue.STRING_VALUE('/opt/local/bin/gnuplot')); | |
825 pl.append(p); | |
826 | |
827 % Output dir | |
828 p = param({'OutputDir', ['The output directory to be used in the case of writing output files.']},... | |
829 paramValue.STRING_VALUE('')); | |
830 pl.append(p); | |
831 | |
832 % Output file | |
833 p = param({'Output', ['The output filename for the given terminal type.\n'... | |
834 'An empty output will result in the output being sent to the terminal.']},... | |
835 paramValue.STRING_VALUE('')); | |
836 pl.append(p); | |
837 | |
838 % Terminal type | |
839 p = param({'Terminal', 'Choose one of the gnuplot supported terminal types.'},... | |
840 paramValue.STRING_VALUE('pdf')); | |
841 pl.append(p); | |
842 | |
843 % Terminal Options | |
844 p = param({'Terminal Options', 'Additional terminal options.'},... | |
845 paramValue.STRING_VALUE('color enhanced fsize 14 size 24cm,16cm')); | |
846 pl.append(p); | |
847 | |
848 % Preamble | |
849 p = param({'Preamble', 'A cell-array of gnuplot commands which are inserted before the plotting but after the basic commands.'},... | |
850 paramValue.EMPTY_CELL); | |
851 pl.append(p); | |
852 | |
853 % Arrangement | |
854 p = param({'Arrangement', ['Chose how to plot multiple AOs:\n'... | |
855 '<ul><li> on one plot (stacked)</li><li>on separate plots (single)</li>'... | |
856 '<li>on subplots (subplots) </li></ul><br>In the case of ''single'', if you use an<br>'... | |
857 'output file, then each file will be appended with a number, e.g., foo_1.pdf, foo_2.pdf.']},... | |
858 {1, {'stacked', 'single', 'subplots'}, paramValue.SINGLE}); | |
859 pl.append(p); | |
860 | |
861 % Marker scale | |
862 p = param({'MarkerScale', ['Scale the size of the markers by an integer amount.']},... | |
863 paramValue.DOUBLE_VALUE(1)); | |
864 pl.append(p); | |
865 | |
866 | |
867 end |