source: issm/trunk-jpl/externalpackages/export_fig/pdftops.m@ 19571

Last change on this file since 19571 was 19571, checked in by Mathieu Morlighem, 10 years ago

CHG: new version of export_fig

File size: 3.6 KB
Line 
1function varargout = pdftops(cmd)
2%PDFTOPS Calls a local pdftops executable with the input command
3%
4% Example:
5% [status result] = pdftops(cmd)
6%
7% Attempts to locate a pdftops executable, finally asking the user to
8% specify the directory pdftops was installed into. The resulting path is
9% stored for future reference.
10%
11% Once found, the executable is called with the input command string.
12%
13% This function requires that you have pdftops (from the Xpdf package)
14% installed on your system. You can download this from:
15% http://www.foolabs.com/xpdf
16%
17% IN:
18% cmd - Command string to be passed into pdftops.
19%
20% OUT:
21% status - 0 iff command ran without problem.
22% result - Output from pdftops.
23
24% Copyright: Oliver Woodford, 2009-2010
25
26% Thanks to Jonas Dorn for the fix for the title of the uigetdir window on
27% Mac OS.
28% Thanks to Christoph Hertel for pointing out a bug in check_xpdf_path
29% under linux.
30% 23/01/2014 - Add full path to pdftops.txt in warning.
31% 27/05/2015 - Fixed alert in case of missing pdftops; fixed code indentation
32
33 % Call pdftops
34 [varargout{1:nargout}] = system(sprintf('"%s" %s', xpdf_path, cmd));
35end
36
37function path_ = xpdf_path
38 % Return a valid path
39 % Start with the currently set path
40 path_ = user_string('pdftops');
41 % Check the path works
42 if check_xpdf_path(path_)
43 return
44 end
45 % Check whether the binary is on the path
46 if ispc
47 bin = 'pdftops.exe';
48 else
49 bin = 'pdftops';
50 end
51 if check_store_xpdf_path(bin)
52 path_ = bin;
53 return
54 end
55 % Search the obvious places
56 if ispc
57 path_ = 'C:\Program Files\xpdf\pdftops.exe';
58 else
59 path_ = '/usr/local/bin/pdftops';
60 end
61 if check_store_xpdf_path(path_)
62 return
63 end
64 % Ask the user to enter the path
65 while 1
66 errMsg = 'Pdftops not found. Please locate the program, or install xpdf-tools from ';
67 url = 'http://foolabs.com/xpdf';
68 fprintf(2, '%s\n', [errMsg '<a href="matlab:web(''-browser'',''' url ''');">' url '</a>']);
69 errMsg = [errMsg url]; %#ok<AGROW>
70 if strncmp(computer,'MAC',3) % Is a Mac
71 % Give separate warning as the MacOS uigetdir dialogue box doesn't have a title
72 uiwait(warndlg(errMsg))
73 end
74 base = uigetdir('/', errMsg);
75 if isequal(base, 0)
76 % User hit cancel or closed window
77 break;
78 end
79 base = [base filesep]; %#ok<AGROW>
80 bin_dir = {'', ['bin' filesep], ['lib' filesep]};
81 for a = 1:numel(bin_dir)
82 path_ = [base bin_dir{a} bin];
83 if exist(path_, 'file') == 2
84 break;
85 end
86 end
87 if check_store_xpdf_path(path_)
88 return
89 end
90 end
91 error('pdftops executable not found.');
92end
93
94function good = check_store_xpdf_path(path_)
95 % Check the path is valid
96 good = check_xpdf_path(path_);
97 if ~good
98 return
99 end
100 % Update the current default path to the path found
101 if ~user_string('pdftops', path_)
102 warning('Path to pdftops executable could not be saved. Enter it manually in %s.', fullfile(fileparts(which('user_string.m')), '.ignore', 'pdftops.txt'));
103 return
104 end
105end
106
107function good = check_xpdf_path(path_)
108 % Check the path is valid
109 [good, message] = system(sprintf('"%s" -h', path_)); %#ok<ASGLU>
110 % system returns good = 1 even when the command runs
111 % Look for something distinct in the help text
112 good = ~isempty(strfind(message, 'PostScript'));
113end
Note: See TracBrowser for help on using the repository browser.