Translate fortran to julia

The dpm.f file in the code I linked above probably contains most features needed. Do you want something executable as well? If so I can build that for you.

I am really impressed by your devotion to parsing and this kind of stuff. This is not urgent and you should in no way feel obliged to do this at all or in any time frame. If you abandon the thing at any point I would completly understand.

4 Likes

Looking at the README here this is radiotherapy simulation code
https://inte.upc.edu/en/downloads/dpm-v1.1/readme/view
Which depends on this Monte Carlo code
https://www.oecd-nea.org/tools/abstract/detail/nea-1525

As @tamasgal says are you not much better using the Monte Carlo code as it stands, and using Julia as a ā€˜front endā€™ for interactive use, plotting etc.
I am not being in any way defeatist, but re-implementing a Monte Carlo code like that could be years of work.

Yes my aim is to use julia as a front end. If there was an API to that code, I would just wrap it. But there is none. So I only see the following options for communication between frontend and backend:

  1. manual (e.g. edit input files by hand)
  2. string based (let julia parse and generate input and output strings)
  3. transpile
  4. rewrite
  5. write API in fortran

I have experience with 1. and 2. on similar codes. I donā€™t like them. I agree that 4. is years of work. So I want to try out 3. If it turns out too hard I will go back to 2. or try 5.

By the way, that Reduce.jl of mine has a parser-generator built-in which can convert blocks of REDUCE program code into Julia AST, it can parse back and forth between the two languages.

https://github.com/chakravala/Reduce.jl

Although this is string rewriting based, it is fundamentally based on Abstract Syntax Treesā€¦ but due to some weird quirks in the REDUCE language it was entirely custom made for this purpose.

It so happens that REDUCE also has a feature to generate FORTAN code in the GENTRAN packge.

I would possibly be interested in writing a translator like this for Fortan; but it wouldnā€™t be first a priority of mine at the moment unless somebody paid me or donated to work on it.

EDIT: locally Iā€™ve also got both the Fortan 77 and Fortan 90-95 texbtooks / specifications available.

3 Likes

Isnā€™t there another half-way option - to rewrite just enough to be able to call the internal Fortran functions from Julia without needing text input? If the problem is just the input files, why do you need to rewrite the whole codebase?

  1. Rewrite input in Julia, call internal Fortran routines with ccall()
1 Like

Yeah, that sounds like a good approach as well. One obstacle is that I do not know how to manipulate common blocks from julia. Probably one needs to write setters and getters to do that?