Fix load of SOD files (remove useless call)
[scilab.git] / scilab / modules / io / macros / %_sodload.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
3 // Copyright (C) 2012 - DIGITEO - Vincent COUVERT
4 //
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution.  The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10
11 function %_sodload(%__filename__, varargin)
12
13     function v = getScilabFileVersion(%__filename__)
14         verStr = h5readattr(%__filename__, "/", "SCILAB_scilab_version")
15         [a,b,c,d] = regexp(verStr, "/scilab-.*(\d)\.(\d)\.(\d)/");
16         if size(d, "*") == 3 then
17             v = evstr(d(1)) * 100 + evstr(d(2)) * 10 + evstr(d(3));
18         else
19             error("unable to find file version: %s", %__filename__);
20         end
21     endfunction
22
23     function [varValues] = %__convertVariable__(varValues, varNames)
24         for i = 1:size(varValues)
25             if typeof(varValues(i)) == "ScilabMatrixHandle" then
26                 //convert tlist to handle
27                 varValues(i) = createMatrixHandle(varValues(i));
28             elseif typeof(varValues(i)) == "ScilabMacro" then
29                 //convert tlist to macro
30                 varValues(i) = createMacro(varValues(i), varNames(i));
31             elseif isList(varValues(i)) then
32                 //list container
33                 varValues(i) = parseList(varValues(i));
34             end
35         end
36     endfunction
37
38     function result = isList(var)
39         //15 : list
40         //16 : tlist
41         //17 : mlist
42         if or(type(var) == [15, 16, 17]) then
43             result  = %t;
44         else
45             result = %f;
46         end
47     endfunction
48
49     function varValue = parseList(varValue)
50         if typeof(varValue)=="list" then
51             for i = definedfields(varValue)
52                 if typeof(varValue(i)) == "ScilabMatrixHandle" then
53                     varValue(i) = createMatrixHandle(varValue(i));
54                 elseif typeof(varValue(i)) == "ScilabMacro" then
55                     //convert tlist to macro
56                     varValue(i) = createMacro(varValue(i), "function");
57                 elseif isList(varValue(i)) then
58                     varValue(i) = parseList(varValue(i));
59                 else
60                     varValue(i) = varValue(i);
61                 end
62             end
63         else
64             fieldNb = size(getfield(1, varValue), "*");
65             for kField = 2:fieldNb // Do not inspect first field (field names)
66                 fieldValue = getfield(kField, varValue);
67                 if typeof(fieldValue) == "ScilabMatrixHandle" then
68                     fieldValue = createMatrixHandle(fieldValue);
69                 elseif typeof(fieldValue) == "ScilabMacro" then
70                     //convert tlist to macro
71                     fieldValue = createMacro(fieldValue, "function");
72                 elseif isList(fieldValue) then
73                     fieldValue = parseList(fieldValue);
74                 end
75                 setfield(kField, fieldValue, varValue);
76             end
77         end
78     endfunction
79
80     function h = createMatrixHandle(matrixHandle)
81         h = [];
82         if typeof(matrixHandle) <> "ScilabMatrixHandle" then
83             return;
84         end
85
86         for i = prod(matrixHandle.dims):-1:1
87
88             newItem = createSingleHandle(matrixHandle.values(i));
89             if newItem == [] then
90                 continue;
91             end
92
93             h($+1) = newItem;
94             if or(fieldnames(matrixHandle.values(i))=="user_data") then // TODO Remove after graphic branch merge
95                 if isList(matrixHandle.values(i).user_data) then
96                     set(h($), "user_data", parseList(matrixHandle.values(i).user_data));
97                 elseif typeof(matrixHandle.values(i).user_data) == "ScilabMatrixHandle" then
98                     set(h($), "user_data", createMatrixHandle(matrixHandle.values(i).user_data));
99                 end
100             end
101         end
102     endfunction
103
104     function h = createSingleHandle(item)
105         select item.type
106         case "Figure"
107             h = createFigure(item);
108         case "Axes"
109             h = createAxes(item);
110         case "Polyline"
111             h = createPolyline(item);
112         case "Plot3d"
113             h = createPlot3d(item);
114         case "Fac3d"
115             h = createFac3d(item);
116         case "Compound"
117             h = createCompound(item);
118         case "Rectangle"
119             h = createRectangle(item);
120         case "Arc"
121             h = createArc(item);
122         case "Champ"
123             h = createChamp(item);
124         case "Segs"
125             h = createSegs(item);
126         case "Grayplot"
127             h = createGrayplot(item);
128         case "Matplot"
129             h = createMatplot(item);
130         case "Fec"
131             h = createFec(item);
132         case "Legend"
133             h = createLegend(item);
134         case "Text"
135             h = createText(item);
136         case "Axis"
137             h = createAxis(item);
138         case "uimenu"
139             h = createuimenu(item);
140         case "uicontextmenu"
141             h = createuicontextmenu(item);
142         case "uicontrol"
143             h = createuicontrol(item);
144         case "Datatip"
145             h = createDatatip(item);
146         case "Light"
147             h = createLight(item);
148         else
149             error("handle of type " + item.type + " unhandled");
150             h = [];
151         end
152     endfunction
153
154     //
155     // FIGURE
156     //
157     function h = createFigure(figureProperties)
158         fields = fieldnames(figureProperties);
159         fields(1) = [];
160
161         h = gcf();
162         isVisible = h.visible;
163         resizefcn = "";
164         event_handler = "";
165         h.visible = "off";
166
167         fields(fields=="figure_id") = [];
168
169         h.figure_position=figureProperties.figure_position;
170         fields(fields=="figure_position") = [];
171         // set auto_resize first otherwise viewport modification may not have any effect.
172         h.auto_resize = figureProperties.auto_resize;
173         fields(fields=="auto_resize") = [];
174         h.figure_size = figureProperties.figure_size;
175         fields(fields=="figure_size") = [];
176         // set axes_size last because it's more important than figure_size
177         h.axes_size = figureProperties.axes_size;
178         fields(fields=="axes_size") = [];
179
180         for i = 1:size(fields, "*")
181             if fields(i) == "children" then
182                 c = figureProperties(fields(i));
183                 s = prod(c.dims);
184                 createSingleHandle(c.values(s));
185                 for  i = s-1:-1:1
186                     xsetech(wrect=[0 0 .1 .1])
187                     createSingleHandle(c.values(i));
188                 end
189             elseif fields(i) == "event_handler" then
190                 event_handler = figureProperties(fields(i));
191             elseif fields(i) == "resizefcn" then
192                 resizefcn = figureProperties(fields(i));
193             elseif fields(i) == "visible" then
194                 isVisible = figureProperties(fields(i));// do not set visible = "true" before the end of load.
195             else
196                 set(h, fields(i), figureProperties(fields(i)));
197             end
198         end
199
200         h.visible = isVisible;
201         h.resizefcn = resizefcn;
202         h.event_handler = event_handler;
203     endfunction
204
205     //
206     // LABEL
207     //
208     function h = createLabel(labelProperties, h)
209         fields = fieldnames(labelProperties);
210         fields(1) = [];
211         for i = 1:size(fields, "*")
212             set(h, fields(i), labelProperties(fields(i)));
213         end
214     endfunction
215
216     //
217     // TICKS
218     //
219     function h = createTicks(ticksProperties)
220         h = tlist(["ticks","locations","labels"], [], []);
221         fields = fieldnames(ticksProperties);
222         for i = 1:size(fields, "*")
223             h(fields(i)) = ticksProperties(fields(i));
224         end
225     endfunction
226
227     //
228     // AXES
229     //
230     function h = createAxes(axesProperties)
231         // Hack to determine whether %h_load has been called by the %h_copy macro
232         // in which case a new Axes object is created
233
234         [lnums, fnames] = where();
235         ind = grep(fnames, "%h_copy");
236         if ~isempty(ind) then
237             newaxes();
238         end;
239
240         h = gca();
241         fields = fieldnames(axesProperties);
242         fields(1) = [];
243
244         // Get log_flags to be sure to set them after data_bounds
245         log_flags = axesProperties.log_flags;
246         fields(fields=="log_flags") = [];
247
248         // Get mark_mode to be sure to set it after mark_style
249         mark_mode = axesProperties.mark_mode;
250         fields(fields=="mark_mode") = [];
251
252         // Get auto_ticks to be sure to set it after ticks labels
253         auto_ticks = axesProperties.auto_ticks;
254         fields(fields=="auto_ticks") = [];
255
256         for i = 1:size(fields, "*")
257             if or(fields(i) == ["title","x_label","y_label","z_label"]) then
258                 createLabel(axesProperties(fields(i)), h(fields(i)));
259             elseif or(fields(i) == ["x_ticks", "y_ticks", "z_ticks"]) then
260                 set(h, fields(i), createTicks(axesProperties(fields(i))));
261             elseif fields(i) == "children" then
262                 createMatrixHandle(axesProperties(fields(i)));
263             elseif fields(i) == "clip_state" then
264                 if axesProperties.clip_state=="on" then
265                     set(h,"clip_box",axesProperties.clip_box);
266                 end
267                 set(h,"clip_state", axesProperties.clip_state);
268             elseif fields(i) == "clip_box" then
269                 // managed with 'clip_state'
270             elseif fields(i) == "data_bounds" then
271                 set(h, "data_bounds", axesProperties.data_bounds);
272                 set(h, "log_flags", log_flags);
273             elseif fields(i) == "mark_style" then
274                 set(h, "mark_style", axesProperties.mark_style);
275                 set(h, "mark_mode", mark_mode);
276             else
277                 set(h, fields(i), axesProperties(fields(i)));;
278             end
279         end
280
281         set(h, "auto_ticks", auto_ticks);
282
283         // Legend management
284         global %LEG
285         if ~isempty(%LEG) then
286             // Get handles from paths
287             links=getlinksfrompath(h, %LEG.paths)
288             if ~isempty(links) then
289                 L = captions(links, %LEG.text)
290                 L.visible         = %LEG.visible
291                 L.font_style      = %LEG.font_style
292                 L.font_size       = %LEG.font_size
293                 L.font_color      = %LEG.font_color
294                 L.fractional_font = %LEG.fractional_font
295                 L.mark_mode       = "off";
296                 L.legend_location = %LEG.legend_location
297                 L.position        = %LEG.position
298                 L.line_mode       = %LEG.line_mode
299                 L.thickness       = %LEG.thickness
300                 L.foreground      = %LEG.foreground
301                 L.fill_mode       = %LEG.fill_mode
302                 L.background      = %LEG.background
303                 if %LEG.clip_state=="on" then
304                     L.clip_box      = %LEG.clip_box
305                 end
306                 L.clip_state      = %LEG.clip_state
307                 L.user_data       = %LEG.user_data
308             else
309                 warning(msprintf(_("%s: Legend does not fit with the current context. Skipped\n"), "load"));
310             end
311         end
312         clearglobal %LEG
313
314     endfunction
315
316     //
317     // POLYLINE
318     //
319     function h = createPolyline(polylineProperties)
320         fields = fieldnames(polylineProperties);
321         fields(1) = [];
322
323         xpoly(polylineProperties.data(:,1), polylineProperties.data(:,2))
324
325         h = gce();
326
327         if polylineProperties.clip_state=="on" then
328             set(h, "clip_box", polylineProperties.clip_box)
329         end
330         set(h, "clip_state", polylineProperties.clip_state);
331         fields(fields=="clip_box") = [];
332         fields(fields=="clip_state") = [];
333
334         if polylineProperties.interp_color_mode=="on" & ~isempty(polylineProperties.interp_color_vector) then
335             set(h, "interp_color_vector", polylineProperties.interp_color_vector);
336             set(h, "interp_color_mode", polylineProperties.interp_color_mode);
337         else
338             if ~isempty(polylineProperties.interp_color_vector) then
339                 h.interp_color_vector = polylineProperties.interp_color_vector;
340             end
341             h.interp_color_mode = polylineProperties.interp_color_mode;
342         end
343         fields(fields=="interp_color_vector") = [];
344         fields(fields=="interp_color_mode") = [];
345
346         // Get mark_mode to be sure to set it after mark_style
347         mark_mode = polylineProperties.mark_mode;
348         fields(fields=="mark_mode") = [];
349
350         global %POLYLINE
351         %POLYLINE = h
352
353         for i = 1:size(fields, "*")
354             if fields(i) == "mark_style" then
355                 set(h, "mark_style", polylineProperties.mark_style);
356                 set(h, "mark_mode", mark_mode);
357             elseif fields(i) == "children" then
358                 createMatrixHandle(polylineProperties(fields(i)));
359             else
360                 h(fields(i)) = polylineProperties(fields(i));
361             end
362         end
363
364         clearglobal %POLYLINE
365
366     endfunction
367
368     //
369     // PLOT3D
370     //
371     function h = createPlot3d(plot3dProperties)
372         h = createSurface(plot3dProperties);
373     endfunction
374
375     //
376     // FAC3D
377     //
378     function h = createFac3d(fac3dProperties)
379         h = createSurface(fac3dProperties);
380     endfunction
381
382     //
383     // SURFACE
384     //
385     function h = createSurface(surfaceProperties)
386         fields = fieldnames(surfaceProperties);
387         fields(1) = [];
388         // plot3d modify the axes properties
389         //  - Save it
390         // - Draw plot3d
391         // - Restore it
392         a=gca();
393         rotation_angles = a.rotation_angles;
394         axes_visible = a.axes_visible;
395         box = a.box;
396         margins = a.margins;
397         x_label_visible = a.x_label.visible;
398         y_label_visible = a.y_label.visible;
399         z_label_visible = a.z_label.visible;
400         x_label_text = a.x_label.text;
401         y_label_text = a.y_label.text;
402         z_label_text = a.z_label.text;
403         axes_isoview = a.isoview;
404
405         if (or(surfaceProperties.color_flag==[2 5]) & ~or(fields=="cdata_mapping")) | ..
406             ((surfaceProperties.color_flag>=2) & or(fields=="cdata_mapping")) then
407             plot3d1(surfaceProperties.data.x, surfaceProperties.data.y, list(surfaceProperties.data.z, surfaceProperties.data.color))
408         else
409             plot3d(surfaceProperties.data.x,surfaceProperties.data.y,surfaceProperties.data.z)
410         end
411         fields(fields=="data") = [];
412
413         // Restore this properties after plot3d.
414         a.rotation_angles = rotation_angles;
415         a.axes_visible = axes_visible;
416         a.box = box;
417         a.margins = margins;
418         a.x_label.visible = x_label_visible;
419         a.y_label.visible = y_label_visible;
420         a.z_label.visible = z_label_visible;
421         a.x_label.text = x_label_text;
422         a.y_label.text = y_label_text;
423         a.z_label.text = z_label_text;
424         a.isoview = axes_isoview;
425
426         // Get mark_mode to be sure to set it after mark_style
427         mark_mode = surfaceProperties.mark_mode;
428         fields(fields=="mark_mode") = [];
429
430         h=gce();
431
432         if or(fields=="cdata_mapping") then // Fac3d specific
433             if surfaceProperties.color_flag >= 2 then
434                 set(h, "cdata_mapping", surfaceProperties.cdata_mapping);
435             end
436             fields(fields=="cdata_mapping") = [];
437         end
438
439         if surfaceProperties.clip_state == "on" then
440             set(h,"clip_box", surfaceProperties.clip_box);
441         end
442         set(h,"clip_state",surfaceProperties.clip_state);
443         fields(fields=="clip_box") = [];
444         fields(fields=="clip_state") = [];
445
446         for i = 1:size(fields, "*")
447             if fields(i) == "mark_style" then
448                 set(h, "mark_style", surfaceProperties.mark_style);
449                 set(h, "mark_mode", mark_mode);
450             else
451                 h(fields(i)) = surfaceProperties(fields(i));
452             end
453         end
454     endfunction
455
456     //
457     // COMPOUND
458     //
459     function h = createCompound(compoundProperties)
460         fields = fieldnames(compoundProperties);
461         fields(1) = [];
462
463         h = glue(createMatrixHandle(compoundProperties.children));
464         fields(fields=="children") = [];
465
466         for i = 1:size(fields, "*")
467             set(h, fields(i), compoundProperties(fields(i)));
468         end
469     endfunction
470
471     //
472     // RECTANGLE
473     //
474     function h = createRectangle(rectangleProperties)
475         fields = fieldnames(rectangleProperties);
476         fields(1) = [];
477
478         xrect(0,1,1,1); // create the rectangle with dummy values
479         h = gce();
480
481         if rectangleProperties.clip_state == "on" then
482             set(h,"clip_box", rectangleProperties.clip_box);
483         end
484         set(h,"clip_state",rectangleProperties.clip_state);
485         fields(fields=="clip_box") = [];
486         fields(fields=="clip_state") = [];
487
488         // Get mark_mode to be sure to set it after mark_style
489         mark_mode = rectangleProperties.mark_mode;
490         fields(fields=="mark_mode") = [];
491
492         for i = 1:size(fields, "*")
493             if fields(i) == "mark_style" then
494                 set(h, "mark_style", rectangleProperties.mark_style);
495                 set(h, "mark_mode", mark_mode);
496             else
497                 h(fields(i)) = rectangleProperties(fields(i));
498             end
499         end
500     endfunction
501
502     //
503     // ARC
504     //
505     function h = createArc(arcProperties)
506         fields = fieldnames(arcProperties);
507         fields(1) = [];
508
509         xarc(0,1,1,1,0,360); // create the arc with dummy values
510         h = gce();
511
512         if arcProperties.clip_state == "on" then
513             set(h,"clip_box", arcProperties.clip_box);
514         end
515         set(h,"clip_state",arcProperties.clip_state);
516         fields(fields=="clip_box") = [];
517         fields(fields=="clip_state") = [];
518
519         for i = 1:size(fields, "*")
520             set(h, fields(i), arcProperties(fields(i)));
521         end
522     endfunction
523
524     //
525     // CHAMP
526     //
527     function h = createChamp(champProperties)
528         fields = fieldnames(champProperties);
529         fields(1) = [];
530
531         champ(champProperties.data.x, champProperties.data.y, champProperties.data.fx, champProperties.data.fy);
532         fields(fields=="data") = [];
533
534         h=gce();
535
536         if champProperties.clip_state == "on" then
537             set(h,"clip_box", champProperties.clip_box);
538         end
539         set(h,"clip_state",champProperties.clip_state);
540         fields(fields=="clip_box") = [];
541         fields(fields=="clip_state") = [];
542
543         for i = 1:size(fields, "*")
544             set(h, fields(i), champProperties(fields(i)));
545         end
546     endfunction
547
548     //
549     // SEG
550     //
551     function h = createSegs(segsProperties)
552         fields = fieldnames(segsProperties);
553         fields(1) = [];
554
555         xsegs(segsProperties.data(:,1), segsProperties.data(:,2))
556
557         h=gce()
558
559         if segsProperties.clip_state == "on" then
560             set(h,"clip_box", segsProperties.clip_box);
561         end
562         set(h,"clip_state",segsProperties.clip_state);
563         fields(fields=="clip_box") = [];
564         fields(fields=="clip_state") = [];
565
566         // Get mark_mode to be sure to set it after mark_style
567         mark_mode = segsProperties.mark_mode;
568         fields(fields=="mark_mode") = [];
569
570         for i = 1:size(fields, "*")
571             if fields(i) == "mark_style" then
572                 set(h, "mark_style", segsProperties.mark_style);
573                 set(h, "mark_mode", mark_mode);
574             else
575                 h(fields(i)) = segsProperties(fields(i));
576             end
577         end
578     endfunction
579
580     //
581     // GRAYPLOT
582     //
583     function h = createGrayplot(grayplotProperties)
584         fields = fieldnames(grayplotProperties);
585         fields(1) = [];
586
587         grayplot(grayplotProperties.data.x, grayplotProperties.data.y, grayplotProperties.data.z);
588         fields(fields=="data") = [];
589
590         h = gce();
591
592         if grayplotProperties.clip_state=="on" then
593             set(h, "clip_box", grayplotProperties.clip_box)
594         end
595         set(h, "clip_state", grayplotProperties.clip_state);
596         fields(fields=="clip_box") = [];
597         fields(fields=="clip_state") = [];
598
599         for i = 1:size(fields, "*")
600             set(h, fields(i), grayplotProperties(fields(i)));
601         end
602     endfunction
603
604     //
605     // MATPLOT
606     //
607     function h = createMatplot(matplotProperties)
608         fields = fieldnames(matplotProperties);
609         fields(1) = [];
610
611         Matplot(matplotProperties.data);
612         fields(fields=="data") = [];
613
614         h = gce();
615
616         if matplotProperties.clip_state=="on" then
617             set(h, "clip_box", matplotProperties.clip_box)
618         end
619         set(h, "clip_state", matplotProperties.clip_state);
620         fields(fields=="clip_box") = [];
621         fields(fields=="clip_state") = [];
622
623         for i = 1:size(fields, "*")
624             set(h, fields(i), matplotProperties(fields(i)));
625         end
626     endfunction
627
628     //
629     // FEC
630     //
631     function h = createFec(fecProperties)
632         fields = fieldnames(fecProperties);
633         fields(1) = [];
634
635         fec(fecProperties.data(:,1), fecProperties.data(:,2), fecProperties.triangles, fecProperties.data(:,3));
636         fields(fields=="data") = [];
637         fields(fields=="triangles") = [];
638
639         h = unglue(gce());
640
641         if fecProperties.clip_state=="on" then
642             set(h, "clip_box", fecProperties.clip_box)
643         end
644         set(h, "clip_state", fecProperties.clip_state);
645         fields(fields=="clip_box") = [];
646         fields(fields=="clip_state") = [];
647
648         for i = 1:size(fields, "*")
649             set(h, fields(i), fecProperties(fields(i)));
650         end
651     endfunction
652
653     //
654     // LEGEND
655     //
656     function h = createLegend(legendProperties)
657         global %LEG
658         %LEG = legendProperties;
659         h = [];
660     endfunction
661
662     //
663     // TEXT
664     //
665     function h = createText(textProperties)
666         fields = fieldnames(textProperties);
667         fields(1) = [];
668
669         if textProperties.text_box_mode == "off" then
670             xstring(textProperties.data(1), textProperties.data(2), textProperties.text)
671         else
672             xstringb(textProperties.data(1), textProperties.data(2), textProperties.text, textProperties.text_box(1), textProperties.text_box(2))
673         end
674
675         h = gce();
676
677         if textProperties.clip_state=="on" then
678             set(h, "clip_box", textProperties.clip_box)
679         end
680         set(h, "clip_state", textProperties.clip_state);
681         fields(fields=="clip_box") = [];
682         fields(fields=="clip_state") = [];
683
684         for i = 1:size(fields, "*")
685             set(h, fields(i), textProperties(fields(i)));
686         end
687     endfunction
688
689     //
690     // DATATIP
691     //
692     function h = createDatatip(datatipProperties)
693
694         fields = fieldnames(datatipProperties);
695         fields(1) = [];
696
697         h = datatipCreate(%POLYLINE, 0);
698
699         if datatipProperties.clip_state=="on" then
700             set(h, "clip_box", datatipProperties.clip_box)
701         end
702         set(h, "clip_state", datatipProperties.clip_state);
703         fields(fields=="clip_box") = [];
704         fields(fields=="clip_state") = [];
705
706         for i = 1:size(fields, "*")
707             set(h, fields(i), datatipProperties(fields(i)));
708         end
709     endfunction
710
711     //
712     // AXIS
713     //
714     function h = createAxis(axisProperties)
715         fields = fieldnames(axisProperties);
716         fields(1) = [];
717
718         if axisProperties.tics_direction == "bottom" then
719             axisdir="d";
720         elseif axisProperties.tics_direction == "top" then
721             axisdir="u";
722         elseif axisProperties.tics_direction == "left" then
723             axisdir="l";
724         elseif axisProperties.tics_direction == "right" then
725             axisdir="r";
726         elseif size(axisProperties.xtics_coord, "*") > 1 then
727             axisdir="u";
728         else
729             axisdir="l";
730         end
731         fields(fields=="tics_direction") = [];
732
733         drawaxis(x=axisProperties.xtics_coord,y=axisProperties.ytics_coord,dir=axisdir);
734         fields(fields=="xtics_coord") = [];
735         fields(fields=="ytics_coord") = [];
736
737         h=gce()
738
739         if axisProperties.clip_state=="on" then
740             set(h, "clip_box", axisProperties.clip_box)
741         end
742         set(h, "clip_state", axisProperties.clip_state);
743         fields(fields=="clip_box") = [];
744         fields(fields=="clip_state") = [];
745
746         for i = 1:size(fields, "*")
747             set(h, fields(i), axisProperties(fields(i)));
748         end
749     endfunction
750
751     //
752     // uimenu
753     //
754     function h = createuimenu(uimenuProperties)
755         fields = fieldnames(uimenuProperties);
756         fields(1) = [];
757
758         h = uimenu();
759
760         for i = 1:size(fields, "*")
761             if fields(i) == "children" then
762                 children = createMatrixHandle(uimenuProperties(fields(i)));
763                 for k=1:size(children, "*")
764                     set(children(k), "parent", h);
765                 end
766             else
767                 set(h, fields(i), uimenuProperties(fields(i)));
768             end
769         end
770     endfunction
771
772     //
773     // UICONTEXTMENU
774     //
775     function h = createuicontextmenu(uicontextmenuProperties)
776         fields = fieldnames(uicontextmenuProperties);
777         fields(1) = [];
778
779         h = uicontextmenu();
780
781         for i = 1:size(fields, "*")
782             if fields(i) == "children" then
783                 children = createMatrixHandle(uicontextmenuProperties(fields(i)));
784                 for k=1:size(children, "*")
785                     set(children(k), "parent", h);
786                 end
787             else
788                 set(h, fields(i), uicontextmenuProperties(fields(i)));
789             end
790         end
791     endfunction
792
793     //
794     // uicontrol
795     //
796     function h = createuicontrol(uicontrolProperties)
797         fields = fieldnames(uicontrolProperties);
798         fields(1) = [];
799
800         h = uicontrol("Style", uicontrolProperties.style);
801         fields(fields=="style") = [];
802
803         for i = 1:size(fields, "*")
804             if fields(i) == "children" then
805                 children = createMatrixHandle(uicontrolProperties(fields(i)));
806                 for k=1:size(children, "*")
807                     set(children(k), "parent", h);
808                 end
809             else
810                 set(h, fields(i), uicontrolProperties(fields(i)));
811             end
812         end
813     endfunction
814
815     //
816     // LIGHT
817     //
818     function h = createLight(lightProperties)
819         fields = fieldnames(lightProperties);
820         fields(1) = [];
821
822         h = light();
823         fields(fields=="children") = [];
824
825         for i = 1:size(fields, "*")
826             set(h, fields(i), lightProperties(fields(i)));
827         end
828     endfunction
829
830     // Utility function for legends, copy/paste from %h_load
831     function links=getlinksfrompath(ax,paths)
832         //  ax is a  handle on an axes entity
833         //  paths a list or row vector which gives the set of paths relative to
834         //  the axes
835         links=[];
836         ok=%t;
837         for p=paths
838             e=ax;
839             p(1)=p(1)-1// the caption does not exists yet
840             for kp=1:size(p,"*"),
841                 if or(e.type==["Axes","Compound"])&p(kp)<=size(e.children,"*") then
842                     e=e.children(p(kp)),
843                 else
844                     ok=%f
845                     break
846                 end
847             end
848             if ~ok then
849                 break
850             end
851             links=[links,e]
852         end
853         if ~ok then
854             links=[];
855         end
856     endfunction
857
858     function macro = createMacro(macroStr, macroName)
859
860         macroSt = macroStr(3);
861         if macroStr(2) == %t then
862             flag = "c";
863         else
864             flag = "n";
865         end
866         header = strsubst(macroSt(1), "function ", "");
867         body = macroSt(2:$-1);
868         if body == [] then
869             body = "";
870         end
871         deff(header, body, flag);
872         execstr("macro = " + macroName);
873     endfunction
874
875     [%__lhs__, %__rhs__] = argn();
876     %__resumeList__ = list();
877     %__resumeVarlist__ = [];
878     if %__rhs__ < 1 then
879         error(999, msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "load", 1));
880     end
881
882     if %__rhs__ >= 1 then
883         if typeof(%__filename__) <> "string" | size(%__filename__, "*") <> 1 then
884             error(999, msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "load", 1));
885         end
886     end
887
888     if isfile(%__filename__) & is_hdf5_file(%__filename__) then
889         %__loadFunction__ = import_from_hdf5;
890         //fileVersion = getScilabFileVersion(%__filename__); // Not needed for the moment
891     else
892         %__loadFunction__ = %_load;
893     end
894
895     //multiple output variables to prevent listinfile prints
896     [%__variableList__, %__varB__, %__varC__, %__varD__] = listvarinfile(%__filename__);
897     //
898     if size(varargin) <> 0 then
899         for i = 1:size(varargin)
900             %__variableName__ = varargin(i);
901             if typeof(%__variableName__) <> "string" | size(%__variableName__, "*") <> 1 then
902                 error(999, msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "load", i));
903             end
904
905             if or(%__variableList__ == %__variableName__) then
906                 %__loadFunction__(%__filename__, %__variableName__);
907                 %__resumeList__($+1) = evstr(%__variableName__);
908                 %__resumeVarlist__($+1) = %__variableName__;
909                 clear(%__variableName__);
910             else
911                 error(999, msprintf(gettext("%s: variable ''%s'' does not exist in ''%s''.\n"), "load", %__variableName__, %__filename__));
912             end
913         end
914     else
915         for i = 1:size(%__variableList__, "*")
916             %__variableName__ = %__variableList__(i);
917             %__loadFunction__(%__filename__, %__variableName__);
918             %__resumeList__($+1) = evstr(%__variableName__);
919             %__resumeVarlist__($+1) = %__variableName__;
920             clear(%__variableName__);
921         end
922     end
923
924     if isfile(%__filename__) & is_hdf5_file(%__filename__) then
925         %__resumeList__ = %__convertVariable__(%__resumeList__, %__resumeVarlist__);
926     end
927
928     execstr("[" + strcat(%__resumeVarlist__, ",") + "] = resume(%__resumeList__(:))");
929 endfunction