File: setvalue.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (188 lines) | stat: -rw-r--r-- 6,516 bytes parent folder | download
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
function [ok,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17,x18]=setvalue(desc,labels,typ,ini)
//  setvalues -  data acquisition, getvalue equivalent without dialog
//%Syntax
//  [ok,x1,..,x18]=setvalue(desc,labels,typ,ini)
//%Parameters
//  desc    : column vector of strings, dialog general comment 
//  labels  : n column vector of strings, labels(i) is the label of 
//            the ith required value
//  typ     : list(typ1,dim1,..,typn,dimn)
//            typi : defines the type of the ith required value
//                   if may have the following values:
//                   'mat' : stands for matrix of scalars 
//                   'col' : stands for column vector of scalars
//                   'row' : stands for row vector of scalars
//                   'vec' : stands for  vector of scalars
//                   'str' : stands for string
//                   'lis' : stands for list
//                   'pol' : stands for polynomials
//                   'r'   : stands for rational
//            dimi : defines the size of the ith required value
//                   it must be 
//                    - an integer or a 2-vector of integers (-1 stands for 
//                      arbitrary dimension)
//                    - an evaluatable character string 
//  ini     : n column vector of strings, ini(i) gives the suggested
//            response for the ith required value
//  ok      : boolean ,%t if ok button pressed, %f if cancel button pressed
//  xi      : contains the ith required value if ok==%t
//%Description
// getvalues function uses ini strings to evaluate required args 
// with error checking,
//%Remarks
// All correct scilab syntax may be used as responses, for matrices 
// and vectors getvalues automatically adds [ ] around the given response
// before numerical evaluation
//%Example
// labels=['magnitude';'frequency';'phase    '];
// [ampl,freq,ph]=setvalue('define sine signal',labels,..
//            list('vec',1,'vec',1,'vec',1),['0.85';'10^2';'%pi/3'])
// 
//%See also
// x_mdialog, dialog
//!
// Copyright INRIA
[lhs,rhs]=argn(0)
n=prod(size(labels))
if lhs<>n+2&lhs<>n+1 then error(41),end
if size(typ)<>2*n then
  error('typ : list(''type'',[sizes],...)')
end
x1=[];x2=[];x3=[];x4=[];x5=[];x6=[];x7=[];x8=[];x9=[];x10=[];x11=[];x12=[];x13=[];x14=[]
if rhs==3 then  ini=emptystr(n,1),end
ok=%t
while %t do
  str=ini;
  if str==[] then ok=%f,break,end
  for k=1:n
    cod=str2code(str(k))
    spe=find(cod==99)
    if spe<>[] then
      semi=str2code(';')
      cod(spe)=semi*ones(spe')
      str(k)=code2str(cod)
    end
  end
  nok=0
  for k=1:n
    select part(typ(2*k-1),1:3)
    case 'mat'
      errcatch(-1,'continue','nomessage')
      v=evstr('['+str(k)+']')
      errcatch(-1)
      if iserror(-1) then nok=-k,errclear(-1);break,end
      if type(v)<>1 then nok=-k,break,end
      sz=typ(2*k);if type(sz)==10 then sz=evstr(sz),end
      [mv,nv]=size(v)
      ssz=string(sz(1))+' x '+string(sz(2))
      if mv*nv==0 then
	if  sz(1)>=0&sz(2)>=0&sz(1)*sz(2)<>0 then nok=k,break,end
      else
	if sz(1)>=0 then if mv<>sz(1) then nok=k,break,end,end
	if sz(2)>=0 then if nv<>sz(2) then nok=k,break,end,end
      end
    case 'vec'
      errcatch(-1,'continue','nomessage')
      v=evstr('['+str(k)+']')
      errcatch(-1)
      if iserror(-1) then nok=-k,errclear(-1);break,end
      if type(v)<>1 then nok=-k,break,end
      sz=typ(2*k);if type(sz)==10 then sz=evstr(sz),end
      ssz=string(sz(1))
      nv=prod(size(v))
      if sz(1)>=0 then if nv<>sz(1) then nok=k,break,end,end
    case 'pol'
      errcatch(-1,'continue','nomessage')
      v=evstr('['+str(k)+']')
      errcatch(-1)
      if iserror(-1) then nok=-k,errclear(-1);break,end
      if type(v)>2 then nok=-k,break,end
      sz=typ(2*k);if type(sz)==10 then sz=evstr(sz),end
      ssz=string(sz(1))
      nv=prod(size(v))
      if sz(1)>=0 then if nv<>sz(1) then nok=k,break,end,end
    case 'row'
      errcatch(-1,'continue','nomessage')
      v=evstr('['+str(k)+']')
      errcatch(-1)
      if iserror(-1) then nok=-k,errclear(-1);break,end
      if type(v)<>1 then nok=-k,break,end
      sz=typ(2*k);if type(sz)==10 then sz=evstr(sz),end
      if sz(1)<0 then
	ssz='1 x *'
      else
	ssz='1 x '+string(sz(1))
      end
      [mv,nv]=size(v)
      if mv<>1 then nok=k,break,end,
      if sz(1)>=0 then if nv<>sz(1) then nok=k,break,end,end
    case 'col'
      errcatch(-1,'continue','nomessage')
      v=evstr('['+str(k)+']')
      errcatch(-1)
      if iserror(-1) then nok=-k,errclear(-1);break,end
      if type(v)<>1 then nok=-k,break,end
      sz=typ(2*k);if type(sz)==10 then sz=evstr(sz),end
      if sz(1)<0 then
	ssz='* x 1'
      else
	ssz=string(sz(1))+' x 1'
      end
      [mv,nv]=size(v)
      if nv<>1 then nok=k,break,end,
      if sz(1)>=0 then if nv<>sz(1) then nok=k,break,end,end
    case 'str'
      v=str(k)
      if type(v)<>10 then nok=-k,break,end
      sz=typ(2*k);if type(sz)==10 then sz=evstr(sz),end
      ssz=string(sz(1))
      nv=prod(size(v))
      if sz(1)>=0 then if nv<>1 then nok=k,break,end,end
    case 'lis'
      errcatch(-1,'continue','nomessage')
      v=evstr(str(k))
      errcatch(-1)
      if iserror(-1) then nok=-k,errclear(-1);break,end
      if type(v)<>15& type(v)<>16 then nok=-k,break,end
      sz=typ(2*k);if type(sz)==10 then sz=evstr(sz),end
      ssz=string(sz(1))
      nv=size(v)
      if sz(1)>=0 then if nv<>sz(1) then nok=k,break,end,end
    case 'r  '
      errcatch(-1,'continue','nomessage')
      v=evstr('['+str(k)+']')
      errcatch(-1)
      if iserror(-1) then nok=-k,errclear(-1);break,end
      if type(v)<>16 then nok=-k,break,end
      if h(1)<>'r' then nok=-k,break,end
      sz=typ(2*k);if type(sz)==10 then sz=evstr(sz),end
      [mv,nv]=size(v(2))
      ssz=string(sz(1))+' x '+string(sz(2))
      if mv*nv==0 then
	if  sz(1)>=0&sz(2)>=0&sz(1)*sz(2)<>0 then nok=k,break,end
      else
	if sz(1)>=0 then if mv<>sz(1) then nok=k,break,end,end
	if sz(2)>=0 then if nv<>sz(2) then nok=k,break,end,end
      end
    else
      error('type non gere :'+typ(2*k-1))
    end
    execstr('x'+string(k)+'=v')
  end
  if nok>0 then 
    message(['answer given for  '+labels(nok);
             'has invalid dimension: ';
             'waiting for dimension  '+ssz])
    ini=str
  elseif nok<0 then
    message(['answer given for  '+labels(-nok);
             'has incorrect type :'+ typ(-2*nok-1)])
    ini=str
  else
    break
  end 
end
if lhs==n+2 then
  execstr('x'+string(lhs-1)+'=str')
end