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

Click For Summary

Discussion Overview

The discussion revolves around the challenges of translating Fortran 77 code into Python for solving a system of ordinary differential equations (ODEs) related to atmospheric emissions. Participants are seeking assistance in running the Fortran code to compare variable values with their Python implementation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant expresses difficulty in understanding Fortran and requests help in running the Fortran code to obtain variable values for comparison with their Python code.
  • Another participant suggests using an online Fortran compiler to run the code.
  • Several participants note that the Fortran code lacks a main program to print the final solution and suggest that an example of how to call the subroutines would be beneficial.
  • One participant emphasizes the importance of correctly calling subroutines to obtain answers and expresses uncertainty about how to do this.
  • There are repeated requests for someone to run the Fortran code and provide results, highlighting a reliance on others for assistance.
  • A participant shares a Python code snippet that includes initial conditions and calculations, indicating an attempt to replicate the Fortran code's functionality.

Areas of Agreement / Disagreement

Participants generally agree on the need for a main program in the Fortran code to print results and the importance of correctly calling subroutines. However, there is no consensus on how to proceed with running the Fortran code or translating it effectively into Python, as multiple participants express varying levels of familiarity with Fortran.

Contextual Notes

Participants mention the complexity of the Fortran code and the potential difficulty in rewriting it within the forum discussion format. There is also a lack of clarity on how to properly execute the Fortran subroutines without additional examples or guidance.

  • #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
2K
  • · Replies 10 ·
Replies
10
Views
4K
Replies
55
Views
7K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K