File: i_notation.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (87 lines) | stat: -rw-r--r-- 2,042 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
function txt=i_notation(txt)
// Copyright INRIA

// 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