Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-10

Converting Fortran to FPC?

29 messages · 10 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I have a question that might be OT here, but I will try nevertheless:

We have a Windows application written in Delphi for data analysis and display.
It uses GLScene as the data rendering engine and it uses 3 Fortran DLL:s to do the number crunching.

I want to port the whole thing to Lazarus/FPC and I have seen that GLScene is available for Lazarus (see separate thread). So far it looks promising, but I also need to handle the three Fortran DLL:s.

They were made using an Intel Fortran compiler plugged into Visual Studio several years back. The developer is no longer with us, but the sources (and the Windows compiler are).

So my question now is if there is any experience of either porting Fortran code to FPC or of compiling Fortran code for a Windows DLL into the corresponding function in Linux?
(By te way, is there such a thing as a DLL in Linux?)

Any info on this greatly appreciated!

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund

On Wed, 06 Oct 2010 23:34:29 +0200, Bo Berglund
wrote:

I found this converter by googling (offered on several websites, but basically the same everywhere):
http://sourceforge.net/projects/fortran2pascal/
but unfortunately it only handles Fortran77 code, whereas our code is Fortran90 syntax.
Tried it on one of the files but it created unusable pascal code.

So is there something for Fortran90 or later?

Bo Berglund Developer in Sweden

Reply by email

David W Noon
to Bo Berglund: I have a question that might be OT here, but I will try nevertheless: We have a Windows…

On Wed, 06 Oct 2010 23:34:29 +0200, Bo Berglund wrote about [Lazarus] Converting Fortran to FPC?:

[snip]

So my question now is if there is any experience of either porting Fortran code to FPC or of compiling Fortran code for a Windows DLL into the corresponding function in Linux?

I doubt you will find an automated tool that can handle newer standards for FORTRAN, as they differ radically from FORTRAN 77 and earlier. However, it is not too difficult to do the translation by hand, provided you have somebody available who is fluent in both languages. The only such person I know of is myself, but I'm not currently available.

(By te way, is there such a thing as a DLL in Linux?)

Yes, it is called a "shared object" library and usually has a .so suffix.

Regards, Dave [RLU #314465] *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* (David W Noon) *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: not available URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101007/d509682d/attachment.bin>

Reply by email

waldo kitty
to Bo Berglund: I have a question that might be OT here, but I will try nevertheless: We have a Windows…
Bo Berglund wrote
I have a question that might be OT here, but I will try nevertheless:

i don't see anything OT about it but then again, i'm just a lowly user like you :P

We have a Windows application written in Delphi for data analysis and display. It uses GLScene as the data rendering engine and it uses 3 Fortran DLL:s to do the number crunching.

ok...

I want to port the whole thing to Lazarus/FPC and I have seen that GLScene is available for Lazarus (see separate thread). So far it looks promising, but I also need to handle the three Fortran DLL:s.

ok... so... if the routines and actual work are known and understood, they should be easy enough to convert rather than attempting to maintain old unsupported code...

in reality, you're only possibly looking at converting the FORTRAN code to PASCAL code... it is doubtful that you'll need any object type stuff if it is just straight forward "old style" procedural code...

They were made using an Intel Fortran compiler plugged into Visual Studio several years back. The developer is no longer with us, but the sources (and the Windows compiler are).

that's at least one GoodThing<tm> ;)

So my question now is if there is any experience of either porting Fortran code to FPC or of compiling Fortran code for a Windows DLL into the corresponding function in Linux?

not sure about this but if the code is there and someone can understand it, it certainly should be easy enough to re-write it in PASCAL... or C or C++ or php or <insert your favorite modern language here> ;)

(By te way, is there such a thing as a DLL in Linux?)
i can definitely answer this last question! :lol;

yes... there certainly is... they are the libraries... in many cases they are named like foo.so or foo.1.2.3.4.so...

FWIW: there is probably a FORTRAN compiler for *nix... whether or not it can take your existing FORTRAN code and compile it to a library for *nix is another question... and, as noted above, there may not be any real need to keep those routines in FORTRAN... it may be pretty easy to convert them to PASCAL (or any other of today's languages)... it really depends on the code and, in the case of math functions, the precision needed...

HTH in some small way...

Reply by email

Mark Morgan Lloyd
to waldo kitty
waldo kitty wrote 7 lines
FWIW: there is probably a FORTRAN compiler for *nix... whether or not it can take your existing FORTRAN code and compile it to a library for *nix is another question... and, as noted above, there may not be any real need to keep those routines in FORTRAN... it may be pretty easy to convert them to PASCAL (or any other of today's languages)... it really depends on the code and, in the case of math functions, the precision needed...

Yes, I believe there's a GNU FORTRAN but other than eyeballing it to see what sort of parallelisation facilities it provides I've not touched FORTRAN for around 30 years.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Bo Berglund: On Wed, 06 Oct 2010 23:34:29 +0200, Bo Berglund I found this converter by googling…
Bo Berglund wrote 11 lines
On Wed, 06 Oct 2010 23:34:29 +0200, Bo Berglund wrote: I found this converter by googling (offered on several websites, but basically the same everywhere): http://sourceforge.net/projects/fortran2pascal/ but unfortunately it only handles Fortran77 code, whereas our code is Fortran90 syntax. Tried it on one of the files but it created unusable pascal code. So is there something for Fortran90 or later?

What sort of unusable? Does it document what target compiler it expects, i.e. GNU Pascal?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Bo Berglund
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 16 lines
Bo Berglund wrote: > On Wed, 06 Oct 2010 23:34:29 +0200, Bo Berglund > wrote: > > I found this converter by googling (offered on several websites, but > basically the same everywhere): > http://sourceforge.net/projects/fortran2pascal/ > but unfortunately it only handles Fortran77 code, whereas our code is > Fortran90 syntax. > Tried it on one of the files but it created unusable pascal code. > > So is there something for Fortran90 or later? What sort of unusable? Does it document what target compiler it expects, i.e. GNU Pascal?

Well it produces syntactically illegal pascal code... Here a short example of the start of a subroutine (newsreader has wrapped the code, long lines are ending with &) :

------ Fortran code -------
subroutine StiffnessFE(NodeX, NodeY, Conductivity, ReducedStiff, abscix, &
iElemX, iElemY, LocalNodes, CenterNodeX,
CenterNodeY, &
ElemArea)

use GlobalForw
implicit none

integer, intent(in) :: iElemX, iElemY
real(Rkind), intent(in), dimension(1:gNumNodes) :: NodeX, NodeY real(Rkind), intent(in), dimension(1:gNumElem) :: Conductivity

----- Translates to this ------------

procedure StiffnessFE(var NodeX, NodeY, Conductivity, ReducedStiff,
abscix,     &;
begin
iElemX, iElemY, LocalNodes, CenterNodeX, CenterNodeY, &;
ElemArea);
use GlobalForw;
, intent: array[in] of .... iElemX integer;
real(Rkind), intent(in), dimension(1:gNumNodes) :: NodeX, NodeY;
real(Rkind), intent(in), dimension(1:gNumElem) :: Conductivity;

------------------

You don't have to be an expert to see that this will not compile at all. The rest of the file looks much the same.

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Mark Morgan Lloyd: Yes, I believe there's a GNU FORTRAN but other than eyeballing it to see what sort of…
Mark Morgan Lloyd wrote 14 lines
waldo kitty wrote: > FWIW: there is probably a FORTRAN compiler for *nix... whether or not it > can take your existing FORTRAN code and compile it to a library for *nix > is another question... and, as noted above, there may not be any real > need to keep those routines in FORTRAN... it may be pretty easy to > convert them to PASCAL (or any other of today's languages)... it really > depends on the code and, in the case of math functions, the precision > needed... Yes, I believe there's a GNU FORTRAN but other than eyeballing it to see what sort of parallelisation facilities it provides I've not touched FORTRAN for around 30 years.

The author is an academcian and he used Fortran for number crunching (there is tomography involved) because he was not comfortable with pascal and there were code examples available from universities he could use. So he got us to buy the Intel compiler to make the DLL:s. Then he left after a few years and noone else understands the code.

I started out in the 60:s with Algol at university, then used assembler in the 70:s, then pascal and C in the 80:s anmd finally object pascal from about 1995 util now (have used all Delphi versions until 7 and then BDS2006).
Can't get my head around the fortran code....

The dll:s are each about 16-20 files varying between 70 to 400 lines of fortran source code.

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Mark Morgan Lloyd: Yes, I believe there's a GNU FORTRAN but other than eyeballing it to see what sort of…
Mark Morgan Lloyd wrote 14 lines
waldo kitty wrote: > FWIW: there is probably a FORTRAN compiler for *nix... whether or not it > can take your existing FORTRAN code and compile it to a library for *nix > is another question... and, as noted above, there may not be any real > need to keep those routines in FORTRAN... it may be pretty easy to > convert them to PASCAL (or any other of today's languages)... it really > depends on the code and, in the case of math functions, the precision > needed... Yes, I believe there's a GNU FORTRAN but other than eyeballing it to see what sort of parallelisation facilities it provides I've not touched FORTRAN for around 30 years.

The author is an academcian and he used Fortran for number crunching (there is tomography involved) because he was not comfortable with pascal and there were code examples available from universities he could use. So he got us to buy the Intel compiler to make the DLL:s. Then he left after a few years and noone else understands the code.

I started out in the 60:s with Algol at university, then used assembler in the 70:s, then pascal and C in the 80:s anmd finally object pascal from about 1995 util now (have used all Delphi versions until 7 and then BDS2006).
Can't get my head around the fortran code....

The dll:s are each about 16-20 files varying between 70 to 400 lines of fortran source code.

Bo Berglund Developer in Sweden

Reply by email

Juha Manninen gmail
to Bo Berglund: I have a question that might be OT here, but I will try nevertheless: We have a Windows…
Bo Berglund wrote
So my question now is if there is any experience of either porting Fortran code to FPC or of compiling Fortran code for a Windows DLL into the corresponding function in Linux?

I don't know Fortran much but it is a simpler language that Pascal and the conversion should be easier than eg. from C++.
You have the DLLs available, don't you? Learn the Fortran syntax, port the code and create proper test cases to compare the output of old and new code.

Or, start to maintain the Fortran code yourself. There are compilers available for many platforms. Besides, that would make you a Real Man. "Real Programmers Don't Use PASCAL" as noted in this article: http://www.ee.ryerson.ca/~elf/hack/realmen.html
Instead they use Fortran.
Ok, it is a bit outdated, written Fortran was already old and Pascal was something new. Today a similar joke would say: "Real Programmers Don't Use C#, They Use Pascal".

(By te way, is there such a thing as a DLL in Linux?)

Learn about command "ldconfig" and some other Linux basics. You will need it. There are lots of tutorials around in intenet.

Regards,
Juha

P.S.
This one was funny :-)

Nicklaus Wirth was once asked, "How do you pronounce your name?". He replied "You can either call me by name, pronouncing it 'Veert', or call me by value, 'Worth'."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101007/43c4e814/attachment.html>

Reply by email

Mark Morgan Lloyd
to Bo Berglund: On Thu, 07 Oct 2010 02:19:34 +0000, Mark Morgan Lloyd The author is an academcian and he…
Bo Berglund wrote 22 lines
On Thu, 07 Oct 2010 02:19:34 +0000, Mark Morgan Lloyd wrote: > Yes, I believe there's a GNU FORTRAN but other than eyeballing it to see > what sort of parallelisation facilities it provides I've not touched > FORTRAN for around 30 years. > The author is an academcian and he used Fortran for number crunching (there is tomography involved) because he was not comfortable with pascal and there were code examples available from universities he could use. So he got us to buy the Intel compiler to make the DLL:s. Then he left after a few years and noone else understands the code. I started out in the 60:s with Algol at university, then used assembler in the 70:s, then pascal and C in the 80:s anmd finally object pascal from about 1995 util now (have used all Delphi versions until 7 and then BDS2006). Can't get my head around the fortran code.... The dll:s are each about 16-20 files varying between 70 to 400 lines of fortran source code.

I'd suggest determining the minimum FORTRAN version that he's coded for then seeing what pretty-printers, flow diagrammers etc are available for that version.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Bo Berglund: On Thu, 07 Oct 2010 02:22:55 +0000, Mark Morgan Lloyd Well it produces syntactically…
Bo Berglund wrote 54 lines
On Thu, 07 Oct 2010 02:22:55 +0000, Mark Morgan Lloyd wrote: > Bo Berglund wrote: >> On Wed, 06 Oct 2010 23:34:29 +0200, Bo Berglund >> wrote: >> >> I found this converter by googling (offered on several websites, but >> basically the same everywhere): >> http://sourceforge.net/projects/fortran2pascal/ >> but unfortunately it only handles Fortran77 code, whereas our code is >> Fortran90 syntax. >> Tried it on one of the files but it created unusable pascal code. >> >> So is there something for Fortran90 or later? > What sort of unusable? Does it document what target compiler it expects, > i.e. GNU Pascal? > Well it produces syntactically illegal pascal code... Here a short example of the start of a subroutine (newsreader has wrapped the code, long lines are ending with &) : ------ Fortran code ------- subroutine StiffnessFE(NodeX, NodeY, Conductivity, ReducedStiff, abscix, & iElemX, iElemY, LocalNodes, CenterNodeX, CenterNodeY, & ElemArea) use GlobalForw implicit none integer, intent(in) :: iElemX, iElemY real(Rkind), intent(in), dimension(1:gNumNodes) :: NodeX, NodeY real(Rkind), intent(in), dimension(1:gNumElem) :: Conductivity ----- Translates to this ------------ procedure StiffnessFE(var NodeX, NodeY, Conductivity, ReducedStiff, abscix, &; begin iElemX, iElemY, LocalNodes, CenterNodeX, CenterNodeY, &; ElemArea); use GlobalForw; , intent: array[in] of .... iElemX integer; real(Rkind), intent(in), dimension(1:gNumNodes) :: NodeX, NodeY; real(Rkind), intent(in), dimension(1:gNumElem) :: Conductivity; ------------------ You don't have to be an expert to see that this will not compile at all. The rest of the file looks much the same.

If I'm reading that correctly & is being used as a continuation flag, in much the same way that \ is used in C or shell script. You might find that if you filtered that out (I tend to use Perl for that sort of job) before trying to run it through the converter that the output will make more sense.

You also need to determine what dialect of Pascal the output is: you could find that you're being given something obscure like Pascal-SC.

A few seconds Googling comes up with
http://community.freepascal.org:10000/bboards/message?message_id=145352&forum_id=24105 which points at a Windows-based converter, still '77 though. There's also apparently a FORTRAN to Ada converter f2a which could be a useful intermediary, however I can't so far see a URL (and I'm not putting much time into this since /I/ don't have any FORTRAN to convert :-)

[Slightly later] http://archive.adaic.com/tools/for2ada95/f2a.pl but the description indicates that it's strictly line-by-line.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Bo Berglund
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 6 lines
A few seconds Googling comes up with http://community.freepascal.org:10000/bboards/message?message_id=145352&forum_id=24105 which points at a Windows-based converter, still '77 though. There's also apparently a FORTRAN to Ada converter f2a which could be a useful intermediary, however I can't so far see a URL (and I'm not putting much time into this since /I/ don't have any FORTRAN to convert :-)

The URL did not work for me. Firefox shows an "Unable to connect" error. On examination of the URL I find the :10000 entry in the middle, which looks kind of funny. Is it by any chance a TCP port redirect? In tha case I have no chance since only port 80 is open in our firewall....

Bo Berglund

Reply by email

Mark Morgan Lloyd
to Bo Berglund: On Thu, 07 Oct 2010 09:04:04 +0000, Mark Morgan Lloyd The URL did not work for me.…
Bo Berglund wrote 15 lines
On Thu, 07 Oct 2010 09:04:04 +0000, Mark Morgan Lloyd wrote: > A few seconds Googling comes up with > http://community.freepascal.org:10000/bboards/message?message_id=145352&forum_id=24105 > which points at a Windows-based converter, still '77 though. There's > also apparently a FORTRAN to Ada converter f2a which could be a useful > intermediary, however I can't so far see a URL (and I'm not putting much > time into this since /I/ don't have any FORTRAN to convert :-) The URL did not work for me. Firefox shows an "Unable to connect" error. On examination of the URL I find the :10000 entry in the middle, which looks kind of funny. Is it by any chance a TCP port redirect? In tha case I have no chance since only port 80 is open in our firewall....

It worked here otherwise I'd not have given you the URL. I've just tried a different browser and it still works, our firewall is adequate and frequently tested (i.e. I'm /not/ running on an unfiltered line) but I'd rather not say much more than that on a public ML.

I've given you a link elsewhere for a Perl conversion script that might possibly be some use, but digging around I notice that a very frequently cited paper is

A Fortran to Pascal Translator R. A. Freak Softw., Pract. Exper., 11(7):717-716, 1981.

with the implication that nobody's done much work on that problem since the early 80s. I've been looking briefly at GNU Fortran and I notice that g77 is superseded by gfortran, and that the latter doesn't appear to have a facility to warn about usage that can't be ported to the older compiler.

I reckon that you've got to find out to what extent your programs are really F77 with a few newer features, because it might be that the bulk could be converted using one of the available tools. Alternatively look to see to what extent conversion tools can cope with the source that you've got, even if you have to modify them. Finally, f2c might help if it can handle a more recent dialect than f2a etc., I've not checked.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to Bo Berglund: On Thu, 07 Oct 2010 09:04:04 +0000, Mark Morgan Lloyd The URL did not work for me.…
Bo Berglund wrote 12 lines
On Thu, 07 Oct 2010 09:04:04 +0000, Mark Morgan Lloyd wrote: > A few seconds Googling comes up with > http://community.freepascal.org:10000/bboards/message?message_id=145352&forum_id=24105 > which points at a Windows-based converter, still '77 though. There's > also apparently a FORTRAN to Ada converter f2a which could be a useful > intermediary, however I can't so far see a URL (and I'm not putting much > time into this since /I/ don't have any FORTRAN to convert :-) The URL did not work for me. Firefox shows an "Unable to connect" error.

I'm sorry, my other response was less than helpful, I meant to reproduce the link on the cited page

http://www.irpcsoft.com/download/forpascsetup.exe

I'm very much not in the business of this sort of conversion. However it occurs to me that I might know somebody who is.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Bo Berglund
to Felipe Monteiro de Carvalho: Try using the same url with port 8080 Felipe Monteiro de Carvalho
Felipe Monteiro de Carvalho wrote
Try using the same url with port 8080

Tried:
http://community.freepascal.org:8080/bboards/message?message_id=145352&forum_id=24105 Same result.

Our IT department has very strict taps on traversing the firewall. For example they require Kerberos authentication to domain accounts for even the simplest web browsing. And they have only recently been persuaded to open FTP and NNTP ports. I have struggled for most of this decade for the NNTP port to be opened so I can do what I am doing now, namely searching for engineering answers in news servers on the Internet...

I guess I have to do the look up back home tonight where I manage the firewall myself...

Bo Berglund

Reply by email

Felipe Monteiro de Carvalho
to Bo Berglund

The contents of the page are small. I'll just copy here:

Fortran to Pascal
Notify me of responses
HI! I've read about a very good converter from Fortran 77 to Pascal, ForPasC, and tried to download it, but all the links seem to be broken. Could anybody provide me with the program, perhaps for Linux? Thanks, bye

Silvio in Ithaca
-- Silvio a Beccara, 15 July 2003 15:14 (email)

Answers:

http://www.irpcsoft.com/download/forpascsetup.exe that it the link for the windows/dos version, i don't know if there is a linux version.

good bye and happy coding :-P

DC740
-- Emilio Moretti, 26 March 2005 16:21 (email)

There is Semi-automatic Fortran to Pascal converter by simple string manipulations at http://www.shokhirev.com/nikolai/programs/tools.html (see also the project at SourceForge:
http://sourceforge.net/projects/fortran2pascal/ ).

Nikolai
-- Nikolai Shokhirev, 22 December 2006 04:24

Felipe Monteiro de Carvalho

Reply by email

Gustavo Enrique Jimenez
to Bo Berglund: I have a question that might be OT here, but I will try nevertheless: We have a Windows…

Hi

2010/10/6 Bo Berglund :

Show quoted text 23 lines
I have a question that might be OT here, but I will try nevertheless: We have a Windows application written in Delphi for data analysis and display. It uses GLScene as the data rendering engine and it uses 3 Fortran DLL:s to do the number crunching. I want to port the whole thing to Lazarus/FPC and I have seen that GLScene is available for Lazarus (see separate thread). So far it looks promising, but I also need to handle the three Fortran DLL:s. They were made using an Intel Fortran compiler plugged into Visual Studio several years back. The developer is no longer with us, but the sources (and the Windows compiler are). So my question now is if there is any experience of either porting Fortran code to FPC or of compiling Fortran code for a Windows DLL into the corresponding function in Linux? (By te way, is there such a thing as a DLL in Linux?) Any info on this greatly appreciated!

There is an Intel Fortran Compiler for Linux, 30 days evaluation for free. You could try to recompile those DLLs. If the recompile works, it will generate a .so file instead of a .dll, wich is a shared object on Linux.

Gustavo

Show quoted text 12 lines
-- Bo Berglund Developer in Sweden -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

C Western
to Gustavo Enrique Jimenez
Gustavo Enrique Jimenez wrote 32 lines
Hi 2010/10/6 Bo Berglund: > I have a question that might be OT here, but I will try nevertheless: > > We have a Windows application written in Delphi for data analysis and > display. > It uses GLScene as the data rendering engine and it uses 3 Fortran > DLL:s to do the number crunching. > > I want to port the whole thing to Lazarus/FPC and I have seen that > GLScene is available for Lazarus (see separate thread). > So far it looks promising, but I also need to handle the three Fortran > DLL:s. > > They were made using an Intel Fortran compiler plugged into Visual > Studio several years back. The developer is no longer with us, but the > sources (and the Windows compiler are). > > So my question now is if there is any experience of either porting > Fortran code to FPC or of compiling Fortran code for a Windows DLL > into the corresponding function in Linux? > (By te way, is there such a thing as a DLL in Linux?) > > Any info on this greatly appreciated! > There is an Intel Fortran Compiler for Linux, 30 days evaluation for free. You could try to recompile those DLLs. If the recompile works, it will generate a .so file instead of a .dll, wich is a shared object on Linux.

The mingw has a port of the GNU fortran compiler for windows, and I have linked fortran compiled with this with free pascal code. On linux the code produced by the GNU fortran compiler can also be linked with free pascal programs - I use the LAPACK library this way.

Colin

Reply by email

Bo Berglund
to Felipe Monteiro de Carvalho: The contents of the page are small. I'll just copy here: Fortran to Pascal Notify me of…
Felipe Monteiro de Carvalho wrote
http://www.irpcsoft.com/download/forpascsetup.exe that it the link for the windows/dos version, i don't know if there is a linux version.

I downloaded and tried it but the result was not very informative:

STIFF.FOR:
Fatal error: invalid FORTRAN text!

Show quoted text 7 lines
There is Semi-automatic Fortran to Pascal converter by simple string manipulations at http://www.shokhirev.com/nikolai/programs/tools.html (see also the project at SourceForge: http://sourceforge.net/projects/fortran2pascal/ ).

This link actually contains sources for the ForToPas program so I loaded that in Delphi7 and stepped through it.
The code is very strange with *lots* of gotos and strange conditionals that seem not to think that I would need a lot of time to go over this and just get it to work correctly according to the comments in the code.... And then I would not know if it actually did the right conversions.

Bo Berglund Developer in Sweden

Reply by email

Juha Manninen gmail
to Bo Berglund
Bo Berglund wrote
I think that I would need a lot of time to go over this and just get it to work correctly according to the comments in the code.... And then I would not know if it actually did the right conversions.

You have the original DLLs to test with, don't you? That is what I understood earlier.

Juha

Reply by email

Bo Berglund
to Juha Manninen gmail
Show quoted text 8 lines
On Thursday 07 October 2010 21:36:14 Bo Berglund wrote: > I think that I would need a lot of time to go over this and just get > it to work correctly according to the comments in the code.... > And then I would not know if it actually did the right conversions. You have the original DLLs to test with, don't you? That is what I understood earlier.

What I meant is that I found the Delphi code for the ForToPas program. Since it did not work I tried to open the ForToPas project in D7 and correct the erroneous code. But it is written in a very strange way so it would need a lot of going over to make it work for converting the Fortran code to Pascal.

Concerning the DLL:s I have the Windows binaries and I have the Fortran90 sourcecode including the VisualSydio sln file (the compiler was plugged into Visual Studio at the time).
But my goal is to convert the functions into pascal so they can be compiled with FPC on both Windows and Linux.
And I don't need them to be DLL:s or the equivalent for Linux either, they may as well be ordinary procedures called from the code in the normal embedded way. I just do not understand what they are doing since I don't read Fortran.

Bo Berglund Developer in Sweden

Reply by email

Juha Manninen gmail
to Bo Berglund
Bo Berglund wrote 5 lines
What I meant is that I found the Delphi code for the ForToPas program. Since it did not work I tried to open the ForToPas project in D7 and correct the erroneous code. But it is written in a very strange way so it would need a lot of going over to make it work for converting the Fortran code to Pascal.

Apparently the automatic conversion doesn't work. You must do it manually. It is not only a bad thing because then you also must understand the code while converting it.

Concerning the DLL:s I have the Windows binaries and I have the Fortran90 sourcecode including the VisualSydio sln file (the compiler was plugged into Visual Studio at the time).

Good. That's what I meant. You can use them to verify that your conversion is correct.

Show quoted text 6 lines
But my goal is to convert the functions into pascal so they can be compiled with FPC on both Windows and Linux. And I don't need them to be DLL:s or the equivalent for Linux either, they may as well be ordinary procedures called from the code in the normal embedded way. I just do not understand what they are doing since I don't read Fortran.

Learn to read it. It can't be very difficult. For example C++ is a complicated and difficult language but Fortran is an old and primitive language. You should be able to learn the syntax quickly. Your code is arithmetic calculation which should map to Pascal's math operators and functions nicely. Googling for "Fortran tutorial" gives for example: http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html which looks good.

After you understood what the functions do and converted them, then create a test program that feeds different input to every function and compares their output with the original Fortran functions' output. You can even create a test-version of the real program which calls those functions, by adding another call for the converted function and then comparing the results.

Juha

Reply by email

Bo Berglund
to Juha Manninen gmail
Apparently the automatic conversion doesn't work. You must do it manually. It is not only a bad thing because then you also must understand the code while converting it.

Yeah, yet another language to master...
I dived into Java for this project back in May, but it was so tedious that I slowed down and then I realized that Lazarus might fit the bill instead.
And now the scope has widened when I realized that all of our Delphi code is candidate for conversion to Lazarus and hence Linux. :-)

This in turn has popped the Fortran conversion issue.

I already had a look at manual conversion of a few functions and tey look fairly simple really, mostly a lot of array manipulations in do loops.

Show quoted text 8 lines
Learn to read it. It can't be very difficult. For example C++ is a complicated and difficult language but Fortran is an old and primitive language. You should be able to learn the syntax quickly. Your code is arithmetic calculation which should map to Pascal's math operators and functions nicely. Googling for "Fortran tutorial" gives for example: http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html which looks good.

Thanks for the link, I'll have a look. I also found this myself: http://www.idris.fr/data/cours/lang/fortran/f90/F77.html

It deals with Fortran77 but also mentions later constructs. Anyway by looking here I could understand how the conversion code works better. Apparently Fortran77 is column oriented such that certain control data are supposed to be located in fixed positions on each line! That never occurred to me. It is a leftover from the punchcard times where each program line was on an 80 char punchcard. Ouch!

Show quoted text 6 lines
After you understood what the functions do and converted them, then create a test program that feeds different input to every function and compares their output with the original Fortran functions' output. You can even create a test-version of the real program which calls those functions, by adding another call for the converted function and then comparing the results.

Exactly!
But there are a lot of files, about 30 in total.
Just work though.

Bo Berglund Developer in Sweden

Reply by email

Mark Morgan Lloyd
to Bo Berglund: On Fri, 8 Oct 2010 01:56:10 +0300, "Juha Manninen (gmail)" Yeah, yet another language to…
Bo Berglund wrote
I already had a look at manual conversion of a few functions and tey look fairly simple really, mostly a lot of array manipulations in do loops.

Be warned that you might need to be careful with numeric accuracy- rounding errors etc. It would be good practice to make sure that you had a suite of test cases available, that you could either put through the original FORTRAN or through your transcribed Pascal. Particular cases to watch out for are where you're dealing with high-order polynomials, and where you're repeatedly iterating to reach a decision (think of the way a Mandelbrot set works).

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Thierry Coq
to Bo Berglund: I have a question that might be OT here, but I will try nevertheless: We have a Windows…
Bo Berglund wrote 7 lines
So my question now is if there is any experience of either porting Fortran code to FPC or of compiling Fortran code for a Windows DLL into the corresponding function in Linux? (By te way, is there such a thing as a DLL in Linux?)

Have you looked here?

http://www.efg2.com/Lab/Library/Delphi/MathInfo/Resources.htm

I had used Hans Lohninger's matrix quite effectively on a previous program. You might find other pascal resources that will allow you not to recode the LAPACK routines.
Be careful about your numerical precision requirements.

FYI, Fortran 77 is rather easy to port. The language is structured, and the data is easily converted, if you bear in mind that most data is stored and exchanged in common blocks. Only some data is passed through subroutines arguments. There would be very limited dynamic data if any. You might have a learning curve for the string (FORMAT) functions, but that should not be a problem here.

Hope this helps,
Thierry

Reply by email

Bo Berglund
to Thierry Coq
Thierry Coq wrote 16 lines
On 06/10/2010 23:34, Bo Berglund wrote: > So my question now is if there is any experience of either porting > Fortran code to FPC or of compiling Fortran code for a Windows DLL > into the corresponding function in Linux? > (By te way, is there such a thing as a DLL in Linux?) > > > Have you looked here? http://www.efg2.com/Lab/Library/Delphi/MathInfo/Resources.htm I had used Hans Lohninger's matrix quite effectively on a previous program. You might find other pascal resources that will allow you not to recode the LAPACK routines. Be careful about your numerical precision requirements.

Couldn't find any downloads at SDL except for "light" or "demo" versions...

Show quoted text 7 lines
FYI, Fortran 77 is rather easy to port. The language is structured, and the data is easily converted, if you bear in mind that most data is stored and exchanged in common blocks. Only some data is passed through subroutines arguments. There would be very limited dynamic data if any. You might have a learning curve for the string (FORMAT) functions, but that should not be a problem here.

I found it to be too hard work for now, so I am concentrating on the simpler parts of the project, communicating with the data acquisition system using 5dpoSerial....

Bo Berglund Developer in Sweden

Reply by email