forked from csdms-contrib/slepian_alpha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
figdisp.m
87 lines (78 loc) · 2.69 KB
/
figdisp.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function varargout=figdisp(name,ext,opt,act,form,convo)
% FIGDISP(name,ext,opt,act,form,convo)
% [fname,pstring]=FIGDISP(...)
%
% Suggests print command for figures.
% Assumes environment variable 'EPS' is set.
% Use PAINTERS to override, sometimes.
%
% INPUT:
%
% name Filename, preferably without graphics extension or any
% dots in the filename, really [default: calling function]
% ext An optional additional extension (number or string)
% opt An option string, e.g. '-zbuffer'
% act 1 Actually print the figure
% 0 Don't print the figure [default]
% 2 Makes a PDF from an EPS which it removes
% form A graphics format [pdf, png, etc: default: epsc]
% convo A graphics converter string [default: 'ps2raster -Tf']
% such as 'epstopdf' or 'ps2raster' or ...
%
% OUTPUT:
%
% fname The full file name, but definitely no graphics extension
% pstring The plot string
%
% Tested on 8.3.0.532 (R2014a) and 9.0.0.341360 (R2016a)
% Last modified by fjsimons-at-alum.mit.edu, 07/01/2016
[p,n]=star69;
defval('name',n)
defval('ext',[])
defval('opt',[])
defval('act',0)
defval('convo','ps2raster -Tf')
defval('form','epsc')
% Calls itself and cleans up afterward
if act==2
[fname,pstring]=figdisp(name,ext,opt,1,'epsc');
% PRINT will keep ANY extension, defined as any period in the filename,
% but also it will make a GRAPHICS extension if the filename had no
% periods in it... so if you GIVE it an extension coming in, careful!
% What normally comes out of FIGDISP as 'fname' has no extension
if ~any(fname==46) ; xtra='.eps'; else xtra=[]; end
system(sprintf('degs %s%s',fname,xtra));
system(sprintf('%s %s%s',convo,fname,xtra));
% Now, depending on the behavior of the conversion, fix ITS extension;
% epstopdf and ps2raster appear to STRIP ANY extension reading from the
% BACK and substitute the right extension in (overwriting a file that
% may have come in with the wrong extension!), so keep on fixing,
% remove the original UNLESS it had the .pdf at the end at this point
if ~all(fname(end-3:end)=='.pdf')
system(sprintf('rm -f %s%s',fname,xtra));
end
% Shortcut and get out
varns={fname,pstring};
varargout=varns(1:nargout);
return
end
if ~isstr(ext)
ext=num2str(ext);
end
if ~isempty(ext)
fname=fullfile(getenv('EPS'),sprintf('%s_%s',name,ext));
else
fname=fullfile(getenv('EPS'),sprintf('%s',name));
end
if ~isempty(opt)
pstring=sprintf('print(''-d%s'',''%s'',''%s'')',form,opt,fname);
else
pstring=sprintf('print(''-d%s'',''%s'')',form,fname);
end
disp(pstring)
if act>=1
eval(pstring)
end
% Optional output
varns={fname,pstring};
varargout=varns(1:nargout);