File: implied_do_loops18.f90

package info (click to toggle)
lfortran 0.60.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,416 kB
  • sloc: cpp: 173,406; f90: 80,491; python: 17,586; ansic: 9,610; yacc: 2,356; sh: 1,401; fortran: 895; makefile: 38; javascript: 15
file content (40 lines) | stat: -rw-r--r-- 1,014 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
32
33
34
35
36
37
38
39
40
program implied_do_loops18
   implicit none

   type :: string_t
      character(len=:), allocatable :: s
   end type string_t

   type(string_t), allocatable :: file_names(:)
   logical, allocatable :: is_source(:)

   integer :: i

   allocate(file_names(3))

   file_names(1)%s = "main.f90"
   file_names(2)%s = ".gitignore"
   file_names(3)%s = "utils.f90"

   i = 100
   is_source = [(is_hidden_file(basename(file_names(i)%s)), i = 1, size(file_names))]

   do i = 1, size(is_source)
      print *, trim(file_names(i)%s), " -> ", is_source(i)
   end do

   if (any(is_source .neqv. [.false., .true., .false.])) error stop

contains
   function basename(path) result(tmp)
      character(len=*), intent(in) :: path
      character(len=:), allocatable :: tmp
      tmp = path
   end function basename

   logical function is_hidden_file(name)
      character(len=*), intent(in) :: name
      is_hidden_file = (len(name) > 0 .and. name(1:1) == ".")
   end function is_hidden_file

end program implied_do_loops18