source:
issm/oecreview/Archive/16554-17801/ISSM-17720-17721.diff@
17802
Last change on this file since 17802 was 17802, checked in by , 11 years ago | |
---|---|
File size: 4.4 KB |
-
../trunk-jpl/src/m/solve/createxml.m
1 function createxml(xmlfilename,md) 2 %EXTRUDEXML - output an XML file compatible with inishell for automatic gui generation 3 % 4 % The routine creates an XML file that list fields from the underlying classes 5 % in model, and that can be use to render a GUI using the java code inishell 6 % 7 % Usage: 8 % createxml(md,xmlfilename) 9 10 disp(['creating XML file ' xmlfilename]); 11 12 %open file for binary writing 13 fid=fopen(xmlfilename,'w'); 14 if fid==-1, 15 error(['extrudexml error message: could not open ' xmlfilename,' file for ASCII writing']); 16 end 17 18 %Go through all model fields: check that it is a class and call checkconsistency 19 fields=properties('model'); 20 fprintf(fid, '<inishell_config application="ISSM prototype">\n\n'); % require header for xml file 21 for i=1:length(fields), 22 field=fields{i}; 23 24 %Some properties do not need to XML rendered 25 if ismember(field,{'results' 'radaroverlay' 'toolkits' 'private'}), 26 continue; 27 end 28 29 %Check that current field is an object 30 if ~isobject(md.(field)) 31 error(['field ''' char(field) ''' is not an object']); 32 end 33 34 %Create XML file for this subclass 35 createxml(md.(field),fid); 36 end 37 fprintf(fid, '\n\n</inishell_config>'); % require footer for xml file 38 %close file 39 st=fclose(fid); 40 if st==-1, 41 error(['createxml error message: could not close file ' xmlfilename]); 42 end -
../trunk-jpl/src/m/solve/convert2str.m
1 function str = convert2str(field) 2 3 str = parsedisplay(field); 4 5 end %function 6 7 function str = parsedisplay(field) % {{{ 8 9 %string 10 if ischar(field), 11 12 if length(field)>30; 13 %str = displayunit('not displayed'); 14 str=field; 15 else 16 str = displayunit(['''' field '''']); 17 end 18 19 %cell 20 elseif iscell(field), 21 str = cell_display(field), 22 23 %structure 24 elseif isstruct(field), 25 str = struct_display(field), 26 27 %numeric 28 elseif isnumeric(field) 29 30 %get size 31 fieldsize=size(field); 32 33 %double 34 if max(fieldsize)==1, 35 str = displayunit(num2str(field)), 36 %matrix 37 else 38 str = displayunit(['(' num2str(fieldsize(1)) 'x' num2str(fieldsize(2)) ')']), 39 end 40 41 %logical 42 elseif islogical(field) 43 44 %get size 45 fieldsize=size(field); 46 47 %single value 48 if max(fieldsize)==1, 49 if (field) 50 str = displayunit('true'); 51 else 52 str = displayunit('false'); 53 end 54 %matrix 55 else 56 str = displayunit(name,['(' num2str(fieldsize(1)) 'x' num2str(fieldsize(2)) ')']); 57 end 58 59 %misc/ 60 else 61 str = displayunit(field); 62 63 end 64 65 end 66 67 function str = displayunit(characterization)% {{{ 68 69 %take care of characterization 70 if (strcmp(characterization,['''' '''']) || strcmp(characterization,'NaN')), 71 characterization='N/A'; 72 end 73 if length(characterization)>15, 74 characterization=[characterization(1:12) '...']; 75 end 76 77 str = characterization; 78 79 end% }}} 80 81 function str = cell_display(field) 82 83 %initialization 84 string='{'; 85 86 %go through the cell and fill string 87 if length(field)<5; 88 for i=1:length(field), 89 if ischar(field{i}), 90 string=[string '''' field{i} ''',']; 91 elseif (isnumeric(field{i}) & length(field{i})==1) 92 string=[string num2str(field{i}) ',' ]; 93 else 94 string='{'; 95 break 96 end 97 end 98 end 99 if strcmp(string,'{'), 100 string=['(' num2str(size(field,1)) 'x' num2str(size(field,2)) ')']; 101 else 102 string=[string(1:end-1) '}']; 103 end 104 str = string; 105 106 %disp(sprintf(string)); 107 end 108 109 function str = struct_display(field) % {{{ 110 111 if ~isempty(fields(field)) 112 displayunit('(structure)'), 113 114 structure_fields=fields(field); 115 116 for i=1:length(structure_fields), 117 118 %get current field 119 sfield=field.(structure_fields{i}); 120 121 %display value 122 %parsedisplay(sfield); 123 str = sfield; 124 end 125 126 else 127 %displayunit('N/A'), 128 str = 'N/A'; 129 end 130 end% }}}
Note:
See TracBrowser
for help on using the repository browser.