···
1
-
IDENTIFICATION DIVISION.
3
-
AUTHOR. Trey Bastian.
5
-
ENVIRONMENT DIVISION.
6
-
INPUT-OUTPUT SECTION.
8
-
SELECT measurements-file ASSIGN TO "./measurements.txt"
9
-
ORGANIZATION IS RECORD SEQUENTIAL.
13
-
FD measurements-file.
14
-
01 measurement-chunk PIC X(10700000).
16
-
WORKING-STORAGE SECTION.
18
-
02 stations OCCURS 10000 TIMES INDEXED BY idx.
20
-
03 min-temp PIC S9(2)V9 VALUE ZEROS.
21
-
03 max-temp PIC S9(2)V9 VALUE ZEROS.
22
-
03 temp-count PIC 9(10) VALUE ZEROS.
23
-
03 total PIC S9(10)V9(2) VALUE ZEROS.
25
-
01 measurement-lines OCCURS 1000000 TIMES.
26
-
02 line-item PIC X(106).
28
-
01 working-measurements.
30
-
02 min-temp PIC S9(2)V9 VALUE ZEROS.
31
-
02 max-temp PIC S9(2)V9 VALUE ZEROS.
32
-
02 temp-count PIC 9(10) VALUE ZEROS.
33
-
02 total PIC S9(10)V9(2) VALUE ZEROS.
35
-
77 last-idx PIC 9(6) VALUE 1.
36
-
77 line-index PIC 9(7) VALUE 1.
37
-
77 line-value PIC X(106).
38
-
77 line-ptr PIC 9(10).
39
-
77 station-name PIC X(100).
40
-
77 temperature PIC S9(2)V9 VALUE ZEROS.
41
-
77 temp-str PIC -(2)9.9 VALUE ZEROS.
42
-
77 mean-calc PIC S9(2)V9 VALUE ZEROS.
43
-
77 line-count PIC 9(10) VALUE 0.
49
-
OPEN INPUT measurements-file.
52
-
READ measurements-file AT END
56
-
MOVE SPACE TO line-value
57
-
MOVE 1 TO line-index
58
-
MOVE 0 TO line-count
59
-
PERFORM VARYING line-index FROM 1 BY 1
60
-
UNTIL line-index = 1000001
61
-
MOVE SPACE to measurement-lines(line-index)
63
-
MOVE 1 to line-index
64
-
INSPECT measurement-chunk TALLYING line-count
66
-
PERFORM line-count TIMES
67
-
UNSTRING measurement-chunk DELIMITED BY X'0A'
68
-
INTO line-value WITH POINTER line-ptr
70
-
MOVE line-value to line-item(line-index)
74
-
PERFORM VARYING line-index FROM 1 BY 1
75
-
UNTIL line-index = 1000001
76
-
UNSTRING line-item(line-index) DELIMITED BY ";"
77
-
INTO station-name, temperature
79
-
IF name OF working-measurements = station-name THEN
80
-
ADD temperature TO total OF working-measurements
81
-
ADD 1 TO temp-count OF working-measurements
82
-
IF min-temp OF working-measurements > temperature
84
-
MOVE temperature TO min-temp OF
85
-
working-measurements
87
-
IF max-temp OF working-measurements < temperature
89
-
MOVE temperature TO max-temp OF
90
-
working-measurements
93
-
IF name OF working-measurements NOT = SPACE THEN
96
-
MOVE name OF working-measurements TO name
97
-
OF stations(last-idx)
98
-
MOVE min-temp OF working-measurements TO
99
-
min-temp OF stations(last-idx)
100
-
MOVE max-temp OF working-measurements TO
101
-
max-temp OF stations(last-idx)
102
-
MOVE total of working-measurements TO total
103
-
OF stations(last-idx)
104
-
MOVE temp-count OF working-measurements TO
105
-
temp-count OF stations(last-idx)
107
-
WHEN name OF stations(idx) = name OF
108
-
working-measurements
109
-
IF min-temp OF stations(idx) > min-temp OF
110
-
working-measurements THEN
111
-
MOVE min-temp OF working-measurements TO
112
-
min-temp OF stations(idx)
114
-
IF max-temp OF stations(idx) < max-temp OF
115
-
working-measurements THEN
116
-
MOVE max-temp OF working-measurements TO
117
-
max-temp OF stations(idx)
119
-
ADD temp-count OF working-measurements TO
120
-
temp-count OF stations(idx)
121
-
ADD total OF working-measurements TO total
126
-
MOVE station-name TO name OF working-measurements
127
-
MOVE temperature TO min-temp OF
128
-
working-measurements
129
-
MOVE temperature TO max-temp OF
130
-
working-measurements
131
-
MOVE temperature TO total OF working-measurements
132
-
MOVE 1 TO temp-count OF working-measurements
137
-
CLOSE measurements-file.
139
-
SORT stations ASCENDING name OF stations.
140
-
PERFORM VARYING idx FROM 1 BY 1 UNTIL idx = 10001
141
-
IF name OF stations(IDX) NOT EQUAL SPACES THEN
142
-
DISPLAY FUNCTION TRIM(name OF stations(idx) TRAILING)
144
-
DISPLAY ";" WITH NO ADVANCING
145
-
MOVE min-temp OF stations(idx)TO temp-str
146
-
DISPLAY FUNCTION TRIM(temp-str LEADING)
148
-
DISPLAY ";" WITH NO ADVANCING
149
-
COMPUTE mean-calc ROUNDED = total OF stations(idx) /
150
-
temp-count OF stations(idx)
151
-
MOVE mean-calc TO temp-str
152
-
DISPLAY FUNCTION TRIM(temp-str LEADING)
154
-
DISPLAY ";" WITH NO ADVANCING
155
-
MOVE max-temp OF stations(idx) TO temp-str
156
-
DISPLAY FUNCTION TRIM(temp-str LEADING)