source: issm/oecreview/Archive/12041-12060/ISSM-12041-12042.diff

Last change on this file was 12325, checked in by Eric.Larour, 13 years ago

11990 to 12321 oec compliance

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 field
    3 #
    4 #   Usage:
    5 #      fielddisplay(md,offset,name,comment)
    6 
    7         #get field
    8         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         return
    14 
    15 function parsedisplay(offset,name,field,comment); %{{{
    16 
    17         %string
    18         if ischar(field),
    19 
    20                 if length(field)>30;
    21                         displayunit(offset,name,'not displayed',comment),
    22                 else
    23                         displayunit(offset,name,['''' field ''''],comment),
    24                 end
    25 
    26         %numeric
    27         elseif isnumeric(field)
    28 
    29                 %get size
    30                 fieldsize=size(field);
    31 
    32                 %double
    33                 if max(fieldsize)==1,
    34                         displayunit(offset,name,num2str(field),comment),
    35                 %matrix
    36                 else
    37                         displayunit(offset,name,['(' num2str(fieldsize(1)) 'x' num2str(fieldsize(2)) ')'],comment),
    38                 end
    39 
    40         %logical
    41         elseif islogical(field)
    42 
    43                 %get size
    44                 fieldsize=size(field);
    45 
    46                 %single value
    47                 if max(fieldsize)==1,
    48                         if (field)
    49                                 displayunit(offset,name,'true',comment),
    50                         else
    51                                 displayunit(offset,name,'false',comment),
    52                         end
    53                 %matrix
    54                 else
    55                         displayunit(offset,name,['(' num2str(fieldsize(1)) 'x' num2str(fieldsize(2)) ')'],comment),
    56                 end
    57 
    58                 %structure
    59         elseif isstruct(field),
    60                 if ~isempty(fields(field))
    61                         displayunit(offset,name,'(structure)',comment),
    62                         struct_display(field,[offset '   ']),
    63                 else
    64                         displayunit(offset,name,'N/A',comment),
    65                 end
    66 
    67         %cell
    68         elseif iscell(field),
    69                 cell_display(offset,name,field,comment),
    70 
    71         else
    72                 displayunit(offset,name,'not displayed',comment),
    73 
    74         end
    75 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 field
    84                 field=structure.(structure_fields{i});
    85 
    86                 %recursive call if necessary
    87                 if isstruct(field),
    88                         displayunit(offset,structure_fields{i},'(structure)',''),
    89                         struct_display(field,[offset '   ']);
    90 
    91                 %display value
    92                 else
    93                         parsedisplay(offset,structure_fields{i},field,'');
    94                 end
    95         end
    96 end% }}}
    97 function cell_display(offset,name,field,comment) % {{{
    98 
    99         %initialization
    100         string='{';
    101 
    102         %go through the cell and fill string
    103         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                         else
    110                                 string='{';
    111                                 break
    112                         end
    113                 end
    114         end
    115         if strcmp(string,'{'),
    116                 string=['(' num2str(size(field,1)) 'x' num2str(size(field,2)) ')'];
    117         else
    118                 string=[string(1:end-1) '}'];
    119         end
    120 
    121         %call displayunit
    122         displayunit(offset,name,string,comment);
    123 end% }}}
    124 function displayunit(offset,name,characterization,comment),% {{{
    125 
    126         %take care of name
    127         if length(name)>23,
    128                 name=[name(1:20) '...'];
    129         end
    130 
    131         %take care of characterization
    132         if (strcmp(characterization,['''' '''']) | strcmp(characterization,'NaN')),
    133                 characterization='N/A';
    134         end
    135         if length(characterization)>15,
    136                 characterization=[characterization(1:12) '...'];
    137         end
    138 
    139         %print
    140         if isempty(comment)
    141                 disp(sprintf('%s%-23s: %-15s',offset,name,characterization));
    142         else
    143                 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                         end
    150                 else
    151                         error('fielddisplay error message: format for comment not supportet yet');
    152                 end
    153         end
    154 end% }}}
Note: See TracBrowser for help on using the repository browser.