-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboxing.f
executable file
·304 lines (247 loc) · 5.84 KB
/
boxing.f
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
INTEGER FUNCTION NEWARR(L)
INTEGER L
INTEGER X(*)
POINTER(P,X)
DATA DESC /2/
CALL RESIZEL(NEWARR,L,0)
END
SUBROUTINE PRINTARR(A)
INTEGER A
INTEGER N
INTEGER :: GETLENGTH
CALL PRINTARRL(A,GETLENGTH(A))
END
SUBROUTINE PRINTARRL(A,L)
INTEGER A,L,Y
INTEGER X(*)
POINTER(P,X)
P=A
PRINT *,A
DO I=1,L
Y=X(I)
PRINT *,I,': ', X(I)
END DO
RETURN
END
SUBROUTINE SETLENGTH(A, L)
COMMON /ARRS / DESC
INTEGER DESC
INTEGER L,A,K
INTEGER X(2)
POINTER (P,X)
P=A-DESC*SIZEOF(A)
X(2)=MIN(X(1),L)
END
INTEGER FUNCTION GETLENGTH(A)
COMMON /ARRS / DESC
INTEGER DESC
INTEGER A,L
INTEGER X(2)
POINTER (P,X)
P=A-DESC*SIZEOF(A)
GETLENGTH = X(2)
RETURN
END FUNCTION
INTEGER FUNCTION GETSIZE(A)
COMMON /ARRS / DESC
INTEGER DESC
INTEGER A
INTEGER X(2)
POINTER (P,X)
P=A-DESC*SIZEOF(A)
GETSIZE = X(1)
RETURN
END FUNCTION
SUBROUTINE INIT(A)
INTEGER A
INTEGER :: GETLENGTH
CALL INITL(A,GETLENGTH(A))
END
SUBROUTINE INITL(A,L)
INTEGER A,L
INTEGER :: GETSIZE
INTEGER X(*)
POINTER(P,X)
P=A
DO I=1,L
X(I)=I
END DO
END
SUBROUTINE DBLSIZE(A)
INTEGER A
INTEGER :: GETSIZE
CALL RESIZE(A,GETSIZE(A)*2)
END
SUBROUTINE RESIZE(A,S)
INTEGER A,S
INTEGER :: GETLENGTH
CALL RESIZEL(A,S,GETLENGTH(A))
END
SUBROUTINE RESIZEL(A,S,L)
COMMON /ARRS / DESC
INTEGER DESC
INTEGER A,S
INTEGER X(*),Y(*)
POINTER(P,X),(Q,Y)
IF(L.NE.0)THEN
IF(L.NE.S)THEN
P=A
A=MALLOC((S+DESC)*SIZEOF(A))
Q=A
Y(1)=S
Y(2)=L
A=A+DESC*SIZEOF(A)
Q=A
CALL POINTERCOPY(P,1,MIN(S,L),Q,1,MIN(S,L))
CALL DELETE(P-DESC*SIZEOF(A))
ENDIF
ELSE
A=MALLOC((S+DESC)*SIZEOF(A))
P=A
X(1)=S
X(2)=0
A=A+DESC*SIZEOF(A)
ENDIF
C A(1:L+2)=Q(1:L+2)
END
SUBROUTINE DELETE(A)
INTEGER A
CALL FREE(A)
END
SUBROUTINE DELETEL(A)
END
SUBROUTINE POINTERCOPY(A,I,J,B,K,L)
INTEGER A,B
INTEGER I,J,K,L
INTEGER :: GETLENGTH
CALL POINTERCOPYL(A,I,J,ABS(J-I),B,K,L,ABS(L-K))
END
SUBROUTINE POINTERCOPYL(A,I,J,SA,B,K,L,SB)
INTEGER A,B,SA,SB
INTEGER I,J,K,L
INTEGER X(SA),Y(SB)
POINTER(P,X),(Q,Y)
P=A
Q=B
CALL ARRAYCOPYL(X,I,J,SA,Y,K,L,SB)
END
SUBROUTINE ARRAYCOPYL(A,I,J,SA,B,K,L,SB)
INTEGER SA,SB
INTEGER I,J,K,L
INTEGER A(SA),B(SB)
B(K:L)=A(I:J)
END
SUBROUTINE ADDVAL(A,V)
INTEGER A,V
INTEGER :: GETLENGTH
CALL SETVAL(A,(GETLENGTH(A)+1),V)
END
SUBROUTINE ADDVALS(A,V)
INTEGER :: GETLENGTH
INTEGER A,V
CALL SETVALS(A,GETLENGTH(A)+1,GETLENGTH(A)+GETLENGTH(V)+1,V)
END
SUBROUTINE SETVAL(A,I,V)
INTEGER J,A,I,V
INTEGER :: GETSIZE
IF(GETSIZE(A).LT.I)THEN
J=0
10 IF(I.GT.2**J)THEN
J=J+1
GOTO 10
ENDIF
CALL RESIZE(A,2**J)
ENDIF
CALL SETVALCHKD(A,I,V)
END
SUBROUTINE SETVALCHKD(A,I,V)
INTEGER A,I,V
INTEGER X(*)
POINTER(P,X)
INTEGER :: GETLENGTH
P=A
IF(GETLENGTH(A).LT.I)CALL SETLENGTH(A,I)
X(I)=V
END
INTEGER FUNCTION GETVAL(A,I)
INTEGER :: GETLENGTH
INTEGER :: GETVALCHKD
INTEGER A,I
IF(GETLENGTH(A).GE.I)THEN
GETVAL=GETVALCHKD(A,I)
ELSE
GETVAL=0
ENDIF
END
INTEGER FUNCTION GETVALCHKD(A,I)
INTEGER A,I
INTEGER X(*)
POINTER(P,X)
P=A
GETVALCHKD=X(I)
END
SUBROUTINE GETVALS(A,I,J,RES)
INTEGER A,I,J,RES
INTEGER :: GETLENGTH
INTEGER :: GETSIZE
IF(GETLENGTH(A).GE.I.AND.GETLENGTH(A).GE.J.AND.I.LE.J)THEN
CALL ENSURESIZE(RES,(J-I+1))
CALL GETVALSCHCKD(A,I,J,RES)
ELSE
CALL ENSURESIZE(RES,ABS(J-I)+1)
CALL ZEROL(RES,ABS(J-I)+1)
GETVAL=0
ENDIF
END
SUBROUTINE GETVALSCHCKD(A,I,J,RES)
INTEGER A,I,J,RES,L
INTEGER :: GETLENGTH
L=GETLENGTH(RES)
CALL POINTERCOPYL(A,I,J,GETLENGTH(A),RES,1,J-I+1,L)
END
RECURSIVE SUBROUTINE SETVALS(A,I,J,RES)
INTEGER A,I,J,K,RES
INTEGER :: GETLENGTH
INTEGER :: GETSIZE
IF(GETSIZE(A).GE.I.AND.GETSIZE(A).GE.J.AND.I.LE.J)THEN
CALL ENSURESIZE(RES,J-I+1)
CALL SETVALSCHCKD(A,I,J,RES)
ELSE
K=0
10 IF(I.GT.2**J)THEN
K=K+1
GOTO 10
ENDIF
CALL RESIZE(A,2**K)
CALL SETVALS(A,1,J,K)
ENDIF
END
SUBROUTINE SETVALSCHCKD(A,I,J,RES)
INTEGER A,I,J,RES,L,M
INTEGER :: GETLENGTH
L=GETLENGTH(RES)
M=GETLENGTH(A)
CALL POINTERCOPYL(RES,1,J,L,A,I,J,M)
CALL SETLENGTH(A,MAX(M,J))
END
SUBROUTINE GETVALSCHCKDL(A,I,J,RES)
END
SUBROUTINE ZERO(A)
INTEGER A
INTEGER :: GETSIZE
CALL ZEROL(A,GETSIZE(A))
END
SUBROUTINE ZEROL(A,L)
INTEGER A, X(L)
INTEGER, INTENT(IN) :: L
POINTER(P,X)
P=A
DO I=1,L
X(I)=0
END DO
END
SUBROUTINE ENSURESIZE(A,L)
INTEGER A
INTEGER :: GETSIZE
IF(GETSIZE(A).LT.L)CALL RESIZE(A,L)
END