bug 11411: save function used unsigned char to store length of string, now it is...
[scilab.git] / scilab / modules / fileio / macros / %_listvarinfile.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2001  - INRIA - Serge Steer
3 // Copyright (C) Enrico Segre
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 // set of functions for getting information about variables saved in a Scilab 
12 //  data file
13
14 function varargout=%_listvarinfile(fil)
15   lhs=argn(1)
16   u=mopen(fil,"rb")
17   typenames=[  // in vector form, in order to cover the first 17
18       "constant";
19       "polynomial";
20       "???"
21       "boolean";
22       "sparse";
23       "boolean sparse";
24       "Matlab sparse";
25       "integer"
26       "graphic handle"; //not yet done
27       "string";
28       "function";
29       "???"
30       "function";
31       "library";
32       "list"
33       "tlist"
34       "mlist"]
35
36
37   nams=[]
38   dims=list()
39   typs=[];vols=[]
40   
41   if lhs==1 then
42   //write the display header
43     write(%io(2),part("Name",1:25)+ part("Type",1:15)+part("Size",1:16)+..
44              part("Bytes",1:10))
45     write(%io(2),"---------------------------------------------------------------")
46   end
47   
48   while %t
49     w=mget(6,"il",u)
50     if size(w,"*")<6|meof(u)<>0 then break,end
51     nam=code2var(w);
52
53     [typ,dim,vol]=listnextvar(u)
54     if typ<=17 then
55       typn=typenames(typ)
56     elseif typ==128 then
57       typn="pointer";
58     elseif typ==129 then
59       typn="size implicit";
60     elseif typ==130 then
61       typn="primitive";
62     else
63        error(msprintf(gettext("%s: Wrong variable type (%s) found in ''%s''. File may be wrong or corrupted.\n"), "listvarinfile", string(typ), fil))
64     end
65
66     if lhs==1 then
67       if typ <>128 & typ <> 130 then
68         write(%io(2),part(nam,1:25)+part(typn,1:15)+..
69            part(strcat(string(dim)," by "),1:16)+part(string(vol),1:10))
70       else //types 9, 128 and 130 are known in scilab, but their API is unpublished
71         write(%io(2),part(nam,1:25)+part(typn,1:15)+"unknown         unknown")
72         warning(".... unknown structure, I''m forced to stop here (bug 2387)")
73       end
74     end
75     typs=[typs;typ]
76     dims($+1)=dim
77     nams=[nams;nam]
78     vols=[vols;vol]
79     if dim==-1 | vol==-1 then break; end // this for types with unknown API
80   end
81   mclose(u)
82   
83   varargout=list(nams,typs,dims,vols)
84 endfunction
85
86 /////////////////////////////////////////////////
87
88 function [typ,dim,vol]=listnextvar(u)
89   typ=mget(1,"il",u) //The variable type
90   dim=-1;vol=-1; //flags to break the caller loop in unknown cases
91   select typ
92   case 1 then //matrix of numbers
93     w=mget(3,"il",u) //header of the variable 
94     m=w(1);n=w(2);it=w(3);dim=[m,n]
95     N=m*n*(it+1)
96     mseek(8*N,u,"cur") //skip the values
97     //A=mget(N,"dl",u)
98     vol=4*4+8*N
99   case 2 then //polynomial
100     w=mget(3,"il",u) //header of the variable 
101     m=w(1);n=w(2);it=w(3);dim=[m,n]
102     mseek(4*4,u,"cur") //skeep the formal variable name
103     w=mget(m*n+1,"il",u) //get the pointer table
104     //I=mget(m*n+1,"il",u)
105     N=(w(m*n+1)-1)*(it+1)
106     mseek(8*N,u,"cur") //skip the values
107     //A=mget(N,"dl",u)
108     vol=(4+4+(m*n+1))*4+8*N
109   case 4 then //boolean
110     w=mget(2,"il",u) //header of the variable 
111     m=w(1);n=w(2);dim=[m,n]
112     N=m*n
113     mseek(4*N,u,"cur") // skip the values
114     //A=mget(N,"il",u)
115     vol=(4+N)*4
116   case 5 then //sparse
117     w=mget(4,"il",u) //header of the variable 
118     m=w(1);n=w(2);it=w(3);nel=w(4);dim=[m,n]
119     mseek(4*(m+nel),u,"cur")// skip the index
120     mseek(8*nel*(it+1),u,"cur") // skip the non zero values
121     //I=mget(((m+nel),"il",u)
122     //A=mget((nel*(it+1)),"dl",u)
123     vol=(5+m+nel)*4+8*nel*(it+1)
124   case 6 then //boolean sparse
125     w=mget(4,"il",u) //header of the variable 
126     m=w(1);n=w(2);it=w(3);nel=w(4);dim=[m,n]
127     mseek(4*(m+nel),u,"cur")// skip the index
128     //I=mget((m+nel),"il",u)
129     vol=(5+m+nel)*4
130   case 8 then //integer
131     w=mget(3,"il",u) //header of the variable 
132     m=w(1);n=w(2);it=w(3);dim=[m,n]
133     select it
134     case 4 then 
135       mseek(m*n*4,u,"cur")
136       //A=mget((m*n,"il",u)
137       vol=4*4+m*n*4
138     case 2 then 
139       mseek(m*n*2,u,"cur")
140       //A=mget((m*n,"sl",u)
141       vol=4*4+m*n*2
142     case 1 then 
143       mseek(m*n*1,u,"cur")
144       //A=mget((m*n,"c",u)
145       vol=4*4+m*n
146     case 14 then 
147       mseek(m*n*4,u,"cur")
148       //A=mget((m*n,"uil",u)
149       vol=4*4+m*n*4
150     case 12 then 
151       mseek(m*n*2,u,"cur")
152       //A=mget((m*n,"usl",u)
153       vol=4*4+m*n*2
154     case 11 then 
155       mseek(m*n*1,u,"cur")
156       //A=mget((m*n,"uc",u)
157       vol=4*4+m*n
158     end
159   case 9 then //graphic handle: API?? 
160         [dim, vol] = getMatrixHandleInfo(u);
161   case 10 then //string
162     w=mget(3,"il",u)
163     m=w(1);n=w(2);it=w(3);dim=[m,n]
164     w=mget(m*n+1,"il",u) //get the pointer table
165     N=w($)-1 //total number of chars
166     mseek(4*N,u,"cur") //skip the values, N characters coded in N integers
167     vol=(4*m*n+1)*4+4*N
168   case 11 then // function (not compiled)
169     dim=[]
170     nout=mget(1,"il",u)
171     mseek(nout*6*4,u,"cur") //skip lhs names, nout names coded over 6 integers
172     nin=mget(1,"il",u)
173     mseek(nin*6*4,u,"cur") //skip rhs names, nin names coded over 6 integers
174     N=mget(1,"il",u) //code length
175     mseek(N*4,u,"cur") //skip code (N characters coded in N integers)
176     vol=(3+(nin+nout)*6+N)*4
177   case 13 then // compiled function 
178     dim=[]
179     nout=mget(1,"il",u)
180     mseek(nout*6*4,u,"cur") //skip lhs names, nout names coded over 6 integers
181     nin=mget(1,"il",u)
182     mseek(nin*6*4,u,"cur") //skip rhs names, nin names coded over 6 integers
183     N=mget(1,"il",u) //code length
184     mseek(N*4,u,"cur") //skip pseudo-code N integers
185     vol=(3+(nin+nout)*6+N)*4
186   case 14 then //library
187     np=mget(1,"il",u) //path length
188     mseek(np*4,u,"cur") //skeep the path
189     nclas=29
190     nn=mget(1,"il",u) //number of names
191     dim=nn
192     mseek((nclas+1)*4,u,"cur") //skeep the class pointers
193     mseek(nn*6*4,u,"cur") //skip the names
194     vol=(2+np+1+nclas+1+nn*6)*4
195   case 15 then //list
196     [dim, vol] = getListInfo(u);
197   case 16 then //tlist
198     [dim, vol] = getListInfo(u);
199   case 17 then //mlist
200     [dim, vol] = getListInfo(u);
201   case 128 then //pointer: API?? 
202     
203   case 129 then //size implicit index (same as polynomial)
204     w=mget(3,"il",u) //header of the variable 
205     m=w(1);n=w(2);it=w(3);dim=[m,n]
206     mseek(4*4,u,"cur") //skeep the formal variable name
207     w=mget(m*n+1,"il",u) //get the pointer table
208     //I=mget(m*n+1,"il",u)
209     N=(w(m*n+1)-1)*(it+1)
210     mseek(8*N,u,"cur") //skip the values
211     //A=mget(N,"dl",u)
212     vol=(4+4+(m*n+1))*4+8*N
213   case 130 then //scilab primitive: API?? 
214     
215   else  //unknown type, or file content plainly wrong
216
217   end
218 endfunction
219
220 //////////////////////////////////////////////////////////
221 function [items, totalSize] = getListInfo(file_descriptor)
222     items = mget(1, "il", file_descriptor);//read item count
223     offset = mget(1 + items, "il", file_descriptor);//read offset between vars
224     totalSize = (2 + (items + 1)) * 4;
225     for i = 1:items
226         //bypass Undefined item
227         if offset(i) <> offset(i + 1) then
228             [t, d, v] = listnextvar(file_descriptor);
229             totalSize = totalSize + v;
230         end
231     end
232 endfunction
233
234 //////////////////////////////////////////////////////////
235 function [hsize, totalSize] = getMatrixHandleInfo(fd)
236     totalSize = 4 + 4;
237     version=mget(4, "uc", fd);
238     if is_higher_than([3 1 0 1]) then // case 3 1 0 2 and after
239         hsize = mget(2, "uc", fd)
240         totalSize = totalSize + 2;
241         for i=1:hsize(1)
242             for j=1:hsize(2)
243                 totalSize = getSingleHandleInfo(fd, totalSize)
244             end
245         end
246     else
247         // a single handle only can be loaded before 3 1 0 2
248         hsize = [1,1];
249         totalSize = getSingleHandleInfo(fd, totalSize);
250     end
251
252 endfunction
253
254 //////////////////////////////////////////////////////////
255 function totalSize = getSingleHandleInfo(fd, totalSize)
256     [totalSize, handleType] = readString(fd, totalSize); // Type
257
258     select handleType
259         case "Figure"
260             totalSize = seekBool(fd, totalSize); // Visible
261             totalSize = seekShortCount(fd, 2, totalSize); //figure_position
262             totalSize = seekShortCount(fd, 2, totalSize); //figure_size
263             totalSize = seekShortCount(fd, 2, totalSize); //axes_size
264             if is_higher_than( [4 1 2 0] ) then
265                 totalSize = seekShortCount(fd, 2, totalSize); //viewport
266                 if is_higher_than([5 4 0 0]) then
267                     totalSize = seekStringInt(fd, totalSize); // info_message
268                 else
269                     totalSize = seekString(fd, totalSize); // info_message
270                 end
271                 totalSize = seekString(fd, totalSize); // tag
272             end
273
274             totalSize = seekBool(fd, totalSize); // auto_resize
275             if is_higher_than([5 4 0 0]) then
276                 totalSize = seekStringInt(fd, totalSize); // figure_name
277             else
278                 totalSize = seekString(fd, totalSize); // figure_name
279             end
280             totalSize = seekShort(fd, totalSize); //figure_id
281             totalSize = seekMatrix(fd, totalSize); // color_map
282             totalSize = seekBool(fd, totalSize); // pixmap
283             totalSize = seekString(fd, totalSize); // pixel_drawing_mode
284             if (is_higher_than([5 1 0 0])) then
285                 totalSize = seekString(fd, totalSize); // anti_aliasing
286             end
287             totalSize = seekBool(fd, totalSize); // immediate_drawing
288             totalSize = seekInt(fd, totalSize); // background
289             totalSize = seekString(fd, totalSize); // rotation_style
290             if ( is_higher_than([4 1 2 0]) ) then
291                 totalSize = seekString(fd, totalSize); // event_handler
292                 totalSize = seekString(fd, totalSize); // event_handler_enable
293             end
294             if ( is_higher_than([5 2 0 0]) ) then // Added in 5.4.0 version
295                 totalSize = seekString(fd, totalSize); // resizefcn
296                 totalSize = seekString(fd, totalSize); // closerequestfcn
297             end
298
299             [totalSize, axesCount] = readInt(fd, totalSize); // children
300             for i = 1 : axesCount
301                 totalSize = getSingleHandleInfo(fd, totalSize);
302             end
303
304             totalSize = seekUserdata(fd, totalSize); // Userdata
305
306         case "Axes"
307             totalSize = seekBool(fd, totalSize); // visible
308             if and(version==[3 0 0 0]) then
309                 totalSize = seekBool(fd, totalSize); // axes_visible
310             else
311                 totalSize = seekBoolMatrix(fd, totalSize); // axes_visible
312             end
313
314             if is_higher_than( [3 1 0 1] ) then
315                 totalSize = seekBoolMatrix(fd, totalSize); // axes_reverse
316             end
317
318             totalSize = seekIntMatrix(fd, totalSize); // grid
319                 if (is_higher_than([5 0 3 0])) then
320                 totalSize = seekString(fd, totalSize); // grid_position
321             end
322             totalSize = seekString(fd, totalSize); // x_location
323             totalSize = seekString(fd, totalSize); // y_location
324             [totalSize, view] = readStringCount(fd, 2, totalSize); // view
325
326             //title
327             totalSize = seekBool(fd, totalSize); // visible
328             if is_higher_than( [4 1 2 0] ) then
329                 totalSize = seekStringMatrix(fd, totalSize); // text
330             else
331                 totalSize = seekString(fd, totalSize); // text
332             end
333
334             if is_higher_than([4 1 2 0]) then
335                 totalSize = seekInt(fd, totalSize); // font_foreground
336                 totalSize = seekBool(fd, totalSize); // fractional_font
337             end
338
339             totalSize = seekInt(fd, totalSize); // foreground
340             if is_higher_than([3 1 0 0]) then
341                 totalSize = seekInt(fd, totalSize); // background
342                 totalSize = seekBool(fd, totalSize); // fill_mode
343             end
344
345             totalSize = seekBool(fd, totalSize); // font_style
346             totalSize = seekBool(fd, totalSize); // font_size
347
348             if is_higher_than([3 1 0 0]) then
349                 totalSize = seekBool(fd, totalSize); // auto_rotation
350                 totalSize = seekDouble(fd, totalSize); // font_angle
351                 totalSize = seekBool(fd, totalSize); // auto_position
352                 totalSize = seekDouble(fd, totalSize); // position 1 
353                 totalSize = seekDouble(fd, totalSize); // position 2
354             end
355
356             //x_label
357             totalSize = seekBool(fd, totalSize); // visible
358             if is_higher_than( [4 1 2 0] ) then
359                 totalSize = seekStringMatrix(fd, totalSize); // text
360             else
361                 totalSize = seekString(fd, totalSize); // text
362             end
363
364             if is_higher_than([4 1 2 0]) then
365                 totalSize = seekInt(fd, totalSize); // font_foreground
366                 totalSize = seekBool(fd, totalSize); // fractional_font
367             end
368
369             totalSize = seekInt(fd, totalSize); // foreground
370             if is_higher_than([3 0 0 0]) then
371                 totalSize = seekInt(fd, totalSize); // background
372                 totalSize = seekBool(fd, totalSize); // fill_mode
373             end
374
375             totalSize = seekBool(fd, totalSize); // font_style
376             totalSize = seekBool(fd, totalSize); // font_size
377
378             if is_higher_than([3 0 0 0]) then
379                 totalSize = seekBool(fd, totalSize); // auto_rotation
380                 totalSize = seekDouble(fd, totalSize); // font_angle
381                 totalSize = seekBool(fd, totalSize); // auto_position
382                 totalSize = seekDouble(fd, totalSize); // position 1 
383                 totalSize = seekDouble(fd, totalSize); // position 2
384             end
385
386             //y_label
387             totalSize = seekBool(fd, totalSize); // visible
388             if is_higher_than( [4 1 2 0] ) then
389                 totalSize = seekStringMatrix(fd, totalSize); // text
390             else
391                 totalSize = seekString(fd, totalSize); // text
392             end
393
394             if is_higher_than([4 1 2 0]) then
395                 totalSize = seekInt(fd, totalSize); // font_foreground
396                 totalSize = seekBool(fd, totalSize); // fractional_font
397             end
398
399             totalSize = seekInt(fd, totalSize); // foreground
400             if is_higher_than([3 0 0 0]) then
401                 totalSize = seekInt(fd, totalSize); // background
402                 totalSize = seekBool(fd, totalSize); // fill_mode
403             end
404
405             totalSize = seekBool(fd, totalSize); // font_style
406             totalSize = seekBool(fd, totalSize); // font_size
407
408             if is_higher_than([3 0 0 0]) then
409                 totalSize = seekBool(fd, totalSize); // auto_rotation
410                 totalSize = seekDouble(fd, totalSize); // font_angle
411                 totalSize = seekBool(fd, totalSize); // auto_position
412                 totalSize = seekDouble(fd, totalSize); // position 1 
413                 totalSize = seekDouble(fd, totalSize); // position 2
414             end
415
416             if view == "3d" then
417                 //z_label
418                 totalSize = seekBool(fd, totalSize); // visible
419                 if is_higher_than( [4 1 2 0] ) then
420                     totalSize = seekStringMatrix(fd, totalSize); // text
421                 else
422                     totalSize = seekString(fd, totalSize); // text
423                 end
424
425                 if is_higher_than([4 1 2 0]) then
426                     totalSize = seekInt(fd, totalSize); // font_foreground
427                     totalSize = seekBool(fd, totalSize); // fractional_font
428                 end
429
430                 totalSize = seekInt(fd, totalSize); // foreground
431                 if is_higher_than([3 0 0 0]) then
432                     totalSize = seekInt(fd, totalSize); // background
433                     totalSize = seekBool(fd, totalSize); // fill_mode
434                 end
435
436                 totalSize = seekBool(fd, totalSize); // font_style
437                 totalSize = seekBool(fd, totalSize); // font_size
438
439                 if is_higher_than([3 0 0 0]) then
440                     totalSize = seekBool(fd, totalSize); // auto_rotation
441                     totalSize = seekDouble(fd, totalSize); // font_angle
442                     totalSize = seekBool(fd, totalSize); // auto_position
443                     totalSize = seekDouble(fd, totalSize); // position 1 
444                     totalSize = seekDouble(fd, totalSize); // position 2
445                 end
446             end
447
448             if is_higher_than([3 0 0 0]) then
449                 totalSize = seekBoolMatrix(fd, totalSize); // auto_ticks
450
451                 //x_ticks
452                 [totalSize, ticksX] = readShort(fd, totalSize); // ticks count
453                 if ticksX > 0 then
454                     totalSize = seekMatrixCount(fd, ticksX,  totalSize); // locations
455                     [totalSize, labels] = readBoolCount(fd, ticksX, totalSize); // label
456                     for i = 1:ticksX
457                         totalSize = seekStringCount(fd, labels(i), totalSize);
458                     end
459                 end
460
461                 //y_ticks
462                 [totalSize, ticksY] = readShort(fd, totalSize); // ticks count
463                 if ticksY > 0 then
464                     totalSize = seekMatrixCount(fd, ticksY,  totalSize); // locations
465                     [totalSize, labels] = readBoolCount(fd, ticksY, totalSize); // label
466                     for i = 1:ticksY
467                         totalSize = seekStringCount(fd, labels(i), totalSize);
468                     end
469                 end
470
471                 //z_ticks
472                 [totalSize, ticksZ] = readShort(fd, totalSize); // ticks count
473                 if ticksZ > 0 then
474                     totalSize = seekMatrixCount(fd, ticksZ,  totalSize); // locations
475                     [totalSize, labels] = readBoolCount(fd, ticksZ, totalSize); // label
476                     for i = 1:ticksZ
477                         totalSize = seekStringCount(fd, labels(i), totalSize);
478                     end
479                 end
480             end
481         
482             if is_higher_than([4 1 2 0]) then
483                 totalSize = seekString(fd, totalSize); // box
484                 totalSize = seekBool(fd, totalSize); // filled
485             else
486                 totalSize = seekBool(fd, totalSize); // box
487             end
488
489             totalSize = seekString(fd, totalSize); // sub_ticks
490
491             if ~(is_higher_than([3 1 0 1]) ) then
492                 totalSize = seekDouble(fd, totalSize); // ticks_color 
493             end
494
495             totalSize = seekBool(fd, totalSize); // font_style
496             totalSize = seekBool(fd, totalSize); // font_size
497             totalSize = seekInt(fd, totalSize); // font_color
498
499             if is_higher_than([4 1 2 0]) then
500                 totalSize = seekBool(fd, totalSize); // fractional_font
501             end
502
503             totalSize = seekBool(fd, totalSize); // isoview
504             totalSize = seekBool(fd, totalSize); // cube_scaling
505             totalSize = seekDouble(fd, totalSize); // rotation_angles 1
506             totalSize = seekDouble(fd, totalSize); // rotation_angles 2
507
508             if is_higher_than([3 0 0 0]) then
509                 totalSize = seekStringCount(fd, 3, totalSize); // log_flags
510             else
511                 totalSize = seekStringCount(fd, 2, totalSize); // log_flags
512             end
513             
514             totalSize = seekBool(fd, totalSize); // tight_limits
515             [totalSize, bounds] = readBool(fd, totalSize); // data_bounds count
516             totalSize = seekDoubleCount(fd, bounds, totalSize); // data_bounds
517         
518             if is_higher_than([3 0 0 0]) then
519                 [totalSize, zooms] = readBool(fd, totalSize); // zoom_box_size
520                 if zooms <> 0 then
521                     totalSize = seekDoubleCount(fd, zooms, totalSize); // zoom_box
522                 end
523             end
524             
525             if is_higher_than([3 1 0 1]) then
526                 totalSize = seekDoubleCount(fd, 4, totalSize); // margins
527             end
528
529             totalSize = seekDoubleCount(fd, 4, totalSize); // axes_bounds
530             totalSize = seekBool(fd, totalSize); // auto_clear
531             totalSize = seekBool(fd, totalSize); // auto_scale
532             
533             if is_higher_than([4 1 2 0] ) then
534                 totalSize = seekInt(fd, totalSize); // hidden_axis_color
535                 totalSize = seekString(fd, totalSize); // arc_drawing_method
536             end
537  
538             totalSize = seekInt(fd, totalSize); // hidden_color
539             totalSize = seekBool(fd, totalSize); // line_mode
540             totalSize = seekBool(fd, totalSize); // line_style
541             totalSize = seekShort(fd, totalSize); // thickness
542             totalSize = seekBool(fd, totalSize); // mark_mode
543             totalSize = seekBool(fd, totalSize); // mark_style
544             totalSize = seekBool(fd, totalSize); // mark_size
545
546             if is_higher_than([3 0 0 0]) then
547                 totalSize = seekBool(fd, totalSize); // mark_size_unit
548                 totalSize = seekInt(fd, totalSize); // mark_foreground
549                 totalSize = seekInt(fd, totalSize); // mark_background
550             end
551
552             totalSize = seekInt(fd, totalSize); // foreground
553             totalSize = seekInt(fd, totalSize); // background
554             [totalSize, clip] = readString(fd, totalSize); // clip_state
555             if clip == "on" then
556                 totalSize = seekDoubleCount(fd, 4, totalSize); // clip_box
557             end
558     
559             global parentAxesView;
560             parentAxesView = view;
561             [totalSize, axesCount] = readInt(fd, totalSize); // children
562             for i = 1 : axesCount
563                 totalSize = getSingleHandleInfo(fd, totalSize);
564             end
565             clearglobal parentAxesView;
566             totalSize = seekUserdata(fd, totalSize); // Userdata
567            
568         case "Polyline"
569             totalSize = seekBool(fd, totalSize); // visible
570             [totalSize, dataCount] = readIntCount(fd, 2, totalSize); // data count
571             totalSize = seekDoubleCount(fd, prod(dataCount), totalSize); // data
572             if is_higher_than([3 1 0 0]) then
573                 totalSize = seekBool(fd, totalSize); // closed
574             end    
575
576             totalSize = seekBool(fd, totalSize); // line_mode
577             if is_higher_than([3 1 0 0]) then
578                 totalSize = seekBool(fd, totalSize); // fill_mode
579             end    
580                 
581             totalSize = seekBool(fd, totalSize); // line_style
582             totalSize = seekShort(fd, totalSize); // thickness
583             if is_higher_than([3 1 0 1]) then
584                 totalSize = seekShort(fd, totalSize); // arrow_size_factor
585             end
586
587             totalSize = seekBool(fd, totalSize); // polyline_style
588
589             if is_higher_than([3 1 0 1] ) then
590                 [totalSize, count] = readShort(fd, totalSize); // interp_color_vector size
591                 totalSize = seekDoubleCount(fd, count, totalSize); // interp_color_vector
592                 totalSize = seekBool(fd, totalSize); // interp_color_mode
593             end
594
595             totalSize = seekBool(fd, totalSize); // mark_mode
596             totalSize = seekBool(fd, totalSize); // mark_style
597             totalSize = seekBool(fd, totalSize); // mark_size
598
599             if is_higher_than([3 0 0 0]) then
600                 totalSize = seekBool(fd, totalSize); // mark_size_unit
601             end
602
603             totalSize = seekInt(fd, totalSize); // foreground
604             if is_higher_than([3 1 0 0]) then
605                 totalSize = seekInt(fd, totalSize); // background
606             end
607
608             if is_higher_than([3 0 0 0]) then
609                 totalSize = seekInt(fd, totalSize); // mark_foreground
610                 totalSize = seekInt(fd, totalSize); // mark_background
611             end
612
613             if is_higher_than([3 1 0 0]) then
614                 [totalSize, count] = readShort(fd, totalSize); // x_shift count
615                 totalSize = seekDoubleCount(fd, count, totalSize); // x_shift
616                 [totalSize, count] = readShort(fd, totalSize); // y_shift count
617                 totalSize = seekDoubleCount(fd, count, totalSize); // y_shift
618                 [totalSize, count] = readShort(fd, totalSize); // z_shift count
619                 totalSize = seekDoubleCount(fd, count, totalSize); // z_shift
620             end
621
622             if is_higher_than([3 1 0 1]) then
623                 totalSize = seekDouble(fd, totalSize); // bar_width
624             end
625
626             [totalSize, state] = readString(fd, totalSize); // clip_state
627             if state == "on" then
628                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
629             end
630
631             totalSize = seekUserdata(fd, totalSize); // Userdata
632
633         case "Plot3d"
634             totalSize = seekBool(fd, totalSize); // visible
635             totalSize = seekBool(fd, totalSize); // surface_mode
636             totalSize = seekInt(fd, totalSize); // foreground
637             totalSize = seekShort(fd, totalSize); // thickness
638             totalSize = seekBool(fd, totalSize); // mark_mode
639             totalSize = seekBool(fd, totalSize); // mark_style
640             totalSize = seekBool(fd, totalSize); // mark_size
641
642             if is_higher_than([3 0 0 0]) then
643                 totalSize = seekBool(fd, totalSize); // mark_size_unit
644                 totalSize = seekInt(fd, totalSize); // mark_foreground
645                 totalSize = seekInt(fd, totalSize); // mark_background
646             end
647
648             if is_higher_than([5 1 1 0]) then
649                 totalSize = seekInt(fd, totalSize); // color_mode
650                 [totalSize, flag] = readInt(fd, totalSize); // color_flag
651             else
652                 totalSize = seekBool(fd, totalSize); // color_mode
653                 [totalSize, flag] = readBool(fd, totalSize); // color_flag
654             end
655
656             //data
657             totalSize = seekDoubleMatrix(fd, totalSize); // x
658             totalSize = seekDoubleMatrix(fd, totalSize); // y
659             totalSize = seekDoubleMatrix(fd, totalSize); // z
660
661             if or(flag == [2,5]) then
662                 [totalSize, count] = readIntCount(fd, 2, totalSize); // color size
663                 totalSize = seekIntCount(fd, prod(count), totalSize); // color
664             end
665
666             totalSize = seekInt(fd, totalSize); // hidden_color
667            
668             if is_higher_than([4 1 2 0])
669                 [totalSize, state] = readString(fd, totalSize); // clip_state
670                 if state == "on" then
671                     totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
672                 end
673             end
674
675             totalSize = seekUserdata(fd, totalSize); // Userdata
676
677         case "Fac3d"
678             totalSize = seekBool(fd, totalSize); // visible
679             totalSize = seekBool(fd, totalSize); // surface_mode
680             totalSize = seekInt(fd, totalSize); // foreground
681             totalSize = seekShort(fd, totalSize); // thickness
682             totalSize = seekBool(fd, totalSize); // mark_mode
683             totalSize = seekBool(fd, totalSize); // mark_style
684             totalSize = seekBool(fd, totalSize); // mark_size
685             if is_higher_than([3 0 0 0]) then
686                 totalSize = seekBool(fd, totalSize); // mark_size_unit
687                 totalSize = seekInt(fd, totalSize); // mark_foreground
688                 totalSize = seekInt(fd, totalSize); // mark_background
689             end
690
691             if is_higher_than([5 1 1 0]) then
692                 totalSize = seekInt(fd, totalSize); // color_mode
693                 [totalSize, flag] = readInt(fd, totalSize); // color_flag
694             else
695                 totalSize = seekBool(fd, totalSize); // color_mode
696                 [totalSize, flag] = readBool(fd, totalSize); // color_flag
697             end
698
699             //data
700             totalSize = seekDoubleMatrix(fd, totalSize); // x
701             totalSize = seekDoubleMatrix(fd, totalSize); // y
702             totalSize = seekDoubleMatrix(fd, totalSize); // z
703
704             if is_higher_than([3 1 0 1]) & flag >= 2 then
705                 [totalSize, count] = readIntCount(fd, 2, totalSize); // color size
706                 totalSize = seekIntCount(fd, prod(count), totalSize); // color
707                 totalSize = seekBool(fd, totalSize); // cdata_mapping
708             elseif or(flag==[2 5]) then
709                 [totalSize, count] = readIntCount(fd, 2, totalSize); // color size
710                 totalSize = seekIntCount(fd, prod(count), totalSize); // color
711             end
712
713             totalSize = seekInt(fd, totalSize); // color_mode
714
715             if is_higher_than([4 1 2 0])
716                 [totalSize, state] = readString(fd, totalSize); // clip_state
717                 if state == "on" then
718                     totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
719                 end
720             end
721
722             totalSize = seekUserdata(fd, totalSize); // Userdata
723
724         case "Compound"
725             [totalSize, count] = readInt(fd, totalSize); // children count
726             for i = 1 : count
727                 totalSize = getSingleHandleInfo(fd, totalSize); // children
728             end
729
730             if is_higher_than([3 1 0 1]) then
731                 totalSize = readBool(fd, totalSize); // visible
732             end
733             
734             totalSize = seekUserdata(fd, totalSize); // Userdata
735
736         case "Agregation"
737             [totalSize, count] = readInt(fd, totalSize); // children count
738             for i = 1 : count
739                 totalSize = getSingleHandleInfo(fd, totalSize); // children
740             end
741
742             if is_higher_than([3 1 0 1]) then
743                 totalSize = readBool(fd, totalSize); // visible
744             end
745             
746             totalSize = seekUserdata(fd, totalSize); // Userdata
747
748         case "Rectangle"
749             totalSize = seekBool(fd, totalSize); // visible
750             totalSize = seekShort(fd, totalSize); // thickness
751             totalSize = seekBool(fd, totalSize); // mark_mode
752             totalSize = seekBool(fd, totalSize); // mark_style
753             totalSize = seekBool(fd, totalSize); // mark_size
754
755             if is_higher_than([3 0 0 0]) then
756                 totalSize = seekBool(fd, totalSize); // mark_size_unit
757             end
758
759             totalSize = seekInt(fd, totalSize); // mark_foreground
760             totalSize = seekInt(fd, totalSize); // mark_background
761             totalSize = seekBool(fd, totalSize); // line_mode
762             totalSize = seekBool(fd, totalSize); // line_style
763             totalSize = seekBool(fd, totalSize); // fill_mode
764             totalSize = seekInt(fd, totalSize); // foreground
765
766             if is_higher_than([3 1 0 1]) then
767                 totalSize = seekInt(fd, totalSize); // background
768             end
769
770             if (is_higher_than([5 0 3 0])) then
771                 totalSize = seekMatrix(fd, totalSize); // data
772             else
773                 global parentAxesView;
774                 if parentAxesView == [] | parentAxesView == "2d" then
775                     totalSize = seekDoubleCount(fd, 4, totalSize); //data
776                 else
777                     totalSize = seekDoubleCount(fd, 5, totalSize); //data
778                 end
779             end
780
781             [totalSize, state] = readString(fd, totalSize); // clip_state
782             if state == "on" then
783                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
784             end
785
786             totalSize = seekUserdata(fd, totalSize); // Userdata
787
788         case "Arc"
789             totalSize = seekBool(fd, totalSize); // visible
790             totalSize = seekShort(fd, totalSize); // thickness
791             totalSize = seekBool(fd, totalSize); // line_style
792
793             if is_higher_than([3 1 0 1])
794                 totalSize = seekBool(fd, totalSize); // line_mode
795             end
796
797             totalSize = seekBool(fd, totalSize); // fill_mode
798             totalSize = seekInt(fd, totalSize); // foreground
799
800             if is_higher_than([3 1 0 1]) then
801                 totalSize = seekInt(fd, totalSize); // background
802             end
803
804             if is_higher_than([5 0 3 0]) then
805                 totalSize = seekMatrix(fd, totalSize); // data
806             else
807                 global parentAxesView;
808                 if parentAxesView == [] | parentAxesView == "2d" then
809                     totalSize = seekDoubleCount(fd, 6, totalSize); //data
810                 else
811                     totalSize = seekDoubleCount(fd, 7, totalSize); //data
812                 end
813             end
814
815             if is_higher_than([4 1 2 0]) then
816                 totalSize = seekString(fd, totalSize); // data_mapping
817             end
818
819             [totalSize, state] = readString(fd, totalSize); // clip_state
820             if state == "on" then
821                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
822             end
823
824             totalSize = seekUserdata(fd, totalSize); // Userdata
825
826         case "Champ"
827             totalSize = seekBool(fd, totalSize); // visible
828             totalSize = seekDoubleMatrix(fd, totalSize); // x
829             totalSize = seekDoubleMatrix(fd, totalSize); // y
830             totalSize = seekDoubleMatrix(fd, totalSize); // fx
831             totalSize = seekDoubleMatrix(fd, totalSize); // fy
832             totalSize = seekBool(fd, totalSize); // line_style
833             totalSize = seekShort(fd, totalSize); // thickness
834             totalSize = seekBool(fd, totalSize); // colored
835             totalSize = seekDouble(fd, totalSize); // arrow_size
836
837             [totalSize, state] = readString(fd, totalSize); // clip_state
838             if state == "on" then
839                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
840             end
841
842             totalSize = seekUserdata(fd, totalSize); // Userdata
843
844         case "Segs"
845             totalSize = seekBool(fd, totalSize); // visible
846             totalSize = seekDoubleMatrix(fd, totalSize); // data
847             totalSize = seekBool(fd, totalSize); // line_mode
848             totalSize = seekBool(fd, totalSize); // line_style
849             totalSize = seekShort(fd, totalSize); // thickness
850             totalSize = seekDouble(fd, totalSize); // arrow_size
851             totalSize = seekIntInt(fd, totalSize); // segs_color
852             totalSize = seekBool(fd, totalSize); // mark_mode
853             totalSize = seekBool(fd, totalSize); // mark_style
854             totalSize = seekBool(fd, totalSize); // mark_size
855
856             if is_higher_than([3 0 0 0]) then
857                 totalSize = seekBool(fd, totalSize); // mark_size_unit
858             end
859
860             totalSize = seekInt(fd, totalSize); // mark_foreground
861             totalSize = seekInt(fd, totalSize); // mark_background
862
863             [totalSize, state] = readString(fd, totalSize); // clip_state
864             if state == "on" then
865                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
866             end
867
868             totalSize = seekUserdata(fd, totalSize); // Userdata
869
870         case "Grayplot"
871             totalSize = seekBool(fd, totalSize); // visible
872             if is_higher_than([3 0 0 0]) then
873                 totalSize = seekDoubleMatrix(fd, totalSize); // x
874                 totalSize = seekDoubleMatrix(fd, totalSize); // y
875                 totalSize = seekDoubleMatrix(fd, totalSize); // z
876             else
877                 totalSize = seekDoubleMatrix(fd, totalSize); // x,y,z
878             end
879
880             totalSize = seekString(fd, totalSize); // data_mapping
881             [totalSize, state] = readString(fd, totalSize); // clip_state
882             if state == "on" then
883                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
884             end
885
886             totalSize = seekUserdata(fd, totalSize); // Userdata
887
888         case "Matplot"
889             totalSize = seekBool(fd, totalSize); // visible
890             totalSize = seekDoubleMatrix(fd, totalSize); // data
891
892             [totalSize, state] = readString(fd, totalSize); // clip_state
893             if state == "on" then
894                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
895             end
896
897             totalSize = seekUserdata(fd, totalSize); // Userdata
898
899         case "Fec"
900             totalSize = seekBool(fd, totalSize); // visible
901             totalSize = seekDoubleMatrix(fd, totalSize); // data
902             totalSize = seekDoubleMatrix(fd, totalSize); // triangles
903             totalSize = seekDoubleCount(fd, 2, totalSize); // z_bounds
904             if is_higher_than( [5 0 3 0] ) then
905                 totalSize = seekDoubleCount(fd, 2, totalSize); // color_range
906                 totalSize = seekDoubleCount(fd, 2, totalSize); // outside_colors
907                 totalSize = seekBool(fd, totalSize); // line_mode
908                 totalSize = seekInt(fd, totalSize); // foreground
909             end
910
911             [totalSize, state] = readString(fd, totalSize); // clip_state
912             if state == "on" then
913                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
914             end
915
916             totalSize = seekUserdata(fd, totalSize); // Userdata
917
918         case "Legend"
919             if is_higher_than( [5 0 0 0] ) then
920                 totalSize = seekBool(fd, totalSize); // visible
921                 totalSize = seekStringInt(fd, totalSize); // text
922                 totalSize = seekBool(fd, totalSize); // font_style
923                 totalSize = seekBool(fd, totalSize); // font_size
924                 totalSize = seekInt(fd, totalSize); // font_color
925                 totalSize = seekBool(fd, totalSize); // fractional_font
926                 [totalSize, count] = readBool(fd, totalSize); // legends size
927                 for i = 1 : count
928                     totalSize = seekIntInt(fd, totalSize); // legends
929                 end
930
931                 totalSize = seekString(fd, totalSize); // legend_location
932                 totalSize = seekDoubleCount(fd, 2, totalSize); // position
933                 totalSize = seekBool(fd, totalSize); // line_mode
934                 totalSize = seekShort(fd, totalSize); // thickness
935                 totalSize = seekInt(fd, totalSize); // foreground
936                 totalSize = seekBool(fd, totalSize); // fill_mode
937                 totalSize = seekInt(fd, totalSize); // background
938
939                 [totalSize, state] = readString(fd, totalSize); // clip_state
940                 if state == "on" then
941                     totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
942                 end
943
944                 totalSize = seekUserdata(fd, totalSize); // Userdata
945             else
946                 totalSize = seekBool(fd, totalSize); // visible
947                 totalSize = seekBool(fd, totalSize); // line_mode
948                 totalSize = seekBool(fd, totalSize); // mark_mode
949                 totalSize = seekInt(fd, totalSize); // mark_foreground
950                 totalSize = seekInt(fd, totalSize); // mark_background
951                 totalSize = seekStringInt(fd, totalSize); // text
952                 totalSize = seekInt(fd, totalSize); // foreground
953                 totalSize = seekBool(fd, totalSize); // font_style
954                 totalSize = seekBool(fd, totalSize); // font_size
955                 if is_higher_than( [4 1 2 0] ) then
956                     totalSize = seekBool(fd, totalSize); // font_size
957                 end
958
959                 [totalSize, state] = readString(fd, totalSize); // clip_state
960                 if state == "on" then
961                     totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
962                 end
963             end
964
965         case "Text"
966             totalSize = seekBool(fd, totalSize); // visible
967             if is_higher_than([4 1 2 0]) then
968                 totalSize = seekStringMatrix(fd, totalSize);
969             else
970                 totalSize = seekStringInt(fd, totalSize);
971             end
972
973             [totalSize, count] = readBoolCount(fd, 2, totalSize); // data size
974             totalSize = seekDoubleCount(fd, prod(count), totalSize); // data
975             totalSize = seekDoubleCount(fd, 2, totalSize); // text_box
976             totalSize = seekString(fd, totalSize); // text_box_mode
977             totalSize = seekInt(fd, totalSize); // foreground
978             totalSize = seekBool(fd, totalSize); // font_style
979             totalSize = seekBool(fd, totalSize); // font_size
980             totalSize = seekDouble(fd, totalSize); // font_angle
981
982             if is_higher_than([3 1 0 1]) then
983                 totalSize = seekBool(fd, totalSize); // box
984                 totalSize = seekBool(fd, totalSize); // line_mode
985                 totalSize = seekBool(fd, totalSize); // fill_mode
986                 totalSize = seekInt(fd, totalSize); // font_foreground
987                 totalSize = seekInt(fd, totalSize); // background
988             end
989
990             if is_higher_than( [4 1 2 0] ) then
991                 totalSize = seekString(fd, totalSize); // alignment
992                 totalSize = seekBool(fd, totalSize); // fractional_font
993             end
994
995             [totalSize, state] = readString(fd, totalSize); // clip_state
996             if state == "on" then
997                 totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
998             end
999
1000             totalSize = seekUserdata(fd, totalSize); // Userdata
1001
1002         case "Axis"
1003             if is_higher_than([3 1 0 0]) then
1004                 totalSize = seekBool(fd, totalSize); // visible
1005                 totalSize = seekBoolInt(fd, totalSize); // tics_direction
1006                 totalSize = seekMatrix(fd, totalSize); // xtics_coord
1007                 totalSize = seekMatrix(fd, totalSize); // ytics_coord
1008                 totalSize = seekInt(fd, totalSize); // tics_color
1009                 totalSize = seekBool(fd, totalSize); // tics_segment
1010                 totalSize = seekBool(fd, totalSize); // tics_style
1011                 totalSize = seekInt(fd, totalSize); // sub_tics
1012                 totalSize = seekStringInt(fd, totalSize); // tics_label
1013                 totalSize = seekInt(fd, totalSize); // label_font_size
1014                 totalSize = seekInt(fd, totalSize); // labels_font_color
1015
1016                 if is_higher_than( [4 1 2 0] ) then
1017                     totalSize = seekBool(fd, totalSize); // fractional_font
1018                 end
1019                 
1020                 [totalSize, state] = readString(fd, totalSize); // clip_state
1021                 if state == "on" then
1022                     totalSize = seekDoubleCount(fd, 4, totalSize); //clip_box
1023                 end
1024
1025                 totalSize = seekUserdata(fd, totalSize); // Userdata
1026             end
1027
1028         case "uimenu"
1029             if is_higher_than( [4 1 2 0] ) then
1030                 totalSize = seekBool(fd, totalSize); // Enable
1031                 totalSize = seekMatrix(fd, totalSize); // Foregroundcolor
1032                 totalSize = seekString(fd, totalSize); // Label
1033                 totalSize = seekBool(fd, totalSize); // Visible
1034                 if is_higher_than([5 4 0 0]) then
1035                     totalSize = seekStringInt(fd, totalSize); // Callback
1036                 else
1037                     totalSize = seekString(fd, totalSize); // Callback
1038                 end
1039                 totalSize = seekInt(fd, totalSize); // Callback Type
1040                 totalSize = seekString(fd, totalSize); // Tag
1041             end
1042
1043             if is_higher_than( [5 1 2 0] ) then
1044                 totalSize = seekBool(fd, totalSize); // Checked
1045             end
1046
1047             if is_higher_than( [5 1 1 0] ) then
1048                 [totalSize, axesCount] = readInt(fd, totalSize); // children
1049                 for i = 1 : axesCount
1050                     totalSize = getSingleHandleInfo(fd, totalSize);
1051                 end
1052             end
1053
1054         case "uicontextmenu"
1055             [totalSize, axesCount] = readInt(fd, totalSize); // children
1056             for i = 1 : axesCount
1057                 totalSize = getSingleHandleInfo(fd, totalSize);
1058             end
1059         case "uicontrol"
1060             if is_higher_than( [4 1 2 0] ) then
1061                 totalSize = seekString(fd, totalSize); // Style
1062                 totalSize = seekMatrix(fd, totalSize); // BackgroundColor
1063                 totalSize = seekBool(fd, totalSize); // Enable
1064                 totalSize = seekString(fd, totalSize); // FontAngle
1065                 totalSize = seekString(fd, totalSize); // FontName
1066                 totalSize = seekDouble(fd, totalSize); // FontSize
1067                 totalSize = seekString(fd, totalSize); // FontUnits
1068                 totalSize = seekString(fd, totalSize); // FontWeight
1069                 totalSize = seekMatrix(fd, totalSize); // ForegroundColor
1070                 totalSize = seekString(fd, totalSize); // HorizontalAlignment
1071                 totalSize = seekMatrix(fd, totalSize); // ListboxTop
1072                 totalSize = seekDouble(fd, totalSize); // Max
1073                 totalSize = seekDouble(fd, totalSize); // Min
1074                 totalSize = seekMatrix(fd, totalSize); // Position
1075                 totalSize = seekString(fd, totalSize); // Relief
1076                 totalSize = seekMatrix(fd, totalSize); // SliderStep
1077                 totalSize = seekStringMatrix(fd, totalSize); // String
1078                 if is_higher_than( [5 2 0 0] ) then  // Added in 5.4.0 version
1079                     totalSize = seekStringMatrix(fd, totalSize); // TooltipString
1080                 end
1081                 totalSize = seekString(fd, totalSize); // Units
1082                 totalSize = seekMatrix(fd, totalSize); // Value
1083                 totalSize = seekString(fd, totalSize); // VerticalAlignment
1084                 totalSize = seekBool(fd, totalSize); // Visible
1085                 if is_higher_than([5 4 0 0]) then
1086                     totalSize = seekStringInt(fd, totalSize); // Callback
1087                 else
1088                     totalSize = seekString(fd, totalSize); // Callback
1089                 end
1090                 totalSize = seekInt(fd, totalSize); // Callback Type
1091                 totalSize = seekUserdata(fd, totalSize); // Userdata
1092                 totalSize = seekString(fd, totalSize); // Tag
1093             end
1094         else
1095             warning("type " +typ+" unhandled");
1096         end
1097 endfunction
1098 //////////////////////////////////////////////////////////
1099 //read 1 "il" value
1100 function newSize = seekInt(fd, currentSize)
1101     data = mget(1, "il", fd);
1102     //disp("int : " + string(data));
1103     newSize = currentSize + 4;
1104 endfunction
1105
1106 //////////////////////////////////////////////////////////
1107 //read 1 "il" value
1108 function newSize = seekIntCount(fd, len, currentSize)
1109     data = mget(len, "il", fd);
1110     //disp("int : " + string(data));
1111     newSize = currentSize + 4 * len;
1112 endfunction
1113
1114 //////////////////////////////////////////////////////////
1115 //read 1 "il" value
1116 function newSize = seekIntMatrix(fd, currentSize)
1117     offset = mget(1, "c", fd);
1118     data = mget(offset, "il", fd);
1119     //disp("int[] : " + string(data));
1120     newSize = currentSize + 4 * offset + 1;
1121 endfunction
1122
1123 //////////////////////////////////////////////////////////
1124 //read 1 "il" value
1125 function newSize = seekIntInt(fd, currentSize)
1126     offset = mget(1, "il", fd);
1127     data = mget(offset, "il", fd);
1128     //disp("int[] : " + string(data));
1129     newSize = currentSize + 4 * offset + 4;
1130 endfunction
1131
1132 //////////////////////////////////////////////////////////
1133 //read 1 "il" value
1134 function [newSize, data] = readInt(fd, currentSize)
1135     data = mget(1, "il", fd);
1136     //disp("int : " + string(data));
1137     newSize = currentSize + 4;
1138 endfunction
1139
1140 //////////////////////////////////////////////////////////
1141 //read 1 "il" value
1142 function [newSize, data] = readIntCount(fd, len, currentSize)
1143     data = mget(len, "il", fd);
1144     //disp("int : " + string(data));
1145     newSize = currentSize + 4 * len;
1146 endfunction
1147
1148 //////////////////////////////////////////////////////////
1149 //read 1 "c" value
1150 function newSize = seekBool(fd, currentSize)
1151     data = mget(1, "c", fd);
1152     //disp("bool : " + string(data));
1153     newSize = currentSize + 1;
1154 endfunction
1155
1156 //////////////////////////////////////////////////////////
1157 //read 1 "c" value
1158 function [newSize, data] = readBool(fd, currentSize)
1159     data = mget(1, "c", fd);
1160     //disp("bool : " + string(data));
1161     newSize = currentSize + 1;
1162 endfunction
1163
1164 //////////////////////////////////////////////////////////
1165 //read 1 "c" value
1166 function newSize = seekBoolMatrix(fd, currentSize)
1167     offset = mget(1, "c", fd);
1168     data = mget(offset, "c", fd);
1169     //disp("bool : " + string(data));
1170     newSize = currentSize + offset + 1;
1171 endfunction
1172
1173 function newSize = seekBoolInt(fd, currentSize)
1174     offset = mget(1, "il", fd);
1175     data = mget(offset, "c", fd);
1176     //disp("bool : " + string(data));
1177     newSize = currentSize + offset + 4;
1178 endfunction
1179
1180 //////////////////////////////////////////////////////////
1181 //read 1 "c" value
1182 function [newSize, data] = readBoolCount(fd, len, currentSize)
1183     data = mget(len, "c", fd);
1184     //disp("bool : " + string(data));
1185     newSize = currentSize + len;
1186 endfunction
1187
1188 //////////////////////////////////////////////////////////
1189 //read 1 "c" value
1190 function newSize = seekDouble(fd, currentSize)
1191     data = mget(1, "dl", fd);
1192     //disp("double : " + string(data));
1193     newSize = currentSize + 8;
1194 endfunction
1195
1196 //////////////////////////////////////////////////////////
1197 //read 1 "c" value
1198 function newSize = seekDoubleCount(fd, len ,currentSize)
1199     data = mget(len, "dl", fd);
1200     //disp("bool : " + string(data));
1201     newSize = currentSize + len * 8;
1202 endfunction
1203
1204 //////////////////////////////////////////////////////////
1205 //read 1 "c" value
1206 function newSize = seekShort(fd, currentSize)
1207     data = mget(1, "sl", fd);
1208     //disp("short : " + string(data));
1209     newSize = currentSize + 2;
1210 endfunction
1211
1212 //////////////////////////////////////////////////////////
1213 //read 1 "c" value
1214 function [newSize, data] = readShort(fd, currentSize)
1215     data = mget(1, "sl", fd);
1216     //disp("short : " + string(data));
1217     newSize = currentSize + 2;
1218 endfunction
1219
1220 //////////////////////////////////////////////////////////
1221 //read 2 "c" value
1222 function newSize = seekShortCount(fd, len, currentSize)
1223     data = mget(len, "sl", fd);
1224     //disp("short : " + string(data));
1225     newSize = currentSize + len * 2;
1226 endfunction
1227
1228 //////////////////////////////////////////////////////////
1229 //read 1 "c" size + size * "c" value
1230 function newSize = seekString(fd, currentSize)
1231     offset = mget(1, "c", fd);
1232     data = mget(offset, "c", fd);
1233     //disp("string : " + ascii(data));
1234     newSize = currentSize + offset + 1;
1235 endfunction
1236
1237 //////////////////////////////////////////////////////////
1238 //read 1 "c" size + size * "c" value
1239 function newSize = seekStringInt(fd, currentSize)
1240     offset = mget(1, "il", fd);
1241     data = mget(offset, "c", fd);
1242     //disp("string : " + ascii(data));
1243     newSize = currentSize + offset + 4;
1244 endfunction
1245
1246 //////////////////////////////////////////////////////////
1247 //read 1 "c" size + size * "c" value
1248 function newSize = seekStringCount(fd, len, currentSize)
1249     data = mget(len, "c", fd);
1250     //disp("string : " + ascii(data));
1251     newSize = currentSize + len;
1252 endfunction
1253
1254 //////////////////////////////////////////////////////////
1255 //read 1 "c" size + size * "c" value
1256 function newSize = seekStringMatrix(fd, currentSize)
1257     row = mget(1, "il", fd);
1258     col = mget(1, "il", fd);
1259     for i = 1 : row * col
1260         if is_higher_than([5 4 0 0])
1261             currentSize = seekStringInt(fd, currentSize); // String
1262         else
1263             currentSize = seekString(fd, currentSize); // String
1264         end
1265     end
1266     newSize = currentSize + 4 * 2;
1267 endfunction
1268
1269 //////////////////////////////////////////////////////////
1270 //read 1 "il" size + size * "dl" value
1271 function newSize = seekMatrix(fd, currentSize)
1272     offset = mget(1, "il", fd);
1273     data = mget(offset, "dl", fd);
1274     //disp("double : " + string(data));
1275     newSize = currentSize + offset * 8 + 4;
1276 endfunction
1277
1278 //////////////////////////////////////////////////////////
1279 //read 1 "il" size + size * "dl" value
1280 function newSize = seekMatrixCount(fd, len, currentSize)
1281     data = mget(len, "dl", fd);
1282     //disp("double : " + string(data));
1283     newSize = currentSize + len * 8;
1284 endfunction
1285
1286 //////////////////////////////////////////////////////////
1287 //read 1 "c" size + size * "c" value
1288 function newSize = seekDoubleMatrix(fd, currentSize)
1289     row = mget(1, "il", fd);
1290     col = mget(1, "il", fd);
1291     currentSize = seekDoubleCount(fd, row * col, currentSize);
1292     newSize = currentSize + 4 * 2;
1293 endfunction
1294
1295 //////////////////////////////////////////////////////////
1296 //read user_data
1297 function newSize = seekUserdata(fd, currentSize)
1298     mget(24, "c", fd);
1299     newSize = currentSize + 24;
1300     [typ,dim,vol] = listnextvar(fd); // Userdata
1301     newSize = newSize + vol;
1302 endfunction
1303
1304 //////////////////////////////////////////////////////////
1305 //read 1 "il" value
1306 function [newSize, data] = readString(fd, currentSize)
1307     offset = mget(1, "c", fd);
1308     data = ascii(mget(offset, "c", fd));
1309     //disp("string : " + data);
1310     newSize = currentSize + offset + 1;
1311 endfunction
1312
1313 //////////////////////////////////////////////////////////
1314 //read 1 "il" value
1315 function [newSize, data] = readStringCount(fd, len, currentSize)
1316     data = ascii(mget(len, "c", fd));
1317     //disp("string : " + data);
1318     newSize = currentSize + len;
1319 endfunction
1320 //////////////////////////////////////////////////////////
1321 function v=code2var(id)
1322   nsiz=6
1323   i1=1
1324   for l=1:nsiz
1325     idl=id(l)
1326     for i=i1:i1+3
1327       k=int((idl+128)/256)
1328       if k<0 then k=k-1,end
1329       ch=idl-256*k
1330       if ch==40 then
1331         n=i-1
1332         v=_code2str(str)
1333         return
1334       end
1335       idl=k
1336       str(i)=ch
1337     end
1338     i1=i1+4
1339     v=_code2str(str)
1340   end
1341 endfunction
1342
1343 function r=is_higher_than(v)
1344 //check if current version is strictly higher than the given one
1345   r=%f
1346   for k=1:4
1347     if version(k)>v(k) then r=%t,break,end
1348     if version(k)<v(k) then r=%f,break,end
1349   end
1350 endfunction