Merge branch 'maint'
[org-mode.git] / testing / examples / ob-fortran-test.org
blob47931bf9daca1b9b406820458e4e92b7b6cbb494
1 #+Title: a collection of examples for ob-fortran tests
2 #+OPTIONS: ^:nil
4 * simple programs
5   :PROPERTIES:
6   :ID:       459384e8-1797-4f11-867e-dde0473ea7cc
7   :END:
8 #+name: hello
9 #+begin_src fortran :results silent
10 print *, 'Hello world'
11 #+end_src
13 #+name: fortran_parameter
14 #+begin_src fortran :results silent
15 integer, parameter :: i = 10
16 write (*, '(i2)') i
17 #+end_src
19 * variable resolution
20   :PROPERTIES:
21   :ID:       d8d1dfd3-5f0c-48fe-b55d-777997e02242
22   :END:
23 #+begin_src fortran :var N = 15 :results silent
24 write (*, '(i2)') N
25 #+end_src
27 Define for preprocessed fortran
28 #+begin_src fortran :defines N 42 :results silent
29 implicit none
30 write (*, '(i2)') N
31 #+end_src
33 #+begin_src fortran :var s="word" :results silent
34 write (*, '(a4)') s
35 #+end_src
36 * arrays
37   :PROPERTIES:
38   :ID:       c28569d9-04ce-4cad-ab81-1ea29f691465
39   :END:
40 Real array as input
41 #+begin_src fortran :var s='(1.0 2.0 3.0) :results silent
42 write (*, '(3f5.2)'), s
43 #+end_src
45 #+tblname: test_tbl
46 | 1.0 |
47 | 2.0 |
49 #+begin_src fortran :var s=test_tbl :results silent
50 write (*, '(2f5.2)'), s
51 #+end_src
53 * failing
54   :PROPERTIES:
55   :ID:       891ead4a-f87a-473c-9ae0-1cf348bcd04f
56   :END:
57 Should fail (TODO: add input variables for the case with explicit
58 program statement)
59 #+begin_src fortran :var s="word" :results silent
60 program ex
61 print *, "output of ex program"
62 end program ex
63 #+end_src
65 Fails to compile (TODO: error check in ob-fortran.el)
66 #+begin_src fortran :var s='(1 ()) :results silent
67 print *, s
68 #+end_src
70 Should fail to compile with gfortran
71 #+begin_src fortran :flags --std=f95 --pedantic-error :results silent
72 program ex
73 integer*8 :: i
74 end program ex
75 #+end_src
77 * programs input parameters
78   :PROPERTIES:
79   :ID:       2d5330ea-9934-4737-9ed6-e1d3dae2dfa4
80   :END:
81 Pass parameters to the program
82 #+begin_src fortran :cmdline "23" :results silent
83 character(len=255) :: cmd
84 call get_command_argument(1, cmd)
85 write (*,*) trim(cmd)
86 #+end_src