Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Parsing and converting Fortran expression

by kikuchiyo (Hermit)
on Aug 25, 2015 at 21:29 UTC ( [id://1139928]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Parsing and converting Fortran expression
in thread Parsing and converting Fortran expression [solved]

I've experimented it with a bit, but apparently it's not that easy: f2c seems to make all sorts of assumptions about variables, functions and expected output, many of which turn out to be wrong (e.g. by default, it interprets the statement "a = foo(1,2)" as if foo were a function, so it turns that into "a = foo_(&c__1, &c__2)" which is useless for me). To coax it into generating usable output I'd have to declare variables with their correct dimensions and sizes and so on, so in the end I'd have to replace the original non-trivial problem with several more, even more non-trivial problems.

Extracting the expression parsing part from the source might be an avenue worth exploring, but then there is this comment in the linked pdf:

"The program f2c is a horror, based on ancient code and hacked unmercifully. Users are only supposed to look at its C output, not at its appalling inner workings."

  • Comment on Re^3: Parsing and converting Fortran expression

Replies are listed 'Best First'.
Re^4: Parsing and converting Fortran expression
by afoken (Chancellor) on Aug 26, 2015 at 05:25 UTC
    f2c seems to make all sorts of assumptions about variables, functions and expected output, many of which turn out to be wrong (e.g. by default, it interprets the statement "a = foo(1,2)" as if foo were a function, so it turns that into "a = foo_(&c__1, &c__2)"

    I've used Fortran exactly twice, for "hello world" class programs, and that was about 20 years ago. But I think this is how Fortran actually works. If there is no matching array in the current scope, it must be a function call. And so on.

    What is the context in which you need to parse / translate Fortran expressions? I.e. what problem are you actually trying to solve? My guess is that Fortran expressions should be quite rare outside a Fortran program, hence f2c.

    "The program f2c is a horror, based on ancient code and hacked unmercifully. Users are only supposed to look at its C output, not at its appalling inner workings."

    How desperate are you? Real world old code almost always looks ugly and has been hacked into a state where at least parts of it "just works, probably by pure magic". f2c looks quite small, so it should not be that hard to find and understand the relevant parts.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

      what problem are you actually trying to solve? My guess is that Fortran expressions should be quite rare outside a Fortran program, hence f2c.

      This guess is unfortunately false. As to the actual problem: ugly old proprietary program at $work that uses Fortran-style expressions in certain contexts needs to be ported to a different framework that required generation of C code.

      Real world old code almost always looks ugly and has been hacked into a state where at least parts of it "just works, probably by pure magic". f2c looks quite small, so it should not be that hard to find and understand the relevant parts.

      Believe me, I've seen more real world old code than I'd have liked. "I've seen things you humans wouldn't believe" and so on. And luckily, a better, or at least easier, solution appeared in this thread.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1139928]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 22:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found