Skip to content

AFNI/NIfTI Server

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

Doxygen Source Code Documentation


HistoryTrace.m

Go to the documentation of this file.
00001 function [err,S] = HistoryTrace ( Opt)
00002 %
00003 %   [err,S] = HistoryTrace (Opt)
00004 %
00005 %Purpose:
00006 %   returns a signature/history sting, useful for keeping a log
00007 %
00008 %   The trace string is formed as such
00009 %      For example if script MainScript calls at line 12 
00010 %          function F1 which at line 6 calls F2 wich at line 192 calls 
00011 %          F3 which at line 56 calls HistoryTrace then the trace string is:
00012 %         MainScript(ln12)->F1(ln6)->F2(ln192)->F3(ln56)
00013 %   
00014 %Input Parameters:
00015 %   Opt is an optional options structure with the following optional fields
00016 %      .NoPath : (0/[1]) strips the paths of the function names in the call trace
00017 %      .PerSig : a string to be used instead of ['Ziad S. Saad LBC/NIMH/NIH']
00018 %      .AFNI_Format : ([0]/1) formats S to fit AFNI's History field
00019 %      .MaxTraceLevel : ([3]) Maximum number of functions to display
00020 %          from the top of the stack. In the example for the trace string, 
00021 %          F3 will not be shown. If .MaxTraceLevel is negative then counting
00022 %          is done from the bottom of the stack. In the example, MainScript 
00023 %          would not show up.
00024 %
00025 %Output Parameters:
00026 %   err : 0 No Problem
00027 %       : 1 Mucho Problems
00028 %   S the string wth PerSig, function call trace with the line numbers in 
00029 %     parenthesis, machine name and current working directory and date
00030 %   
00031 %   
00032 %      
00033 %Key Terms:
00034 %   
00035 %More Info :
00036 %   plotsign2
00037 %   tross_Encode_String
00038 %   
00039 %
00040 %     Author : Ziad Saad
00041 %     Date : Tue Apr 10 17:29:11 PDT 2001
00042 %     LBC/NIMH/ National Institutes of Health, Bethesda Maryland
00043 
00044 
00045 %Define the function name for easy referencing
00046 FuncName = 'HistoryTrace';
00047 
00048 %Debug Flag
00049 DBG = 1;
00050 
00051 %initailize return variables
00052 err = 1;
00053 
00054 if (nargin == 0), Opt = []; end
00055 
00056 if (~isfield(Opt,'NoPath') | isempty(Opt.NoPath)), Opt.NoPath = 1; end
00057 if (~isfield(Opt,'AFNI_Format') | isempty(Opt.AFNI_Format)), Opt.AFNI_Format = 0; end
00058 if (~isfield(Opt,'MaxTraceLevel') | isempty(Opt.MaxTraceLevel)), Opt.MaxTraceLevel = 3; end
00059 
00060 if (~isfield(Opt,'PerSig') | isempty(Opt.PerSig)), 
00061         Opt.PerSig = sprintf ('Ziad Saad LBC/NIMH/NIH'); 
00062 end
00063 
00064         [ST,I] = dbstack; 
00065         N_ST = length(ST);
00066         if (N_ST > 1),
00067                 if (Opt.AFNI_Format),   stk = sprintf('\n\t'); else stk = sprintf('\n');end
00068                 if (Opt.MaxTraceLevel > 0),
00069                         strt = N_ST; stp = max([(N_ST - Opt.MaxTraceLevel + 1) 2]);
00070                 else
00071                         strt = min([(1-Opt.MaxTraceLevel) N_ST]); stp = 2;
00072                 end
00073                 for (i=strt:-1:stp), 
00074                         if (Opt.NoPath), [err,PathString,ST(i).name] = GetPath (ST(i).name); end
00075                         stk = sprintf('%s%s(ln%d)->', stk, ST(i).name, ST(i).line);
00076                 end
00077                 stk = stk(1:1:length(stk)-2);
00078         else
00079                 stk = '';
00080         end             
00081         [tmp, smach] = unix('hostname');
00082         %remove this annoying tset message (some bug ....)
00083         [err, snl, Nlines] = GetNextLine(smach, 2);
00084         if (Nlines >= 2),
00085                 [err, smach] = GetNextLine(smach,Nlines);
00086         end 
00087         if (tmp), 
00088                 smach = sprintf('Dunno');       
00089                 else
00090                 smach = zdeblank(smach); 
00091         end
00092         c=datevec(now);
00093 
00094         if (Opt.AFNI_Format),
00095                 S = sprintf ('[%s@%s: %s %s:%s:%s]\n\t%s%s',...
00096                                  Opt.PerSig,smach,...
00097                                  date,...
00098                                  pad_strn(num2str(c(4)), '0', 2, 1),...
00099                                  pad_strn(num2str(c(5)), '0', 2, 1),...
00100                                  pad_strn(num2str(round(c(6))), '0', 2, 1),...
00101                                  pwd, ...
00102                                  stk);
00103 
00104                 [err, S] = tross_Encode_String(S);
00105         else
00106                 S = sprintf ('%s: %s %s:%s:%s\n%s (%s)%s',...
00107                                          Opt.PerSig,...
00108                                          date,...
00109                                          pad_strn(num2str(c(4)), '0', 2, 1),...
00110                                          pad_strn(num2str(c(5)), '0', 2, 1),...
00111                                          pad_strn(num2str(round(c(6))), '0', 2, 1),...
00112                                          smach, pwd, ...
00113                                          stk);
00114         end
00115         
00116 err = 0;
00117 return;
00118 
 

Powered by Plone

This site conforms to the following standards: