Kernighans large earthquake problem: Difference between revisions
Kernighans large earthquake problem (view source)
Revision as of 11:10, 12 December 2023
, 5 months ago→{{header|Wren}}: Minor tidy
m (→{{header|Wren}}: Minor tidy) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 1:
{{task}}
[
;Problem:
Line 1,007:
First, with a data file. This adds a fair amount of verbosity to COBOL. For something this one-off, a simpler cut using ACCEPT from standard in is shown.
<syntaxhighlight lang="
*> Kernighan large earthquake problem
*> Tectonics: cobc -xj kernighan-earth-quakes.cob
*>
*>
>>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. quakes.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION ALL INTRINSIC.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
ASSIGN
ORGANIZATION IS
STATUS
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 quake-fd-status
88 ok
"05", "06", "07", "08", "09".
88 no-more
88 io-error
01 line-length USAGE IS BINARY-LONG.
01 date-time PICTURE IS X(10).
01 quake PICTURE IS X(20).
01 magnitude PICTURE IS 99V99.
01 command-filename
PROCEDURE DIVISION.
show-big-ones.
OPEN INPUT quake-data
PERFORM status-check
IF io-error THEN
DISPLAY TRIM(command-filename) " not found" UPON SYSERR
GOBACK
END-IF
READ quake-data
PERFORM status-check
PERFORM UNTIL no-more OR io-error
UNSTRING data-line DELIMITED BY ALL SPACES
INTO date-time quake magnitude
END-UNSTRING
IF magnitude IS GREATER THAN 6
DISPLAY date-time SPACE quake SPACE magnitude
END-IF
READ quake-data
PERFORM status-check
END-PERFORM
CLOSE quake-data
PERFORM status-check
GOBACK.
*> ****
status-check.
IF NOT ok AND NOT no-more THEN *> not normal status, bailing
SET io-error TO TRUE
EXIT
END PROGRAM quakes.</syntaxhighlight>
{{output}}
Line 1,110 ⟶ 1,108:
<syntaxhighlight lang="cobol"> *>
*> Tectonics: ./kerighan-earth-quakes <quakes.txt
01 data-line
88 no-more
01 date-time
01 quake
01 magnitude
show-big-ones.
That cut would be used as <pre>prompt$ ./kernighans-large-earthquakes <quakes.txt</pre>
=={{header|Cowgol}}==
Line 2,343 ⟶ 2,340:
=={{header|Wren}}==
{{libheader|Wren-pattern}}
<syntaxhighlight lang="
import "os" for Process
import "./pattern" for Pattern
var args = Process.arguments
|