[m2sci] kernel code reorganization: clarify dependencies & ease code browsing
[scilab.git] / scilab / modules / m2sci / macros / mfile2sci.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2002-2004 - INRIA - Vincent COUVERT
3 // Copyright (C) ???? - INRIA - Serge STEER
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 // Copyright (C) 2018 - Samuel GOUGEON
6 //
7 // This file is hereby licensed under the terms of the GNU GPL v2.0,
8 // pursuant to article 5.3.4 of the CeCILL v.2.1.
9 // This file was originally licensed under the terms of the CeCILL v2.1,
10 // and continues to be available under such terms.
11 // For more information, see the COPYING file which you should have received
12 // along with this program.
13
14 function res = mfile2sci(fil, results_path, Recmode, only_double, verbose_mode, prettyprintoutput)
15     // This function performs translation of a single M-file
16     // - fil: file name
17     // - results_path: path to write translated file in (default value is fil path)
18     // - Recmode: recursive mode (default value is false)
19
20     // Get default arguments
21     [lhs,rhs]=argn(0)
22     if ~isdef("prettyprintoutput","l"), prettyprintoutput = %F, end
23     if ~isdef("verbose_mode","l"),      verbose_mode = 3,       end
24     if ~isdef("only_double","l"),       only_double = %F,       end
25     if ~isdef("Recmode","l"),           Recmode = %F,           end
26     if ~isdef("results_path","l"),      results_path = ".",     end
27     if rhs<1 then
28         m2sci_gui();
29         res = [];
30         return
31     end
32     fil = strsubst(fil,filesep(),"/")
33     results_path = getshortpathname(pathconvert(results_path));
34     results_path = strsubst(results_path,"\","/")
35     res_path = results_path  // res_path: environment variable in some called functions
36
37     // Loads libraries related to m2sci
38     if exists("m2scikernellib")==0 then load("SCI/modules/m2sci/macros/kernel/lib"),end
39     if exists("m2scipercentlib")==0 then load("SCI/modules/m2sci/macros/percent/lib"),end
40     if exists("m2scisci_fileslib")==0 then load("SCI/modules/m2sci/macros/sci_files/lib"),end
41
42     if multi_fun_file(fil,results_path,Recmode,only_double,verbose_mode,prettyprintoutput) then
43         res=1
44         return
45     end
46
47     // Get context
48     global("m2sci_infos")
49     global("mtlbref_fun")
50     global("mtlbtool_fun")
51     global("not_mtlb_fun")
52     [l,mac]=where()
53     Reclevel=size(find(mac=="mfile2sci"),"*")
54     tpcallpos=min(find(mac=="translatepaths"));
55     guicallpos=min(find(mac=="m2sci_gui"));
56     if size(find(mac=="m2sci_gui"),"*")==1 & tpcallpos<guicallpos then // Bug 679
57         Reclevel=Reclevel-1
58     end
59     if size(find(mac=="multi_fun_file"),"*")==1 then
60         Reclevel=Reclevel-1
61     end
62
63     if Reclevel==1 then
64         nametbl=[]
65     else
66         m2sci_infos_save=m2sci_infos
67     end
68     m2sci_infos=[%f %f]
69
70     margin=part(" ",ones(1,3*(Reclevel-1)))
71     margin="  "
72     rec=gettext("OFF");
73     dble=gettext("NO");
74     pretty=gettext("NO");
75     if prettyprintoutput then pretty=gettext("YES");end
76     if Recmode then rec=gettext("ON");end
77     if only_double then dble=gettext("YES");end
78
79     res=[]
80
81     // Handle file path
82     // File name
83     k=strindex(fil,".")
84     if k<>[]
85         ke=k($)-1
86         base_name=part(fil,1:ke)
87     else
88         ke=length(fil)
89         base_name=fil
90     end
91     // File path
92     k=strindex(fil,"/")
93     if k==[] then
94         file_path="./"
95     else
96         file_path=part(fil,1:k($))
97     end
98     // Others M-files in directory
99     if exists("Paths")==0 then
100         Paths=file_path,
101         if getos() == "Windows" then
102             Paths=strsubst(Paths,"/","\")
103             mfiles=listfiles(Paths+"*.m")
104             sep=filesep()
105         else
106             mfiles=listfiles(Paths+"*.m")
107             sep=filesep()
108         end
109     end
110
111     // Function name
112     if k~=[] then
113         fnam = part(base_name,k($)+1:ke) // File name without extension
114     else
115         fnam = base_name
116     end
117
118     // logfile initialisation
119     if exists("logfile")==0 then
120         File = getshortpathname(pathconvert(TMPDIR))+"logfile.dat"
121         [tempfd1,ierr1] = file("open",File,"old")
122         if ierr1==0 then
123             load(File)
124             file("close",tempfd1)
125             file("close",logfile)
126             mdelete(File)
127         end
128         logfile = file("open",results_path+"m2sci_"+fnam+".log","unknown")
129         save(File, "logfile")
130     end
131
132     // Output beginning message
133     mss=[gettext("****** Beginning of mfile2sci() session ******");
134     gettext("File to convert:")+" "+fil;
135     gettext("Result file path:")+" "+results_path;
136     gettext("Recursive mode:")+" "+rec;
137     gettext("Only double values used in M-file:")+" "+dble;
138     gettext("Verbose mode:")+" "+string(verbose_mode);
139     gettext("Generate formatted code:")+" "+pretty]
140     m2sci_info(mss,-1);
141
142     // Read in the file as text
143     m2sci_info(gettext("M-file reading..."),-1);
144     txt=mgetl(fil);
145     m2sci_info(gettext("M-file reading: Done"),-1);
146
147     //Replace TAB by SPACE
148     txt=strsubst(txt, ascii(9), "");
149
150     if txt==[] then
151         m2sci_infos(msprintf(gettext("File %s is an empty file.\n"),fil),-1);
152         return
153     end
154     tmptxt=txt
155
156     // Make minor changes on syntax
157     // ----------------------------
158     m2sci_info(gettext("Syntax modification..."),-1);
159     ierr=execstr("load(''"+pathconvert(TMPDIR)+fnam+ ".tree'',''txt'',''helppart'',''batch'')","errcatch","n")
160     if ierr<>0 | exists("txt")==0 | exists("batch")==0 & ..
161                  strindex(results_path,getshortpathname(TMPDIR))==[] then
162         [helppart,txt,batch]=m2sci_syntax(txt)
163     elseif ierr==0 & newest(fil,pathconvert(TMPDIR)+fnam+ ".tree")==1 then
164         [helppart,txt,batch]=m2sci_syntax(tmptxt)
165     end
166
167     m2sci_info(gettext("Syntax modification: Done"),-1);
168
169     // Write .cat file and update whatis
170     if helppart<>[] then
171         catfil = results_path + fnam+".cat"
172         whsfil = results_path + "whatis"
173         mputl(helppart,catfil);
174         if exists("whsfil_unit")==1 then
175             write(whsfil_unit,stripblanks(helppart(1))+" |"+fnam,"(a)")
176         end
177     end
178
179     if txt~=[] then
180         quote="''";
181         dquote="""";
182         kc=strindex(txt(1),"function");
183         kc=kc(1);
184
185         // Define Scilab function
186         fprot=funcprot();
187         funcprot(0);
188
189         // Blanks in file name are replaced by _ for batch
190         // kc+9 because 'function '
191         ksc=min(strindex(txt(1),";")) // searching for a comment on first line after function prototype
192         if isempty(ksc) then
193             ksc=length(txt(1))+1;
194             firstline=[]
195         else
196             firstline=part(txt(1),ksc+1:length(txt(1)));
197         end
198
199         // Extraction of the macro's name
200         func_proto=part(txt(1),kc+9:ksc-1)
201         keq=min(strindex(func_proto,"="))
202         kpar=min(strindex(func_proto,"("))
203         if isempty(keq) then
204             keq=1
205         end
206         if isempty(kpar) then
207             kpar=length(func_proto)+1
208         end
209
210         func_proto=part(func_proto,1:keq)+strsubst(stripblanks(part(func_proto,keq+1:kpar-1))," ","_")+part(func_proto,kpar:length(func_proto))
211
212         mname = getMacroNameFromPrototype(func_proto)
213         if mname=="" | mname==[]
214             msg = _("%s: ""%s"" does not exist or is not the macro name.\n");
215             error(msprintf(msg,"mfile2sci", mname))
216         end
217         w = mname;
218         nametbl=[nametbl;mname]
219         if fnam<>mname & ~batch then // warning is not displayed for a batch file
220             mss=msprintf(gettext("Warning: file %s defines function %s instead of %s\n         %s.sci, %s.cat and sci_%s.sci will be generated !"),fil,mname,fnam,mname,mname,mname);
221             m2sci_info(mss,-1);
222         end
223
224         txt($+1) = "endfunction"
225         // Compilation
226         txt = [part(txt(1),kc:ksc-1);firstline;txt(2:$)]
227         mputl(txt, TMPDIR+"/"+mname+".sci");
228         err = exec(TMPDIR+"/"+mname+".sci", "errcatch", -1);
229         if err~=0
230             // Maybe a final {end} closing {function} => try without it
231             txt($) = []   // removing "endfunction"
232             while size(txt,1)>0 & stripblanks(txt($))==""
233                 txt($) = []
234             end
235             if size(txt,1)>0 & stripblanks(txt($))=="end" then
236                 txt($) = []
237                 txt = [txt ; "endfunction"]
238                 mputl(txt, TMPDIR+"/"+mname+".sci");
239             end
240             exec(TMPDIR+"/"+mname+".sci", -1);
241         end
242         funcprot(fprot);
243         mdelete(TMPDIR+"/"+mname+".sci");
244
245         // Get Scilab pseudo code of the function
246         m2sci_info(gettext("Macro to tree conversion..."),-1);
247         macr=evstr(mname)
248         mtlbtree=macr2tree(macr);
249         if ~batch then
250             mtlbtree.name=mname;
251         else
252             mtlbtree.name="";
253         end
254
255         //Transfom a equal instructions(if lhs are multi_operation insert and expression is a funcall) in the matlab tree to sup_equal instructions
256         global("tmpvarnb")
257         tmpvarnb=0;
258         level=[0,0];
259         ninstr=1;
260         while ninstr<=size(mtlbtree.statements)-3
261             mtlbtree.statements(ninstr)=transformtree(mtlbtree.statements(ninstr))
262             ninstr=ninstr+1
263         end
264
265         // Perform the translation
266         [scitree,trad,hdr,crp]=m2sci(mtlbtree,w(1),Recmode,prettyprintoutput)
267
268         //Creation of fname_resume.log file
269         // if mtlbref_fun<>[]|not_mtlb_fun<>[]|mtlbtool_fun<>[] then
270         //resume_logfile initialisation
271         if exists("resume_logfile")==0 then
272             File = getshortpathname(pathconvert(TMPDIR))+gettext("resumelogfile.dat")
273             [tempfd2,ierr2] = file("open",File,"old")
274             if ierr2==0 then
275                 load(pathconvert(TMPDIR)+gettext("resumelogfile.dat"))
276                 file("close", tempfd2)
277                 file("close", resume_logfile)
278                 mdelete(pathconvert(TMPDIR)+gettext("resumelogfile.dat"))
279             end
280             resume_logfile = results_path+gettext("resume")+"_m2sci_"+fnam+".log"
281             resume_logfile = file("open", resume_logfile, "unknown")
282             save(pathconvert(TMPDIR)+gettext("resumelogfile.dat"), "resume_logfile")
283         end
284
285         //number of matlab reference functions, matlab toolboxes functions, not matlab functions
286         size1=size(mtlbref_fun,1)
287         size2=size(mtlbtool_fun,1)
288         size3=size(not_mtlb_fun,1)
289
290         if size(mtlbref_fun,"*")<>0 then
291             mtlbref_fun(:,1) = """"+mtlbref_fun(:,1)+"""";
292             mtlbref_fun12 = mtlbref_fun(:,1) + mtlbref_fun(:,2);
293         else
294             mtlbref_fun12 = [];
295         end
296         if size(mtlbtool_fun,"*")<>0 then
297             mtlbtool_fun(:,1) = """"+mtlbtool_fun(:,1)+"""";
298             mtlbtool_fun12 = mtlbtool_fun(:,1) + mtlbtool_fun(:,2);
299         else
300             mtlbtool_fun12 = [];
301         end
302         if size(not_mtlb_fun,"*")<>0 then
303             not_mtlb_fun(:,1) = """"+not_mtlb_fun(:,1)+"""";
304             not_mtlb_fun12 = not_mtlb_fun(:,1) + not_mtlb_fun(:,2);
305         else
306             not_mtlb_fun12 = [];
307         end
308
309         info_resume=[msprintf(gettext("****** %s: Functions of mfile2sci() session ******"),fnam);
310         "*";
311         msprintf(gettext("%d Matlab Function(s) not yet converted, original calling sequence used:"),size1);
312         mtlbref_fun12;
313         "*";
314         msprintf(gettext("%d Matlab Toolbox(es) Functions, original calling sequence used :"),size2);
315         mtlbtool_fun12;
316         "*";
317         msprintf(gettext("%d Unknown Function(s), original calling sequence used :"),size3);
318         not_mtlb_fun12;
319         "*"]
320
321         write(resume_logfile,margin+info_resume)
322         file("close",resume_logfile)
323         mdelete(pathconvert(TMPDIR)+gettext("resumelogfile.dat"))
324         //end
325
326         m2sci_info(gettext("Macro to tree conversion: Done"),-1);
327
328         crp(1)=""; // Delete function prototype
329         if isempty(firstline) then
330             res=[hdr;crp]
331         else
332             hdr(1)=hdr(1)+" "+crp(2);
333             crp(2)=[];
334             res=[hdr;crp];
335         end
336
337         // Strip last return and blank lines
338         n=size(res,1)
339         while res(n)==part(" ",1:length(res(n))) then
340             n=n-1
341         end
342         res=res(1:n)
343
344         // Write sci-file
345         ext = ".sci"
346         scifil = results_path + fnam + ext
347         mputl(res, scifil);
348
349         // Write sci_<mname>.sci translation file
350         if trad<>[] then
351             sci_fil = results_path + "sci_" + mname + ".sci"
352             mputl(trad,sci_fil);
353             res=1
354         else
355             res=0
356         end
357
358         // Output summary information
359         infos = []
360         if m2sci_infos(1) then
361             infos = gettext("Translation may be improved: see the //! comments and for all mtlb_<funname> function call\n  Type help mtlb_<funname> in Scilab command window to get information about improvements.");
362         end
363         if m2sci_infos(2) then
364             infos = [infos ; gettext("Translation may be wrong (see the //!! comments).")]
365         end
366
367         nametbl($)=[]
368
369     else
370         infos=gettext("File contains no instruction, no translation made...");
371     end
372
373     // End of translation messages
374     mss=gettext("****** End of mfile2sci() session ******");
375
376     m2sci_info([infos;mss],-1);
377
378     if Reclevel>1 then
379         m2sci_infos = m2sci_infos_save
380     end
381
382     file("close", logfile)
383     clearglobal m2sci_infos
384     clearglobal mtlbref_fun
385     clearglobal mtlbtool_fun
386     clearglobal not_mtlb_fun
387     // For execution called by translatepaths()
388     //nametbl=resume(nametbl)
389     mdelete(pathconvert(TMPDIR)+fnam+ ".tree")
390     mdelete(pathconvert(TMPDIR)+"logfile.dat")
391
392 endfunction
393
394 // ---------------------------------------------------------------------------
395
396 function funcname = getMacroNameFromPrototype(proto)
397     // PRIVATE UTILITY FUNCTION called only by mfile2sci()
398     //
399     // Extraction of the macro's name
400     tmp = tokens(proto,["(" "=" ")"]);
401     if size(tmp,1)>1
402         [?,?,?,funcname] = regexp(proto, "/(?:.*?=(.*?)\(|(.*?)\(|[^(]+?=\s*([^(]+))/","o");
403         funcname = stripblanks(funcname);
404         funcname(funcname=="") = [];
405     else
406         funcname = proto;
407     end
408     // proto = "[b,hy]=fun2(bar=3)";
409     // proto = "fun3 (bar=3)";
410     // proto = "a = fun4 ()";
411     // proto = "fun5";
412     // proto = "a = fun6"; // from bug_2341 use case
413 endfunction
414
415 // ---------------------------------------------------------------------------
416
417 function instr = transformtree(instr)
418     // PRIVATE UTILITY FUNCTION called only by mfile2sci()
419     //
420     // Copyright (C) 2004-2006 - INRIA - Farid BELAHCENE
421     //
422     //TRANSFORMTREE function
423     //This function research and transform the equal instructions(if the lhs are a multi_operation and expression is a funcall)
424     //of the matlab tree to a sup_equal instructions
425     //sup_equal is a tlist : tlist([sup_equal,sup_instr,nb_op],sup_instr,nb_op)
426     //i.e : the equal instruction [a(1),b(2:3)]=f() is replaced by
427     //sup_equal, whith sup_intr list is composed to :
428     //[%v1,%v2]=f()
429     //a(1)=%v1
430     //b(2:3)=%v2
431     //and nb_op is: the number of insert operation (in this case 2)
432     //Input
433     //instr : instruction of matlab tree before tranformation
434     //Output
435     //instr : instruction of matlab tree after transformation
436
437     Unknown=-1;
438     // Browse all the instrucions of the matlab tree:
439     if typeof(instr)=="ifthenelse" then
440         for i=1:size(instr.then)
441             instr.then(i)=transformtree((instr.then(i)))
442         end
443         for i=1:size(instr.elseifs)
444             for k=1:size(instr.elseifs(i).then)
445                 instr.elseifs(i).then(k)=transformtree((instr.elseifs(i).then(k)))
446             end
447         end
448         for i=1:size(instr.else)
449         instr.else(i)=transformtree((instr.else(i)))
450         end
451     elseif typeof(instr)=="selectcase" then
452         for i=1:size(instr.cases)
453             for j=1:size(instr.cases(i).then)
454                 instr.cases(i).then(j)=transformtree((instr.cases(i).then(j)))
455             end
456         end
457         for i=1:size(instr.else)
458         instr.else(i)=transformtree(instr.else(i))
459         end
460     elseif typeof(instr)=="while" then
461         for i=1:size(instr.statements)
462             instr.statements(i)=transformtree(instr.statements(i))
463         end
464     elseif typeof(instr)=="for" then
465         for i=1:size(instr.statements)
466             instr.statements(i)=transformtree(instr.statements(i))
467         end
468         //instruction is an equal instruction
469     elseif typeof(instr)=="equal" then
470         if typeof(instr.expression)=="funcall" then //expression is a funcall
471             nb_opr=0;
472             for ind=1:size(instr.lhs)
473                 if typeof(instr.lhs(ind))=="operation" then
474                     nb_opr=nb_opr+1
475                 end
476             end
477             if nb_opr>1 then //more than one lhs insert operation
478                 sup_instr=list("");
479                 lhstemp=list();
480                 for j=1:size(instr.lhs)
481                     if typeof(instr.lhs(j))=="operation" then
482                         x=gettempvar();
483                         sup_instr($+1)=Equal(list(instr.lhs(j)),x);
484                         lhstemp(j)=x;
485                     else
486                         lhstemp(j)=instr.lhs(j)
487                     end
488                 end
489                 sup_instr(1)=Equal(lhstemp,instr.expression)
490                 //creation of the sup_equal
491                 instr=tlist(["sup_equal","sup_instr","nb_opr"],sup_instr,nb_opr)
492             end
493         end
494     end
495 endfunction
496
497 // ---------------------------------------------------------------------------
498
499 function bval = multi_fun_file(fil,res_path,Recmode,only_double,verbose_mode,prettyprintoutput)
500     // PRIVATE UTILITY FUNCTION called only by mfile2sci()
501     //
502     // This function converts M-Files containing more than one function
503     // Inputs are the same as mfile2sci()
504     // Outputs :
505     // - bval: boolean value, %t if file contains more than on function, %f else
506
507     sciparam();
508
509     // File name
510     k=strindex(fil,".")
511     if k<>[]
512         ke=k($)-1
513         base_name=part(fil,1:ke)
514     else
515         ke=length(fil)
516         base_name=fil
517     end
518     // File path
519     k=strindex(fil,"/")
520     if k==[] then
521         file_path="./"
522     else
523         file_path=part(fil,1:k($))
524         base_name=part(base_name,k($)+1:ke)
525     end
526
527     txt=mgetl(fil);
528
529     kf=grep(txt,["function[","function "])
530
531     if isempty(kf) then
532         // Batch file
533         bval=%f
534     elseif size(kf,"*")==1 then
535         // Only one function defined
536         bval=%f
537     else
538         funcdecl=[]
539         for kk=kf
540             ind=strindex(txt(kk),["function[";"function "])
541             if isacomment(txt(kk))==0 & ~isinstring(txt(kk),ind) & part(stripblanks(txt(kk),%T),1:8)=="function"  then // function prototype
542                 funcdecl=[funcdecl kk]
543             end
544         end
545
546         if isempty(funcdecl) then
547             // "function" only exists in comments and strings
548             bval=%f
549             return
550         elseif size(funcdecl,"*")==1 then
551             bval=%f
552             return
553         end
554
555         // Verify if the directory exists
556         dirnam = ls(pathconvert(TMPDIR)+base_name);
557
558         sep = filesep();
559
560         if or(dirnam<>"") then
561             rmdir(pathconvert(TMPDIR)+base_name,"s")
562         end
563         mkdir(pathconvert(TMPDIR),base_name)
564         write(%io(2),msprintf(gettext(" -- File %s contains more than one function -- "),fil));
565
566         bval= %t
567
568         // First split file into as many files as function declared
569         funcdecl=[funcdecl size(txt,"*")+1]
570
571         tmpfiles=[]
572         for k=1:size(funcdecl,"*")-1
573             functxt=txt(funcdecl(k):funcdecl(k+1)-1)
574             str=  strindex(txt(funcdecl(k)),"(")
575             if str==[] then
576                 funcname=stripblanks(part(txt(funcdecl(k)),strindex(txt(funcdecl(k)),["function[","function "])+8:length(txt(funcdecl(k)))))
577             else
578                 funcname=stripblanks(part(txt(funcdecl(k)),strindex(txt(funcdecl(k)),["function[","function "])+8:str(1)-1))
579             end
580
581             keq=strindex(funcname,"=")
582             if ~isempty(keq) then
583                 funcname=stripblanks(part(funcname,keq+1:length(funcname)))
584             end
585             tmpfiles=[tmpfiles;funcname]
586             mputl(functxt,pathconvert(TMPDIR)+base_name+sep+tmpfiles($)+".m");
587         end
588
589         write(%io(2),msprintf(gettext(" -- Each function converted separately: %s -- "),strcat(tmpfiles," ")));
590         write(%io(2),msprintf(gettext(" -- Temporary files put in: %s -- "),pathconvert(TMPDIR)));
591
592         // Conversion of each file
593
594         for k=1:size(tmpfiles,"*")
595             txt=mgetl(pathconvert(TMPDIR)+base_name+sep+tmpfiles(k)+".m")
596             //mfile2sci(pathconvert(TMPDIR)+tmpfiles(k)+".m",res_path,Recmode,only_double,verbose_mode,prettyprintoutput)
597         end
598
599         translatepaths(pathconvert(TMPDIR)+base_name,pathconvert(TMPDIR)+base_name)
600
601         txt=[]
602         if isfile(pathconvert(TMPDIR)+base_name+sep+"log") then
603             txt=mgetl(pathconvert(TMPDIR)+base_name+sep+"log")
604         end
605         mputl(txt,res_path+"log");
606         if isfile(pathconvert(TMPDIR)+base_name+sep+"resumelog") then
607             txt=mgetl(pathconvert(TMPDIR)+base_name+sep+"resumelog")
608         end
609         mputl(txt,res_path+"resumelog");
610
611         // Catenation of all .sci files to have only one output file
612         txt=[]
613         for k=1:size(tmpfiles,"*")
614             txt=[txt ;"";mgetl(pathconvert(TMPDIR)+base_name+sep+tmpfiles(k)+".sci")]
615         end
616
617         // Delete useless .sci files
618         //for k=1:size(tmpfiles,"*")
619         //mdelete(res_path+tmpfiles(k)+".sci")
620         //end
621
622         mputl(txt,res_path+base_name+".sci");
623
624         // Catenation of all .log files to have only one output file
625         //if exists("logfile")==0 then
626         //txt=[]
627         //for k=1:size(tmpfiles,"*")
628         //txt=[txt ; mgetl(pathconvert(TMPDIR)+base_name+sep+"m2sci_"+tmpfiles(k)+".log")]
629         //end
630
631         // Delete useless .log files
632         //for k=1:size(tmpfiles,"*")
633         //mdelete(pathconvert(TMPDIR)+base_name+sep+"m2sci_"+tmpfiles(k)+".log")
634         //end
635
636         //mputl(txt,res_path+"m2sci_"+base_name+".log");
637         //end
638
639         // Catenation of all resume.log files to have only one output file
640         //if exists("resume_logfile")==0 then
641         //txt=[]
642         //for k=1:size(tmpfiles,"*")
643         //txt=[txt ; mgetl(res_path+"m2sci_"+tmpfiles(k)+"_resume.log")]
644         //end
645
646         // Delete useless _resume.log files
647         //for k=1:size(tmpfiles,"*")
648         //mdelete(res_path+"m2sci_"+tmpfiles(k)+"_resume.log")
649         //end
650
651         //mputl(txt,res_path+"m2sci_"+base_name+"_resume.log");
652         //end
653
654         // Delete useless .m files
655         //for k=1:size(tmpfiles,"*")
656         //mdelete(pathconvert(TMPDIR)+tmpfiles(k)+".m")
657         //end
658
659         rmdir(pathconvert(TMPDIR)+base_name,"s")
660         for k=1:size(tmpfiles,"*")
661             mdelete(pathconvert(TMPDIR)+tmpfiles(k)+".tree")
662         end
663     end
664
665 endfunction