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

Click For Summary
SUMMARY

The discussion centers on the challenges of translating Fortran 77 code into Python for solving a system of 66 ordinary differential equations (ODEs) related to atmospheric emissions. Users emphasize the necessity of running the original Fortran code to obtain variable values such as RC, DJ, Y, and T at TIME=331250 for validation against the Python implementation. It is highlighted that a main program is required to call the Fortran subroutines and print results, which is crucial for debugging and ensuring the accuracy of the Python translation.

PREREQUISITES
  • Understanding of Fortran 77 syntax and structure
  • Familiarity with Python programming, particularly for scientific computing
  • Knowledge of numerical methods for solving ordinary differential equations (ODEs)
  • Experience with debugging techniques in both Fortran and Python
NEXT STEPS
  • Research how to implement Fortran subroutine calls in Python using tools like F2PY
  • Learn about the Radau5 solver for ODEs in Python
  • Explore methods for validating numerical solutions between different programming languages
  • Investigate online Fortran compilers and debugging tools for testing legacy code
USEFUL FOR

Researchers, software developers, and environmental scientists working on atmospheric modeling and emissions analysis who need to translate legacy Fortran code into modern programming languages for enhanced accessibility and functionality.

  • #61
PS:
Below the results from solving the 66 ODEs in Python using Radau5:
Figure_1.png
 
  • Like
Likes   Reactions: 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
 
  • Like
Likes   Reactions: BvU
  • #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   Reactions: FactChecker and harborsparrow

Similar threads

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