2011-07-20 18:44:50 -04:00
|
|
|
#+Title: a collection of examples for ob-fortran tests
|
|
|
|
#+OPTIONS: ^:nil
|
|
|
|
|
|
|
|
* simple programs
|
|
|
|
:PROPERTIES:
|
|
|
|
:ID: 459384e8-1797-4f11-867e-dde0473ea7cc
|
|
|
|
:END:
|
|
|
|
#+source: hello
|
|
|
|
#+begin_src fortran :results silent
|
2011-07-18 03:44:07 -04:00
|
|
|
print *, 'Hello world'
|
|
|
|
#+end_src
|
|
|
|
|
2011-07-20 18:44:50 -04:00
|
|
|
#+source: fortran_parameter
|
|
|
|
#+begin_src fortran :results silent
|
2011-07-18 03:44:07 -04:00
|
|
|
integer, parameter :: i = 10
|
2011-07-20 18:44:50 -04:00
|
|
|
write (*, '(i2)') i
|
2011-07-18 03:44:07 -04:00
|
|
|
#+end_src
|
|
|
|
|
2011-07-20 18:44:50 -04:00
|
|
|
* variable resolution
|
|
|
|
:PROPERTIES:
|
|
|
|
:ID: d8d1dfd3-5f0c-48fe-b55d-777997e02242
|
|
|
|
:END:
|
|
|
|
#+begin_src fortran :var N = 15 :results silent
|
|
|
|
write (*, '(i2)') N
|
2011-07-18 03:44:07 -04:00
|
|
|
#+end_src
|
|
|
|
|
|
|
|
Define for preprocessed fortran
|
2011-07-20 18:44:50 -04:00
|
|
|
#+begin_src fortran :defines N 42 :results silent
|
2011-07-18 03:44:07 -04:00
|
|
|
implicit none
|
2011-07-20 18:44:50 -04:00
|
|
|
write (*, '(i2)') N
|
2011-07-18 03:44:07 -04:00
|
|
|
#+end_src
|
|
|
|
|
2011-07-20 18:44:50 -04:00
|
|
|
#+begin_src fortran :var s="word" :results silent
|
|
|
|
write (*, '(a4)') s
|
2011-07-18 03:44:07 -04:00
|
|
|
#+end_src
|
2011-07-20 18:44:50 -04:00
|
|
|
* arrays
|
|
|
|
:PROPERTIES:
|
|
|
|
:ID: c28569d9-04ce-4cad-ab81-1ea29f691465
|
|
|
|
:END:
|
|
|
|
Real array as input
|
|
|
|
#+begin_src fortran :var s='(1.0 2.0 3.0) :results silent
|
|
|
|
write (*, '(3f5.2)'), s
|
2011-07-18 03:44:07 -04:00
|
|
|
#+end_src
|
|
|
|
|
2011-07-20 18:44:50 -04:00
|
|
|
#+tblname: test_tbl
|
|
|
|
| 1.0 |
|
|
|
|
| 2.0 |
|
|
|
|
|
|
|
|
#+begin_src fortran :var s=test_tbl :results silent
|
|
|
|
write (*, '(2f5.2)'), s
|
2011-07-18 03:44:07 -04:00
|
|
|
#+end_src
|
|
|
|
|
2011-07-20 18:44:50 -04:00
|
|
|
* failing
|
|
|
|
:PROPERTIES:
|
|
|
|
:ID: 891ead4a-f87a-473c-9ae0-1cf348bcd04f
|
|
|
|
:END:
|
2011-07-18 03:44:07 -04:00
|
|
|
Should fail (TODO: add input variables for the case with explicit
|
|
|
|
program statement)
|
2011-07-20 18:44:50 -04:00
|
|
|
#+begin_src fortran :var s="word" :results silent
|
2011-07-18 03:44:07 -04:00
|
|
|
program ex
|
|
|
|
print *, "output of ex program"
|
|
|
|
end program ex
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
Fails to compile (TODO: error check in ob-fortran.el)
|
2011-07-20 18:44:50 -04:00
|
|
|
#+begin_src fortran :var s='(1 ()) :results silent
|
2011-07-18 03:44:07 -04:00
|
|
|
print *, s
|
|
|
|
#+end_src
|
|
|
|
|
|
|
|
Should fail to compile with gfortran
|
2011-07-20 18:44:50 -04:00
|
|
|
#+begin_src fortran :flags --std=f95 --pedantic-error :results silent
|
2011-07-18 03:44:07 -04:00
|
|
|
program ex
|
|
|
|
integer*8 :: i
|
|
|
|
end program ex
|
|
|
|
#+end_src
|
|
|
|
|
2011-07-20 18:44:50 -04:00
|
|
|
* programs input parameters
|
|
|
|
:PROPERTIES:
|
|
|
|
:ID: 2d5330ea-9934-4737-9ed6-e1d3dae2dfa4
|
|
|
|
:END:
|
2011-07-18 03:44:07 -04:00
|
|
|
Pass parameters to the program
|
2011-07-20 18:44:50 -04:00
|
|
|
#+begin_src fortran :cmdline "23" :results silent
|
2011-07-18 03:44:07 -04:00
|
|
|
character(len=255) :: cmd
|
2011-07-20 18:44:50 -04:00
|
|
|
call get_command_argument(1, cmd)
|
2011-07-18 03:44:07 -04:00
|
|
|
write (*,*) trim(cmd)
|
|
|
|
#+end_src
|