# Translate fortran to julia

**URL:** <https://discourse.julialang.org/t/translate-fortran-to-julia/23624>\
**Category:** General Usage\
**Tags:** question, fortran\
**Created:** [April 28, 2019, 6:51pm UTC](https://discourse.julialang.org/t/translate-fortran-to-julia/23624 "2019-04-28T18:51:59Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [April 29, 2019, 9:24am UTC](https://discourse.julialang.org/t/translate-fortran-to-julia/23624/21 "2019-04-29T09:24:48Z")

</div>

The `dpm.f` file in the [code I linked above](https://inte.upc.edu/en/downloads/dpm-v1.1/dpmv1.1.zip/@@download/file/dpm1.1.zip) probably contains most features needed. Do you want something executable as well? If so I can build that for you.

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [April 29, 2019, 9:32am UTC](https://discourse.julialang.org/t/translate-fortran-to-julia/23624/22 "2019-04-29T09:32:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [April 30, 2019, 1:51pm UTC](https://discourse.julialang.org/t/translate-fortran-to-julia/23624/23 "2019-04-30T13:51:27Z")

</div>

Looking at the README here this is radiotherapy simulation code  
[https://inte.upc.edu/en/downloads/dpm-v1.1/readme/view](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](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.

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [April 30, 2019, 2:10pm UTC](https://discourse.julialang.org/t/translate-fortran-to-julia/23624/24 "2019-04-30T14:10:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [April 30, 2019, 2:20pm UTC](https://discourse.julialang.org/t/translate-fortran-to-julia/23624/25 "2019-04-30T14:20:10Z")

</div>

By the way, that [Reduce.jl](https://github.com/chakravala/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](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](http://www.reduce-algebra.com/manual/manualse119.html#x152-49000016.26) 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](https://liberapay.com/chakravala) to work on it.

_EDIT_: locally I’ve also got both the Fortan 77 and Fortan 90-95 texbtooks / specifications available.

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [May 1, 2019, 3:31pm UTC](https://discourse.julialang.org/t/translate-fortran-to-julia/23624/26 "2019-05-01T15:31:34Z")

</div>

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()

---

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [May 1, 2019, 3:58pm UTC](https://discourse.julialang.org/t/translate-fortran-to-julia/23624/27 "2019-05-01T15:58:23Z")

</div>

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?

[Previous page](https://discourse.julialang.org/t/translate-fortran-to-julia/23624.md?page=1)
