From: Baalzamon on
I am attempting to convert some old fortran codes and becoming somewhat annoyed by the apparent jumping of code. WOuld I be correct in assuming that the code is read top to bottom and in line number order? If so where does the do label numbers figure into this scheme? Any advice from fortan programmers would be appreciated. To be explicit I think the coxde was written in F77...
From: Rune Allnor on
On 20 Mai, 13:37, "Baalzamon " <baalzamon_mori...(a)yahoo.com> wrote:
> I am attempting to convert some old fortran codes and becoming somewhat annoyed by the apparent jumping of code.

The infamous spaghetti style coding

http://en.wikipedia.org/wiki/Spaghetti_code

is the main reason why you ought not learn fortran at all.
It was obsolete 40 years ago. The only reason it remains
in use is the vast amount of legacy code present.


> WOuld I be correct in assuming that the code is read top to bottom and in line number order?

No. It *starts* that way, but from the first jump / break /
continue /
goto statement you are on your own with respect to untangling program
flow. Hence the spaghetti metafor.

> If so where does the do label numbers figure into this scheme?

They are the spots at which a jump / break / continue / goto might
refer. One serious problem with fortran is that there is no
convenient
way to find out where the jump that landed on the label was made.

> Any advice from fortan programmers would be appreciated. To be explicit I think the coxde was written in F77...

Don't write fortran. It might be more cost effective to find
out what the program is supposed to do, and then develop and
code the algorithm from scratch in matlab, C, C++ or Java.

No kidding.

Rune
From: Baalzamon on
Ah right much thanks. I don't intend to actually learn fortran - or rather just enough to understand the darn code. Well i'll ontinue my attemts at following it but like you suggested i might just see if i can obtain the actual maths behind this code and attempt to implement it straight into matlab. Fun Fun Fun?
Anyway thanks for the reply.
From: Rune Allnor on
On 20 Mai, 14:26, "Baalzamon " <baalzamon_mori...(a)yahoo.com> wrote:
> Ah right much thanks. I don't intend to actually learn fortran - or rather just enough to understand the darn code. Well i'll ontinue my attemts at following it but like you suggested i might just see if i can obtain the actual maths behind this code and attempt to implement it straight into matlab. Fun Fun Fun?

Fact of Life. And a reason for paying accute attention to
the algorithm development and documentation as opposed to
the source code. Whenever I implement something, I write a
companion document where all the minute deliberations are
recorded. I might not use the first matlab version for
eternity, but as long as I have access to that document
I can implement the algorithm in whatever language in a
matter of hours.

Rune
From: dpb on
Baalzamon wrote:
> Ah right much thanks. I don't intend to actually learn fortran - or
> rather just enough to understand the darn code. Well i'll ontinue my
> attemts at following it but like you suggested i might just see if i can
> obtain the actual maths behind this code and attempt to implement it
> straight into matlab. Fun Fun Fun?
> Anyway thanks for the reply.

Fortran is _NOT_ obsolete; the last Standard was for F2003 and F2008 is
in process. F77 was supplanted by F90/95 which incorporated much of
dynamic memory and other features. Control for structured programming
have been in common extensions since well before F77 and F77 formalized
IF blocks while F90 standardized CASE and DO WHILE, etc.

The answer to the specific questions you posed are...

a) Yes, code is sequential until a branch path is taken

b) Label numbers are only significant as the target for a branch (GOTO
computed IF, DO construct end or ERR= or END= location, etc.). The
magnitude of the label is not significant altho most coders had a
general convention the value itself is immaterial to the structure of
the code; it's just a label.

One key to Fortran that sometimes puzzles those who come from a C
background--the scope of Fortran compilation is the program unit, which
is _NOT_ the file but the individual PROGRAM, FUNCTION or SUBROUTINE mor
than one of which can be contained within a single file. Thus there are
not "file scope" variables, etc. For F77, global variables, if any,
typically will be in COMMON blocks (hopefully all of which will be
named, not blank COMMON).

There are tools that can help -- I've been very pleased w/ the
demonstration/trial usage of the "Understand for XXXX_Language"
analyzers from Scientific Toolworks <www.scitools.com> to help in
digging into legacy code. At the last time I actually had need altho
I've been retired for a few years now, it was still available fully
functional for a reasonable time as a free download that was sufficient
to accomplish a relatively small task such as yours sounds as if would
be. I know there are some other open source tools but I don't have a
handle on them; requests along that line would best be posted to
comp.lang.fortran instead of c.s-s.m. Also, if have future specific
questions regarding the code itself c.l.f is active and very helpful w/
several who are both ML and Fortran-literate.

--