File: rwstack.f

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 (288 lines) | stat: -rw-r--r-- 7,885 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
      subroutine readmat(name,m,n,scimat)
c     see creadmat 
c     ==========================================
c     Copyright INRIA
      double precision scimat(m,*)
      integer m,n
      logical creadmat,j
      character*(*) name
      j=creadmat(name,m,n,scimat)
      return
      end

      logical function creadmat(name,m,n,scimat)
c     ==========================================
c!purpose
c     readmat reads vector/matrix in scilab's internal stack
c
c!calling sequence
c     logic=creadmat('matrixname',m,n,scimat)
c
c  matrixname: character string; name of the scilab variable.
c  m: number of rows (output of readmat)
c  n: number of columns (output of readmat)
c  scimat: matrix entries stored columnwise (output of readmat)
c 
c    Example of use:
c    Amat is a real 2 x 3 scilab matrix
c    your subroutine should be as follows:
c
c    subroutine mysubr(...)
c
c    ...
c    call readmat('Amat',m,n,scimat)
c    => m=3 , n=2, and scimat(1)=Amat(1,1)
c                      scimat(2)=Amat(2,1)
c                      scimat(3)=Amat(3,1)
c                      scimat(4)=Amat(1,2) ...
c                      scimat(5)=Amat(3,2)
c!
c     ==========================================
      integer m,n
      logical getrmat
      character*(*) name
      double precision scimat(m,*)
c
      include '../stack.h'
      integer il,it,l,id(nsiz)
      creadmat=.false.
      call str2name(name,id)
c     read   : from scilab stack -> fortran variable
c     -------
      fin=-1
      call stackg(id)
      if (err .gt. 0) return
      if (fin .eq. 0) then
         call putid(ids(1,pt+1),id)
         call error(4)
         return
      endif
      if(.not.getrmat('creadmat',fin,fin,m,n,l))return
      call dmcopy(stk(l),m,scimat,m,m,n)
      creadmat=.true.
      return
      end

      logical function cwritemat(name,m,n,mat)
c     =========================================
c!purpose
c     cwritemat writes vector/matrix in scilab's internal stack
c
c!calling sequence
c     logic=cwritemat('matrixname'//char(0),m,n,mat)
c
c  name: character string; name of the scilab variable ( null terminated)
c  m: number of rows
c  n: number of columns 
c  mat: matrix entries stored columnwise in Scilab object 
c    call readmat('Amat',m,n,scimat)
c!
c     =========================================
      character*(*) name
      double precision mat(*)
      include '../stack.h'
      integer id(nsiz),m,n,lr,lc,srhs,l4
      logical cremat
      cwritemat=.false.
      call str2name(name,id)
      top=top+1
      if(.not.cremat('cwritemat',top,0,m,n,lr,lc)) return
      call dcopy(m*n,mat,1,stk(lr),1)
      srhs=rhs
      rhs=0
      l4=lct(4)
      lct(4)=-1
      call stackp(id,0)
      lct(4)=l4
      top=top-1
      rhs=srhs
      if(err.gt.0) return
      cwritemat=.true.
      return
      end

      subroutine readchain(name,itslen,chai)
c     see creadchain
c     ==========================================
      character*(*) chai,name
      logical creadchain,j 
      j=creadchain(name,itslen,chai)
      return
      end


      logical function creadchain(name,itslen,chai)
c     ==========================================
c!but
c     this routine reads a string in scilab's  memory
c     and store it into chai 
c!calling sequence
c
c     integer       itslen
c     character*(*) chai,name
c
c     name    : character string = name of scilab variable (input)
c     chai    : chain to be read (output) 
c               null terminated 
c     itslen  : (input) maximum number of character that can ne stored
c               in chain 
c               (output) number of copied characters into chai
c               
c               
c     if Scilab variable x='qwert' exists 
c     character ch*(10)
c     l=10
c     logic= creadchain('x',l,ch) returns l=5 and ch='qwert'
c
c     ==========================================
      character*(*) chai,name
      include '../stack.h'
      integer id(nsiz),m1,n1,lr1,nlr1
      logical getsmat
      iadr(l)=l+l-1
      creadchain=.false.
      call str2name(name,id)
      fin=-1
      call stackg(id)
      if(err.gt.0) return
      if(fin.eq.0)  then 
         call putid(ids(1,pt+1),id)
         call error(4)
         return
      endif
      if(.not.getsmat('creadchain',fin,fin,m1,n1,1,1,lr1,nlr1)) 
     $     return
      if( m1*n1.ne.1) then 
         buf = 'creadchain' // ': argument must be a string '
         call error(999)
         return
      endif
      itslen=min(itslen-1,nlr1)
      call cvstr(itslen,istk(lr1),chai,1)
      chai(itslen+1:itslen+1)=char(0)
      creadchain=.true.
      end

      logical function cwritechain(name,m,chai)
c     =========================================
c!purpose
c     cwritemat writes vector/matrix in scilab's internal stack
c
c!calling sequence
c     logic=cwritemat('matrixname'//char(0),m,n,mat)
c
c  name: character string; name of the scilab variable ( null terminated)
c  m: number of rows
c  n: number of columns 
c  mat: matrix entries stored columnwise in Scilab object 
c    call readmat('Amat',m,n,scimat)
c!
c     =========================================
      integer m
      character*(*) name,chai
      include '../stack.h'
      integer id(nsiz),nlr,lr,srhs,l4
      logical cresmat2
      cwritechain=.false.
      call str2name(name,id)
      top=top+1
      if(.not.cresmat2('cwritechain',top,m,lr)) return
      call cvstr(m,istk(lr),chai,0)
      srhs=rhs
      rhs=0
      l4=lct(4)
      lct(4)=-1
      call stackp(id,0)
      lct(4)=l4
      top=top-1
      rhs=srhs
      if(err.gt.0) return
      cwritechain=.true.
      return
      end

      subroutine matptr(name,m,n,lp)
c     ==========================================
c     see cmatptr 
c     ==========================================
      character*(*) name
      integer m,n,lp
      logical i,cmatptr
      i=cmatptr(name,m,n,lp)
      return
      end

      logical function cmatptr(name,m,n,lp)
c     ==========================================
c!purpose
c     matptr returns the adress of real matrix "name"
c     in scilab's internal stack
c     m=number of rows
c     n=number of columns
c     stk(lp),stk(lp+1),...,stk(lp+m*n-1)= entries (columnwise)
c     If matrix "name" not in Scilab stack, returns m=n=-1.
c
c    Example of use:
c    Amat is a real 2 x 3 scilab matrix
c    your subroutine should be as follows:
c
c    subroutine mysubr(...)
c    include '../stack.h'
c    ...
c    logic= cmatptr('Amat',m,n,lp)
c    => m=3 , n=2, and stk(lp)=Amat(1,1)
c                      stk(lp+1)=Amat(2,1)
c                      stk(lp+2)=Amat(3,1)
c                      stk(lp+3)=Amat(1,2) ...
c                      stk(lp+5)=Amat(3,2)
c   see example in fydot.f file
c   see also  readmat.f, matz.f
c     ==========================================
      character*(*) name
      include '../stack.h'
      integer id(nsiz)
      logical getrmat 
      cmatptr=.false.
c     ---- get the id 
      call str2name(name,id)
c     ---- get the position in fin 
      fin=-1
      call stackg(id)
      if (fin .eq. 0) then
         call putid(ids(1,pt+1),id)
         call error(4)
         m=-1
         n=-1
         return
      endif
c     ---- get data 
      if(.not.getrmat('creadmat',fin,fin,m,n,lp))return
      cmatptr=.true.
      end

      subroutine str2name(name,id)
c     =====================
c     string conversion to Scilab ID 
c     Warning : the character name is null terminated 
c             and len(name) is not used 
c             since it can be wrong (ex when name is transmited 
c             by fort (intfort : function )
c     =====================
      include '../stack.h'
      integer id(nsiz),lon 
      character*(*) name
      lon = 0 
      do 100 i=1,nlgh
         if(name(i:i).eq.char(0)) goto 200
         lon=lon+1
 100  continue
 200  continue
      call cvname(id,name(1:lon),0)
      return
      end