File: dmrdsp.f

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 (523 lines) | stat: -rw-r--r-- 16,463 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
      subroutine dmrdsp(mpn,dn,mpd,dd,nl,mm,nn,var,lvar,maxc,mode,ll,
     1    lunit,cw,iw)
c!but 
c     dmpdsp ecrit une matrice polynomiale (ou un polynome) sous
c     la forme d'un tableau de polynomes, avec gestion automatique de
c     l'espace disponible.
c!liste d'appel
c     
c     subroutine dmrdsp(mpn,dn,mpd,dd,nl,m,n,var,lvar,maxc,mode,ll,
c     1 lunit,cw,iw)
c     
c     double precision mp(*)
c     integer d(nl*n+1),nl,m,n,lvar,maxc,mode,iw(*),ll,lunit
c     character var*(*),cw*(*)
c     
c     pm : tableau reel contenant les coefficients des polynomes,
c     le coefficient de degre k du polynome pm(i,j) est range
c     dans pm( d(i + (j-1)*nl + k) )
c     pm doit etre de taille au moins d(nl*n+1)-d(1)
c     d : tableau entier de taille nl*n+1,  si k=i+(j-1)*nl alors
c     d(k)) contient  l'adresse dans pm du coeff de degre 0
c     du polynome pm(i,j). Le degre du polynome pm(i,j) vaut:
c     d(k+1)-d(k) -1
c     nl : entier definissant le rangement dans d
c     m : nombre de ligne de la matrice polynomiale
c     n : nombre de colonnes de la matrice polynomiale
c     var : nom de la variable muette
c     lvar : nombre de caracteres de var
c     maxc : nombre de caracteres maximum autorise pour
c     representer un nombre
c     mode : si mode = 1 alors representation variable
c     si mode = 0 alors representation d(maxc).(maxc-7)
c     ll : longueur de ligne maximum admissible
c     lunit : etiquette logique du support d'edition
c     cw : chaine de caracteres de travail de longueur au moins ll*2
c     iw : tableau de travail entier de taille au moins egale a
c     n*(4+m)+1+dn(n*m+1)+dd(n*m+1)
c!origine
c     s. steer inria 1986
c     Copyright INRIA

c!    
c     
      double precision mpn(*),mpd(*),a
      integer dd(*),dn(*),iw(*),maxc,mode
      integer fl,sk,sl,c1,c2,typ
      logical first
      character var*(*),cw*(*),sgn*1,dl*1
      character*10 form(2),fexp,expo
      integer nind
c     
      data nind/5/
c     
      m=abs(mm)
      n=abs(nn)
c
      cw=' '
      write(form(1),130) maxc,maxc-7
      dl=' '
      if(m*n.gt.1) dl=' '
c     
c     phase d'analyse: pour chaque coefficient a representer on determine
c     format avec lequel on va l'editer, on en deduit la longueur
c     de la representation de chacun des polynomes.
c     les differents formats sont stockes sous forme codee dans iw
c     a partir de lf
c     la taille respective des representation des chacun des polynomes
c     est contenue dans iw a partir de 1 .
c     
      lcol=1
      lbloc=lcol+n-1
      lfn=lbloc+n+2
      lfd=lfn+dn(n*m+1)
      ldelta=lfd+dd(n*m+1)
      ldeb=ldelta+m*n
      lfin=ldeb+n
c     
      lines=0
      nbloc=1
      iw(lbloc+nbloc)=n
      sk=0
      ldefn=lfn
      ldg=-nl
      ldefd=lfd
      idelta=ldelta
c     
      k0=1
      do 11 k=1,n
         sl=0
         iw(lcol-1+k)=0
         ldg=ldg+nl
         do 10 l=1,m
c     
c     traitement du polynome (l,k)
            lpn=dn(ldg+l)-1
            npn=dn(ldg+l+1)-dn(ldg+l)
            lghn=0
            first=.true.
            do 05 i=1,npn
               a=abs(mpn(lpn+i))
               iw(ldefn)=0
               if(a.ne.0.0d+0) then
                  first=.false.
c     determination du format devant representer a
                  typ=1
                  if(mode.eq.1) call fmt(a,maxc,typ,n1,n2)
                  if(typ.eq.2) then
                     fl=n1
                     iw(ldefn)=n2+32*n1
                  elseif(typ.lt.0) then
                     iw(ldefn)=typ
                     n2=1
                     fl=3
                  else
                     iw(ldefn)=1
                     fl=maxc
                     n2=maxc-7
                  endif
c     
c     determination de la longueur de la representation du monome,
c     cette longueur est a priori fl+2 (' '//sgn//rep(a)//var).
c     mais peut etre reduite dans des cas particulier
                  lghn=lghn+fl+2
                  if(n2.eq.0) then
                     lghn=lghn-1
                     if(i.ne.1.and.int(a+0.1).eq.1) lghn=lghn-1
                  endif
                  if(i.ne.1) lghn=lghn+lvar
               endif
               ldefn=ldefn+1
 05         continue
            
c     
c     cas particulier du dernier exposant du polynome
            nd=ifix(log10(0.5+npn))+1
            lghn=lghn+nd
c     cas particulier d'un polynome reduit a 0
            if(first) lghn=4
c     
            lpd=dd(ldg+l)-1
            npd=dd(ldg+l+1)-dd(ldg+l)
            lghd=0
            first=.true.
            do 08 i=1,npd
               a=abs(mpd(lpd+i))
               iw(ldefd)=0
               if(a.ne.0.0d+0) then
                  first=.false.
c     determination du format devant representer a
                  typ=1
                  if(mode.eq.1) call fmt(a,maxc,typ,n1,n2)
                  if(typ.eq.2) then
                     fl=n1
                     iw(ldefd)=n2+32*n1
                  elseif(typ.lt.0) then
                     iw(ldefd)=typ
                     n2=1
                     fl=3
                  else
                     iw(ldefd)=1
                     fl=maxc
                     n2=maxc-7
                  endif
c     determination de la longueur de la representation du monome,
c     cette longueur est a priori fl+2 (' '//sgn//rep(a)//var).
c     mais peut etre reduite dans des cas particulier
                  lghd=lghd+fl+2
                  if(n2.eq.0) then
                     lghd=lghd-1
                     if(i.ne.1.and.int(a+0.1).eq.1) lghd=lghd-1
                  endif
                  if(i.ne.1) lghd=lghd+lvar
               endif
               ldefd=ldefd+1
 08         continue
c     
c     cas particulier du dernier exposant du polynome
            nd=ifix(log10(0.5+npd))+1
            lghd=lghd+nd
c     cas particulier d'un polynome reduit a 0
            if(first) lghd=4
c     
            iw(k)=max(iw(k),lghn,lghd)
            sl=sl+(lghn/(ll-10))+(lghd/(ll-10))+2
            iw(idelta)=min(lghn,ll-2)-min(lghd,ll-2)
            idelta=idelta+1
c     
 10      continue
         sk=sk+iw(k)
         if(sk.gt.ll-2) then
            if(k.eq.k0) then
               iw(lbloc+nbloc)=k
               sk=0
               k0=k+1
            else
               iw(lbloc+nbloc)=k-1
               sk=iw(k)
               k0=k
            endif
            nbloc=nbloc+1
            iw(lbloc+nbloc)=n
c     lines=lines+2*sl+m+2
         endif
 11   continue
      nbloc=min(nbloc,n)
c     
      l1=1
      if(mm.lt.0) then
         write(cw(l1:l1+4),'(''eye *'')') 
         l1=l1+5
         call basout(io,lunit,cw(1:l1-1))
         call basout(io,lunit,' ')
         if(io.eq.-1) goto 99
      endif

c     
c     phase d'edition : les deux chaines de caracteres representant
c     la ligne des exposants et la ligne des coefficients,sont
c     constituees puis imprimees.
c     
      k1=1
      do 70 ib=1,nbloc
         k2=iw(lbloc+ib)
         ll1=0
         if(nbloc.ne.1) then
            call blktit(lunit,k1,k2,io)
            if (io.eq.-1) goto 99
         endif
c     
         cw(1:1)=dl
         c1=2
         cw(1+ll:1+ll)=dl
         c2=max(3+ll,nind+maxc+15)
c     
         do 60 l=1,m
c     numerateur
            l1=c1
            l2=c2
            if(iw(k1).gt.ll-2) ll1=ll
            do 45 k=k1,k2
               l0=l1
               idelta=ldelta-1+l+(k-1)*m
               ndelta=0
               if(iw(idelta).lt.-1) then
                  ndelta=-iw(idelta)/2
                  cw(l1:l1+ndelta-1)=' '
                  cw(l2:l2+ndelta-1)=' '
                  l1=l1+ndelta
                  l2=l2+ndelta
               endif
c     
               ldg=(k-1)*nl+l
               lpn=dn(ldg)-1
               npn=dn(ldg+1)-dn(ldg)
               ldefn=lfn-1+dn(ldg)-dn(1)
               first=.true.
c     
               iw(ldeb-1+k)=l2
               iw(lfin-1+k)=0
               do 40 j=1,npn
                  ifmt=iw(ldefn+j)
                  if(ifmt.eq.0) goto 40
                  sgn='+'
                  if(first) sgn=' '
                  first=.false.
                  if(mpn(lpn+j).lt.0.0d+0) sgn='-'
                  a=abs(mpn(lpn+j))
c     
                  if(ifmt.eq.1) then
                     nf=1
                     fl=maxc
                     n2=1
                  elseif(ifmt.ge.0) then
                     nf=2
                     n1=ifmt/32
                     n2=ifmt-32*n1
                     fl=n1
                     write(form(nf),120) fl,n2
                  elseif(ifmt.lt.0) then
c     Inf/Nan
                     fl=3
                     n2=1
                  endif

c     
                  nd=0
                  if(j.gt.2) nd=ifix(log10(0.5+j))+1
                  if(l2+fl+2+lvar+nd.gt.c2+ll-2) then
c     gestion des lignes suites
                     if(l1.le.ll-1) then
                        cw(l1:ll-1)=' '
                        l1=ll
                     endif
                     if(l2.le.c2+ll-2) then
                        cw(l2:c2+ll-2)=' '
                        l2=c2+ll-2
                     endif
                     iw(lfin-1+k)=l2-1
                     cw(l1:l1)=dl
                     call basout(io,lunit,cw(c1-1:l1))
                     cw(l2:l2)=dl
                     cw(c2-1:c2-1)=dl
                     call basout(io,lunit,cw(c2-1:l2))
                     if(io.eq.-1) goto 99
                     cw(c2-1:c2+nind-1)=' '
                     cw(c2-1:c2-1)=dl
                     l2=c2+nind
                     cw(c1-1:c1+nind-1)=' '
                     cw(c1-1:c1-1)=dl
                     l1=c1+nind
                  endif
c     representation du monome
                  cw(l2:l2+1)=' '//sgn
                  l2=l2+1
                  if(ifmt.ge.0) then
                     write(cw(l2+1:l2+fl),form(nf)) a
                  elseif(ifmt.eq.-1) then
                     cw(l2+1:l2+fl)='Inf'
                  elseif(ifmt.eq.-2) then
                     cw(l2+1:l2+fl)='Nan'
                  endif
                  l2=l2+fl
                  if(n2.eq.0) l2=l2-1
                  if(j.gt.1) then
                     if(n2.eq.0.and.int(a+0.1).eq.1) l2=l2-1
                     cw(l2+1:l2+lvar)=var(1:lvar)
                     l2=l2+lvar
                  endif
                  nl1=l2+c1-c2
                  cw(l1:nl1)=' '
                  if(j.gt.2) then
                     write(fexp,110) nd
                     write(expo,fexp) j-1
                     cw(nl1+1:nl1+nd)=expo(1:nd)
                     l1=nl1+nd
                  endif
                  l1=l1+1
                  l2=l2+1
 40            continue
               if(first) then
c     cas particulier du polynome nul
                  cw(l1:l1+3)=' '
                  cw(l2:l2+3)='   0'
                  l1=l1+4
                  l2=l2+4
                  nd=0
               endif
               if(iw(lfin-1+k).eq.0) iw(lfin-1+k)=l2
               if(nd.ne.0) cw(l2:l2+nd-1)=' '
               nl1=l0+iw(k)
               if(ll1.eq.ll) nl1=ll-1
               cw(l1:nl1)=' '
               l1=nl1+1
               cw(l2:c2+nl1-c1)=' '
               l2=c2+nl1-c1+1
 45         continue
            if(cw(c1:l1-1).ne.' ') then
               cw(l1:l1)=dl
               call basout(io,lunit,cw(c1-1:l1))
            endif
            cw(l2:l2)=dl
            cw(c2-1:c2-1)=dl
            call basout(io,lunit,cw(c2-1:l2))
            if(io.eq.-1) goto 99
c     
c     trait de fraction
            cw(c2:l2-1)=' '
            jjb1=c2
            do 47 k=k1,k2
               idelta=ldelta-1+l+(k-1)*m
               ndelta=max(0,-iw(idelta)/2)
               ideb=max(jjb1,iw(ldeb-1+k)-ndelta+2)
               ifin=iw(lfin-1+k)+ndelta-2
               if(ifin-ideb+1.eq.2) ideb=ideb-1
               do 46 i=ideb,ifin
                  cw(i+1:i+1)='-'
 46            continue
               jjb1=iw(lfin-1+k)+1
 47         continue
            cw(l2:l2)=dl
            call basout(io,lunit,cw(c2-1:l2))
            if(io.eq.-1) goto 99
c     
c     denominateur
            l1=c1
            l2=c2
            do 55 k=k1,k2
               l0=l1
               idelta=ldelta-1+l+(k-1)*m
               ndelta=0
               if(iw(idelta).gt.1) then
                  ndelta=iw(idelta)/2
                  cw(l1:l1+ndelta-1)=' '
                  cw(l2:l2+ndelta-1)=' '
                  l1=l1+ndelta
                  l2=l2+ndelta
               endif
c     
               ldg=(k-1)*nl+l
               lpd=dd(ldg)-1
               npd=dd(ldg+1)-dd(ldg)
               ldefd=lfd-1+dd(ldg)-dd(1)
               first=.true.
c     
               do 50 j=1,npd
                  ifmt=iw(ldefd+j)
                  if(ifmt.eq.0) goto 50
                  sgn='+'
                  if(first) sgn=' '
                  first=.false.
                  if(mpd(lpd+j).lt.0.0d+0) sgn='-'
                  a=abs(mpd(lpd+j))
c     
                  if(ifmt.eq.1) then
                     nf=1
                     fl=maxc
                     n2=1
                  elseif(ifmt.ge.0) then
                     nf=2
                     n1=ifmt/32
                     n2=ifmt-32*n1
                     fl=n1
                     write(form(nf),120) fl,n2
                  elseif(ifmt.lt.0) then
c     Inf/Nan
                     fl=3
                     n2=1
                  endif
c     
                  nd=0
                  if(j.gt.2) nd=ifix(log10(0.5+j))+1
                  if(l2+fl+2+lvar+nd.gt.c2+ll-2) then
c     gestion des lignes suites
                     if(l1.le.ll-1) then
                        cw(l1:ll-1)=' '
                        l1=ll
                     endif
                     if(l2.le.c2+ll-2) then
                        cw(l2:c2+ll-2)=' '
                        l2=c2+ll-2
                     endif
                     cw(l1:l1)=dl
                     call basout(io,lunit,cw(c1-1:l1))
                     cw(l2:l2)=dl
                     call basout(io,lunit,cw(c2-1:l2))
                     if(io.eq.-1) goto 99
                     cw(c2:c2-1+nind)=' '
                     cw(c2-1:c2-1)=dl
                     l2=c2+nind
                     cw(c1:c1-1+nind)=' '
                     cw(c1-1:c1-1)=dl
                     l1=c1+nind
                  endif
c     representation du monome
                  cw(l2:l2+1)=' '//sgn
                  l2=l2+1
                  if(ifmt.ge.0) then
                     write(cw(l2+1:l2+fl),form(nf)) a
                  elseif(ifmt.eq.-1) then
                     cw(l2+1:l2+fl)='Inf'
                  elseif(ifmt.eq.-2) then
                     cw(l2+1:l2+fl)='Nan'
                  endif
                  l2=l2+fl
                  if(n2.eq.0) l2=l2-1
                  if(j.gt.1) then
                     if(n2.eq.0.and.int(a+0.1).eq.1) l2=l2-1
                     cw(l2+1:l2+lvar)=var(1:lvar)
                     l2=l2+lvar
                  endif
                  nl1=l2+c1-c2
                  cw(l1:nl1)=' '
                  if(j.gt.2) then
                     write(fexp,110) nd
                     write(expo,fexp) j-1
                     cw(nl1+1:nl1+nd)=expo(1:nd)
                     l1=nl1+nd
                  endif
                  l1=l1+1
                  l2=l2+1
 50            continue
               if(first) then
c     cas particulier du polynome nul
                  cw(l1:l1+3)=' '
                  cw(l2:l2+3)='   0'
                  l1=l1+4
                  l2=l2+4
                  nd=0
               endif
               if(nd.ne.0) cw(l2:l2+nd-1)=' '
               nl1=l0+iw(k)
               if(ll1.eq.ll) nl1=ll-1
               cw(l1:nl1)=' '
               l1=nl1+1
               cw(l2:c2+nl1-c1)=' '
               l2=c2+nl1-c1+1
 55         continue
            if(cw(c1:l1-1).ne.' ') then
               cw(l1:l1)=dl
               call basout(io,lunit,cw(c1-1:l1))
            endif
            cw(l2:l2)=dl
            cw(c2-1:c2-1)=dl
            call basout(io,lunit,cw(c2-1:l2))
            cw(c1:l1-1)=' '
            cw(l1:l1)=dl
            if(io.eq.-1) goto 99
            if(l.ne.m) then
               call basout(io,lunit,cw(c1-1:l1))
               if(io.eq.-1) goto 99
            endif
 60      continue
c     
         k1=k2+1
 70   continue
c     
 99   return
c     
 110  format('(i',i2,')')
 120  format('(f',i2,'.',i2,')')
 130  format('(1pd',i2,'.',i2,')')
c     
      end