~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to macros/sci2for/f_maxi.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [stk,nwrk,txt,top]=f_maxi(nwrk)
 
2
//!purpose
 
3
//  Scilab maxi function translation
 
4
//!
 
5
txt=[]
 
6
select rhs
 
7
case 1 then
 
8
  s2=stk(top)
 
9
  if lhs==1 then
 
10
    if s2(3)=='0' then fun='ivmax',else fun='dvmax',end
 
11
    nwrk=dclfun(nwrk,fun,s2(3))
 
12
    out=callfun([fun,mulf(s2(4),s2(5)),s2(1),'1'],s2(3))
 
13
    stk=list(out,'0',s2(3),'1','1')
 
14
  else
 
15
    [out,nwrk,t1]=outname(nwrk,[s2(3);'0'],['1';'1'],['1';'1'])
 
16
    w=getentry1(s2(1),'loop')
 
17
    txt=[t1;
 
18
        ' '+out(2)+'='+getentry1(s2(1),'1')
 
19
        ' do loop=2,'+mulf(s2(4),s2(5))
 
20
        indentfor(genif(w+'.gt.'+out(2),..
 
21
            [' '+out(2)+'='+w;
 
22
             ' '+out(1)+'=loop']))
 
23
       ' enddo']
 
24
    stk=list(list(out(1),'-1','1','1','1'),list(out(2),'-1','0','1','1'))
 
25
  end
 
26
case 2 then
 
27
  s2=stk(top);s1=stk(top-1);top=top-1
 
28
  if lhs==1 then
 
29
    if s2(4)=='1'&s2(5)=='1'&s1(4)=='1'&s1(5)=='1'then
 
30
      stk=list('max('+s1(1)+','+s2(1)+')','0',s2(3),'1','1')
 
31
    else
 
32
      warning('max with 2 matrix args not translated')
 
33
    end
 
34
  else
 
35
    warning('max with 2 lhs arguments not translated')
 
36
  end
 
37
else
 
38
  warning('max with more than 2 args not translated')
 
39
end
 
40
 
 
41
function var=getentry1(var,i)
 
42
if part(var,1:5)=='work(' then
 
43
  pti=part(var,6:length(var)-1)
 
44
  
 
45
  var='work('+addf(pti,addf(i,'-1'))+')'
 
46
elseif  part(var,1:6)=='iwork(' then
 
47
  pti=part(var,7:length(var)-1)
 
48
  var='iwork('+addf(pti,addf(i,'-1'))+')'
 
49
else
 
50
  var=var+'('+i+')'
 
51
end