File: spec_expr_01.f90

package info (click to toggle)
lfortran 0.61.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 61,892 kB
  • sloc: cpp: 181,767; f90: 92,175; python: 17,616; ansic: 10,170; yacc: 2,377; sh: 1,444; fortran: 892; makefile: 38; javascript: 15
file content (31 lines) | stat: -rw-r--r-- 868 bytes parent folder | download
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
module spec_expr_01_mod
contains
  pure integer function nlen(n)
    integer, intent(in) :: n
    nlen = int(log10(real(abs(n), kind(1d0)) + 0.1d0)) + 1
  end function nlen
end module spec_expr_01_mod

program spec_expr_01
  use spec_expr_01_mod, only: nlen
  implicit none
  character(22) :: cinput = '42 666 -42 -666 10 9 0'
  integer :: input(7), i
  read(cinput, *) input
  if (input(1) /= 42) error stop
  if (input(2) /= 666) error stop
  if (input(3) /= -42) error stop
  if (input(4) /= -666) error stop
  if (input(5) /= 10) error stop
  if (input(6) /= 9) error stop
  if (input(7) /= 0) error stop
  do i = 1, 7
    print *, 'input was "'//i0(input(i))//'"'
  end do
contains
  pure function i0(n) result(outstring)
    integer, intent(in) :: n
    character(nlen(n)+1) :: outstring
    write(outstring, "(I0)") n
  end function i0
end program spec_expr_01