Python Can Fortran 77 Code Be Used to Debug Python Code for Solving ODEs Using Radau5?

Click For Summary
The discussion centers around the challenges of translating Fortran code into Python, particularly for a system of 66 ordinary differential equations (ODEs) related to atmospheric emissions. The original poster seeks assistance in running the Fortran code to obtain variable values for comparison with their Python implementation. They express difficulty in understanding the Fortran code, noting that it lacks a main program to call the necessary subroutines and print results. Participants emphasize the need for a main program to execute the subroutines correctly and suggest that without it, the Fortran code cannot be run as intended. There is a consensus that debugging the Fortran code is essential before any translation can be effectively completed. Some participants recommend hiring a Fortran programmer for more specialized help, as the code's current state does not provide the expected output. The conversation highlights the complexities of working with legacy code and the importance of having complete, functional code before attempting to translate it into another programming language.
  • #61
PS:
Below the results from solving the 66 ODEs in Python using Radau5:
Figure_1.png
 
  • Like
Likes Tom.G, pbuk and FactChecker
Technology news on Phys.org
  • #62
For what it's worth: I found the program that calls the routines in emep.f
The site has been moved to http://pitagora.dm.uniba.it/~testset/solvers/radau5.php
Pdf: radau5
The program is radau5d
It calls prob, init etc, and radau5
Other stuff in radaua and report

PDF http://archimede.dm.uniba.it/~testset/report/prologue.pdf has some documentation (page 16 onwards)
IV.3 Format of the problem codes
The eight subroutines that define the problem are called PROB, INIT, SETTOLERANCES, SETOUTPUT,FEVAL, JEVAL, MEVAL, and SOLUT. The following subsections describe the format of these subroutinesin full detail. An additional function PIDATE ...

Vick's emep.f from https://archimede.uniba.it/~testset/problems/emep.php

[edit]
@Vick: no fortran needed so far. I see that report.f has some utility to generate a
MATLAB and a SCILAB function to print the plots of the solution

just in case I can get a fortran compiler to run on this ancient PC: can you post a link to the .py source used for post #61 ?

##\ ##
 
Last edited:
  • #63
BvU said:
For what it's worth: I found the program that calls the routines in emep.f
The site has been moved to http://pitagora.dm.uniba.it/~testset/solvers/radau5.php
Pdf: radau5
The program is radau5d
It calls prob, init etc, and radau5
Other stuff in radaua and report

PDF http://archimede.dm.uniba.it/~testset/report/prologue.pdf has some documentation (page 16 onwards)


Vick's emep.f from https://archimede.uniba.it/~testset/problems/emep.php

[edit]
@Vick: no fortran needed so far. I see that report.f has some utility to generate a
MATLAB and a SCILAB function to print the plots of the solution

just in case I can get a fortran compiler to run on this ancient PC: can you post a link to the .py source used for post #61 ?

##\ ##
The testset emep.f is Fortran coding. As I am using Python, I needed a translation of the emep.f into Python. I succeeded and post 61 is the result of my own code using my own Radau5 code. Thanks
 
  • #64
I will just say that in my experience the biggest hazard in translating numerical computations from one language to another may have to do with differences in how the two languages store and organize arrays internally. I don't know what Python does but there is a good chance it is different from what Fortran does.
 
  • #65
harborsparrow said:
I will just say that in my experience the biggest hazard in translating numerical computations from one language to another may have to do with differences in how the two languages store and organize arrays internally. I don't know what Python does but there is a good chance it is different from what Fortran does.
This is a hazard in at least two ways: indexing (is the initial index one or zero), and ordering (row major vs column major). Fortran and MATLAB use one-based indexing and column major order. C, C++, and several other languages use zero-based indexing and row major order. The zero vs one based indexing can be overcome. The order issue is harder to overcome.

As an example, the initial versions of the book "Numerical Recipes in C" were a direct transliteration of the original FORTRAN code (not Fortran, but FORTRAN. FORTRAN was the original name, which means very old code). They used some clever (or perhaps not clever) hacks to get around the indexing issue. They did not do anything with regard to multidimensional arrays, which meant that the memory-efficient FORTRAN algorithms became memory-inefficient in C. Recoding algorithms that use multidimensional arrays is non-trivial. Transliteration oftentimes results in poor performing code.

As far as Python goes, numpy does offer an "order=C" (the default) and "order=F" option on creating and populating a multidimensional array, which might offer some improvements. However, the slowness of Python vs C, C++, Fortran, and Julia typically removes all of those improvements.
 
  • Informative
  • Like
Likes FactChecker and harborsparrow

Similar threads

Replies
3
Views
2K
  • · Replies 14 ·
Replies
14
Views
5K
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 10 ·
Replies
10
Views
3K
Replies
55
Views
6K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
Replies
7
Views
2K