File: mdlset.f

package info (click to toggle)
x13as 1.1-b59-1
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm
  • size: 9,088 kB
  • sloc: fortran: 114,121; makefile: 14
file content (208 lines) | stat: -rw-r--r-- 9,508 bytes parent folder | download | duplicates (3)
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
C     Last change:  BCM  22 Feb 1999    3:02 pm
      SUBROUTINE mdlset(Nrar,Nrdiff,Nrma,Nsar,Nsdiff,Nsma,Locok)
      IMPLICIT NONE
c-----------------------------------------------------------------------
c      INCLUDE 'lex.i'
      INCLUDE 'srslen.prm'
      INCLUDE 'model.prm'
      INCLUDE 'model.cmn'
      INCLUDE 'error.cmn'
      INCLUDE 'stdio.i'
      INCLUDE 'units.cmn'
c     ------------------------------------------------------------------
      LOGICAL T,F
      PARAMETER(T=.true.,F=.false.)
c     ------------------------------------------------------------------
      CHARACTER str*(POPRCR)
      LOGICAL arfix,argok,dffix,Locok,mafix
      INTEGER arlag,dflag,itmp,malag,MULT,naimcf,nchr,ndcoef,Nrar,
     &        Nrdiff,Nrma,Nsar,Nsdiff,Nsma
      DOUBLE PRECISION arcoef,dfcoef,macoef
      PARAMETER(MULT=3)
      DIMENSION arcoef(PORDER),arfix(PORDER),arlag(PORDER),
     &          dfcoef(PDIFOR),dffix(PDIFOR),dflag(PDIFOR),
     &          macoef(PORDER),mafix(PORDER),malag(PORDER)
c-----------------------------------------------------------------------
c     Get factors (AR DIFF MA)SP until the next name.
c-----------------------------------------------------------------------
      Locok=T
      Nseadf=Nsdiff
      Nnsedf=Nrdiff
      naimcf=0
c-----------------------------------------------------------------------
      CALL mkmdsn(Nrar,Nrdiff,Nrma,Nsar,Nsdiff,Nsma,Mdldsn,Nmddcr)
      IF(Lfatal)RETURN
c-----------------------------------------------------------------------
c     set up model operators based on values input...
c     nonseasonal AR
c-----------------------------------------------------------------------
      IF(Nrar.gt.0)THEN
       CALL setopr(AR,arcoef,arlag,arfix,Nrar,itmp,naimcf,argok,Locok)
       IF(Lfatal)RETURN
       IF(Locok)THEN
        CALL iscrfn(MULT,1,arlag,Nrar,PORDER,arlag)
        CALL mkoprt(AR,1,Sp,str,nchr)
        IF(.not.Lfatal)CALL insopr(AR,arcoef,arlag,arfix,Nrar,1,
     &                             str(1:nchr),argok,Locok)
        IF(Lfatal)RETURN
        CALL maxlag(Arimal,Opr,Mdl(AR-1),Mdl(AR)-1,Mxarlg)
       END IF
      END IF
c-----------------------------------------------------------------------
c       nonseasonal differencing
c-----------------------------------------------------------------------
      IF(Nrdiff.gt.0)THEN
       ndcoef=Nrdiff
       CALL setopr(DIFF,dfcoef,dflag,dffix,ndcoef,Nrdiff,naimcf,argok,
     &             Locok)
       IF(Lfatal)RETURN
       IF(ndcoef.gt.PDIFOR)THEN
        CALL writln('ERROR: Order of the differencing operator is '//
     &              'too large.',STDERR,Mt2,T)
        Locok=F
       ELSE
        CALL iscrfn(MULT,1,dflag,ndcoef,PDIFOR,dflag)
        CALL mkoprt(DIFF,1,Sp,str,nchr)
        IF(.not.Lfatal)CALL insopr(DIFF,dfcoef,dflag,dffix,ndcoef,
     &                             1,str(1:nchr),argok,Locok)
        IF(Lfatal)RETURN
       END IF
       CALL maxlag(Arimal,Opr,Mdl(DIFF-1),Mdl(DIFF)-1,Mxdflg)
      END IF
c-----------------------------------------------------------------------
c       nonseasonal MA
c-----------------------------------------------------------------------
      IF(Nrma.gt.0)THEN
       CALL setopr(MA,macoef,malag,mafix,Nrma,itmp,naimcf,argok,Locok)
       IF(Lfatal)RETURN
       IF(Locok)THEN
        CALL iscrfn(MULT,1,malag,Nrma,PORDER,malag)
        CALL mkoprt(MA,1,Sp,str,nchr)
        IF(.not.Lfatal)CALL insopr(MA,macoef,malag,mafix,Nrma,1,
     &                             str(1:nchr),argok,Locok)
        IF(Lfatal)RETURN
        CALL maxlag(Arimal,Opr,Mdl(MA-1),Mdl(MA)-1,Mxmalg)
       END IF
      END IF
c-----------------------------------------------------------------------
c       seasonal AR
c-----------------------------------------------------------------------
      IF(Nsar.gt.0)THEN
       CALL setopr(AR,arcoef,arlag,arfix,Nsar,itmp,naimcf,argok,Locok)
       IF(Lfatal)RETURN
       IF(Locok)THEN
        CALL iscrfn(MULT,Sp,arlag,Nsar,PORDER,arlag)
        CALL mkoprt(AR,Sp,Sp,str,nchr)
        IF(.not.Lfatal)CALL insopr(AR,arcoef,arlag,arfix,Nsar,Sp,
     &                             str(1:nchr),argok,Locok)
        IF(Lfatal)RETURN
c-----------------------------------------------------------------------
c      Check the of maximum lag of all the AR operators added so far
c does not exceed the maximum order otherwise is will exceed temporary
c storage in the filtering operations where the operators are
c expanded/multiplied into just the coefficients of one full operator.
c This is only going to be a problem for seasonal models.
c-----------------------------------------------------------------------
        CALL maxlag(Arimal,Opr,Mdl(AR-1),Mdl(AR)-1,Mxarlg)
        IF(Mxarlg.gt.PORDER)THEN
         CALL writln('ERROR: Order of the AR operator is too large.',
     &               STDERR,Mt2,T)
         Locok=F
        END IF
       END IF
      END IF
c-----------------------------------------------------------------------
c       seasonal differencing
c-----------------------------------------------------------------------
      IF(Nsdiff.gt.0)THEN
       ndcoef=Nsdiff
       CALL setopr(DIFF,dfcoef,dflag,dffix,ndcoef,Nsdiff,naimcf,argok,
     &             Locok)
       IF(Lfatal)RETURN
c-----------------------------------------------------------------------
c     Check that we don't have a seasonal difference and a seasonal
c effect variables or a U(B) operator.
c-----------------------------------------------------------------------
       Lseadf=(Sp.gt.1).or.(Sp.eq.1.and.ndcoef.eq.Sp-1)
       IF(Lseadf.and.Lseff)THEN
        CALL writln('ERROR: Cannot have a seasonal difference with'//
     &              ' seasonal regression effects.',STDERR,Mt2,T)
        Locok=F
       END IF
c     ------------------------------------------------------------------
       IF(ndcoef.gt.PDIFOR)THEN
        CALL writln('ERROR: Order of the differencing operator is '//
     &              'too large.',STDERR,Mt2,T)
        Locok=F
       ELSE
        CALL iscrfn(MULT,Sp,dflag,ndcoef,PDIFOR,dflag)
        CALL mkoprt(DIFF,Sp,Sp,str,nchr)
        IF(.not.Lfatal)CALL insopr(DIFF,dfcoef,dflag,dffix,ndcoef,
     &                             Sp,str(1:nchr),argok,Locok)
        IF(Lfatal)RETURN
       END IF
c-----------------------------------------------------------------------
c     Check the maximum lag of all the differencing operators added
c does not exceed the maximum order otherwise it will exceed
c temporary storage in the filtering operations where the operators
c are expanded/multiplied into the coefficients of one full
c operator.  This is only a problem for seasonal models.
c-----------------------------------------------------------------------
       CALL maxlag(Arimal,Opr,Mdl(DIFF-1),Mdl(DIFF)-1,Mxdflg)
       IF(Mxdflg.gt.PDIFOR)THEN
        CALL writln('ERROR: Order of the full differencing operator '//
     &              'is too large.',STDERR,Mt2,T)
        Locok=F
       END IF
      END IF
c-----------------------------------------------------------------------
c      seasonal MA
c-----------------------------------------------------------------------
      IF(Nsma.gt.0)THEN
       CALL setopr(MA,macoef,malag,mafix,Nsma,itmp,naimcf,argok,Locok)
       IF(Lfatal)RETURN
       IF(Locok)THEN
        CALL iscrfn(MULT,Sp,malag,Nsma,PORDER,malag)
        CALL mkoprt(MA,Sp,Sp,str,nchr)
        IF(.not.Lfatal)CALL insopr(MA,macoef,malag,mafix,Nsma,Sp,
     &                             str(1:nchr),argok,Locok)
        IF(Lfatal)RETURN
c-----------------------------------------------------------------------
c      Check the maximum lag of all the MA operators added does not
c exceed the maximum order otherwise it will exceed temporary storage
c in the filtering operations where the operators are expanded/
c multiplied into one full operator. This is only going to be a problem
c for seasonal models.
c-----------------------------------------------------------------------
        CALL maxlag(Arimal,Opr,Mdl(MA-1),Mdl(MA)-1,Mxmalg)
        IF(Mxmalg.gt.PORDER)THEN
         CALL writln('ERROR: Order of the MA operator is too large.',
     &               STDERR,Mt2,T)
         Locok=F
        END IF
       END IF
      END IF
c-----------------------------------------------------------------------
c     Compute the number of effective observations and initialize |G'G|
c-----------------------------------------------------------------------
      Lar=Lextar.and.Mxarlg.gt.0
      Lma=Lextma.and.Mxmalg.gt.0
c     ------------------------------------------------------------------
      IF(Lextar)THEN
       Nintvl=Mxdflg
       Nextvl=Mxarlg+Mxmalg
c     ------------------------------------------------------------------
      ELSE
       Nintvl=Mxdflg+Mxarlg
c     ------------------------------------------------------------------
       Nextvl=0
       IF(Lextma)Nextvl=Mxmalg
      END IF
c-----------------------------------------------------------------------
c     We processed the last operator so start wrapping up.
c     Increment NMDL, indicating we have an ARIMA model.
c-----------------------------------------------------------------------
      IF(Locok)Nmdl=Nmdl+1
c     ------------------------------------------------------------------
      RETURN
      END