0001 function data_st = ensemble_display_table(data_st,params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 cols = set_var_col_const(data_st.vars);
0021
0022
0023
0024 ncols = size(data_st.data{cols.data},2);
0025 for icol = 1:ncols
0026 if numel(data_st.data{cols.data}{icol}) ~= ...
0027 length(data_st.data{cols.data}{icol})
0028 msgstr = sprintf('%s: Display data column contains a matrix', mfilename);
0029 error(msgstr);
0030 else
0031 data_st.data{cols.data}{icol} = data_st.data{cols.data}{icol}(:);
0032 end
0033 end
0034
0035
0036 fid = ensemble_init_fid(params);
0037
0038
0039 try add_datestamp = params.add_datestamp; catch add_datestamp = false; end
0040 if add_datestamp
0041 fprintf(fid,'\nTable generated on: %s\n\n', datestr(now,0));
0042 end
0043
0044
0045 colnames = data_st.data{cols.column_labels};
0046 if length(colnames) ~= ncols
0047 msgstr = sprintf(['%s: Mismatch between number of data columns (%d) and number of ' ...
0048 'column labels (%d)', ncols, length(colnames)]);
0049 error(msgstr)
0050 end
0051
0052 for icol = 1:ncols
0053 fprintf(fid,'%s', colnames{icol});
0054 if icol < ncols, fprintf(fid,'\t');
0055 else fprintf(fid,'\n');
0056 end
0057 end
0058
0059
0060 try replace_nan = params.replace_nan; catch replace_nan = false; end
0061 if replace_nan
0062 try nan_str = params.nan_str; catch nan_str = '.'; end
0063 end
0064
0065
0066 nrows = length(data_st.data{cols.data}{1});
0067 for irow = 1:nrows
0068 for icol = 1:ncols
0069 format_str = data_st.data{cols.column_formats}{icol};
0070 if ~isempty(findstr(format_str,'s'))
0071 if iscell(data_st.data{cols.data}{icol}{irow})
0072 data_val = cell2str(data_st.data{cols.data}{icol}{irow},',');
0073 else
0074 data_val = data_st.data{cols.data}{icol}{irow};
0075 end
0076 else
0077 data_val = data_st.data{cols.data}{icol}(irow);
0078 if isnan(data_val) && replace_nan
0079 data_val = nan_str;
0080 format_str = '%s';
0081 end
0082 end
0083 fprintf(fid, format_str, data_val);
0084 if icol < ncols, fprintf(fid,'\t');
0085 else fprintf(fid,'\n');
0086 end
0087 end
0088 end
0089
0090 if fid > 1
0091 fclose(fid);
0092 end