source:
issm/oecreview/Archive/12041-12060/ISSM-12041-12042.diff
Last change on this file was 12325, checked in by , 13 years ago | |
---|---|
File size: 3.9 KB |
-
proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/model/display/fielddisplay.rest
1 def fielddisplay(md,name,comment):2 #FIELDDISPLAY - display model field3 #4 # Usage:5 # fielddisplay(md,offset,name,comment)6 7 #get field8 field=getattr(md,name)9 10 #disp corresponding line as a function of field type (offset set as 9 spaces)11 #parsedisplay(' ',name,field,comment);12 13 return14 15 function parsedisplay(offset,name,field,comment); %{{{16 17 %string18 if ischar(field),19 20 if length(field)>30;21 displayunit(offset,name,'not displayed',comment),22 else23 displayunit(offset,name,['''' field ''''],comment),24 end25 26 %numeric27 elseif isnumeric(field)28 29 %get size30 fieldsize=size(field);31 32 %double33 if max(fieldsize)==1,34 displayunit(offset,name,num2str(field),comment),35 %matrix36 else37 displayunit(offset,name,['(' num2str(fieldsize(1)) 'x' num2str(fieldsize(2)) ')'],comment),38 end39 40 %logical41 elseif islogical(field)42 43 %get size44 fieldsize=size(field);45 46 %single value47 if max(fieldsize)==1,48 if (field)49 displayunit(offset,name,'true',comment),50 else51 displayunit(offset,name,'false',comment),52 end53 %matrix54 else55 displayunit(offset,name,['(' num2str(fieldsize(1)) 'x' num2str(fieldsize(2)) ')'],comment),56 end57 58 %structure59 elseif isstruct(field),60 if ~isempty(fields(field))61 displayunit(offset,name,'(structure)',comment),62 struct_display(field,[offset ' ']),63 else64 displayunit(offset,name,'N/A',comment),65 end66 67 %cell68 elseif iscell(field),69 cell_display(offset,name,field,comment),70 71 else72 displayunit(offset,name,'not displayed',comment),73 74 end75 end%}}}76 77 function struct_display(structure,offset) % {{{78 79 structure_fields=fields(structure);80 81 for i=1:length(structure_fields),82 83 %get current field84 field=structure.(structure_fields{i});85 86 %recursive call if necessary87 if isstruct(field),88 displayunit(offset,structure_fields{i},'(structure)',''),89 struct_display(field,[offset ' ']);90 91 %display value92 else93 parsedisplay(offset,structure_fields{i},field,'');94 end95 end96 end% }}}97 function cell_display(offset,name,field,comment) % {{{98 99 %initialization100 string='{';101 102 %go through the cell and fill string103 if length(field)<5;104 for i=1:length(field),105 if ischar(field{i}),106 string=[string '''' field{i} ''','];107 elseif (isnumeric(field{i}) & length(field{i})==1)108 string=[string num2str(field{i}) ',' ];109 else110 string='{';111 break112 end113 end114 end115 if strcmp(string,'{'),116 string=['(' num2str(size(field,1)) 'x' num2str(size(field,2)) ')'];117 else118 string=[string(1:end-1) '}'];119 end120 121 %call displayunit122 displayunit(offset,name,string,comment);123 end% }}}124 function displayunit(offset,name,characterization,comment),% {{{125 126 %take care of name127 if length(name)>23,128 name=[name(1:20) '...'];129 end130 131 %take care of characterization132 if (strcmp(characterization,['''' '''']) | strcmp(characterization,'NaN')),133 characterization='N/A';134 end135 if length(characterization)>15,136 characterization=[characterization(1:12) '...'];137 end138 139 %print140 if isempty(comment)141 disp(sprintf('%s%-23s: %-15s',offset,name,characterization));142 else143 if ischar(comment),144 disp(sprintf('%s%-23s: %-15s -- %s',offset,name,characterization,comment));145 elseif iscell(comment),146 disp(sprintf('%s%-23s: %-15s -- %s',offset,name,characterization,comment{1}));147 for i=2:length(comment),148 disp(sprintf('%s%-23s %-15s %s',offset,'','',comment{i}));149 end150 else151 error('fielddisplay error message: format for comment not supportet yet');152 end153 end154 end% }}}
Note:
See TracBrowser
for help on using the repository browser.