Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Comparing versions of a Fortran source code

488 views
Skip to first unread message

Beliavsky

unread,
Sep 4, 2014, 12:50:54 PM9/4/14
to
I can compare two versions of a Fortran source file, containing a single module with multiple procedures, using diff on Unix or fc on Windows. I'd like something that is more Fortran-aware and which can say for example that code foo_2.f90 has procedures x, y, and z not present in foo_1.f90 and that procedures a and b have been modified but that procedures c and d are the same in the two files.

I could write a code in Python that does this, but I wonder if someone has already written such a utility.


Terence

unread,
Sep 4, 2014, 10:59:25 PM9/4/14
to
Beliavski wrote:-
>I can compare two versions of a Fortran source file, containing a single
>module with multiple procedures, using diff on Unix or fc on Windows. >I'd
like something that is more Fortran-aware and which can say for >example
that code foo_2.f90 has procedures x, y, and z not present in >foo_1.f90 and
that procedures a and b have been modified but that >procedures c and d are
the same in the two files.

And asked if a program existed to do this.

Well, I don't know, but I DID write and offer a program to re-write
fixed-form (F77 style) code in a standard way, eliminating Hollertith in
favor of literals, making every single or nested DO loop end on its unique
CONTINUE; renumbering statement labels sequentially from 1, and format
statements labels from 9000, and much, much more, including unused and
missing label checks and subroutine usage by name, indenting option for
nestinga, etc.

But to achieve what Beliavski wants, you then only need a compare of the
output files for each processed sample sample.

And there are two well-known compare programs:
COMPARE file 1 file2 /A (for ascii, /B for binary-hex)
FM (Caltechs CCO file ascii/hex dump amd edit).

I wrote and have often offered two somewhat better versions of FM (one for
command line, one for native Windows).

When I was in IBM, I wrote in 1961 a Fortran flow-chart program where code
blocks were shown as rectangular blocks, if statements were in old-fashioned
diamonds, with decision routing lines wandering around where needed. I have
often wished I still had THAT code listing; (others, yes, including playing
any simply-coded coded music on the IBM 1403 printer, but not that flowchart
one). Output was always IBM 1403 132-line fanfold of course.




abrsvc

unread,
Sep 5, 2014, 7:17:13 AM9/5/14
to

>
> Well, I don't know, but I DID write and offer a program to re-write
>
> fixed-form (F77 style) code in a standard way, eliminating Hollertith in
>
> favor of literals, making every single or nested DO loop end on its unique
>
> CONTINUE; renumbering statement labels sequentially from 1, and format
>
> statements labels from 9000, and much, much more, including unused and
>
> missing label checks and subroutine usage by name, indenting option for
>
> nestinga, etc.
>
>


Any chance this program is still available anywhere. I have a potential project that could use this (over 800,000 lines).

Thanks,
Dan

michael...@compuserve.com

unread,
Sep 5, 2014, 10:53:39 AM9/5/14
to
On Thursday, September 4, 2014 6:50:54 PM UTC+2, Beliavsky wrote:
> I can compare two versions of a Fortran source file, containing a single module with multiple procedures, using diff on Unix or fc on Windows. I'd like something that is more Fortran-aware and which can say for example that code foo_2.f90 has procedures x, y, and z not present in foo_1.f90 and that procedures a and b have been modified but that procedures c and d are the same in the two files.
>
>
>
> I could write a code in Python that does this, but I wonder if someone has already written such a utility.

You might want to look at Julian Bunn's floppy/flow: http://www.netlib.org/floppy/

Regards,

Mike Metcalf

Beliavsky

unread,
Sep 5, 2014, 1:41:51 PM9/5/14
to
Thanks, but those tools are for Fortran 77 code. Some Fortran 77 codes were written so that every function or subroutine was in a separate source file. Then "diff" would do what I want. But in Fortran 90 and later versions of Fortran, much code will be in modules, and each module will contain several procedures.

FortranFan

unread,
Sep 5, 2014, 3:22:24 PM9/5/14
to
Looks like what you want is a semantics based diff'ing (and perhaps merging) tool along the lines of what other coders have at their easy disposal (see http://visualstudiogallery.msdn.microsoft.com/2528ed09-0518-4da5-a988-bdc2eacfcc27 for C# and Visual Basic programmers in .NET for Microsoft Windows platform).

Good luck finding such a tool for "modern Fortran" - if you do find one or create one, please report back here!

What you're after will be of even more importance if and when OOP features start to get used more and more. As noted in literature (Arabas et al., 2013), "Support for the OOP features of Fortran among compilers, debuggers and other programming aids remains immature at the time of writing." I'd chalk your diff'ing tool requirement in this "immature" category.

Whereas when I program in many of these other languages, I'm quite amazed at the "richness" of tools at my disposal.

Ian Harvey

unread,
Sep 10, 2014, 1:35:15 PM9/10/14
to
On 2014-09-05 2:50 AM, Beliavsky wrote:
> I can compare two versions of a Fortran source file, containing a single module with multiple procedures, using diff on Unix or fc on Windows. I'd like something that is more Fortran-aware and which can say for example that code foo_2.f90 has procedures x, y, and z not present in foo_1.f90 and that procedures a and b have been modified but that procedures c and d are the same in the two files.
>
> I could write a code in Python that does this, but I wonder if someone has already written such a utility.


I [now] have a utility written in Fortran 2003, building on some
previous Fortran source tools, that does a "semantic" comparison of sets
of Fortran source, such that:

- source form is not significant.
- comments are not significant.
- name and keyword case is not significant.
- program unit, module procedure and internal procedure ordering is not
significant.
- bugs in the utility are probably quite significant.

The source to be compared has to be reasonably conforming F2008, at
least such that the necessary semantics can be determined.

Readable source in a zip at http://1drv.ms/1pPGpM4

Unreadable source in a single fixed form file at http://1drv.ms/1tKQx04

If you break it, let me know.

Terence

unread,
Sep 11, 2014, 2:55:12 AM9/11/14
to
Ian Harvey offered:
>Readable source in a zip at http://1drv.ms/1pPGpM4
>Unreadable source in a single fixed form file at http://1drv.ms/1tKQx04

But my browser translated the address as a site called "OneDrive" but I
could not find how to abcess antything therealthough the files name had a
familiar ring "diff".



Gordon Sande

unread,
Sep 11, 2014, 9:30:33 AM9/11/14
to
You forgot to tithe MicroSoft so your OneDrive account is not enabled. Once
your correct the fact that you are living in a state of sin the great
authorities of MS will absolve your misdeeds.

Strange interface of select item and then download it by slecting elsewhere.

Ian Harvey

unread,
Sep 11, 2014, 6:41:31 PM9/11/14
to
If you want to tithe to someone else... I think this is a link to the
the zip archive of the source on dropbox.

https://db.tt/PEDSuWyR

But you will need a [mostly] F2003 compiler to build it. I use ifort
15.0, which still gets a bit wobbly around the edges. I think it a
reasonable test source for that language level - it uses things like
allocatable arguments, allocatable components, deferred length character
and a lot of the polymorphic stuff (no UDDTIO or user defined type
parameters yet).

For solving the problem as initially described it is probably a bit like
taking a sledgehammer to a chicken egg, but it originally started out as
a Fortran 200[3|8] language learning exercise, plus I had fun.

(I tried a build of current gfortran trunk yesterday and it complained
about a function with a deferred length allocatable result. I'll try
and work out why later.)

(I've fixed a few silly bugs since first posting the link. If you break
it after building it (or can't build it) let me know - perhaps on email.)

Richard Maine

unread,
Sep 11, 2014, 8:06:51 PM9/11/14
to
Ian Harvey <ian_h...@bigpond.com> wrote:

> If you want to tithe to someone else... I think this is a link to the
> the zip archive of the source on dropbox.
>
> https://db.tt/PEDSuWyR
>
> But you will need a [mostly] F2003 compiler to build it. I use ifort
> 15.0, which still gets a bit wobbly around the edges. I think it a
> reasonable test source for that language level - it uses things like
> allocatable arguments, allocatable components, deferred length character
> and a lot of the polymorphic stuff (no UDDTIO or user defined type
> parameters yet).
>
> For solving the problem as initially described it is probably a bit like
> taking a sledgehammer to a chicken egg, but it originally started out as
> a Fortran 200[3|8] language learning exercise, plus I had fun.

Speaking of fun, that sounds like it would be fun to take a glance at.
(I know, I have strange ideas of fun. :-)) So I snarfed a copy. Didn't
bother to look at it right away, but just stashed it for later perusal.
Thanks.

--
Richard Maine
email: last name at domain . net
domain: summer-triangle

john.c...@simconglobal.com

unread,
Oct 27, 2014, 3:26:16 PM10/27/14
to
On Thursday, September 4, 2014 5:50:54 PM UTC+1, Beliavsky wrote:
> I can compare two versions of a Fortran source file, containing a single module with multiple procedures, using diff on Unix or fc on Windows. I'd like something that is more Fortran-aware and which can say for example that code foo_2.f90 has procedures x, y, and z not present in foo_1.f90 and that procedures a and b have been modified but that procedures c and d are the same in the two files.
>
> I could write a code in Python that does this, but I wonder if someone has already written such a utility.


We did this in fpt -
http://www.simconglobal.com/fpt_ref_compare_subprograms.html
However, in this forum, please be warned that it may not work for some post-Fortran 95 constructs. If you succeed in breaking it please tell us!

Best wishes,

John
0 new messages