-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfortex.f
613 lines (540 loc) · 14.6 KB
/
cfortex.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
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
C cfortex.f 20210827
C http://www-zeus.desy.de/~burow/cfortran/
C Burkhard Burow [email protected] 1990 - 2001.
C NAG f90 only
C Uses an exclamation mark, '!', to start comments. Do:
C prompt> mv cfortex.f cf_temp.f &&sed 's/^C/\!/g' cf_temp.f >cfortex.f
C to convert the comments here into f90 compliant ones.
C NAG f90 only
subroutine ss1(b)
implicit none
character*(*) b
character*(13) a
data a/'first'/
b = a
return
end
subroutine abc(a,b,c)
implicit none
character*(*) b,a,c
character*(13) d
d = a
a = b
b = c
c = d
return
end
subroutine forstr1(b)
implicit none
character*(*) b
character*(13) a
character*(13) forstr
data a/'firs'/
b = forstr(a)
return
end
subroutine EASY(a,b)
implicit none
integer a,b
a = b
return
end
character*(*) function forstr(a)
implicit none
character*(*) a
forstr = a
return
end
real function rr(i)
implicit none
integer i
rr = i
return
end
character*(*) function forstr2()
implicit none
C character*(13) a VAX/Ultrix complains about these ().
character*13 a
data a/'first'/
forstr2 = a
return
end
character*(*) function ft(v, w, a)
implicit none
character *(*) v(4), w(4)
real a
print*,'FT:len(v(1 or 2 or 3 or 4)) =',len(v(1))
print*,'FT:len(w(1 or 2 or 3)) =',len(w(1))
print*,'FT:a = ',a
print*,'FT:v(1,2,3,4) =',v(1),',',v(2),',',v(3),',',v(4)
print*,'FT:w(1,2,3,4) =',w(1),',',w(2),',',w(3),',',w(4)
ft = v(1)
return
end
character*(*) function fz(v, w, i)
implicit none
integer i,j
character *(*) v(i), w(i)
print*,'FZ:len(v(1 or 2 or 3 or 4)) =',len(v(1))
print*,'FZ:len(w(1 or 2 or 3)) =',len(w(1))
do 100 j = 1,i
print*,'FZ:v(',j,') =',v(j),' w(',j,') =',w(j)
100 continue
fz = v(1)
return
end
subroutine sz(v, w, i)
implicit none
integer i,j
character *(*) v(i), w(i)
print*,'SZ:len(v(1 or 2 or 3 or 4)) =',len(v(1))
print*,'SZ:len(w(1 or 2 or 3)) =',len(w(1))
do 100 j = 1,i
print*,'SZ:v(',j,') =',v(j),' w(',j,') =',w(j)
100 continue
return
end
subroutine subt(v, w, a)
implicit none
character *(*) v(4), w(4)
real a
print*,'SUBT:len(v(1 or 2 or 3 or 4)) =',len(v(1))
print*,'SUBT:len(w(1 or 2 or 3)) =',len(w(1))
print*,'SUBT:a = ',a
print*,'SUBT:v(1,2,3,4) =',v(1),',',v(2),',',v(3),',',v(4)
print*,'SUBT:w(1,2,3,4) =',w(1),',',w(2),',',w(3),',',w(4)
return
end
subroutine rev(a)
implicit none
integer a(2),t
t = a(1)
a(1) = a(2)
a(2) = t
return
end
integer function frev(a)
implicit none
integer a(2)
frev = a(1)
a(1) = a(2)
a(2) = frev
return
end
subroutine ffcb()
implicit none
common /fcb/ v,w,x
character *(13) v, w(4), x(3,2)
print*,'FFCB:v =',v,'.'
print*,'FFCB:w(1,2,3,4) =',w(1),',',w(2),',',w(3),',',w(4),'.'
print*,'FFCB:x([1,2,3],1) =',x(1,1),',',x(2,1),',',x(3,1),'.'
print*,'FFCB:x([1,2,3],2) =',x(1,2),',',x(2,2),',',x(3,2),'.'
v = 'fcb v'
w(1) = 'fcb w(1)'
w(2) = 'fcb w(2)'
w(3) = 'fcb w(3)'
x(1,1) = 'fcb x(1,1)'
x(2,1) = 'fcb x(2,1)'
x(3,1) = 'fcb x(3,1)'
x(1,2) = 'fcb x(1,2)'
x(2,2) = 'fcb x(2,2)'
x(3,2) = 'fcb x(3,2)'
end
subroutine feq()
parameter (kwbank=690)
C The & in the next line is for f90 line continuation.
C It is in column 74, i.e. part of f77 comments.
common/gcbank/nzebra,gversn,zversn,ixstor,ixdiv,ixcons,fendq(16) &
& ,lmain,lr1,ws(kwbank)
dimension iq(2),q(2),lq(80),iws(2)
equivalence (q(1),iq(1),lq(9)),(lq(1),lmain) ,(iws(1),ws(1))
nzebra = 1
gversn = 2
zversn = 3
ixstor = 4
ixcons = 5
fendq(16) = 6
lmain = 7
lr1 = 8
ws(kwbank) = 9
lq(9) = 10
end
subroutine fexist()
implicit none
print*,'FEXIST: was called'
call exist()
return
end
subroutine fa(i)
implicit none
integer i
print*,'FA: integer argument =',i
call cfortranca(i)
return
end
subroutine fb(i)
implicit none
integer i
print*,'FB: integer argument =',i
i = i*2
call cfcb(i)
return
end
subroutine fc(b)
implicit none
character*(*) b
print*,'FC: string argument =',b
call cfcc(b)
return
end
subroutine fd(b)
implicit none
character*(*) b
character*(13) a
data a/'birthday'/
b = a
call cdcfort(b)
return
end
subroutine fe(v)
implicit none
character*(*) v(4)
print*,'FE:len(v(1 or 2 or 3 or 4)) =',len(v(1))
print*,'FE:v(1,2,3,4) =',v(1),',',v(2),',',v(3),',',v(4)
call ce(v)
return
end
subroutine ff(v,n)
implicit none
integer n
character*(*) v(4)
print*,'FF:len(v(1 or 2 or 3 or 4)) =',len(v(1))
print*,'FF:v(1,2,3,4) =',v(1),',',v(2),',',v(3),',',v(4)
print*,'FF:n =',n
call ccff(v,n)
return
end
integer function fg()
implicit none
integer ccg
fg = ccg()
return
end
character*(*) function fh()
implicit none
character*200 cch
fh = cch()
return
end
character*(*) function fi(v)
implicit none
character*(*) v(6)
character*200 ci
fi = ci(v)
return
end
character*(*) function fj(v)
implicit none
integer v
character*200 cj
print*,'FJ:v =',v
fj = cj(v)
return
end
real function fk()
implicit none
real ck
fk = ck()
return
end
double precision function fl()
implicit none
double precision cl
fl = cl()
return
end
real function fm(r)
implicit none
external cm
real cm,r
fm = cm(r)
return
end
double precision function fn(a,b)
implicit none
double precision cn,a,b
fn = cn(a,b)
return
end
subroutine vv(d,f,i)
implicit none
double precision d(2,2)
real f(2,2)
integer i(2,2)
call cvv(d,f,i)
return
end
double precision function v7(d)
implicit none
external cv7
double precision d(1,13,11,7,5,3,2), cv7
integer i,j,k,l,m,n,o
print *, 'function cv7 returns the value ', cv7(d)
v7 = 0
do 1 i=1, 2
do 1 j=1, 3
do 1 k=1, 5
do 1 l=1, 7
do 1 m=1, 11
do 1 n=1, 13
do 1 o=1, 1
v7 = v7 + d(o,n,m,l,k,j,i)
1 continue
return
end
logical function fand(a,b)
implicit none
logical cand,a,b
fand = cand(a,b)
return
end
logical function forr(a,b)
implicit none
logical cor,a,b
print *, 'FORTRAN thinks you called forr(a=',a,',b=',b,').'
forr = cor(a,b)
print *, 'FORTRAN thinks cor(a,b) returned with a=',a,',b=',b,').'
if (a.eqv..true.)then
print *,'Double check: a is true:',a
endif
if (a.eqv..false.)then
print *,'Double check: a is false:',a
endif
if (.not.((a.eqv..false.) .or. (a.eqv..true.))) then
print *,'Double check: ERROR: a is neither true nor false:',a
print *,' Please contact [email protected]'
endif
if (b.eqv..true.)then
print *,'Double check: b is true:',b
endif
if (b.eqv..false.)then
print *,'Double check: b is false:',b
endif
if (.not.((b.eqv..false.) .or. (b.eqv..true.))) then
print *,'Double check: ERROR: b is neither true nor false:',b
print *,' Please contact [email protected]'
endif
C print *, ' '
C print *, ' Testing non-FORTRAN/77 (b .eq. .true.) which'
C print *, ' will not compile on NAG f90 or Apollo or IBM RS/6000.'
C print *, ' Compile cfortest.c with LOGICAL_STRICT defined'
C print *, ' if you wish this test to work as expected.'
C print *, ' This test requires a and b to match the internal '
C print *, ' representation of .TRUE. and .FALSE. exactly.'
C if (a.eq..true.)then
C print *,'Representation check: a matches .true.'
C endif
C if (a.eq..false.)then
C print *,'Representation check: a matches .false.'
C endif
C if (.not.(a.eq..false. .or. a.eq..true.)) then
C print *,'Representation check: '
C print *,' a matches neither .true. nor .false.'
C endif
C if (b.eq..true.)then
C print *,'Representation check: b matches .true.'
C endif
C if (b.eq..false.)then
C print *,'Representation check: b matches .false.'
C endif
C if (.not.(b.eq..false. .or. b.eq..true.)) then
C print *,'Representation check: '
C print *,' b matches neither .true. nor .false.'
C endif
C print *,' '
return
end
subroutine fstrtok()
implicit none
character*70 cstrtok, a
C Setting up NULL as the NULL pointer for cfortran.h using 4 NUL bytes.
character NULL*4, NUL(4)
equivalence (NULL,NUL)
C HP-UX Fortran requires DATA statements to not follow executable statements.
DATA a/'first+second-third+forth-fifth-sixth seventh'/
CSUNBUG Have to use an equivalenced NUL array to fill NULL with 4 NUL bytes
CSUNBUG since Sun's 'Sep 8 1987 /usr/bin/f77' has a bug which didn't set NULL
CSUNBUG to 4 NUL bytes in the following.
CSUNBUG NULL = CHAR(0)//CHAR(0)//CHAR(0)//CHAR(0)
NUL(1) = CHAR(0)
NUL(2) = CHAR(0)
NUL(3) = CHAR(0)
NUL(4) = CHAR(0)
C NUL character in a will force cfortran.h to pass address of a,
C not of a copy as it usually does.
a(70:) = NULL
C String until the first '-', then until the first '+'.
print *,cstrtok(a, '-')
print *,cstrtok(NULL, '+')
C Flush the rest of the string.
C Recall cfortran.h kills all trailing blanks. i.e. FORTRAN ' ' -> C "".
print *,cstrtok(NULL, ' ')
C Further calls return nothing.
print *,cstrtok(NULL, ' ')
return
end
integer function fadd(a,b)
implicit none
integer a,b
fadd = a + b
return
end
integer function funadd(fun,a,b)
implicit none
external fun
integer a,b,fun
C WARNING FOR Alpha/OSF!
C The DEC Fortran and the DEC C compilers of DEC OSF/1 [RT] V1.2 (Rev. 10)
C will crash on this example as it stands.
C See cfortran.doc for a cleaner example of this misbehavior.
C Note that the routine funarg below, whose argument f is also an integer
C function, does not have this problem.
C This example will work if an extra argument is given to function 'fun'.
C i.e. For Alpha/OSF replace the following line with the kludge:
C funadd = fun(a,b,1)
funadd = fun(a,b)
return
end
subroutine funarg(f,a,b,c)
implicit none
external fadd3,f
integer a,b,c,f
c = f(fadd3,a,b)
return
end
subroutine fadd3(a,b,c)
implicit none
integer a,b,c
c = a + b
return
end
subroutine fqsortex(size)
implicit none
C Because it's convinient here, we let C tell us the size of INTEGER.
integer size
integer base(10),cmp,i
external cmp
data base /1,10,2,9,3,8,4,7,5,6/
call fqsort(base,10,size,cmp)
print '(10I3)', (base(i), i=1,10)
return
end
integer function cmp(a,b)
implicit none
integer a,b
cmp = a-b
return
end
subroutine fstr()
implicit none
character*(4) a,b,c
character*(1) d(5)
character*(5) dd
equivalence (d,dd)
character*(16) n
call pstru(n)
print *,n,'<-'
a = '1'
a(2:2) = CHAR(0)
call ppstr(a)
b = '22'
call pstr(b)
print *,b,'<-'
call pstr(b)
print *,b,'<-'
c(1:1) = CHAR(0)
c(2:2) = CHAR(0)
c(3:3) = CHAR(0)
c(4:4) = CHAR(0)
call pnstr(c)
c = '333'
c(4:4) = CHAR(0)
call pnstr(c)
call pnstr(b)
print *,b,'<-'
call pnstr(b)
print *,b,'<-'
c(1:1) = CHAR(0)
c(2:2) = CHAR(0)
c(3:3) = CHAR(0)
c(4:4) = CHAR(0)
call pnstr(c)
d(1) = '1'
d(2) = '2'
d(3) = '3'
d(4) = '4'
d(5) = CHAR(0)
C Need to use equivalenced dd because using d causes f90 to complain:
C Error: Inconsistent structure for arg 1 in call to PPSTR at line 533
call ppstr(dd)
call pstr(b)
print *,b,'<-'
call pstr(b)
print *,b,'<-'
return
end
subroutine f14(a,b,c,d,e,f,g,h,i,j,k,l,m,n)
implicit none
integer a,b,c,d,e,f,g,h,i,j,k,l,m,n
call cf14(a,b,c,d,e,f,g,h,i,j,k,l,m,n)
return
end
subroutine f20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)
implicit none
integer a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t
call cf14(a,b,c,d,e,f,g,h,i,j,k,l,m,n)
o = 15
p = 16
q = 17
r = 18
s = 19
t = 20
return
end
subroutine f27(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t
+ ,u,v,w,x,y,z,aa)
implicit none
integer a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t
+ ,u,v,w,x,y,z,aa
call cf27(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t
+ ,u,v,w,x,y,z,aa)
return
end
subroutine sz1(s, is, z, iz)
implicit none
integer is,iz,j
character *(*) s(is), z(iz)
print*,'SZ1:len(s(1)) =',len(s(1)), ' len(z(1)) =',len(z(1))
do 100 j = 1,is
print*,'SZ1:s(',j,') =',s(j),'.'
100 continue
do 200 j = 1,iz
print*,'SZ1:z(',j,') =',z(j),'.'
200 continue
return
end
subroutine pz(s, is, z, iz)
implicit none
integer is,iz,j
character *(*) s(is),z(iz)
print*,'PZ:len(s(1)) =',len(s(1)), ' len(z(1)) =',len(z(1))
do 100 j = 1,is
print*,'PZ:s(',j,') =',s(j),'.'
s(j) = '12345678'
100 continue
do 200 j = 1,iz
print*,'PZ:z(',j,') =',z(j),'.'
z(j) = '12345678'
200 continue
return
end