emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob 530d15e50e240a55bbb0a621e7b71eb04a3bb9b3 2384 bytes (raw)
name: testing/examples/ob-fortran-test.org 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
 
#+Title: a collection of examples for ob-fortran tests
#+OPTIONS: ^:nil

* simple programs
  :PROPERTIES:
  :ID:       459384e8-1797-4f11-867e-dde0473ea7cc
  :END:
#+name: hello
#+begin_src fortran :results silent
print *, 'Hello world'
#+end_src

#+name: fortran_parameter
#+begin_src fortran :results silent
integer, parameter :: i = 10
write (*, '(i2)') i
#+end_src

* variable resolution
  :PROPERTIES:
  :ID:       d8d1dfd3-5f0c-48fe-b55d-777997e02242
  :END:
#+begin_src fortran :var N = 15 :results silent
write (*, '(i2)') N
#+end_src

Define for preprocessed fortran
#+begin_src fortran :defines N 42 :results silent
implicit none
write (*, '(i2)') N
#+end_src

#+begin_src fortran :var s="word" :results silent
write (*, '(a4)') s
#+end_src
* 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
#+end_src

#+tblname: test_tbl
| 1.0 |
| 2.0 |

#+begin_src fortran :var s=test_tbl :results silent
write (*, '(2f5.2)'), s
#+end_src

* matrix
  :PROPERTIES:
  :ID:       3f73ab19-d25a-428d-8c26-e8c6aa933976
  :END:
Real matrix as input
#+name: fortran-input-matrix1
| 0.0 | 42.0 |
| 0.0 |  0.0 |
| 0.0 |  0.0 |

#+name: fortran-input-matrix2
| 0.0 | 0.0 | 0.0 |
| 0.0 | 0.0 | 42.0 |

#+begin_src fortran :var s=fortran-input-matrix1 :results silent
write (*, '(i2)'), nint(s(1,2))
#+end_src

#+begin_src fortran :var s=fortran-input-matrix2 :results silent
write (*, '(i2)'), nint(s(2,3))
#+end_src

* failing
  :PROPERTIES:
  :ID:       891ead4a-f87a-473c-9ae0-1cf348bcd04f
  :END:
Should fail (TODO: add input variables for the case with explicit
program statement)
#+begin_src fortran :var s="word" :results silent
program ex
print *, "output of ex program"
end program ex
#+end_src

Fails to compile (TODO: error check in ob-fortran.el)
#+begin_src fortran :var s='(1 ()) :results silent
print *, s
#+end_src

Should fail to compile with gfortran
#+begin_src fortran :flags --std=f95 --pedantic-error :results silent
program ex
integer*8 :: i
end program ex
#+end_src

* programs input parameters
  :PROPERTIES:
  :ID:       2d5330ea-9934-4737-9ed6-e1d3dae2dfa4
  :END:
Pass parameters to the program
#+begin_src fortran :cmdline "23" :results silent
character(len=255) :: cmd
call get_command_argument(1, cmd)
write (*,*) trim(cmd)
#+end_src

debug log:

solving 530d15e ...
found 530d15e in https://git.savannah.gnu.org/cgit/emacs/org-mode.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).