Brian Kernighan, in a lecture at the University of Nottingham, described a problem on which this task is based.

Problem

You are given a a data file of thousands of lines; each of three `whitespace` separated fields: a date, a one word name and the magnitude of the event.

Example lines from the file would be lines like:

8/27/1883    Krakatoa            8.8
5/18/1980    MountStHelens       7.6
3/13/2009    CostaRica           5.1
Task

 Create a program or script invocation to find all the events with magnitude greater than 6
 Assuming an appropriate name e.g. "data.txt" for the file:
 Either: Show how your program is invoked to process a data file of that name.
 Or: Incorporate the file name into the program, (as it is assumed that the program is single use).


INCLUDE "H6:REALMATH.ACT"
 
BYTE FUNC FindFirstNonspace(CHAR ARRAY s BYTE start)
  WHILE start<=s(0) AND s(start)=32
  DO
    start==+1
  OD
RETURN (start)
 
BYTE FUNC FindFirstSpace(CHAR ARRAY s BYTE start)
  WHILE start<=s(0) AND s(start)#32
  DO
    start==+1
  OD
RETURN (start)
 
BYTE FUNC Found(CHAR ARRAY s REAL POINTER value)
  BYTE pos,v
  CHAR ARRAY sub
 
  pos=FindFirstNonspace(s,1)
  pos=FindFirstSpace(s,pos)
  pos=FindFirstNonspace(s,pos)
  pos=FindFirstSpace(s,pos)
  pos=FindFirstNonspace(s,pos)
  IF pos>s(0) THEN RETURN (0) FI
 
  SCopyS(sub,s,pos,s(0))
  ValR(sub,v)
  IF RealGreaterOrEqual(value,v)=0 THEN
    RETURN (1)
  FI
RETURN (0)
 
PROC Process(CHAR ARRAY fname REAL POINTER value BYTE search)
  CHAR ARRAY line(255)
  BYTE dev=[1]
 
  Close(dev)
  Open(dev,fname,4)
  WHILE Eof(dev)=0
  DO
    InputSD(dev,line)
    IF search=0 OR Found(line,value)=1 THEN
      PrintE(line)
    FI
  OD
  Close(dev)
RETURN
 
PROC Main()
  CHAR ARRAY fname="H6:QUAKES.TXT"
  REAL value
 
  Put(125) PutE() ;clear the screen
  IntToReal(6,value)
  PrintF("Reading ""%S""...%E%E",fname)
  Process(fname,value,0)
  PutE()
  Print("Searching for earthquakes > ")
  PrintRE(value) PutE()
  Process(fname,value,1)
RETURN