-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreader.f90
More file actions
77 lines (63 loc) · 2.16 KB
/
reader.f90
File metadata and controls
77 lines (63 loc) · 2.16 KB
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
program testit
character*200 :: line
character*5, allocatable, dimension(:) :: stations
character*2, allocatable, dimension(:) :: states
integer :: numpts, errval
call system("mkdir /tmp/pounds")
call system("mkdir /tmp/pounds/data")
call system("wget -O /tmp/pounds/data/station.txt -q http://theochem.mercer.edu/csc330/data/station.txt")
call system("wget -O /tmp/pounds/data/daily.txt -q http://theochem.mercer.edu/csc330/data/daily.txt")
open (unit=15, file='/tmp/pounds/data/station.txt', status='old')
! Count the number of lines in the file so we can allocate space for them
numpts = 0
errval = 1
do while ( errval /= -1 )
read (15,'(a5)',iostat=errval) stationid
if ( errval == 0 ) then
numpts = numpts + 1
else
rewind(15)
end if
end do
allocate (stations(numpts), stat=errval)
if (errval /= 0) stop "Error in stations array allocation"
allocate (states(numpts), stat=errval)
if (errval /= 0) stop "Error in state array allocation"
numpts = 0
errval = 1
do while ( errval /= -1 )
read (15,'(a200)',iostat=errval) line
if ( errval == 0 ) then
numpts = numpts + 1
! Find location of first delimiter
linepos = 0
do while ( (line(linepos:linepos) .ne. '|') .and. ( linepos .le. 200 ) )
linepos = linepos + 1;
end do
! Put the substring into an array
stations(numpts) = line(1:linepos-1)
! Now go find the state by looking for 7th delimiter
linepos = linepos + 1
do i = 1, 6
do while ( (line(linepos:linepos) .ne. '|') .and. ( linepos .le. 200 ) )
linepos = linepos + 1
end do
linepos = linepos + 1
enddo
! Now that we are one space beyond the 7th delimiter, store it and move to
! find the next one. The substring between them should contain the state.
linestart = linepos
do while ( (line(linepos:linepos) .ne. '|') .and. ( linepos .le. 200 ) )
linepos = linepos + 1;
end do
! Stick it in an array
states(numpts) = line(linestart:linepos)
else
close(15)
end if
end do
do i=1, numpts
print *, stations(i), ' ', states(numpts)
enddo
call system("rm -rf /tmp/pounds")
end program