summaryrefslogtreecommitdiff
path: root/modules/cacsd/src/fortran/arl2.f
blob: a96bcfef982d9081c965b2a5ce475ae57003d555 (plain)
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
c Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
c Copyright (C) INRIA - M Cardelli, L Baratchart  INRIA sophia-Antipolis 1989, S Steer 
c 
c This file must be used under the terms of the CeCILL.
c This source file is licensed as described in the file COPYING, which
c you should have received as part of this distribution.  The terms
c are also available at    
c http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

      subroutine arl2(f,nf,num,tq,dgmin,dgmax,errl2,w,iw,inf,ierr,ilog)
C!but
C     Cette procedure a pour but de gerer l'execution dans
C     le cas ou un unique polynome approximant est desire
C!liste d'appel
C      subroutine arl2(f,nf,num,tq,dgmin,dgmax,errl2,w,
C     $     inf,ierr,ilog)
C
C     double precision tq(dgmax+1),f(nf),num(dgmax)
C     double precision w(*)
C     integer dgmin,dgmax,dginit,info,ierr,iw(*)
C
C     Entree :
C     dgmin. est le degre du polynome de depart quand il est
C        fourni, (vaux 0 s'il ne l'est pas).
C     dginit. est le premier degre pour lequel aura lieu la
C        recherche.
C     dgmax. est le degre desire du dernier approximant
C     tq. est le tableau contenant le polynome qui peut etre
C        fourni comme point de depart par l'utilisateur.
C
C     Sortie :
C     tq. contient la solution obtenu de degre dgmax.
C     num. contient les coefficients du numerateur optimal
C     errl2. contient l'erreur L2 pour l'optimum retourne
C     ierr. contient l'information sur le deroulement du programme
C          ierr=0 : ok
C          ierr=3 : boucle indesirable sur 2 ordres
C          ierr=4 : plantage lsode
C          ierr=5 : plantage dans recherche de l'intersection avec une face
C
C  tableau de travail
C     w: dimension:  32+32*dgmax+7*ng+dgmax*ng+dgmax**2*(ng+2)
C     iw : dimension  29+dgmax**2+4*dgmax
C!sous programme appeles
C  optml2,feq,jacl2,outl2,lq,phi (arl2)
C  dcopy,dnrm2,dscal,dpmul1
C!organigramme
C arl2
C    optml2
C          outl2
C          feq
C          domout
C                 onface
C                        rootgp
C                        feq
C                        outl2
C                 outl2
C                 phi
C                 lsode
C                 front
C                 watfac
C          front
C          lsode
C                 feq
C                 jacl2
C                        hessl2
C                              lq
C    outl2
C          feq 
C          phi
C          lq
C          jacl2
C    phi
C          lq
C          calsca
C    feq
C          lq
C          calsca       
C    lq
C!
c     Copyright INRIA
      integer dgmin,dgmax,dginit,info,ierr,iw(*)
      double precision tq(dgmax+1),f(nf),num(dgmax),w(*),x
C
      double precision errl2,xx(1)
      double precision tps(2),tms(2),dnrm2,sqrt,phi,gnrm,phi0
      integer dg,dgback,dgr
      external feq, jacl2
      common /sortie/ io,info,ll
      common /no2f/ gnrm
C
c     taille des tableaux de travail necessaires a lsode
      lrw = dgmax**2 + 9*dgmax + 22  
      liw = 20+dgmax

C     decoupage du tableau de travail w
      ncoeff=nf
      ng=nf-1
      ltq   = 1
      ltg   = ltq+dgmax+1
      lwode = ltg+ng+1
      ltr   = lwode+5+5*dgmax+5*ng+dgmax*ng+dgmax**2*(ng+1)
      lfree = ltr + 25+26*dgmax+ng+dgmax**2

c     les lrw elements de w suivant w(ltr) ne doivent pas etre modifies 
c     d'un appel de optml2 a l'autre 
      lw=ltr+lrw
C
C     decoupage du tableau de travail iw
      liwode = 1
      liww   = liwode+4+(dgmax+1)*(dgmax+2)
      lifree = liww+20+dgmax
      iw(liwode+1)=ng
      iw(liwode+2)=dgmax
      ll   = 80
      info = inf
      io   = ilog
C
C test validite des arguments
C
      if (dgmin .gt. 0) then
        dginit = dgmin
        call dcopy(dgmin+1,tq,1,w(ltq),1)
      else
        w(ltq) = 1.d0
        dginit = 1
      endif
C
      dgr=dginit
      ierr = 0
      ntest1 = -1
C
      ng = nf - 1
      call dcopy(nf,f,1,w(ltg),1)
      gnrm = dnrm2(nf,f,1)
      call dscal(nf,1.0d+0/gnrm,w(ltg),1)
      gnrm = gnrm**2
C
      tps(1) = 1.0d+0
      tps(2) = 1.0d+0
      tms(1) = -1.0d+0
      tms(2) = 1.0d+0
C
C     ---- Boucle de calcul ---------------------------------------------
C
      do 500 nnn = dginit,dgmax
C
        ifaceo = 0
C
        if (nnn .eq. dginit) then
          if (dgmin .gt. 0) then
            dg = dginit
            goto 230
          else
            dg = dginit - 1
          endif
        endif
C
 200    dg = dg + 1
C
C     -- Initialisation du nouveau point de depart --
C     (dans l'espace de dimension dg , Hyperespace superieur
C     d'une dimension par rapport au precedent ).
C
        if (ntest1 .eq. 1) then
          call dpmul1(w(ltq),dg-1,tps,1,w(ltr))
          call dcopy(dg+1,w(ltr),1,w(ltq),1)
        elseif (ntest1 .eq. -1) then
          call dpmul1(w(ltq),dg-1,tms,1,w(ltr))
          call dcopy(dg+1,w(ltr),1,w(ltq),1)
        endif
C
C     ------------------------
C
 230    dgback = dg
C
        if (info .gt. 1) call outl2(20,dg,dgback,xx,xx,x,x)
C
        nch = 1
        iw(liwode)=dg
        call optml2(feq,jacl2,iw(liwode),w(ltq),nch,w(ltr),iw)
        dg=iw(liwode)
        if (info .gt. 1) then
             call lq(dg,w(ltq),w(lw),w(ltg),ng)
             x=sqrt(gnrm)
             call dscal(dg,x,w(lw),1)
             call outl2(nch,dg,dg,w(ltq),w(lw),x,x)

             phi0= abs(phi(w(ltq),dg,w(ltg),ng,w(lw)))
             lqdot=lw
             call feq(iw(liwode),t,w(ltq),w(lqdot))
             call outl2(17,dg,dg,w(ltq),w(lqdot),phi0,x)
        endif

        if (nch .ge. 15) then
          if(nch.eq.17) then
             call dcopy(dg+1,w(ltq),1,tq,1)
             dgr=dg
             goto 231
          endif
          ierr = 4 + nch - 15
          goto 510
        endif
C
        if (nch .lt. 0) then
          ifaceo = ifaceo + 1
          ntest1 = (-1) * ntest1
          if (dg .eq. 0) goto 200
          goto 230
        endif
C
        if (info .gt. 1) call outl2(21,dg,dg,xx,xx,x,x)
        nch = 2
        iw(liwode)=dg
        call optml2(feq,jacl2,iw(liwode),w(ltq),nch,w(ltr),iw)
        if (info .gt. 0) then
             call lq(dg,w(ltq),w(lw),w(ltg),ng)
             x=sqrt(gnrm)
             call dscal(dg,x,w(lw),1)
             call outl2(nch,dg,dg,w(ltq),w(lw),x,x)

             phi0= abs(phi(w(ltq),dg,w(ltg),ng,w(lw)))
             lqdot=lw
             call feq(iw(liwode),t,w(ltq),w(lqdot))
             call outl2(17,dg,dg,w(ltq),w(lqdot),phi0,x)
        endif
        if (nch .ge. 15) then
          if(nch.eq.17) then
             call dcopy(dg+1,w(ltq),1,tq,1)
             dgr=dg
             goto 231
          endif
          ierr = 4 + nch - 15
          goto 510
        endif
C
        if (nch .lt. 0) then
          ifaceo = ifaceo + 1
          ntest1 = (-1) * ntest1
          if (dg .eq. 0) goto 200
          goto 230
        endif
C
C
 231    if (ifaceo .eq. 8) then
          if (info .ge. 0) call outl2(22,dg,dg,xx,xx,x,x)
          ierr = 3
          goto 510
        endif
C
        if (dg .lt. nnn) goto 200
        call dcopy(dg+1,w(ltq),1,tq,1)
        dgr=dg
C
 500  continue
C
C Fin de la recherche Optimale
C numerateur optimal
 510  gnrm = sqrt(gnrm)
      call lq(dgr,tq,w(ltr),w(ltg),ng)
      call dcopy(dgr,w(ltr),1,num,1)
      call dscal(dgr,gnrm,num,1)
C     Le gradient de la fonction critere y vaut :-tqdot
C     call feq(dg,t,w(ltq),tqdot)
C     valeur du critere
      lw = ltg+ncoeff+1
      errl2 = sqrt(phi(tq,dgr,w(ltg),ng,w(lw))) * gnrm
      dgmax=dgr
C
      return
      end