Update Matplot doc to take into account image_type property
[scilab.git] / scilab / modules / io / macros / %_save.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
3 //
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
9
10 //2012/08/06 transform macros to string to save it
11
12 //called by save function, transform handle in tlist and save result
13 function [] = %_save(%__filename__, varargin)
14
15     function result = isList(var)
16
17         //15 : list
18         //16 : tlist
19         //17 : mlist
20         if or(type(var) == [15, 16, 17]) then
21             result  = %t;
22         else
23             result = %f;
24         end
25     endfunction
26
27     function result = isMacro(var)
28         //11 : sci_u_function
29         if or(type(var) == [11]) then
30             result  = %t;
31         else
32             result = %f;
33         end
34     endfunction
35
36     function result = isCompiledMacro(var)
37         //11 : sci_c_function
38         if or(type(var) == [13]) then
39             result  = %t;
40         else
41             result = %f;
42         end
43     endfunction
44
45     function result = inspectList(l)
46         if typeof(l)=="list" then
47             result = list();
48             for %__i__ = definedfields(l)
49                 if typeof(l(%__i__)) == "handle" then
50                     if ~is_handle_valid(l(%__i__)) then
51                         oldMode = warning("query");
52                         warning("on");
53                         warning(msprintf(gettext("%s: handle no more valid ignored.\n"), "save"));
54                         warning(oldMode);
55                         result(%__i__) = [];
56                     else
57                         result(%__i__) = extractMatrixHandle(l(%__i__));
58                     end
59                 elseif isMacro(l(%__i__)) | isCompiledMacro(l(%__i__)) then
60                     //build an arbitrary name to the macro
61                     result(%__i__) = extractMacro(l(%__i__), "function");
62                 elseif isList(l(%__i__)) then
63                     result(%__i__) = inspectList(l(%__i__));
64                 elseif type(l(%__i__)) == 14 then //library, must not be save
65                     result(%__i__) = [];
66                 else
67                     result(%__i__) = l(%__i__);
68                 end
69             end
70         else
71             fieldNb = size(getfield(1, l), "*");
72             for kField = 2:fieldNb // Do not inspect first field (field names)
73                 fieldValue = getfield(kField, l);
74                 if typeof(fieldValue) == "handle" then
75                     fieldValue = extractMatrixHandle(fieldValue);
76                 elseif isMacro(fieldValue) | isCompiledMacro(fieldValue) then
77                     //build an arbitrary name to the macro
78                     fieldValue = extractMacro(fieldValue, "function");
79                 elseif isList(fieldValue) then
80                     fieldValue = inspectList(fieldValue);
81                 end
82                 setfield(kField, fieldValue, l);
83             end
84             result = l;
85         end
86     endfunction
87
88     function matrixHandle = extractMatrixHandle(h)
89
90         if typeof(h) <> "handle" then
91             matrixHandle = [];
92             return;
93         end
94
95         matrixHandle = tlist(["ScilabMatrixHandle", "dims", "values"]);
96         matrixHandle.dims = size(h);
97         matrixHandle.values = list();
98         for %__i__ = 1:size(h, "*")
99             matrixHandle.values($+1) = extractSingleHandle(h(%__i__));
100             if or(fieldnames(matrixHandle.values($))=="user_data") then
101                 if isList(matrixHandle.values($).user_data) then
102                     matrixHandle.values($).user_data = inspectList(matrixHandle.values($).user_data)
103                 elseif typeof(matrixHandle.values($).user_data) == "handle" then
104                     matrixHandle.values($).user_data = extractMatrixHandle(matrixHandle.values($).user_data)
105                 end
106             end
107         end
108     endfunction
109
110
111     function item = extractSingleHandle(h)
112
113         select h.type
114         case "Figure"
115             item = extractFigure(h);
116         case "Axes"
117             item = extractAxes(h);
118         case "Polyline"
119             item = extractPolyline(h);
120         case "Plot3d"
121             item = extractPlot3d(h);
122         case "Fac3d"
123             item = extractFac3d(h);
124         case "Compound"
125             item = extractCompound(h);
126         case "Rectangle"
127             item = extractRectangle(h);
128         case "Arc"
129             item = extractArc(h);
130         case "Champ"
131             item = extractChamp(h);
132         case "Segs"
133             item = extractSegs(h);
134         case "Grayplot"
135             item = extractGrayplot(h);
136         case "Matplot"
137             item = extractMatplot(h);
138         case "Fec"
139             item = extractFec(h);
140         case "Legend"
141             item = extractLegend(h);
142         case "Text"
143             item = extractText(h);
144         case "Axis"
145             item = extractAxis(h);
146         case "uimenu"
147             item = extractuimenu(h);
148         case "uicontextmenu"
149             item = extractuicontextmenu(h);
150         case "uicontrol"
151             item = extractuicontrol(h);
152         case "Light"
153             item = extractLight(h);
154         else
155             error("handle of type " + h.type + " unhandled");
156             item = [];
157         end
158     endfunction
159
160     //
161     // FIGURE
162     //
163     function returnedFigure = extractFigure(h)
164         returnedFigure = tlist([
165         "ScilabSingleHandle", ...
166         "type", ...
167         "visible", ...
168         "figure_position", ...
169         "figure_size", ...
170         "axes_size", ...
171         "viewport", ...
172         "info_message", ...
173         "tag", ...
174         "auto_resize", ...
175         "figure_name", ...
176         "figure_id", ...
177         "color_map", ...
178         "pixmap", ...
179         "pixel_drawing_mode", ...
180         "anti_aliasing", ...
181         "immediate_drawing", ...
182         "background", ...
183         "rotation_style", ...
184         "event_handler", ...
185         "event_handler_enable", ...
186         "resizefcn", ...
187         "closerequestfcn", ...
188         "children", ...
189         "user_data"]);
190
191         fields = fieldnames(returnedFigure);
192
193         for %__i__ = 1:size(fields, "*")
194             if fields(%__i__) == "children" then
195                 returnedFigure(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
196             else
197                 returnedFigure(fields(%__i__)) = h(fields(%__i__));
198             end
199         end
200     endfunction
201
202     //
203     // LABEL
204     //
205     function returnedLabel = extractLabel(h)
206         returnedLabel = tlist([
207         "ScilabSingleHandle", ...
208         "type", ...
209         "visible", ...
210         "text", ...
211         "font_foreground", ...
212         "foreground", ...
213         "background", ...
214         "fill_mode", ...
215         "font_style", ...
216         "font_size", ...
217         "fractional_font", ...
218         "font_angle", ...
219         "auto_rotation", ...
220         "position", ...
221         "auto_position"]);
222
223         fields = fieldnames(returnedLabel);
224
225         for %__i__ = 1:size(fields, "*")
226             returnedLabel(fields(%__i__)) = h(fields(%__i__));
227         end
228     endfunction
229
230     //
231     // TICKS
232     //
233     function returnedTicks = extractTicks(ticks)
234         returnedTicks = tlist([
235         "Ticks", ...
236         "locations", ...
237         "labels"]);
238
239         fields = fieldnames(returnedTicks);
240
241         for %__i__ = 1:size(fields, "*")
242             returnedTicks(fields(%__i__)) = ticks(fields(%__i__));
243         end
244     endfunction
245
246     //
247     // AXES
248     //
249     function returnedAxes = extractAxes(h)
250         returnedAxes = tlist([
251         "ScilabSingleHandle", ...
252         "type", ...
253         "visible", ...
254         "axes_visible", ...
255         "axes_reverse", ...
256         "grid", ...
257         "grid_position", ...
258         "x_location", ...
259         "y_location", ...
260         "view", ...
261         "title", ...
262         "x_label", ...
263         "y_label", ...
264         "z_label", ...
265         "auto_ticks", ...
266         "x_ticks", ...
267         "y_ticks", ...
268         "z_ticks", ...
269         "box", ...
270         "filled", ...
271         "sub_tics", ...
272         "font_style", ...
273         "font_size", ...
274         "font_color", ...
275         "fractional_font", ...
276         "isoview", ...
277         "cube_scaling", ...
278         "rotation_angles", ...
279         "log_flags", ...
280         "tight_limits", ...
281         "data_bounds", ...
282         "zoom_box", ...
283         "margins", ...
284         "axes_bounds", ...
285         "auto_clear", ...
286         "auto_scale", ...
287         "hidden_axis_color", ...
288         "arc_drawing_method", ...
289         "hiddencolor", ...
290         "line_mode", ...
291         "line_style", ...
292         "thickness", ...
293         "mark_mode", ...
294         "mark_style", ...
295         "mark_size", ...
296         "mark_size_unit", ...
297         "mark_foreground", ...
298         "mark_background", ...
299         "foreground", ...
300         "background", ...
301         "clip_state", ...
302         "clip_box", ...
303         "children", ...
304         "user_data"]);
305
306         fields = fieldnames(returnedAxes);
307
308         for %__i__ = 1:size(fields, "*")
309             if or(fields(%__i__) == ["title","x_label","y_label","z_label"]) then
310                 returnedAxes(fields(%__i__)) = extractLabel(h(fields(%__i__)));
311             elseif or(fields(%__i__) == ["x_ticks", "y_ticks", "z_ticks"]) then
312                 returnedAxes(fields(%__i__)) = extractTicks(h(fields(%__i__)));
313             elseif fields(%__i__) == "children" then
314                 returnedAxes(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
315             else
316                 returnedAxes(fields(%__i__)) = h(fields(%__i__));
317             end
318         end
319     endfunction
320
321     //
322     // POLYLINE
323     //
324     function returnedPolyline = extractPolyline(h)
325         returnedPolyline = tlist([
326         "ScilabSingleHandle", ...
327         "type", ...
328         "visible", ...
329         "data", ...
330         "closed", ...
331         "line_mode", ...
332         "fill_mode", ...
333         "line_style", ...
334         "thickness", ...
335         "arrow_size_factor", ...
336         "polyline_style", ...
337         "interp_color_vector", ...
338         "interp_color_mode", ...
339         "mark_mode", ...
340         "mark_style", ...
341         "mark_size", ...
342         "mark_size_unit", ...
343         "foreground", ...
344         "background", ...
345         "mark_foreground", ...
346         "mark_background", ...
347         "x_shift", ...
348         "y_shift", ...
349         "z_shift", ...
350         "bar_width", ...
351         "clip_state", ...
352         "clip_box", ...
353         "user_data"]);
354
355         fields = fieldnames(returnedPolyline);
356
357         for %__i__ = 1:size(fields, "*")
358             returnedPolyline(fields(%__i__)) = h(fields(%__i__));
359         end
360     endfunction
361
362     //
363     // PLOT3D
364     //
365     function returnedPlot3d = extractPlot3d(h)
366         returnedPlot3d = extractSurface(h);
367     endfunction
368
369     //
370     // FAC3D
371     //
372     function returnedFac3d = extractFac3d(h)
373         returnedFac3d = extractSurface(h);
374     endfunction
375
376     //
377     // SURFACE
378     //
379     function returnedSurface = extractSurface(h)
380         returnedSurface = tlist([
381         "ScilabSingleHandle", ...
382         "type", ...
383         "visible", ...
384         "surface_mode", ...
385         "foreground", ...
386         "thickness", ...
387         "mark_mode", ...
388         "mark_style", ...
389         "mark_size", ...
390         "mark_size_unit", ...
391         "mark_foreground", ...
392         "mark_background", ...
393         "color_mode", ...
394         "color_flag", ...
395         "data", ...
396         "color_flag", ...
397         "use_color_material", ...
398         "hiddencolor", ...
399         "clip_state", ...
400         "clip_box", ...
401         "user_data", ...
402         "cdata_mapping"]);
403
404         fields = fieldnames(returnedSurface);
405
406         for %__i__ = 1:size(fields, "*")
407             if fields(%__i__)=="cdata_mapping" then
408                 if h.type=="Fac3d" then
409                     returnedSurface(fields(%__i__)) = h(fields(%__i__));
410                 end
411             else
412                 returnedSurface(fields(%__i__)) = h(fields(%__i__));
413             end
414         end
415     endfunction
416
417     //
418     // COMPOUND
419     //
420     function returnedCompound = extractCompound(h)
421         returnedCompound = tlist([
422         "ScilabSingleHandle", ...
423         "type", ...
424         "visible", ...
425         "children", ...
426         "user_data"]);
427
428         fields = fieldnames(returnedCompound);
429
430         for %__i__ = 1:size(fields, "*")
431             if fields(%__i__) == "children" then
432                 returnedCompound(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
433             else
434                 returnedCompound(fields(%__i__)) = h(fields(%__i__));
435             end
436         end
437     endfunction
438
439     //
440     // RECTANGLE
441     //
442     function returnedRectangle = extractRectangle(h)
443         returnedRectangle = tlist([
444         "ScilabSingleHandle", ...
445         "type", ...
446         "visible", ...
447         "thickness", ...
448         "mark_mode", ...
449         "mark_style", ...
450         "mark_size", ...
451         "mark_size_unit", ...
452         "mark_foreground", ...
453         "mark_background", ...
454         "line_mode", ...
455         "line_style", ...
456         "fill_mode", ...
457         "foreground", ...
458         "background", ...
459         "data", ...
460         "clip_state", ...
461         "clip_box", ...
462         "user_data"]);
463
464         fields = fieldnames(returnedRectangle);
465
466         for %__i__ = 1:size(fields, "*")
467             returnedRectangle(fields(%__i__)) = h(fields(%__i__));
468         end
469     endfunction
470
471     //
472     // ARC
473     //
474     function returnedArc = extractArc(h)
475         returnedArc = tlist([
476         "ScilabSingleHandle", ...
477         "type", ...
478         "visible", ...
479         "thickness", ...
480         "line_style", ...
481         "line_mode", ...
482         "fill_mode", ...
483         "foreground", ...
484         "background", ...
485         "data", ...
486         "arc_drawing_method", ...
487         "clip_state", ...
488         "clip_box", ...
489         "user_data"]);
490
491         fields = fieldnames(returnedArc);
492
493         for %__i__ = 1:size(fields, "*")
494             returnedArc(fields(%__i__)) = h(fields(%__i__));
495         end
496     endfunction
497
498     //
499     // CHAMP
500     //
501     function returnedChamp = extractChamp(h)
502         returnedChamp = tlist([
503         "ScilabSingleHandle", ...
504         "type", ...
505         "visible", ...
506         "data", ...
507         "line_style", ...
508         "thickness", ...
509         "colored", ...
510         "arrow_size", ...
511         "clip_state", ...
512         "clip_box", ...
513         "user_data"]);
514
515         fields = fieldnames(returnedChamp);
516
517         for %__i__ = 1:size(fields, "*")
518             returnedChamp(fields(%__i__)) = h(fields(%__i__));
519         end
520     endfunction
521
522     //
523     // SEG
524     //
525     function returnedSeg = extractSegs(h)
526         returnedSeg = tlist([
527         "ScilabSingleHandle", ...
528         "type", ...
529         "visible", ...
530         "data", ...
531         "line_mode", ...
532         "line_style", ...
533         "thickness", ...
534         "segs_color", ...
535         "mark_mode", ...
536         "mark_style", ...
537         "mark_size", ...
538         "mark_size_unit", ...
539         "mark_foreground", ...
540         "mark_background", ...
541         "clip_state", ...
542         "clip_box", ...
543         "user_data"]);
544
545         fields = fieldnames(returnedSeg);
546
547         for %__i__ = 1:size(fields, "*")
548             returnedSeg(fields(%__i__)) = h(fields(%__i__));
549         end
550     endfunction
551
552     //
553     // GRAYPLOT
554     //
555     function returnedGrayplot = extractGrayplot(h)
556         returnedGrayplot = tlist([
557         "ScilabSingleHandle", ...
558         "type", ...
559         "visible", ...
560         "data", ...
561         "data_mapping", ...
562         "clip_state", ...
563         "clip_box", ...
564         "user_data"]);
565
566         fields = fieldnames(returnedGrayplot);
567
568         for %__i__ = 1:size(fields, "*")
569             returnedGrayplot(fields(%__i__)) = h(fields(%__i__));
570         end
571     endfunction
572
573     //
574     // MATPLOT
575     //
576     function returnedMatplot = extractMatplot(h)
577         returnedMatplot = tlist([
578         "ScilabSingleHandle", ...
579         "type", ...
580         "visible", ...
581         "data", ...
582         "image_type", ...
583         "clip_state", ...
584         "clip_box", ...
585         "user_data"]);
586
587         fields = fieldnames(returnedMatplot);
588
589         for %__i__ = 1:size(fields, "*")
590             returnedMatplot(fields(%__i__)) = h(fields(%__i__));
591         end
592     endfunction
593
594     //
595     // FEC
596     //
597     function returnedFec = extractFec(h)
598         returnedFec = tlist([
599         "ScilabSingleHandle", ...
600         "type", ...
601         "visible", ...
602         "data", ...
603         "triangles", ...
604         "z_bounds", ...
605         "color_range", ...
606         "outside_colors", ...
607         "line_mode", ...
608         "foreground", ...
609         "clip_state", ...
610         "clip_box", ...
611         "user_data"]);
612
613         fields = fieldnames(returnedFec);
614
615         for %__i__ = 1:size(fields, "*")
616             returnedFec(fields(%__i__)) = h(fields(%__i__));
617         end
618     endfunction
619
620     //
621     // LEGEND
622     //
623     function returnedLegend = extractLegend(h)
624         returnedLegend = tlist([
625         "ScilabSingleHandle", ...
626         "type", ...
627         "visible", ...
628         "text", ...
629         "font_style", ...
630         "font_size", ...
631         "font_color", ...
632         "fractional_font", ...
633         "links", ...
634         "legend_location", ...
635         "position", ...
636         "line_mode", ...
637         "thickness", ...
638         "foreground", ...
639         "fill_mode", ...
640         "background", ...
641         "clip_state", ...
642         "clip_box", ...
643         "user_data", ..
644         "paths"]);
645
646         fields = fieldnames(returnedLegend);
647
648         for %__i__ = 1:size(fields, "*")
649             if fields(%__i__) == "links" then
650                 returnedLegend(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
651             elseif fields(%__i__) == "paths" then
652                 p = list();
653                 for kl=1:size(h.links,"*");
654                     p($+1) = get_entity_path(h.links(kl));
655                 end
656                 returnedLegend(fields(%__i__)) = p;
657             else
658                 returnedLegend(fields(%__i__)) = h(fields(%__i__));
659             end
660         end
661     endfunction
662
663     //
664     // TEXT
665     //
666     function returnedText = extractText(h)
667         returnedText = tlist([
668         "ScilabSingleHandle", ...
669         "type", ...
670         "visible", ...
671         "text", ...
672         "data", ...
673         "text_box", ...
674         "text_box_mode", ...
675         "foreground", ...
676         "font_style", ...
677         "font_size", ...
678         "font_angle", ...
679         "box", ...
680         "line_mode", ...
681         "fill_mode", ...
682         "font_foreground", ...
683         "background", ...
684         "alignment", ...
685         "fractional_font", ...
686         "clip_state", ...
687         "clip_box", ...
688         "user_data"]);
689
690         fields = fieldnames(returnedText);
691
692         for %__i__ = 1:size(fields, "*")
693             returnedText(fields(%__i__)) = h(fields(%__i__));
694         end
695     endfunction
696
697     //
698     // AXIS
699     //
700     function returnedAxis = extractAxis(h)
701         returnedAxis = tlist([
702         "ScilabSingleHandle", ...
703         "type", ...
704         "visible", ...
705         "tics_direction", ...
706         "xtics_coord", ...
707         "ytics_coord", ...
708         "tics_color", ...
709         "tics_segment", ...
710         "tics_style", ...
711         "sub_tics", ...
712         "tics_labels", ...
713         "labels_font_size", ...
714         "labels_font_color", ...
715         "fractional_font", ...
716         "clip_state", ...
717         "clip_box", ...
718         "user_data"]);
719
720         fields = fieldnames(returnedAxis);
721
722         for %__i__ = 1:size(fields, "*")
723             returnedAxis(fields(%__i__)) = h(fields(%__i__));
724         end
725     endfunction
726
727     //
728     // uimenu
729     //
730     function returneduimenu = extractuimenu(h)
731         returneduimenu = tlist([
732         "ScilabSingleHandle", ...
733         "type", ...
734         "enable", ...
735         "foregroundcolor", ...
736         "label", ...
737         "visible", ...
738         "callback", ...
739         "callback_type", ...
740         "tag", ...
741         "checked", ...
742         "children", ..
743         "user_data"]);
744
745         fields = fieldnames(returneduimenu);
746
747         for %__i__ = 1:size(fields, "*")
748             if fields(%__i__) == "children" then
749                 returneduimenu(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
750             else
751                 returneduimenu(fields(%__i__)) = h(fields(%__i__));
752             end
753         end
754     endfunction
755
756     //
757     // UICONTEXTMENU
758     //
759     function returneduicontextmenu = extractuicontextmenu(h)
760         returneduicontextmenu = tlist([
761         "ScilabSingleHandle", ...
762         "type", ...
763         "children"]);
764
765         fields = fieldnames(returneduicontextmenu);
766
767         for %__i__ = 1:size(fields, "*")
768             if fields(%__i__) == "children" then
769                 returneduicontextmenu(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
770             else
771                 returneduicontextmenu(fields(%__i__)) = h(fields(%__i__));
772             end
773         end
774     endfunction
775
776     //
777     // uicontrol
778     //
779     function returneduicontrol = extractuicontrol(h)
780         returneduicontrol = tlist([
781         "ScilabSingleHandle", ...
782         "type", ...
783         "style", ...
784         "backgroundcolor", ...
785         "enable", ...
786         "fontangle", ...
787         "fontname", ...
788         "fontsize", ...
789         "fontunits", ...
790         "fontweight", ...
791         "foregroundcolor", ...
792         "horizontalalignment", ...
793         "listboxtop", ...
794         "max", ...
795         "min", ...
796         "position", ...
797         "relief", ...
798         "sliderstep", ...
799         "string", ...
800         "tooltipstring", ...
801         "units", ...
802         "value", ...
803         "verticalalignment", ...
804         "visible", ...
805         "callback", ...
806         "callback_type", ...
807         "user_data", ...
808         "tag", ...
809         "children"]);
810
811         fields = fieldnames(returneduicontrol);
812
813         for %__i__ = 1:size(fields, "*")
814             if fields(%__i__) == "children" then
815                 returneduicontrol(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
816             else
817                 returneduicontrol(fields(%__i__)) = h(fields(%__i__));
818             end
819         end
820     endfunction
821         
822     //
823     // LIGHT
824     //
825     function returnedLight = extractLight(h)
826         returnedLight = tlist([
827                 "ScilabSingleHandle", ...
828         "type", ...
829         "visible", ...
830         "light_type", ...
831         "position", ...
832         "direction", ...
833         "ambient_color", ...
834         "diffuse_color", ...
835         "specular_color"]);
836
837         fields = fieldnames(returnedLight);
838
839         for %__i__ = 1:size(fields, "*")
840             returnedLight(fields(%__i__)) = h(fields(%__i__));
841         end
842     endfunction
843
844     // Utility function for legends, copy/paste from %h_load
845     function p=get_entity_path(e)
846         // given a handle e on an entity this function returns its path relative
847         // to its parent axes.
848         // the path is a vector of child index.
849         p=[];
850         parent=e.parent;
851
852         while  %t
853             pos=find(parent.children==e,1)
854             if pos==[] then
855                 error(msprintf(_("%s : Invalid entity %s\n"),"save","Legend"))
856             end
857             p=[pos p]
858             if parent.type=="Axes" then
859                 break
860             end
861             e=parent
862             parent=e.parent;
863         end
864     endfunction
865
866     function macro = extractMacro(macroPtr, macroName)
867         macroSt = fun2string(macroPtr, macroName);
868         oldMode = warning("query");
869         warning("off");
870         macro = tlist("ScilabMacro", isCompiledMacro(macroPtr), macroSt);
871         warning(oldMode);
872     endfunction
873
874     //main
875
876     //save environment
877     if size(varargin) == 0 then
878         %__excludeList__ = [
879         "%_save"
880         "isList"
881         "isMacro"
882         "isCompiledMacro"
883         "inspectList"
884         "extractMatrixHandle"
885         "extractSingleHandle"
886         "extractFigure"
887         "extractLabel"
888         "extractTicks"
889         "extractAxes"
890         "extractPolyline"
891         "extractPlot3d"
892         "extractFac3d"
893         "extractSurface"
894         "extractCompound"
895         "extractRectangle"
896         "extractArc"
897         "extractChamp"
898         "extractSegs"
899         "extractGrayplot"
900         "extractMatplot"
901         "extractFec"
902         "extractLegend"
903         "extractText"
904         "extractAxis"
905         "extractuimenu"
906         "extractuicontextmenu"
907         "extractuicontrol"
908         "get_entity_path"
909         "extractMacro"
910         "%__excludeList__"
911         "%__filename__"
912         "varargin"
913         "%__varList__"];
914
915         //get all user variables
916         %__varList__ = who_user(%f);
917         //remove exclude variables/functions
918         %__grepResult__ = grep(%__varList__, %__excludeList__);
919         %__varList__(%__grepResult__) = [];
920         for %__i__ = 1:size(%__varList__, "*")
921             //store them as input arguments
922             varargin(%__i__) = %__varList__(%__i__);
923         end
924     end
925
926     oldMode = warning("query");
927     warning("off");
928
929     if size(varargin) == 0 then
930     end
931
932     for %__i__ = size(varargin):-1:1
933
934         if varargin(%__i__) == "-append" then
935             continue;
936         end
937
938         temp = evstr(varargin(%__i__));
939
940         if isList(temp) then
941             //list container
942             value = inspectList(temp);
943             //update
944             execstr(varargin(%__i__) + " = value");
945         elseif typeof(temp) == "handle" then
946             if ~is_handle_valid(temp) then // Invalid handle ignored
947                 warning(oldMode);
948                 warning(msprintf(gettext("%s: handle no more valid ignored.\n"), "save"));
949                 warning("off");
950                 varargin(%__i__) = null();
951             else //convert handle to tlist
952                 value = extractMatrixHandle(temp);
953                 //update
954                 execstr(varargin(%__i__) + " = value");
955             end
956         elseif isMacro(temp) | isCompiledMacro(temp) then
957             //convert macro to tlist
958             value = extractMacro(temp, varargin(%__i__));
959             //update
960             execstr(varargin(%__i__) + " = value");
961         elseif type(temp) == 14 then //library, must not be save
962             varargin(%__i__) = null();
963         end
964     end
965     warning(oldMode);
966
967     //if size(varargin) == 0, create an empty file
968     result = export_to_hdf5(%__filename__, varargin(:));
969
970 endfunction