본문 바로가기

Programming

[Fortran code convert to Python] 포트란 코드를 파이썬 코드로 바꾸기

728x90
반응형
회사 업무로인해 공력해석을 진행하면서 관련 도서를 뒤져보면 최신의 책들이 아닌이상 거의 포트란 코드들이 많다. 포트란 코드를 파이썬 코드로 자동 converting 해주면 좋겠지만, 내 맘처럼 쉽게 찾지 못했다... 누군가 만들었지 않았을까 싶은데. gfortran 깔아서 사용하려고 하다가 포기했다.

그래서 내린 결론!

 

 

그냥 포트란 코드를 line by line으로 읽어서 파이썬으로 코드를 짜자!

예전에 대학원에서 학우들과 했던 기억을 되살려 하려고 하니, 당연하겠지만 하나도 기억에 남지 않았다.

그래서 다시 web surfing을 하던 중 발견한 사이트가 있다.

http://www.numericalexpert.com/blog/fotran90_to_python/

 

Fortran 90 to Python conversion

Numerical experiments, Tips, Tricks and Gotchas All classical numerical algorithms were first implemented in FORTRAN and ALGOL [1-6] and later translated to many other languages. Numerous robust, efficient and reliable algorithms in FORTRAN still are freel

www.numericalexpert.com

위 사이트를 참고하였음

1. 알고리즘

(1) 포트랑 문장를 파이썬 문장로 변경

(2) Math function 파이썬으로 변경

(3) 포트란 특정 문장을 주석처리

(4) 포트란의 'do' loop를 파이썬의 'for' loop로 변경

(5) Array 접근을 '()'에서 '[]'로 변경

(6) function header 변경

 

2. 참고 사이트

(1) 아래는 주피터 노트북에 복사붙여넣기 해서 사용할 수 있는 소스코드이다.

http://www.numericalexpert.com/blog/fotran90_to_python/f90_to_py.html

 

Fortran 90 to Python conversion by string manipulation

Simple Fortran 90 to Python conversion by string manipulations: 1. Replacement of Fortran statements with corresponding Python statements 2. Replacement of math functions 3. Commenting out Fortan-specific statment (e.g. integer, end do) 4. Conversion of do

www.numericalexpert.com

 

 

(2) 아래에서는 소스코드를 다운받을 수 있는 곳이고,

http://www.numericalexpert.com/blog/fotran90_to_python/f90_to_py.ipynb

 

(3) 아래는 Youtube에서 찾은건데 위의 접근방식과 비슷하게 실시간으로 따라해볼 수 있는 영상이다.

https://www.youtube.com/watch?v=nqsxjwUmmuA 

 

728x90
반응형