% logfile - log the time-taking batch operation into a text file % % data logged include: % start & end time, operation & comment, files processed % % Usage: % logfile(startTime,operationComment,operation,processed) % Arguments: % startTime - the starting time % operationComment - 'string', comments for operation % operation - 'string', the core codes being run % processed - 'string', the files processed (& directory) % Output: % Nil % % Example codes : % % startTime = sprintf('Started at: %s',datestr(now,31)); disp(startTime); % % operationComment = 'Content within for loop'; % operation = sprintf('%s\n%s\n%s\n',... % 'CodeCodeCode;',... % 'CodeCodeCode;',... % 'CodesCodesCodes;'... % ); % eval(operation) % Operation code can be put into text and use eval to run it % % So, what is logged = what is ran % % processed = sprintf('"%s" - "%s" from "%s"',fst_name_in,lst_name_in,dir_in); % Author: % Tzu Yen Wong % wongt AT csse DOT uwa DOT edu DOT au % Department of Computer Science & Software Engineering % The University of Western Australia % % Nov 2003 % June 2004 change email address to fight SPAM!!! function logfile(startTime,operationComment,operation,processed) logfilename=sprintf('%s log.txt',datestr(date,29)); linebreak = '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'; fid = fopen(logfilename,'a'); fprintf(fid,'\n %s\n',startTime); fprintf(fid,' %s:\n\n%s',operationComment,operation); %fprintf(fid,'\n Processed %20s - %20s from "%s" \n Output %20s - %20s to "%s" \n',... % fst_name_in,lst_name_in,dir_in,fst_name_out,lst_name_out,dir_out); fprintf(fid,'\n Processed: \n%s\n',processed); endTime = sprintf('Finished at: %s',datestr(now,31)); fprintf(fid,'\n %s',endTime); disp(endTime); fprintf(fid,'\n%s\n',linebreak); fclose(fid); disp(sprintf('A log file named "%s" is dumped in "%s"',logfilename,pwd)) return