Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


PurgeComments.m

Go to the documentation of this file.
00001 function [CnoCom] = PurgeComments (C, ch)
00002 %
00003 %   [CnoCom] = PurgeComments (C, [ch])
00004 %
00005 %Purpose:
00006 %   purges all matlab coments from character array
00007 %   
00008 %   
00009 %Input Parameters:
00010 %   C : character array
00011 %   ch : is the character indicating a comment line, default is '%'
00012 %   
00013 %Output Parameters:
00014 %   err : 0 No Problem
00015 %       : 1 Mucho Problems
00016 %   CnoCom : comment purged caharacter array
00017 %   Com : Comment array
00018 %      
00019 %More Info :
00020 %   
00021 %  SkipMatlabHelp
00022 %  FindChar
00023 %       NextString
00024 %   
00025 %   C = sprintf (...
00026 %  '%%Hello \n%%Couci Couci \nAbc = 00\n%%Wald\njon\n%%ert\nMlk\n%%brt%%crt\nflp\n%%kr\n\nko=6\n%%bizz\n%%Bozz\n\nfly')
00027 %   [CnoCom] = PurgeComments (C)
00028 %   
00029 %
00030 %     Author : Ziad Saad
00031 %     Date : Sat Mar 27 15:42:11 CST 1999 
00032 
00033 
00034 %Define the function name for easy referencing
00035 FuncName = 'PurgeComments';
00036 
00037 if (nargin == 1), ch = '%'; end
00038 
00039 %Debug Flag
00040 DBG = 1;
00041 
00042 %initailize return variables
00043 err = 1;
00044 CnoCom = [];
00045 Com = '';
00046 
00047 %skip the help lines (top comments) if there are any
00048 if (C(1) == ch),
00049         [C] = SkipMatlabHelp (C);
00050 end
00051 
00052 [err, Loc_1] = FindChar (C, ch);
00053 
00054 if (~isempty(Loc_1)),
00055         cnt = 1;
00056         CnoCom = C;
00057         nC = length(C);
00058         %fprintf ('C purged of heading is :\n');
00059         %fprintf ('%c', C);
00060         FirstChunk = C(1:Loc_1(1)-1);
00061         CnoCom(1:length(FirstChunk)) = FirstChunk;
00062         nCnoCom = length(FirstChunk);
00063         %fprintf ('CnoCom at first chunk : \n');
00064         %fprintf ('%c', CnoCom(1:nCnoCom));
00065 
00066         while (cnt < length(Loc_1)),
00067                 %skip that line
00068                 [err,Cnext, cend] = NextString (C, 'NewLine', Loc_1(cnt));
00069 
00070                 %make sure next line is not a comment
00071                 if (cend+1 == Loc_1(cnt+1)), lop = 1; else lop = 0; end
00072                 while (lop), %looks like it is a comment, cycle through block
00073                         % fprintf (1,'Looping, cnt = %g/%g\n', cnt, length(Loc_1));
00074                         cnt = cnt+1;
00075                         [err,Cnext, cend] = NextString (C, 'NewLine', Loc_1(cnt));
00076                         lop = 0;
00077                         if (cnt < length(Loc_1))
00078                                 if (cend+1 == Loc_1(cnt+1)), 
00079                                         lop = 1; 
00080                                 end
00081                         end
00082                 end
00083 
00084                 %copy the next good piece, 
00085                 %if you did not run out of cnt in the looping condition above
00086                 if (cnt < length(Loc_1)),
00087                         GoodChunk = C(cend+1:Loc_1(cnt+1)-1);
00088                         CnoCom(1+nCnoCom:nCnoCom+length(GoodChunk)) = GoodChunk;
00089                         nCnoCom = nCnoCom+length(GoodChunk);
00090                         %fprintf ('CnoCom at middle chunk (cnt = %g) : \n', cnt);
00091                         %fprintf ('%c', CnoCom(1:nCnoCom));
00092 
00093                         %increment and go on
00094                         cnt = cnt + 1;
00095                 end
00096         end
00097 
00098                 %append last piece if any
00099                 if (Loc_1(cnt) < nC),
00100                         [err,Cnext, cend] = NextString (C, 'NewLine', Loc_1(cnt));
00101                         LastChunk = C(cend+1:nC);
00102                         CnoCom(1+nCnoCom:nCnoCom+length(LastChunk)) = LastChunk;
00103                         nCnoCom = nCnoCom+length(LastChunk);
00104                         %fprintf ('Last Chunk : \n');
00105                         %fprintf ('%c',LastChunk);
00106                 end
00107 
00108                 CnoCom = CnoCom(1:nCnoCom);
00109 
00110                 %fprintf ('\n***\nFinal CnoCom\n***\n');
00111                 %fprintf ('%c', CnoCom(1:nCnoCom));
00112 else %no comments
00113         CnoCom = C;
00114 end
00115 
00116 return;
00117 
00118 
 

Powered by Plone

This site conforms to the following standards: