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