Fix load/save after https://codereview.scilab.org/#/c/15681/.
[scilab.git] / scilab / modules / graphics / macros / %h_save.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2004 - INRIA - Serge Steer
3 // Copyright (C) 2004-2006 - INRIA - Fabrice Leray
4 // Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
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
12 function %h_save(h,fd)
13     version=[5 5 2 0]
14     mput(version,"uc",fd)
15
16     // There are issues when saving characters with 'c' format
17     // characterFormat format behave smoothly
18     characterFormat = "uc";
19     stringFormat = "il";
20
21     hsize = size(h);
22     mput(hsize,characterFormat,fd);
23     // introduced in version 3 1 0 2 to handle
24     // the case where we have a matrix of handles to save
25
26     if or(hsize>1)
27         for i=1:hsize(1)
28             for j=1:hsize(2)
29                 save_graphichandle(h(i,j),fd)
30             end
31         end
32     else
33         save_graphichandle(h,fd)
34     end
35 endfunction
36
37 function save_graphichandle(h,fd)
38     if ~is_handle_valid(h) then
39         warning(msprintf(gettext("%s: handle no more valid ignored.\n"),"save_graphichandle"));
40         return
41     end
42     typ=h.type
43     select h.type
44
45     case "Figure"
46         mput( length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
47         // handle => new style
48         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
49         mput(h.figure_position,"sl",fd) // figure_position
50         mput(h.figure_size,"sl",fd) // figure size
51         mput(h.axes_size,"sl",fd) // axes_size
52         mput(h.viewport,"sl",fd) // viewport
53         mput(length(ascii(h.info_message)),stringFormat,fd) ; // info_message
54         mput(ascii(h.info_message),characterFormat,fd) ;
55         mput(length(ascii(h.tag)),characterFormat,fd) ; // tag
56         mput(ascii(h.tag),characterFormat,fd) ;
57         mput(bool2s(h.auto_resize=="on"),characterFormat,fd) // auto_resize
58         mput(length(ascii(h.figure_name)),stringFormat,fd); // figure_name
59         mput(ascii(h.figure_name),characterFormat,fd);
60         mput(h.figure_id,"sl",fd); // figure_id
61
62         mput(size(h.color_map,"*"),"il",fd); // color_map
63         mput(h.color_map,"dl",fd) ;
64         mput(length(h.pixel_drawing_mode),characterFormat,fd); // pixel_drawing_mode
65         mput(ascii(h.pixel_drawing_mode),characterFormat,fd);
66         mput(length(h.anti_aliasing),characterFormat,fd); // anti_aliasing
67         mput(ascii(h.anti_aliasing),characterFormat,fd);
68         mput(bool2s(h.immediate_drawing=="on"),characterFormat,fd) // immediate_drawing
69         mput(h.background,"il",fd) // background
70         mput(length(h.rotation_style),characterFormat,fd); // rotation style
71         mput(ascii(h.rotation_style),characterFormat,fd);
72
73         mput(length(ascii(h.event_handler)),characterFormat,fd); // event_handler
74         mput(ascii(h.event_handler),characterFormat,fd);
75         mput(length(h.event_handler_enable),characterFormat,fd); // even_handler_enable
76         mput(ascii(h.event_handler_enable),characterFormat,fd); // need to be put after event_handler
77
78         mput(length(ascii(h.resizefcn)),characterFormat,fd) ; // resizefcn
79         mput(ascii(h.resizefcn),characterFormat,fd) ;
80         mput(length(ascii(h.closerequestfcn)),characterFormat,fd) ; // closerequestfcn
81         mput(ascii(h.closerequestfcn),characterFormat,fd) ;
82
83         // children
84         c=h.children;
85         n=size(c,"*")
86         mput(n,"il",fd)
87         for k=n:-1:1
88             save_graphichandle(c(k),fd)
89         end
90
91         user_data=h.user_data; // user_data
92         save(fd,user_data) ;
93
94
95     case "Axes"
96         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
97         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
98         mput(size(h.axes_visible,"*"),characterFormat,fd); // axes_visible
99         mput(bool2s(h.axes_visible=="on"),characterFormat,fd) ;
100         mput(size(h.axes_reverse,"*"),characterFormat,fd); // axes_reverse
101         mput(bool2s(h.axes_reverse=="on"),characterFormat,fd) ;
102         mput(size(h.grid,"*"),characterFormat,fd); mput(h.grid,"il",fd); // grid
103         mput(length(h.grid_position),characterFormat,fd); // grid_position
104         mput(ascii(h.grid_position),characterFormat,fd);
105         mput(length(h.x_location),characterFormat,fd); // x_location
106         mput(ascii(h.x_location),characterFormat,fd);
107         mput(length(h.y_location),characterFormat,fd); // y_location
108         mput(ascii(h.y_location),characterFormat,fd);
109         mput(ascii(h.view),characterFormat,fd) ; // view
110
111         // title
112         l=h.title;
113         mput(bool2s(l.visible=="on"),characterFormat,fd) ; // title.visible
114         save_text_matrix( l.text, fd ) ;
115         mput(l.font_foreground,"il",fd); // title_label.font_foreground
116         mput(bool2s(l.fractional_font=="on"),characterFormat,fd) // title.fractional_font
117         mput(l.foreground,"il",fd) // title.foreground
118         mput(l.background,"il",fd) // title.background
119         mput(bool2s(l.fill_mode=="on"),characterFormat,fd) // title.fill_mode
120         mput(l.font_style,characterFormat,fd) ; // title.font_style
121         mput(l.font_size,characterFormat,fd)  ; // title.font_size
122
123         mput(bool2s(l.auto_rotation=="on"),characterFormat,fd) // title.auto_rotation
124         mput(l.font_angle,"dl",fd) // title.font_angle
125         mput(bool2s(l.auto_position=="on"),characterFormat,fd) // title.auto_position
126         mput(l.position,"dl",fd) // title.position
127
128         // x_label
129         l=h.x_label
130         mput(bool2s(l.visible=="on"),characterFormat,fd) // x_label.visible
131         save_text_matrix( l.text, fd ) ;
132         mput(l.font_foreground,"il",fd); // x_label.font_foreground
133         mput(bool2s(l.fractional_font=="on"),characterFormat,fd) // x_label.fractional_font
134         mput(l.foreground,"il",fd) // x_label.foreground
135         mput(l.background,"il",fd) // x_label.background
136         mput(bool2s(l.fill_mode=="on"),characterFormat,fd) // x_label.fill_mode
137         mput(l.font_style,characterFormat,fd) // x_label.font_style
138         mput(l.font_size,characterFormat,fd)  // x_label.font_size
139
140         mput(bool2s(l.auto_rotation=="on"),characterFormat,fd) // x_label.auto_rotation
141         mput(l.font_angle,"dl",fd) // x_label.font_angle
142         mput(bool2s(l.auto_position=="on"),characterFormat,fd) // x_label.auto_position
143         mput(l.position,"dl",fd) // x_label.position
144
145         // y_label
146         l=h.y_label
147         mput(bool2s(l.visible=="on"),characterFormat,fd) // y_label.visible
148         save_text_matrix( l.text, fd ) ;
149         mput(l.font_foreground,"il",fd); // y_label.font_foreground
150         mput(bool2s(l.fractional_font=="on"),characterFormat,fd) // y_label.fractional_font
151         mput(l.foreground,"il",fd) // y_label.foreground
152         mput(l.background,"il",fd) // y_label.background
153         mput(bool2s(l.fill_mode=="on"),characterFormat,fd) // y_label.fill_mode
154         mput(l.font_style,characterFormat,fd) // y_label.font_style
155         mput(l.font_size,characterFormat,fd) // y_label.font_size
156
157         mput(bool2s(l.auto_rotation=="on"),characterFormat,fd) // y_label.auto_rotation
158         mput(l.font_angle,"dl",fd) // y_label.font_angle
159         mput(bool2s(l.auto_position=="on"),characterFormat,fd) // y_label.auto_position
160         mput(l.position,"dl",fd) // y_label.position
161
162         if h.view=="3d" then
163             // z_label
164             l=h.z_label
165             mput(bool2s(l.visible=="on"),characterFormat,fd) // z_label.visible
166             save_text_matrix( l.text, fd ) ;
167             mput(l.font_foreground,"il",fd); // z_label.font_foreground
168             mput(bool2s(l.fractional_font=="on"),characterFormat,fd) // z_label.fractional_font
169             mput(l.foreground,"il",fd) // z_label.foreground
170             mput(l.background,"il",fd) // z_label.background
171             mput(bool2s(l.fill_mode=="on"),characterFormat,fd) // z_label.fill_mode
172             mput(l.font_style,characterFormat,fd) // z_label.font_style
173             mput(l.font_size,characterFormat,fd) // z_label.font_size
174             mput(bool2s(l.auto_rotation=="on"),characterFormat,fd) // z_label.auto_rotation
175             mput(l.font_angle,"dl",fd) // z_label.font_angle
176             mput(bool2s(l.auto_position=="on"),characterFormat,fd) // z_label.auto_position
177             mput(l.position,"dl",fd) // z_label.position
178         end
179
180         mput(size(h.auto_ticks,"*"),characterFormat,fd); // auto_ticks
181         mput(bool2s(h.auto_ticks=="on"),characterFormat,fd)
182         // x_ticks
183         sz=size(h.x_ticks.locations,"*");
184         mput(sz,"sl",fd);
185         if sz>0 then
186             mput(h.x_ticks.locations,"dl",fd)
187             mput(length(h.x_ticks.labels),characterFormat,fd); // x_ticks.labels
188             mput(ascii(strcat(h.x_ticks.labels)),characterFormat,fd);
189         end
190         // y_ticks
191         sz=size(h.y_ticks.locations,"*");
192         mput(sz,"sl",fd);
193         if sz>0 then
194             mput(h.y_ticks.locations,"dl",fd)
195             mput(length(h.y_ticks.labels),characterFormat,fd); // y_ticks.labels
196             mput(ascii(strcat(h.y_ticks.labels)),characterFormat,fd);
197         end
198         // z_ticks
199         sz=size(h.z_ticks.locations,"*");
200         mput(sz,"sl",fd);
201         if sz>0 then
202             mput(h.z_ticks.locations,"dl",fd)
203             mput(length(h.z_ticks.labels),characterFormat,fd); // z_ticks.labels
204             mput(ascii(strcat(h.z_ticks.labels)),characterFormat,fd);
205         end
206         mput(length(h.box), characterFormat, fd ) ; // box
207         mput(ascii(h.box),  characterFormat, fd ) ;
208         mput(bool2s(h.filled == "on"),characterFormat,fd); // filled
209         mput(size(h.sub_tics,"*"),characterFormat,fd);mput(h.sub_tics,characterFormat,fd); // sub_ticks
210         //mput(-1,'il',fd) // tics_color is removed F.Leray 15.03.05
211         mput(h.font_style,characterFormat,fd) // font_style
212         mput(h.font_size,characterFormat,fd) //font_size
213         mput(h.font_color,"il",fd) // font_color
214         mput(bool2s(h.fractional_font=="on"),characterFormat,fd) // fractional_font
215         mput(bool2s(h.isoview=="on"),characterFormat,fd)    // isoview
216         mput(bool2s(h.cube_scaling=="on"),characterFormat,fd) // cube_scaling
217         mput(h.rotation_angles,"dl",fd) // rotation_angles
218         mput(ascii(h.log_flags),characterFormat,fd) // log_flags
219         mput(size(h.tight_limits,"*"),characterFormat,fd); // tight_limits
220         mput(bool2s(h.tight_limits=="on"),characterFormat,fd);
221         mput(size(h.data_bounds,"*"),characterFormat,fd); // data_bounds
222         mput(h.data_bounds,"dl",fd);
223         mput(size(h.zoom_box,"*"),characterFormat,fd);  // zoom_box
224         if size(h.zoom_box,"*")>0 then mput(h.zoom_box,"dl",fd);end
225         mput(h.margins,"dl",fd); // margins
226         mput(h.axes_bounds,"dl",fd); // axes_bounds
227         mput(bool2s(h.auto_clear=="on"),characterFormat,fd) // auto_clear
228         mput(bool2s(h.auto_scale=="on"),characterFormat,fd) // auto_scale
229         mput(h.hidden_axis_color,"il",fd); // hidden_axis_color
230         mput(length(h.arc_drawing_method),characterFormat,fd); // arc_drawing_method
231         mput(ascii(h.arc_drawing_method),characterFormat,fd);
232         mput(h.hiddencolor,"il",fd) // hidden_color
233         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
234         mput(h.line_style,characterFormat,fd) // line_style
235         mput(h.thickness,"sl",fd) // thickness
236         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
237         mput(h.mark_style,characterFormat,fd) // mark_style
238         mput(h.mark_size,characterFormat,fd) // mark_size
239         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
240         mput(h.mark_foreground,"il",fd) // mark_foreground
241         mput(h.mark_background,"il",fd) // mark_background
242
243         mput(h.foreground,"il",fd) // foreground
244         mput(h.background,"il",fd) // background
245
246         mput(length(h.clip_state),characterFormat,fd); // clip_state
247         mput(ascii(h.clip_state),characterFormat,fd);
248         if h.clip_state=="on" then
249             mput(h.clip_box,"dl",fd) // clip_box
250         end
251
252         // children
253         c=h.children;
254         n=size(c,"*")
255         mput(n,"il",fd)
256         for k=n:-1:1
257             save_graphichandle(c(k),fd)
258         end
259
260         user_data=h.user_data;save(fd,user_data) // user_data
261
262     case "Polyline"
263         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
264
265         mput(bool2s(h.visible=="on"),characterFormat,fd) ; // visible
266         mput(size(h.data),"il",fd);mput(h.data,"dl",fd) // data
267         mput(bool2s(h.closed=="on"),characterFormat,fd) // closed
268         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
269         mput(bool2s(h.fill_mode=="on"),characterFormat,fd) // fill_mode
270         mput(h.line_style,characterFormat,fd) // line_style
271         mput(h.thickness,"sl",fd) // thickness
272         mput(h.arrow_size_factor,"sl",fd) // arrow_size_factor
273         mput(max(1,h.polyline_style),characterFormat,fd) // ployline_style
274
275         mput( size( h.interp_color_vector, "*" ), "sl", fd ) ; // interp_color_vector
276         mput( h.interp_color_vector, "dl", fd ) ;
277         mput( bool2s(h.interp_color_mode=="on"), characterFormat, fd ) ; // interp_color_mode
278
279         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
280         mput(h.mark_style,characterFormat,fd) // mark_style
281         mput(h.mark_size,characterFormat,fd) // mark_size
282         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
283         mput(h.foreground,"il",fd) // foreground
284         mput(h.background,"il",fd) // background
285         mput(h.mark_foreground,"il",fd) // mark_foreground
286         mput(h.mark_background,"il",fd) // mark_background
287         mput(h.mark_offset,"il",fd) // mark_offset
288         mput(h.mark_stride,"il",fd) // mark_stride
289
290         mput(size(h.x_shift,"*"),"sl",fd); mput(h.x_shift,"dl",fd); // x_shift
291         mput(size(h.y_shift,"*"),"sl",fd); mput(h.y_shift,"dl",fd); // y_shift
292         mput(size(h.z_shift,"*"),"sl",fd); mput(h.z_shift,"dl",fd); // z_shift
293
294         mput( h.bar_width, "dl", fd ) ; // bar_width
295         mput(length(h.clip_state),characterFormat,fd); // clip_state
296         mput(ascii(h.clip_state),characterFormat,fd);
297         if h.clip_state=="on" then
298             mput(h.clip_box,"dl",fd) // clip_box
299         end
300         user_data=h.user_data;save(fd,user_data) // user_data
301
302     case "Datatip"
303         mput(length(h.type),characterFormat,fd); // type
304         mput(ascii(h.type),characterFormat,fd);
305         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
306         mput(size(h.data),characterFormat,fd); // data
307         mput(h.data,"dl",fd);
308         mput(length(h.box_mode),characterFormat,fd); // box_mode
309         mput(ascii(h.box_mode),characterFormat,fd);
310         mput(length(h.label_mode),characterFormat,fd); // label_mode
311         mput(ascii(h.label_mode),characterFormat,fd);
312         mput(h.orientation,characterFormat,fd) // orientation
313         mput(bool2s(h.z_component=="on"),characterFormat,fd) // z_component
314         mput(bool2s(h.auto_orientation=="on"),characterFormat,fd) // auto_orientation
315         mput(bool2s(h.interp_mode=="on"),characterFormat,fd) // interp_mode
316         mput(length(ascii(h.display_function)),stringFormat,fd); // display_function
317         mput(h.font_foreground, "il", fd) ; // font_foreground
318         mput(h.foreground,"il",fd) // foreground
319         mput(h.background, "il", fd) ; // background
320         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
321         mput(h.mark_style,characterFormat,fd) // mark_style
322         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
323         mput(h.mark_size,characterFormat,fd) // mark_size
324         mput(h.mark_foreground,"il",fd) // mark_foreground
325         mput(h.mark_background,"il",fd) // mark_background
326         user_data=h.user_data;save(fd,user_data) // user_data
327         mput(length(h.tag),"c",fd); // tag
328         mput(ascii(h.tag),"c",fd);
329
330     case "Plot3d";
331         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
332         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
333         mput(bool2s(h.surface_mode=="on"),characterFormat,fd) // surface_mode
334         mput(h.foreground,"il",fd) // foreground
335         mput(h.thickness,"sl",fd) // thickness
336         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
337         mput(h.mark_style,characterFormat,fd) // mark_style
338         mput(h.mark_size,characterFormat,fd) // mark_size
339         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
340         mput(h.mark_foreground,"il",fd) // mark_foreground
341         mput(h.mark_background,"il",fd) // mark_background
342         mput(h.color_mode,"il",fd) // color_mode
343         mput(h.color_flag,"il",fd) // color_flag
344         x=h.data.x;sz=size(x)
345         mput(sz,"il",fd) // data.x
346         mput(x,"dl",fd)
347         y=h.data.y;sz=size(y)
348         mput(sz,"il",fd) // data.y
349         mput(y,"dl",fd)
350         z=h.data.z;sz=size(z)
351         mput(sz,"il",fd) // data.z
352         mput(z,"dl",fd)
353         if or(h.color_flag==[2 5]) then
354             clr=h.data.color;sz=size(clr)
355             mput(sz,"il",fd) // data.color
356             mput(clr,"il",fd)
357         end
358         mput(h.hiddencolor,"il",fd) // hidden_color
359         mput(length(h.clip_state),characterFormat,fd); // clip_state
360         mput(ascii(h.clip_state),characterFormat,fd);
361         if h.clip_state=="on" then
362             mput(h.clip_box,"dl",fd) // clip_box
363         end
364         user_data=h.user_data;save(fd,user_data) // user_data
365
366     case "Fac3d";
367         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd) ; // type
368         mput(bool2s(h.visible=="on"),characterFormat,fd) ; // visible
369         mput(bool2s(h.surface_mode=="on"),characterFormat,fd) // surface_mode
370         mput(h.foreground,"il",fd) // foreground
371         mput(h.thickness,"sl",fd) // thickness
372         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
373         mput(h.mark_style,characterFormat,fd) // mark_style
374         mput(h.mark_size,characterFormat,fd) // mark_size
375         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
376         mput(h.mark_foreground,"il",fd) // mark_foreground
377         mput(h.mark_background,"il",fd) // mark_background
378         mput(h.color_mode,"il",fd) // color_mode
379         mput(h.color_flag,"il",fd) // color_flag
380         x=h.data.x;sz=size(x)
381         mput(sz,"il",fd) // data.x
382         mput(x,"dl",fd)
383         y=h.data.y;sz=size(y)
384         mput(sz,"il",fd) // data.y
385         mput(y,"dl",fd)
386         z=h.data.z;sz=size(z)
387         mput(sz,"il",fd) // data.z
388         mput(z,"dl",fd)
389         if h.color_flag >=2 then
390             clr=h.data.color;sz=size(clr) // data.color
391             mput(sz,"il",fd)
392             mput(clr,"il",fd)
393             mput(ascii(part(h.cdata_mapping,1)),characterFormat,fd) ; // cdata_mapping
394         end
395         mput(h.hiddencolor,"il",fd) // hidden_color
396         mput(length(h.clip_state),characterFormat,fd); // clip_state
397         mput(ascii(h.clip_state),characterFormat,fd);
398         if h.clip_state=="on" then
399             mput(h.clip_box,"dl",fd) // clip_box
400         end
401         user_data=h.user_data;save(fd,user_data) // user_data
402
403     case "Compound"
404         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
405
406         // children
407         children=h.children
408         n=size(children,"*")
409         mput(n,"il",fd)
410         for k=1:n
411             save_graphichandle(children(k),fd)
412         end
413         mput( bool2s( h.visible=="on"), characterFormat, fd ) ; // visible
414
415         user_data=h.user_data;save(fd,user_data) // user_data
416
417     case "Rectangle"
418         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
419         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
420         mput(h.thickness,"sl",fd) // thickness
421         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
422         mput(h.mark_style,characterFormat,fd) // mark_style
423         mput(h.mark_size,characterFormat,fd) // mark_size
424         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
425         mput(h.mark_foreground,"il",fd) // mark_foreground
426         mput(h.mark_background,"il",fd) // mark_background
427         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
428         mput(h.line_style,characterFormat,fd) // line_style
429         mput(bool2s(h.fill_mode=="on"),characterFormat,fd) // fill_mode
430         mput(h.foreground,"il",fd) // foreground
431         mput(h.background,"il",fd) // background
432         mput(size(h.data, "*"), "il", fd); // data
433         mput(h.data,"dl",fd);
434         mput(length(h.clip_state),characterFormat,fd); // clip_state
435         mput(ascii(h.clip_state),characterFormat,fd);
436         if h.clip_state=="on" then
437             mput(h.clip_box,"dl",fd) // clip_box
438         end
439
440         user_data=h.user_data;save(fd,user_data) ; // user_data
441
442     case "Arc"
443         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
444         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
445         mput(h.thickness,"sl",fd) // thickness
446         mput(h.line_style,characterFormat,fd) // line_style
447         mput(bool2s(h.line_mode=="on"),characterFormat,fd) ;// line_mode
448         mput(bool2s(h.fill_mode=="on"),characterFormat,fd) // fill_mode
449         mput(h.foreground,"il",fd) // foreground
450         mput(h.background,"il",fd) ; // background
451         mput(size(h.data, "*"), "il", fd); // data
452         mput(h.data,"dl",fd);
453         mput(length(h.arc_drawing_method),characterFormat,fd); // arc_drawing_method
454         mput(ascii(h.arc_drawing_method),characterFormat,fd);
455         mput(length(h.clip_state),characterFormat,fd); // clip_state
456         mput(ascii(h.clip_state),characterFormat,fd);
457         if h.clip_state=="on" then
458             mput(h.clip_box,"dl",fd) // clip_box
459         end
460         user_data=h.user_data;save(fd,user_data) // user_data
461
462     case "Champ"
463         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
464         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
465         x=h.data.x;sz=size(x)
466         mput(sz,"il",fd) // data.x
467         mput(x,"dl",fd)
468         y=h.data.y;sz=size(y)
469         mput(sz,"il",fd) // data.y
470         mput(y,"dl",fd)
471         fx=h.data.fx;sz=size(fx)
472         mput(sz,"il",fd) // data.fx
473         mput(fx,"dl",fd)
474         fy=h.data.fy;sz=size(fy)
475         mput(sz,"il",fd) // data.fz
476         mput(fy,"dl",fd)
477         mput(h.line_style,characterFormat,fd) // line_style
478         mput(h.thickness,"sl",fd) // thickness
479         mput(bool2s(h.colored=="on"),characterFormat,fd) // colored
480         mput(h.arrow_size,"dl",fd) // arrow_size
481         mput(length(h.clip_state),characterFormat,fd); // clip_state
482         mput(ascii(h.clip_state),characterFormat,fd);
483         if h.clip_state=="on" then
484             mput(h.clip_box,"dl",fd) // clip_box
485         end
486         user_data=h.user_data;save(fd,user_data) // user_data
487
488     case "Segs"
489         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
490         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
491         mput(size(h.data),"il",fd);mput(h.data,"dl",fd) // data
492         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
493         mput(h.line_style,characterFormat,fd) // line_style
494         mput(h.thickness,"sl",fd) // thickness
495         mput(h.arrow_size,"dl",fd) // arrow_size
496         mput(size(h.segs_color,"*"),"il",fd); // segs_color
497         mput(h.segs_color,"il",fd)
498         mput(bool2s(h.mark_mode=="on"),characterFormat,fd) // mark_mode
499         mput(h.mark_style,characterFormat,fd) // mark_style
500         mput(h.mark_size,characterFormat,fd) // mark_size
501         mput(ascii(part(h.mark_size_unit,1)),characterFormat,fd) // mark_size_unit
502         mput(h.mark_foreground,"il",fd) // mark_foreground
503         mput(h.mark_background,"il",fd) // mark_background
504         mput(length(h.clip_state),characterFormat,fd); // clip_state
505         mput(ascii(h.clip_state),characterFormat,fd); // clip_state
506         if h.clip_state=="on" then
507             mput(h.clip_box,"dl",fd) // clip_box
508         end
509         user_data=h.user_data;save(fd,user_data) // user_data
510
511     case "Grayplot"
512         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
513         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
514         x=h.data.x;sz=size(x)
515         mput(sz,"il",fd) // data.x
516         mput(x,"dl",fd)
517         y=h.data.y;sz=size(y)
518         mput(sz,"il",fd) // data.y
519         mput(y,"dl",fd)
520         z=h.data.z;sz=size(z)
521         mput(sz,"il",fd) // data.z
522         mput(z,"dl",fd)
523         mput(length(h.data_mapping),characterFormat,fd); // data_mapping
524         mput(ascii(h.data_mapping),characterFormat,fd);
525         mput(length(h.clip_state),characterFormat,fd); // clip_state
526         mput(ascii(h.clip_state),characterFormat,fd);
527         if h.clip_state=="on" then
528             mput(h.clip_box,"dl",fd) // clip_box
529         end
530         user_data=h.user_data;save(fd,user_data) // user_data
531
532     case "Matplot"
533         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
534         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
535         mput(size(h.data),"il",fd);mput(h.data,"dl",fd) // datat
536         //    mput(length(h.data_mapping),characterFormat,fd);mput(ascii(h.data_mapping),characterFormat,fd);
537         mput(length(h.clip_state),characterFormat,fd); // clip_state
538         mput(ascii(h.clip_state),characterFormat,fd);
539         if h.clip_state=="on" then
540             mput(h.clip_box,"dl",fd) // clip_box
541         end
542         user_data=h.user_data;save(fd,user_data) // user_data
543
544     case "Fec"
545         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
546         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
547         mput(size(h.data),"il",fd);mput(h.data,"dl",fd) // data
548         mput(size(h.triangles),"il",fd);mput(h.triangles,"dl",fd) // triangles
549         mput(h.z_bounds,"dl",fd); // z_bounds
550         mput(h.color_range,"dl",fd); // color_range
551         mput(h.outside_colors,"dl",fd); // outside_colors
552         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
553         mput(h.foreground,"il",fd) // foreground
554         mput(length(h.clip_state),characterFormat,fd); // clip_state
555         mput(ascii(h.clip_state),characterFormat,fd);
556         if h.clip_state=="on" then
557             mput(h.clip_box,"dl",fd) // clip_box
558         end
559         user_data=h.user_data;save(fd,user_data) // user_data
560
561     case "Legend"
562         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); //type
563         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
564         save_text_vector(h.text,fd); // text
565         mput(h.font_style,characterFormat,fd) // font_style
566         mput(h.font_size,characterFormat,fd) // font_size
567         mput(h.font_color,"il",fd) // font_color
568         mput(bool2s(h.fractional_font=="on"),characterFormat,fd) // fractional_font
569         //replace links by a path relative to the parent axes
570         links=h.links;nlegends=size(links,"*");
571         mput(nlegends,characterFormat,fd)
572         for kl=1:nlegends
573             p=get_entity_path(links(kl))
574             mput(size(p,"*"),"il",fd)
575             mput(p,"il",fd)
576         end
577         mput(length(h.legend_location),characterFormat,fd);mput(ascii(h.legend_location),characterFormat,fd); //legend_location
578         mput(h.position,"dl",fd);
579         mput(bool2s(h.line_mode=="on"),characterFormat,fd) // line_mode
580         mput(h.thickness,"sl",fd) // thickness
581         mput(h.foreground,"il",fd) // foreground
582         mput(bool2s(h.fill_mode=="on"),characterFormat,fd) // fill_mode
583         mput(h.background,"il",fd) ; // background
584
585         mput(length(h.clip_state),characterFormat,fd); // clip_state
586         mput(ascii(h.clip_state),characterFormat,fd);
587         if h.clip_state=="on" then
588             mput(h.clip_box,"dl",fd) // clip_box
589         end
590         user_data=h.user_data;save(fd,user_data) // user_data
591
592     case "Text"
593         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
594         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
595         //save_text_vector(h.text,fd) // text
596         save_text_matrix( h.text, fd ) ;
597         mput(size(h.data),characterFormat,fd); // data // size could be 2 or 3
598         mput(h.data,"dl",fd);
599         mput(h.text_box,"dl",fd); // text_box
600         mput(length(h.text_box_mode),characterFormat,fd);
601         mput(ascii(h.text_box_mode),characterFormat,fd); // text_box_mode
602
603         mput(h.foreground,"il",fd) // foreground
604         mput(h.font_style,characterFormat,fd) // font_style
605         mput(h.font_size,characterFormat,fd) // font_size
606         mput(h.font_angle,"dl",fd) // font_angle
607
608         //adding JB Silvy 28/11/05
609         // box drawing
610         mput( bool2s( h.box       == "on" ), characterFormat, fd ) ; // box
611         mput( bool2s( h.line_mode == "on" ), characterFormat, fd ) ; // line_mode
612         mput( bool2s( h.fill_mode == "on" ), characterFormat, fd ) ; // fill_mode
613
614         mput( h.font_foreground, "il", fd ) ; // font_foreground
615         mput( h.background     , "il", fd ) ; // background
616
617         mput(length(h.alignment),characterFormat,fd);
618         mput(ascii(h.alignment),characterFormat,fd) ; // alignment
619         mput(bool2s(h.fractional_font=="on"),characterFormat,fd) // fractional_font
620
621         mput(length(h.clip_state),characterFormat,fd); // clip_state
622         mput(ascii(h.clip_state),characterFormat,fd);
623         if h.clip_state=="on" then
624             mput(h.clip_box,"dl",fd) // clip_box
625         end
626         user_data=h.user_data;save(fd,user_data) // user_data
627
628     case "Axis"
629         mput(length(h.type),characterFormat,fd);mput(ascii(h.type),characterFormat,fd); // type
630         mput(bool2s(h.visible=="on"),characterFormat,fd) // visible
631         mput(length(h.tics_direction),"il",fd); // ticks_direction
632         mput(ascii(h.tics_direction),characterFormat,fd);
633         mput(size(h.xtics_coord,"*"),"il",fd); // xtics_coord
634         mput(h.xtics_coord,"dl",fd)
635         mput(size(h.ytics_coord,"*"),"il",fd); // ytics_coord
636         mput(h.ytics_coord,"dl",fd)
637         mput(h.tics_color,"il",fd) // tics_color
638         mput(bool2s(h.tics_segment=="on"),characterFormat,fd) // tics_segment
639         mput(ascii(h.tics_style),characterFormat,fd) // tics_style
640         mput(h.sub_tics,"il",fd) // sub_tics
641         save_text_vector(h.tics_labels,fd) // tics_labels
642         mput(h.labels_font_size,"il",fd) // label_font_size
643         mput(h.labels_font_color,"il",fd) // labels_font_color
644         mput(h.labels_font_style,"il",fd) // labels_font_style
645         mput(bool2s(h.fractional_font=="on"),characterFormat,fd) // fractional_font
646         mput(length(h.clip_state),characterFormat,fd); // clip_state
647         mput(ascii(h.clip_state),characterFormat,fd);
648         if h.clip_state=="on" then
649             mput(h.clip_box,"dl",fd) // clip_box
650         end
651         user_data=h.user_data;save(fd,user_data) // user_data
652
653     case "uimenu"
654         mput(length(h.type),"c",fd);mput(ascii(h.type),"c",fd); // Type
655         mput(bool2s(h.enable=="on"),"c",fd); // Enable
656         mput(size(h.foregroundcolor,"*"),"il",fd); // ForegroundColor (size)
657         mput(h.foregroundcolor,"dl",fd); // ForegroundColor (data)
658         mput(length(h.label),"c",fd);mput(ascii(h.label),"c",fd); // Label
659         mput(bool2s(h.visible=="on"),"c",fd); // Visible
660         mput(length(h.callback),stringFormat,fd);mput(ascii(h.callback),"c",fd); // Callback
661         mput(h.callback_type,"il",fd); // Callback Type
662         mput(length(h.tag),"c",fd);mput(ascii(h.tag),"c",fd); // Tag
663         mput(bool2s(h.checked=="on"),"c",fd); // Checked
664         // children
665         c=h.children;
666         n=size(c,"*")
667         mput(n,"il",fd)
668         for k=n:-1:1
669             save_graphichandle(c(k),fd)
670         end
671
672     case "uicontextmenu"
673         mput(length(h.type),"c",fd);mput(ascii(h.type),"c",fd); // Type
674         // children
675         c=h.children;
676         n=size(c,"*")
677         mput(n,"il",fd)
678         for k=n:-1:1
679             save_graphichandle(c(k),fd)
680         end
681
682     case "uicontrol"
683         mput(length(h.type),"c",fd);mput(ascii(h.type),"c",fd); // Type
684         mput(length(h.style),"c",fd);mput(ascii(h.style),"c",fd); // Style
685         mput(size(h.backgroundcolor,"*"),"il",fd); // BackgroundColor (size)
686         mput(h.backgroundcolor,"dl",fd); // BackgroundColor (data)
687         mput(bool2s(h.enable=="on"),"c",fd); // Enable
688         mput(length(h.fontangle),"c",fd);mput(ascii(h.fontangle),"c",fd); // FontAngle
689         mput(length(h.fontname),"c",fd);mput(ascii(h.fontname),"c",fd); // FontName
690         mput(h.fontsize,"dl",fd); // FontSize
691         mput(length(h.fontunits),"c",fd);mput(ascii(h.fontunits),"c",fd); // FontUnits
692         mput(length(h.fontweight),"c",fd);mput(ascii(h.fontweight),"c",fd); // FontWeight
693         mput(size(h.foregroundcolor,"*"),"il",fd); // ForegroundColor (size)
694         mput(h.foregroundcolor,"dl",fd); // ForegroundColor (data)
695         mput(length(h.horizontalalignment),"c",fd);mput(ascii(h.horizontalalignment),"c",fd); // HorizontalAlignment
696         mput(size(h.listboxtop,"*"),"il",fd); // ListboxTop (size)
697         mput(h.listboxtop,"dl",fd); // ListboxTop (data)
698         mput(h.max,"dl",fd); // Max
699         mput(h.min,"dl",fd); // Min
700         mput(size(h.position,"*"),"il",fd); // Position (size)
701         mput(h.position,"dl",fd); // Position (data)
702         mput(length(h.relief),"c",fd);mput(ascii(h.relief),"c",fd); // Relief
703         mput(size(h.sliderstep,"*"),"il",fd); // SliderStep (size)
704         mput(h.sliderstep,"dl",fd); // SliderStep (data)
705         save_text_matrix( h.string, fd ) ; // String
706         save_text_matrix( h.tooltipstring, fd ) ; // TooltipString
707         mput(length(h.units),"c",fd);mput(ascii(h.units),"c",fd); // Units
708         mput(size(h.value,"*"),"il",fd); // Value (size)
709         mput(h.value,"dl",fd); // Value (data)
710         mput(length(h.verticalalignment),"c",fd);mput(ascii(h.verticalalignment),"c",fd); // VerticalAlignment
711         mput(bool2s(h.visible=="on"),"c",fd); // Visible
712         mput(length(h.callback),stringFormat,fd);mput(ascii(h.callback),"c",fd); // Callback
713         mput(h.callback_type,"il",fd); // Callback Type
714         user_data=h.user_data;save(fd,user_data); // Userdata
715         mput(length(h.tag),"c",fd);mput(ascii(h.tag),"c",fd); // Tag
716
717     else
718         warning("handle of type "+h.type+" unhandled")
719     end
720
721 endfunction
722
723 function save_text_vector(t,fd)
724     t=ascii(strcat(t,ascii(10)));
725     mput(length(t),"il",fd);mput(t,characterFormat,fd);
726 endfunction
727
728 // save a text matrix
729 function save_text_matrix(strMat,fd)
730     // put nbRow and nbCol
731     nbRow = size( strMat, 1 ) ;
732     nbCol = size( strMat, 2 ) ;
733     mput( nbRow, "il", fd ) ;
734     mput( nbCol, "il", fd ) ;
735     for i = 1:nbRow
736         for j = 1:nbCol
737             mput(length(ascii(strMat(i,j))), stringFormat, fd) ;
738             mput(ascii(strMat(i,j)),characterFormat,fd) ;
739         end
740     end
741 endfunction
742
743 function p=get_entity_path(e)
744     // given a handle e on an entity this function returns its path relative
745     // to its parent axes.
746     // the path is a vector of child index.
747     p=[];parent=e.parent;
748
749     while  %t
750         pos=find(parent.children==e,1)
751         if pos==[] then
752             error(msprintf(_("%s : Invalid entity %s\n"),"save","Legend"))
753         end
754         p=[pos p]
755         if parent.type=="Axes" then break,end
756         e=parent
757         parent=e.parent;
758     end
759 endfunction