Fortran hash table  0.1
 All Classes Namespaces Files Functions Variables
read_write.f90
Go to the documentation of this file.
1 
3 
14 
15 program use_ssdm
16  use dictionary_m
17  implicit none
18 
19  type(dictionary_t) :: b
20  character(len=128) :: line
21  character(len=:), allocatable :: k, v, fname
22  integer :: iostat, eq_location, funit, dict_size
23 
24  if (command_argument_count() < 1) then
25  stop 'missing argument for parameter file'
26  end if
27 
28  call get_command_argument(1, line)
29  fname = trim(adjustl(line))
30 
31  if (command_argument_count() < 2) then
32  dict_size = 1024
33  else
34  call get_command_argument(2, line)
35  read(line, *) dict_size
36  end if
37 
38  call b%init(dict_size)
39 
40  open(file=fname, newunit=funit)
41  read_loop: do
42  read(funit, '(a)', iostat=iostat) line
43  if (iostat < 0) exit read_loop
44  if (iostat > 0) cycle read_loop
45  eq_location = index(line, '=')
46  if (eq_location == 0) cycle read_loop
47 
48  k = trim(adjustl(line(1:eq_location-1)))
49  v = trim(adjustl(line(eq_location+1:)))
50 
51  if (len(k) ==0) then
52  write(*,*) 'empty key while reading data'
53  stop
54  end if
55  if (len(v) ==0) then
56  write(*,*) 'empty value while reading data'
57  stop
58  end if
59 
60  call b%set(k, v)
61 
62  end do read_loop
63 
64  close(funit)
65 
66  call fileshow(b)
67 
68 contains
69 
70  subroutine fileshow(d)
71  class(dictionary_t), intent(in) :: d
72 
73  integer :: i, j, s
74 
75  do i = 1, d%dict_size
76  s = d%buckets(i)%current_idx
77  if (s > 0) then
78  do j = 1, s
79  write(*,'(a)', advance='no') d%buckets(i)%entries(j)%key
80  write(*,'(a)', advance='no') ' = '
81  write(*,'(a)', advance='no') d%buckets(i)%entries(j)%value
82  write(*,*)
83  end do
84  end if
85  end do
86 
87  end subroutine fileshow
88 
89 end program use_ssdm
The dictionary contains dict_size buckets (defined at run time)
subroutine fileshow(d)
Definition: read_write.f90:70
program use_ssdm
Read a "equal sign" separated input file.
Definition: read_write.f90:15
Dictionary type that uses strings for the keys and values.