Home > database > ensemble_init_fid.m

ensemble_init_fid

PURPOSE ^

Initializes a file identifier to which to direct output.

SYNOPSIS ^

function fid = ensemble_init_fid(params)

DESCRIPTION ^

 Initializes a file identifier to which to direct output.
 fid = ensemble_init_fid(params);

 Initializes a file identifier to which to direct output.  The default in the
 absence of input parameters is standard out (fid=1).

 params is a structure with the following possible fields

 .print - a flag to indicate whether printing should occur
 .write2file - a flag to indicate whether or not printing should be done to
               file
 .fname - name of file to print to
 .filemode - mode with which to open file. Defaults to 'wt'.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function fid = ensemble_init_fid(params)
0002 % Initializes a file identifier to which to direct output.
0003 % fid = ensemble_init_fid(params);
0004 %
0005 % Initializes a file identifier to which to direct output.  The default in the
0006 % absence of input parameters is standard out (fid=1).
0007 %
0008 % params is a structure with the following possible fields
0009 %
0010 % .print - a flag to indicate whether printing should occur
0011 % .write2file - a flag to indicate whether or not printing should be done to
0012 %               file
0013 % .fname - name of file to print to
0014 % .filemode - mode with which to open file. Defaults to 'wt'.
0015 
0016 % 02/03/07 Petr Janata
0017 
0018 % Check to see if we already have a registered output file id
0019 if nargin > 0 && isfield(params, 'fid') && ~isempty(params.fid) && params.fid>0
0020   return
0021 end
0022 
0023 fid = 1;  % default to standard out
0024 
0025 try print_tables = params.print; catch print_tables=1; end
0026 try write2file = params.write2file; catch write2file = 0; end
0027 try filemode = params.filemode; catch filemode = 'wt'; end
0028 try verbose = params.verbose; catch verbose = 1; end
0029 
0030 if print_tables
0031   
0032   if write2file
0033     fid = fopen(params.fname,filemode);
0034     if fid == -1
0035       error(sprintf('Problem opening logfile: %s\n',params.fname));
0036     end
0037     if verbose == 1
0038       fprintf('Writing tables to file: %s\n', params.fname);
0039     end
0040   else
0041     fid = 1;
0042   end
0043 end

Generated on Fri 22-Mar-2019 04:00:52 by m2html © 2003