1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) ???? - INRIA - Scilab
3 // Copyright 2018 - Samuel GOUGEON
5 // Copyright (C) 2012 - 2016 - Scilab Enterprises
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.
14 function txt = i_notation(txt)
15 // This function changes 1i ,... by 1*i,...
17 // M2SCI kernel functions called :
20 // To succeed in this work, we successively suppress occurences which can be proved not to be complex notation
21 // Until we are 'sure' to have a complex notation
26 matches=[string(0:9)+I(ones(1,10)),".i",string(0:9)+J(ones(1,10)),".j"]
27 symbs=["+","-","*","/","\","(","["," ","^"," ",",",";","=","{"]
28 s1=["+","-","*","/","\",",",";"," ","^",".","&","|","''","]",")","}"]
29 s2=[string(0:9),"d","e","D","E","."]
32 // Isolate a possible appended comment
33 st=strindex(txt(k),[";//","//"])
37 for stk=1:size(st,"*")
38 if ~isinstring(txt(k),st(stk)) then
39 endComment = part(txt(k), st(stk):$);
40 tk = part(txt(k), 1:st(stk)-1)
46 // Find possible occurence of complex notation
47 kc=strindex(tk,matches)
49 // Kill indexes which point to non complex values (e.g. : a1item...)
50 for kk=size(kc,"*"):-1:1
52 if find(part(tk,km)==s1)==[] then kc(kk)=[],end
57 for kk=size(kc,"*"):-1:2
60 // Reads numeric value leading complex variable
61 while or(part(tk,km)==s2)
63 if km<=kc(kk-1)+1 then
71 num=part(tk,km+1:kc(kk)-1)
72 ke=strindex(convstr(num),["e","d"])
73 kd=strindex(convstr(num),".")
75 // Searching for invalid numeric values (more than one dot...)
76 if size(ke,2)>1|size(kd,2)>1 then
78 elseif size(ke,2)==1&size(kd,2)==1 then
79 if ke<kd then tokill=%T,end
83 // If char which follows supposed complex notation is not an operation symbol
85 if and(part(tk,km)<>symbs) then tokill=%T,end
91 // If supposed complex notation is not in a string
92 if ~isinstring(tk,km) then
93 tk=part(tk,1:km)+"*%"+part(tk,km+1:length(tk))
97 txt(k) = tk + endComment