···
-
IDENTIFICATION DIVISION.
-
SELECT measurements-file ASSIGN TO "./measurements.txt"
-
ORGANIZATION IS RECORD SEQUENTIAL.
-
01 measurement-chunk PIC X(10700000).
-
WORKING-STORAGE SECTION.
-
02 stations OCCURS 10000 TIMES INDEXED BY idx.
-
03 min-temp PIC S9(2)V9 VALUE ZEROS.
-
03 max-temp PIC S9(2)V9 VALUE ZEROS.
-
03 temp-count PIC 9(10) VALUE ZEROS.
-
03 total PIC S9(10)V9(2) VALUE ZEROS.
-
01 measurement-lines OCCURS 1000000 TIMES.
-
02 line-item PIC X(106).
-
01 working-measurements.
-
02 min-temp PIC S9(2)V9 VALUE ZEROS.
-
02 max-temp PIC S9(2)V9 VALUE ZEROS.
-
02 temp-count PIC 9(10) VALUE ZEROS.
-
02 total PIC S9(10)V9(2) VALUE ZEROS.
-
77 last-idx PIC 9(6) VALUE 1.
-
77 line-index PIC 9(7) VALUE 1.
-
77 line-value PIC X(106).
-
77 station-name PIC X(100).
-
77 temperature PIC S9(2)V9 VALUE ZEROS.
-
77 temp-str PIC -(2)9.9 VALUE ZEROS.
-
77 mean-calc PIC S9(2)V9 VALUE ZEROS.
-
77 line-count PIC 9(10) VALUE 0.
-
OPEN INPUT measurements-file.
-
READ measurements-file AT END
-
MOVE SPACE TO line-value
-
PERFORM VARYING line-index FROM 1 BY 1
-
UNTIL line-index = 1000001
-
MOVE SPACE to measurement-lines(line-index)
-
INSPECT measurement-chunk TALLYING line-count
-
PERFORM line-count TIMES
-
UNSTRING measurement-chunk DELIMITED BY X'0A'
-
INTO line-value WITH POINTER line-ptr
-
MOVE line-value to line-item(line-index)
-
PERFORM VARYING line-index FROM 1 BY 1
-
UNTIL line-index = 1000001
-
UNSTRING line-item(line-index) DELIMITED BY ";"
-
INTO station-name, temperature
-
IF name OF working-measurements = station-name THEN
-
ADD temperature TO total OF working-measurements
-
ADD 1 TO temp-count OF working-measurements
-
IF min-temp OF working-measurements > temperature
-
MOVE temperature TO min-temp OF
-
IF max-temp OF working-measurements < temperature
-
MOVE temperature TO max-temp OF
-
IF name OF working-measurements NOT = SPACE THEN
-
MOVE name OF working-measurements TO name
-
MOVE min-temp OF working-measurements TO
-
min-temp OF stations(last-idx)
-
MOVE max-temp OF working-measurements TO
-
max-temp OF stations(last-idx)
-
MOVE total of working-measurements TO total
-
MOVE temp-count OF working-measurements TO
-
temp-count OF stations(last-idx)
-
WHEN name OF stations(idx) = name OF
-
IF min-temp OF stations(idx) > min-temp OF
-
working-measurements THEN
-
MOVE min-temp OF working-measurements TO
-
min-temp OF stations(idx)
-
IF max-temp OF stations(idx) < max-temp OF
-
working-measurements THEN
-
MOVE max-temp OF working-measurements TO
-
max-temp OF stations(idx)
-
ADD temp-count OF working-measurements TO
-
temp-count OF stations(idx)
-
ADD total OF working-measurements TO total
-
MOVE station-name TO name OF working-measurements
-
MOVE temperature TO min-temp OF
-
MOVE temperature TO max-temp OF
-
MOVE temperature TO total OF working-measurements
-
MOVE 1 TO temp-count OF working-measurements
-
CLOSE measurements-file.
-
SORT stations ASCENDING name OF stations.
-
PERFORM VARYING idx FROM 1 BY 1 UNTIL idx = 10001
-
IF name OF stations(IDX) NOT EQUAL SPACES THEN
-
DISPLAY FUNCTION TRIM(name OF stations(idx) TRAILING)
-
DISPLAY ";" WITH NO ADVANCING
-
MOVE min-temp OF stations(idx)TO temp-str
-
DISPLAY FUNCTION TRIM(temp-str LEADING)
-
DISPLAY ";" WITH NO ADVANCING
-
COMPUTE mean-calc ROUNDED = total OF stations(idx) /
-
temp-count OF stations(idx)
-
MOVE mean-calc TO temp-str
-
DISPLAY FUNCTION TRIM(temp-str LEADING)
-
DISPLAY ";" WITH NO ADVANCING
-
MOVE max-temp OF stations(idx) TO temp-str
-
DISPLAY FUNCTION TRIM(temp-str LEADING)