File: i_notation.sci

package info (click to toggle)
scilab 5.3.3-10
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 330,656 kB
file content (94 lines) | stat: -rw-r--r-- 2,420 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) ???? - INRIA - Scilab
// 
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at    
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt

function txt=i_notation(txt)
// This function changes 1i ,... by 1*i,...

// M2SCI kernel functions called :
//  - isinstring


// To succeed in this work, we successively suppress occurences which can be proved not to be complex notation
// Until we are 'sure' to have a complex notation

n=size(txt,"r")

I="i";J="j"
matches=[string(0:9)+I(ones(1,10)),".i",string(0:9)+J(ones(1,10)),".j"]
symbs=['+','-','*','/','\','(','[',' ','^',' ',',',';','=','{']
s1=['+','-','*','/','\',',',';',' ','^','.','&','|','''',']',')','}']
s2=[string(0:9),'d','e','D','E','.']

for k=1:n
  st=strindex(txt(k),[";//","//"])
  if st<> [] then
    for stk=1:size(st,"*")
       if ~isinstring(txt(k),stk) then
       break
       end
    end
    continue
  end
  tk=txt(k)+' '
  
  // Find possible occurence of complex notation
  kc=strindex(tk,matches)
  
  // Kill indexes which point to non complex values (e.g. : a1item...)
  for kk=size(kc,'*'):-1:1
    km=kc(kk)+2
    if find(part(tk,km)==s1)==[] then kc(kk)=[],end
  end

  kc=[0 kc]
  
  for kk=size(kc,'*'):-1:2
    km=kc(kk)
    num=%T
    // Reads numeric value leading complex variable
    while or(part(tk,km)==s2)
      km=km-1
      if km<=kc(kk-1)+1 then 
	km=kc(kk-1);
	num=%F;
	break
      end
    end
    
    tokill=%F
    num=part(tk,km+1:kc(kk)-1)
    ke=strindex(convstr(num),['e','d'])
    kd=strindex(convstr(num),'.')
    
    // Searching for invalid numeric values (more than one dot...)
    if size(ke,2)>1|size(kd,2)>1 then
      tokill=%T
    elseif size(ke,2)==1&size(kd,2)==1 then
      if ke<kd then tokill=%T,end
    end
    
    
    if ~tokill then
      // If char which follows supposed complex notation is not a operation symbol
      if km<>kc(kk-1) then
	if and(part(tk,km)<>symbs) then tokill=%T,end
      end
    end

    if ~tokill then
      km=kc(kk)
      // If supposed complex notation is not in a string
      if ~isinstring(tk,km) then
	tk=part(tk,1:km)+'*%'+part(tk,km+1:length(tk))
      end
    end
  end
  txt(k)=tk
end
endfunction