I have Fortran 77 source files that I am trying to convert from the non-standard STRUCTURE
and RECORD
syntax to the standard Fortran 90 TYPE
. One tricky aspect of this is the different way you look at structural elements.
Non-standard:
s.member = 1
Standard:
s%member = 1
So, I need to catch all the use of periods in these scenarios and replace them with %
characters. It's not so bad if you haven't thought about all the ways you can use periods (decimal points in numbers, file names in include
statements, punctuation in comments, Fortran 77 relational operators, and maybe others). I did some preprocessing to fix relational operators to use Fortran 90 characters, and I don't really care about the grammar of the comments, but I don't have a suitable translation approach .
in %
for the above cases. It seems I should be able to do this with sed, but I'm not sure how to match the instances I need to fix. Here are the rules I was thinking about:
Step by step:
If a line starts with <whitespace>include
, we should not do anything with this line; pass it to the output, so we won’t mess up the file name inside the include statement.
The following lines are statements that have no symbolic equivalents, so you need to leave them alone: .not. .and. .or. .eqv. .neqv.
.not. .and. .or. .eqv. .neqv.
Otherwise, if we find a period that is surrounded by 2 non-numeric characters (so this is not a decimal point), then this should be the operator that I want to replace. Change this period to %
.
I am not a Fortran native speaker, so here are a few examples:
include 'file.inc' ! We don't want to do anything here. The line can ! begin with some amount of whitespace if x == 1 .or. y > 2.0 ! In this case, we don't want to touch the periods that ! are part of the logical operator ".or.". We also don't ! want to touch the period that is the decimal point ! in "2.0". if a.member < 4.0 .and. b.othermember == 1.0 ! We don't want to touch the periods ! inside the numbers, but we need to ! change the "a." and "b." to "a%" ! and "b%".
What is a good way to solve this problem?
Edit: I really found some additional operators that contain a point in them that have no symbolic equivalents. I updated the list of rules above.
source share