print_jd

PURPOSE ^

SYNOPSIS ^

function print_jd(opt,savename,savedir,fignum,res)

DESCRIPTION ^

 prints (opt = 0) and (opt = 1) / or (opt = 2, default) saves to file the current figure under the name savename

 by J. Decker (jodecker@alum.mit.edu) 09/28/04

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function print_jd(opt,savename,savedir,fignum,res)
0002 %
0003 % prints (opt = 0) and (opt = 1) / or (opt = 2, default) saves to file the current figure under the name savename
0004 %
0005 % by J. Decker (jodecker@alum.mit.edu) 09/28/04
0006 %
0007 if nargin < 5
0008     res = 600;
0009 end
0010 if nargin < 4
0011     fignum = NaN;
0012 end
0013 if nargin < 3
0014     savedir = NaN;
0015 end
0016 if nargin < 2
0017     savename = NaN;
0018 end
0019 if nargin < 1
0020     opt = 1;
0021 end
0022 %
0023 if isnan(savedir),
0024     savedir = 'figures/';
0025 elseif isempty(savedir),
0026     savedir = './';
0027 elseif ~strcmp(savedir(end),filesep),
0028     savedir = [savedir,filesep];
0029 end
0030 if ishandle(fignum),
0031 %     figure(fignum)
0032 else
0033     fignum = get(0,'currentfigure');
0034 end
0035 if isnan(savename)
0036     savename = ['fig_',num2str(fignum)];
0037 end
0038 %
0039 % Printing default options
0040 %
0041 set(gcf,'PaperPositionMode','auto');
0042 set(gca, 'XTickMode','manual');
0043 set(gca, 'YTickMode','manual');
0044 set(gca, 'ZTickMode','manual');
0045 %
0046 if opt >= 0 && opt <= 1,
0047     print
0048 end
0049 %
0050 if opt >= 1,
0051     if opt == 3,
0052         keyboard
0053     end
0054     if opt == -1,
0055         return
0056     end
0057     if exist(savedir,'dir') ~= 7
0058         mkdir(savedir)
0059     end
0060 %     wd = pwd;
0061 %     cd(savedir)
0062     %
0063     print(fignum,'-depsc2','-loose',['-r',num2str(res)],[savedir,savename,'.eps']);
0064 %     eval(['print -depsc -loose -r',num2str(res),' ',savename,'.eps']);
0065     saveas(fignum,[savedir,savename,'.fig'],'fig')
0066     if strcmp(computer,'PCWIN'),
0067 %         eval(['print -dmeta -r',num2str(res),' ',savename,'.emf']);
0068         print(fignum,'-dmeta',['-r',num2str(res)],[savedir,savename,'.emf']);
0069     else
0070 %         eval(['print -dpng -r',num2str(res),' ',savename,'.png']);
0071         print(fignum,'-dpng',['-r',num2str(res)],[savedir,savename,'.png']);
0072         %eval(['print -djpeg90 -r',num2str(res),' ',savename,'.jpg']);
0073     end    
0074     %
0075     % Patch for EPS file written by MatLab 7.5 under OS X 10.5.1 to be
0076     % readable by LyX word TeX processor
0077     %
0078     if strcmp(computer,'MAC'),
0079         eval(['!/Applications/Edition/TeX/macghostview/bin/eps2eps ''',savedir,savename,'.eps'' ''temp_',savedir,savename,'.eps'''])
0080         eval(['!/Applications/Edition/TeX/macghostview/bin/eps2eps ''temp_',savedir,savename,'.eps'' ''',savedir,savename,'.eps'''])
0081         eval(['delete ''temp_',savedir,savename,'.eps''']) 
0082     end
0083     %
0084 %     cd(wd)
0085 end
0086

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.