LFortran - modern interactive LLVM-based Fortran compiler
lfortran [OPTIONS] [files...] [SUBCOMMAND]
| module semigroup_m | |
| !! A semigroup is a type with a sensible operation for combining two objects | |
| !! of that type to produce another object of the same type. | |
| !! A sensible operation has the associative property (i.e. (a + b) + c == a + (b + c)) | |
| !! Given this property, it also makes sense to combine a list of objects of | |
| !! that type into a single object, or to repeatedly combine an object with | |
| !! itself. These operations can be derived in terms of combine. | |
| !! Examples include integer (i.e. +), and character (i.e. //) | |
| implicit none | |
| private |
| PROGRAM Calibration | |
| IMPLICIT NONE | |
| INTEGER :: total_sum, first_digit, last_digit, calibration_value | |
| CHARACTER(100), DIMENSION(:), ALLOCATABLE :: calibration_document | |
| INTEGER :: i, len_line, char_value, status | |
| ! Initialize total sum | |
| total_sum = 0 |
| program XX | |
| requirement is_binary_op(T, op) | |
| type, deferred :: T | |
| function op(lhs, rhs) result(res) | |
| type(T), intent(in) :: lhs, rhs | |
| type(T) :: res | |
| end function | |
| end requirement |
| program expr2 | |
| implicit none | |
| integer :: y, z | |
| z = f(y) | |
| print *, z, y | |
| contains |
| print *, "OK 5" | |
| end |
| program mandelbrot | |
| integer, parameter :: Nx = 600, Ny = 450, n_max = 255, dp=kind(0.d0) | |
| real(dp), parameter :: xcenter = -0.5_dp, ycenter = 0.0_dp, & | |
| width = 4, height = 3, dx_di = width/Nx, dy_dj = -height/Ny, & | |
| x_offset = xcenter - (Nx+1)*dx_di/2, y_offset = ycenter - (Ny+1)*dy_dj/2 | |
| integer :: image(Nx,Ny), image_color(4,Nx,Ny), palette(3,4), i, j, n, idx | |
| real(dp) :: x, y, x_0, y_0, x_sqr, y_sqr | |
| interface | |
| subroutine show_img(w, h, A) bind(c) | |
| integer, intent(in) :: w, h |
| program mandelbrot | |
| integer, parameter :: Nx = 600, Ny = 450, n_max = 255, dp=kind(0.d0) | |
| real(dp), parameter :: xcenter = -0.5_dp, ycenter = 0.0_dp, & | |
| width = 4, height = 3, dx_di = width/Nx, dy_dj = -height/Ny, & | |
| x_offset = xcenter - (Nx+1)*dx_di/2, y_offset = ycenter - (Ny+1)*dy_dj/2 | |
| integer :: image(Nx,Ny), image_color(4,Nx,Ny), palette(3,4), i, j, n, idx | |
| real(dp) :: x, y, x_0, y_0, x_sqr, y_sqr | |
| interface | |
| subroutine show_img_color(w, h, A) bind(c) | |
| integer, intent(in) :: w, h |
| subroutine surfdisp96(thkm, vpm, vsm, rhom, nlayer, iflsph, iwave, mode, igr, kmax, t, cg, err) | |
| parameter(ler = 0, lin = 5, lot = 6) | |
| integer :: nl, nl2, nlay | |
| parameter(nl = 100, nlay = 100, nl2 = nl + nl) | |
| integer :: np | |
| parameter(np = 60) | |
| real(4) :: thkm(nlay), vpm(nlay), vsm(nlay), rhom(nlay) | |
| integer :: nlayer, iflsph, iwave, mode, igr, kmax, err | |
| double precision :: twopi, one, onea | |
| double precision :: cc, c1, clow, cm, dc, t1 |
| program test_rsqrt | |
| ! Prints: | |
| ! $ gfortran test_rsqrt.f90 && ./a.out | |
| ! 0.81649658092772603 | |
| ! 0.81649658092772626 | |
| ! 0.81649658092772603 | |
| ! 0.81649658092772603 | |
| implicit none |