source: issm/oecreview/Archive/16554-17801/ISSM-17720-17721.diff@ 17802

Last change on this file since 17802 was 17802, checked in by Mathieu Morlighem, 11 years ago

Added archives

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