Skip to content

AFNI/NIfTI Server

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

Doxygen Source Code Documentation


BrikInfo_SectionValue.m

Go to the documentation of this file.
00001 function [err,v, typ] = BrikInfo_SectionValue (BRIKinfo, sSection)
00002 %
00003 %   [err,s, typ] = BrikInfo_SectionValue (sHead, sSection)
00004 %
00005 %Purpose:
00006 %   Get the values of a section in the .HEAD string
00007 %   This function is dedicated for BrikInfo function
00008 %   
00009 %Input Parameters:
00010 %   sHead, a string vector containing the .HEAD info
00011 %   sSection, the section name such as: 'DATASET_DIMENSIONS'
00012 %   
00013 %   
00014 %Output Parameters:
00015 %   err : 0 No Problem
00016 %       : 1 Mucho Problems
00017 %   v a vector (or a string) containing the values in that section
00018 %     v is empty (and err = 1) if the section can't be found
00019 %   typ : is a string to indicate the type of parameter (string or number)
00020 %      that v is
00021 %   
00022 %Key Terms:
00023 %   
00024 %More Info :
00025 %  see also BrikInfo 
00026 %   
00027 %   
00028 %
00029 %     Author : Ziad Saad
00030 %     Date : Mon Oct 18 13:46:28 CDT 1999 
00031 
00032 
00033 %Define the function name for easy referencing
00034 FuncName = 'BrikInfo_SectionValue';
00035 
00036 %Debug Flag
00037 DBG = 1;
00038 
00039 %initailize return variables
00040 err = 1;
00041         
00042         N_BRIKinfo = length(BRIKinfo);
00043 
00044         itmp = findstr (BRIKinfo, sSection);
00045         
00046         if (isempty(itmp)), v = []; return; end
00047         
00048         %findout where this section ends
00049                 inxt = findstr (BRIKinfo(itmp:N_BRIKinfo),'type');
00050                 if (isempty(inxt)), inxt = N_BRIKinfo; else inxt = inxt(1) + itmp -2; end
00051         
00052         %Get the count value    
00053                 [err,sn, jnk, strt,stp] = GetNextLine(BRIKinfo(itmp:inxt),2);
00054                 ic = findstr(sn,'count'); %watch it, spacing sensitive section
00055                 if (~isempty(ic)),
00056                         %skip the = sign
00057                                 sn = sn(ic+5:length(sn));
00058                                 ic = findstr(sn, '=');
00059                                 sn = sn(ic+1:length(sn));
00060                 else
00061                         err = ErrEval(FuncName,'Err_could not find count field');
00062                         return;
00063                 end
00064                 %get the count value
00065                 n = str2num(sn);
00066                 if (~n), %empty field
00067                         v = [];
00068                         typ = '';
00069                         return;
00070                 end
00071                 
00072         %advance to the next line, after count 
00073                 itmp = itmp + stp + 1;
00074                 
00075         %read all values
00076                 Svals = BRIKinfo(itmp:inxt); %that's where the values are
00077                 inl = find(setstr(Svals) == 10 | setstr(Svals) == 13); %find any new lines left in Svals (13 was added to work in DOS (CR and LF))
00078                 
00079                 if (~isempty(inl)), 
00080                         Svals(inl) = ' '; %replace them by space characters
00081                 end
00082         
00083         %if (sum(isletter(Svals))), %isletter fails when you have numbers such as 1.4e-3
00084            v = zdeblank(Svals);
00085       if isempty(v)
00086                         typ = 'string';
00087       elseif strcmp(v(1),'''') & strcmp(v(length(v)),'~')
00088                         %This parameter is a string, do not change to numbers
00089                         %remove first and last chars
00090                    v = v(2:length(v)-1); 
00091                         typ = 'string';
00092                 else
00093                         v = str2num(Svals);
00094                         typ = 'number';
00095                 end
00096 
00097 %pause
00098 
00099 err = 0;
00100 return;
00101 
 

Powered by Plone

This site conforms to the following standards: