spm_help.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. function varargout = spm_help(varargin)
  2. % SPM help and manual facilities
  3. % FORMAT spm_help
  4. %
  5. % The "Help" facilities are about software and implementation. The
  6. % underlying mathematics, concepts and operational equations have been (or
  7. % will be) published in the peer reviewed literature and the interested
  8. % user is referred to these sources. An intermediate theoretical exposition
  9. % is given in the SPM course notes. This and other resources are available
  10. % via the SPM Web site.
  11. % Visit https://www.fil.ion.ucl.ac.uk/spm/, or press the "SPMweb" button.
  12. %
  13. %--------------------------------------------------------------------------
  14. %
  15. % `spm_help('Topic')` or `spm_help Topic` displays the help for a
  16. % particular topic.
  17. %
  18. %--------------------------------------------------------------------------
  19. % The SPM package provides help at three levels, the first two being
  20. % available via the SPM graphical help system:
  21. %
  22. % (i) Manual pages on specific topics.
  23. % These give an overview of specific components or topics its
  24. % relation to other components, the inputs and outputs and
  25. % references to further information.
  26. %
  27. % Many of the buttons in the help menu window lead to such "man"
  28. % pages. These are contained in ASCII files named spm_*.man.
  29. % These can be viewed on the MATLAB command line with the `help`
  30. % command, e.g. `help spm_help` prints out this manual file in
  31. % the MATLAB command window.
  32. %
  33. % (ii) Help information for each routine within SPM (E.g. This is the).
  34. % help information for spm_help.m - the help function.)
  35. % This help information is the help header of the actual MATLAB
  36. % function, and can be displayed on the command line with the
  37. % `help` command, e.g. `help spm_help`.
  38. %
  39. % (iii) SPM is (mainly) implemented as MATLAB functions and scripts.
  40. % These are ASCII files named spm_*.m, which can be viewed in the
  41. % MATLAB command window with the `type` command, e.g. `type
  42. % spm_help`, or read in a text editor.
  43. %
  44. % --- MATLAB syntax is very similar to standard matrix notation that
  45. % would be found in much of the literature on matrices. In this
  46. % sense the SPM routines can be used (with MATLAB) for data
  47. % analysis, or they can be regarded as the ultimate pseudocode
  48. % specification of the underlying ideas.
  49. %
  50. % In addition, the MATLAB help system provides keyword searching through
  51. % the H1 lines (the first comment line) of the help entries of *all*
  52. % M-files found on MATLABPATH. This can be used to identify routines from
  53. % keywords. Type `help lookfor` in the MATLAB command window for further
  54. % details.
  55. %__________________________________________________________________________
  56. % Copyright (C) 1994-2012 Wellcome Trust Centre for Neuroimaging
  57. % Andrew Holmes, Karl Friston
  58. % $Id: spm_help.m 7478 2018-11-08 14:51:54Z guillaume $
  59. %__________________________________________________________________________
  60. %
  61. % FORMAT spm_help
  62. % Defaults to spm_help('!Topic').
  63. %
  64. % FORMAT spm_help('Topic')
  65. % Defaults to spm_help('!Topic','Topic').
  66. %
  67. % FORMAT spm_help('!Topic',Topic)
  68. % Topic - Help topic: Either name of file from which to display help,
  69. % or name of an internal help topic
  70. % Defaults to README.md
  71. % Loads file Topic and displays it in the Help window.
  72. %
  73. % FORMAT spm_help('!Disp',Fname,S,F)
  74. % Fname - Name of file from which to display help
  75. % S - [Optional] String vector containing a previously read in
  76. % contents of file Fname
  77. % F - Figure to use
  78. % Displays the help for the given file in the Help window (creating
  79. % one if required).
  80. %
  81. % FORMAT spm_help('!Quit')
  82. % FORMAT spm_help('!DrawMenuWin')
  83. % FORMAT [S,Err] = spm_help('!ShortTopics',Topic)
  84. % FORMAT F = spm_help('!Create')
  85. % FORMAT F = spm_help('!CreateHelpWin')
  86. % FORMAT spm_help('!CreateBar',F)
  87. % FORMAT spm_help('!Clear',F)
  88. % FORMAT h = spm_help('!ContextHelp',Topic)
  89. % Deprecated function calls.
  90. %__________________________________________________________________________
  91. %-Condition arguments
  92. %--------------------------------------------------------------------------
  93. %-All actions begin '!' - Other (string) actions are topics
  94. if nargin==0 || isempty(varargin{1})
  95. Fhelp = spm_figure('FindWin','Help');
  96. if ~isempty(Fhelp), set(Fhelp,'Visible','on')
  97. else spm_help('!Topic'); end
  98. return
  99. elseif varargin{1}(1)~='!'
  100. spm_help('!Topic',varargin{:}); return
  101. end
  102. %-
  103. %--------------------------------------------------------------------------
  104. action = varargin{1};
  105. switch lower(action)
  106. case {'!quit','!drawmenuwin','!shorttopics','!create','!createhelpwin',...
  107. '!createbar','!pulldowntopic','!figkeypressfcn','!clear','!contexthelp'}
  108. %==========================================================================
  109. warning('Action ''%s'' is deprecated.',action);
  110. case '!disp'
  111. % FORMAT spm_help('!Disp',Fname,S,F)
  112. %==========================================================================
  113. if nargin<4, F='Help'; else F=varargin{4}; end
  114. if nargin<3, S=''; else S=varargin{3}; end
  115. if nargin<2, Fname = fullfile(spm('Dir'),'README.md');
  116. else Fname = varargin{2}; end
  117. F = spm_figure('GetWin',F);
  118. spm_clf(F);
  119. if isempty(S), S = get_content(Fname); end
  120. [H,HC]=spm_browser(S,F);
  121. varargout = {H, HC};
  122. case '!topic'
  123. % FORMAT spm_help('!Topic',Topic)
  124. %==========================================================================
  125. F = spm_figure('GetWin','Help');
  126. spm_clf(F);
  127. if nargin > 1
  128. topic = varargin{2};
  129. else
  130. topic = fullfile(spm('Dir'),'README.md');
  131. end
  132. spm_help('!Disp',topic);
  133. otherwise
  134. %==========================================================================
  135. error('Unknown action string');
  136. end
  137. %==========================================================================
  138. % function url = get_content(topic)
  139. %==========================================================================
  140. function url = get_content(topic)
  141. % Get content to be displayed concerning topic
  142. switch lower(spm_file(topic,'ext'))
  143. case 'm'
  144. H = help(topic);
  145. case {'html','htm'}
  146. if any(strncmp(topic,{'file','http','ftp:'},4))
  147. url = topic;
  148. else
  149. url = ['file:///' topic];
  150. end
  151. case {'txt','man'}
  152. fid = fopen(topic,'rt');
  153. if fid == -1, H = '';
  154. else H = fread(fid,'*char')'; fclose(fid); end
  155. H = strrep(H,char([10 37]),char(10));
  156. if numel(H) && H(1)=='%', H(1)=''; end
  157. case 'md'
  158. url = topic;
  159. otherwise
  160. if exist([topic '.m'],'file')
  161. url = get_content([topic '.m']);
  162. else
  163. H = spm_jobman('help',topic,80);
  164. [H{2,:}] = deal(sprintf('\n'));
  165. H = [H{:}];
  166. end
  167. end
  168. if ~exist('url','var')
  169. url = ['<h1>' spm_file(topic,'filename') '</h1>',...
  170. '<pre style="font-size:15;">' escapechar(H) '</pre>'];
  171. end
  172. %==========================================================================
  173. % function f = fullurl(varargin)
  174. %==========================================================================
  175. function f = fullurl(varargin)
  176. % Build URL from parts
  177. f = strrep(fullfile(varargin{:}),'\','/');
  178. %==========================================================================
  179. % function str = escapechar(str)
  180. %==========================================================================
  181. function str = escapechar(str)
  182. % Escape HTML special characters
  183. % See http://www.w3.org/TR/html4/charset.html#h-5.3.2
  184. str = strrep(str,'&','&amp;');
  185. str = strrep(str,'<','&lt;');
  186. str = strrep(str,'>','&gt;');
  187. str = strrep(str,'"','&quot;');
  188. %==========================================================================
  189. % function varargout = spmfcn
  190. %==========================================================================
  191. function varargout = spmfcn
  192. % List filenames of all SPM functions
  193. persistent b f
  194. if ~isempty(b) && ~isempty(f), varargout = {b,f}; return; end
  195. f = cellstr(spm_select('FPListRec',spm('Dir'),'^.*\m$'));
  196. b = cellfun(@(x) spm_file(x,'basename'),f,'UniformOutput',false);
  197. i = cellfun(@(x) ~isempty(strmatch('spm_',x)),b);
  198. f = f(i);
  199. b = b(i);
  200. varargout = {b,f};