-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchTCDs.hs
40 lines (26 loc) · 941 Bytes
/
SearchTCDs.hs
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
import TCD
import Control.Exception (catch, SomeException(..))
import Control.Monad (forM_, unless, when)
import System.Environment (getArgs)
import System.IO (hPutStrLn, stderr)
import Text.Printf (printf)
main :: IO ()
main = do
(station:dbs) <- getArgs
forM_ dbs $ \db -> do
catch (searchDb station db)
(\e -> hPutStrLn stderr $ printf "%s: %s" db $ show (e :: SomeException))
searchDb :: String -> FilePath -> IO ()
searchDb station db = do
opened <- openTideDb db
unless opened $ fail "Cannot open tide database"
count <- hdrNumberOfRecords <$> getTideDbHeader
let loop = do
num <- searchStation station
when (num >= 0) $ do
(ok, r) <- getPartialTideRecord num
unless ok $ fail "Cannot read record"
putStrLn $ printf "%s\t%s\t%d/%d" db (tshName r) num count
loop
loop
closeTideDb