-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimeftnxlate.pl
81 lines (61 loc) · 1.7 KB
/
primeftnxlate.pl
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
#!/usr/bin/perl
# primeftnxlate.pl, Boone, 11/29/16
# Translate Prime FTNisms for gfortran
#
# Modifications:
# 11/29/16 Boone Initial coding
# End Modifications
# Files
$inf = shift;
$outf = shift;
# Read input
open(IN, $inf) ||
die "usage: $0 infile outfile";
@lines = <IN>;
close(IN);
# Simple string substitutions
s/\/\*/\!/g for (@lines);
s/\*\// /g for (@lines);
/^\$INSERT/ && s/$/\"/ for (@lines);
s/SYSCOM>// for (@lines);
s/^\$INSERT /\#include \"/ for (@lines);
s/\.INS\.FTN/.INS.f/ for (@lines);
s/KEYS\.F/KEYS.INS.f/ for (@lines);
s/ERRD\.F/ERRD.INS.f/ for (@lines);
s/G\$KEYS/G_KEYS/ for (@lines);
s/:([0-7]+)/oct16tosigned10($1)/eg for (@lines);
s/\s+$/\n/g for (@lines);
s/DECODE\(([^,]+),([^,]+),([^,]+),ERR=(\d+)\) (.*)/READ(UNIT=$3,ERR=$4) $5/
for (@lines);
# Delete a few things
@lines = grep (!/NOLIST/, @lines);
@lines = grep (!/LIST/, @lines);
# Multiple-line handling
$block = join('', @lines);
$block =~ s/^(\s+)PARAMETER(.*\n)((.....[X\+0-9].*\n|C.*\n)+)/\1PARAMETER \(\2\3 +\)\n/mg;
#use re 'debugcolor';
$block =~ s/(^\s+(SUBROUTINE|\w FUNCTION).*\n)((.....\+.*\n)*)((#include.*\n|C.*\n)+)(\s+IMPLICIT.*\n)/$1$3$7$5/mg;
# Write output
open(OUT, '>', $outf) ||
die "unable to open output $outf: $!";
print OUT $block;
close(OUT);
# Done
exit(0);
###############################################################################
# 16-bit octal conversion, signed
###############################################################################
sub oct16tosigned10
{
my $oct = shift;
my $dec;
$dec = oct($oct);
if ($dec > 32767)
{
$dec = -(32768 - oct($oct));
}
else
{
return $dec;
}
}