Home > matlab > utilities > doc > get_internal_doc_block.m

get_internal_doc_block

PURPOSE ^

Extract doc sections from matlab's routine.

SYNOPSIS ^

function block = get_internal_doc_block(fname,fpath)

DESCRIPTION ^

 Extract doc sections from matlab's routine.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function block = get_internal_doc_block(fname,fpath)
0002 % Extract doc sections from matlab's routine.
0003  
0004 % Copyright (C) 2011 Dynare Team
0005 % stephane DOT adjemian AT univ DASH lemans DOT fr
0006 %
0007 % This file is part of Dynare.
0008 %
0009 % Dynare is free software: you can redistribute it and/or modify
0010 % it under the terms of the GNU General Public License as published by
0011 % the Free Software Foundation, either version 3 of the License, or
0012 % (at your option) any later version.
0013 %
0014 % Dynare is distributed in the hope that it will be useful,
0015 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 % GNU General Public License for more details.
0018 %
0019 % You should have received a copy of the GNU General Public License
0020 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0021 
0022 % Default output
0023 block = [];
0024     
0025 % Open the matlab file.
0026 mid = fopen([fpath '/' fname '.m'],'r');
0027 
0028 % Read the matlab file.
0029 file = textscan(mid,'%s','delimiter','\n');
0030 file = file{1};
0031 
0032 % Close the matlab file.
0033 fclose(mid);
0034 
0035 % Locate the test blocks.
0036 b1 = find(strncmp(file,'%@info:',7))+1;
0037 b2 = find(strncmp(file,'%@eod:',6))-1;
0038 b  = find(strncmp(file,'%!',2));
0039 
0040 if ( isempty(b1) && isempty(b2) && isempty(b) )
0041     % No internal documentation available.
0042     return
0043 else
0044     if ( (~isempty(b1) && isempty(b2) && isempty(b)) || ...
0045             (isempty(b1) && ~isempty(b2) && isempty(b)) || ...
0046             (isempty(b1) && isempty(b2) && ~isempty(b)) || ...
0047             (isempty(b1) && ~isempty(b2) && ~isempty(b)) || ...
0048             (~isempty(b1) && isempty(b2) && ~isempty(b)) || ...
0049             (~isempty(b1) && ~isempty(b2) && isempty(b)) )
0050         error('get_internal_doc_block:: There is a problem with the internal block definition!')
0051     end
0052     if ( b2~=b(end) || b1~=b(1) || any(b-transpose(b1:1:b2)) ) 
0053         error('get_internal_doc_block:: There is a problem with the internal block definition!')
0054     end
0055 end
0056 
0057 % Extract the internal documentation block.
0058 for i=b(1):1:b(end)
0059     str = file{i};
0060     block = char(block, str(3:end));
0061 end
0062 block = block(2:end,:);

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005