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