1 |
% |
---|
2 |
% PRINTFILE create a dialog box to print figures to files |
---|
3 |
% |
---|
4 |
function printfile(opt,subopt) |
---|
5 |
if nargin==0,opt='Initialize';,end |
---|
6 |
|
---|
7 |
curfig=gcf; |
---|
8 |
if strcmp(opt,'Initialize') % Setup |
---|
9 |
printfig=findobj(0,'Type','figure','Tag','PrintFig'); |
---|
10 |
if ~isempty(printfig),return,end |
---|
11 |
|
---|
12 |
printfig = figure('Position',[150 350 500 220],... |
---|
13 |
'NumberTitle','off',... |
---|
14 |
'Name','Printfile Setup',... |
---|
15 |
'NextPlot','new',... |
---|
16 |
'Tag','PrintFig'); |
---|
17 |
set(printfig,'UserData',curfig); |
---|
18 |
|
---|
19 |
ColorButton = uicontrol('Parent',printfig,... |
---|
20 |
'Style','checkbox',... |
---|
21 |
'String','Color ?',... |
---|
22 |
'Units','normalized',... |
---|
23 |
'Position',[.05 .2 .2 .125],... |
---|
24 |
'Tag','ColorButton'); |
---|
25 |
set(ColorButton,'UserData',str2mat('<NULL>','<NULL>')); |
---|
26 |
|
---|
27 |
EncapButton = uicontrol('Parent',printfig,... |
---|
28 |
'Style','checkbox',... |
---|
29 |
'String','Encapsulate ?',... |
---|
30 |
'Units','normalized',... |
---|
31 |
'Position',[.3 .2 .3 .125],... |
---|
32 |
'Tag','EncapButton'); |
---|
33 |
|
---|
34 |
FNameButton=uicontrol('Parent',printfig,... |
---|
35 |
'Style','pushbutton',... |
---|
36 |
'String','File Name',... |
---|
37 |
'Units','normalized',... |
---|
38 |
'Position',[.3 .4 .3 .125],... |
---|
39 |
'Callback','printfile(''To File'')',... |
---|
40 |
'Tag','FNameButton'); |
---|
41 |
|
---|
42 |
PrintButton=uicontrol('Parent',printfig,... |
---|
43 |
'Style','pushbutton',... |
---|
44 |
'String','Print',... |
---|
45 |
'Units','normalized',... |
---|
46 |
'Position',[.7 .4 .2 .125],... |
---|
47 |
'Callback','printfile(''Exec Print'')',... |
---|
48 |
'Tag','PrintButton'); |
---|
49 |
|
---|
50 |
CancelButton=uicontrol('Parent',printfig,... |
---|
51 |
'Style','pushbutton',... |
---|
52 |
'String','Cancel',... |
---|
53 |
'Units','normalized',... |
---|
54 |
'Position',[.7 .2 .2 .125],... |
---|
55 |
'Callback','printfile(''Kill'')',... |
---|
56 |
'Tag','CancelButton'); |
---|
57 |
|
---|
58 |
elseif strcmp(opt,'To File') |
---|
59 |
ColorButton=findobj(0,'Type','uicontrol','Tag','ColorButton'); |
---|
60 |
[outfile, outpath] = uiputfile('', 'Save As'); |
---|
61 |
set(ColorButton,'UserData',str2mat(outpath,outfile)); |
---|
62 |
elseif strcmp(opt,'Kill') |
---|
63 |
printfig=findobj(0,'Type','figure','Tag','PrintFig'); |
---|
64 |
delete(printfig); |
---|
65 |
elseif strcmp(opt,'Exec Print') |
---|
66 |
printfig=findobj(0,'Type','figure','Tag','PrintFig'); |
---|
67 |
ColorButton=findobj(printfig,'Type','uicontrol','Tag','ColorButton'); |
---|
68 |
ud=get(ColorButton,'UserData'); |
---|
69 |
if strcmp(ud(2),'<null>')|strcmp(ud(2),' ') |
---|
70 |
errstr=['No filename set. No file printed.']; |
---|
71 |
herr=errordlg(errstr); |
---|
72 |
return |
---|
73 |
end |
---|
74 |
|
---|
75 |
outname=deblank([ud(1,:) ud(2,:)]); |
---|
76 |
curfig=get(printfig,'UserData'); |
---|
77 |
|
---|
78 |
EncapButton=findobj(printfig,'Type','uicontrol','Tag','EncapButton'); |
---|
79 |
ColorButton=findobj(printfig,'Type','uicontrol','Tag','ColorButton'); |
---|
80 |
EncapButtonVal=get(EncapButton,'value'); |
---|
81 |
ColorButtonVal=get(ColorButton,'value'); |
---|
82 |
|
---|
83 |
if (EncapButtonVal&ColorButtonVal) |
---|
84 |
dash='-depsc' ; % Encapsulated Color PostScript (EPSF) |
---|
85 |
elseif (EncapButtonVal) |
---|
86 |
dash='-deps' ; % Encapsulated B&W PostScript (EPSF) |
---|
87 |
elseif (ColorButtonVal) |
---|
88 |
dash='-dpsc' ; % Color PostScript |
---|
89 |
else |
---|
90 |
dash='-dps'; % B&W PostScript |
---|
91 |
end |
---|
92 |
|
---|
93 |
% If printer is defined in shell, use it; else, let MATLAB do its default |
---|
94 |
PRINTER=getenv('PRINTER'); |
---|
95 |
if ~isempty(PRINTER) |
---|
96 |
dash = [dash ' -P' PRINTER]; |
---|
97 |
end |
---|
98 |
|
---|
99 |
if ~strcmp(outname,'<NULL><NULL>') |
---|
100 |
prcom=['print ' dash ' ' outname]; |
---|
101 |
else |
---|
102 |
prcom=['print ' dash]; |
---|
103 |
end |
---|
104 |
|
---|
105 |
figure(curfig); |
---|
106 |
eval(prcom); |
---|
107 |
set(ColorButton,'UserData',str2mat('<NULL>','<NULL>')); |
---|
108 |
end |
---|
109 |
% |
---|
110 |
% Brian O. Blanton |
---|
111 |
% Curriculum in Marine Science |
---|
112 |
% Ocean Processes Numerical Modeling Laboratory |
---|
113 |
% 15-1A Venable Hall |
---|
114 |
% CB# 3300 |
---|
115 |
% Uni. of North Carolina |
---|
116 |
% Chapel Hill, NC |
---|
117 |
% 27599-3300 |
---|
118 |
% |
---|
119 |
% 919-962-4466 |
---|
120 |
% blanton@marine.unc.edu |
---|
121 |
% |
---|
122 |
% March 1995 |
---|
123 |
% |
---|
124 |
|
---|