1 ## Pipelines solution
\r
5 import "Apros/Legacy"
\r
7 isNonemptyString :: String -> Boolean
\r
8 isNonemptyString = (!= "")
\r
10 removeComment :: String -> String
\r
11 removeComment text = (splitString text "!")!0
\r
13 loadAndPreprocess :: String -> <Proc> [String]
\r
14 loadAndPreprocess = filter isNonemptyString . map (trim . removeComment) . readLines
\r
16 isPointEntry entry = (entry!0) == "POINT"
\r
17 isPipeEntry entry = (entry!0) == "PIPE"
\r
19 handlePointEntry diagram ["POINT", id, pointElevation, x, y] = do
\r
21 aadd diagram "POINT" name (read x, read y)
\r
22 amodi name "PO11_ELEV" pointElevation
\r
24 handlePipeEntry :: String -> (String -> Maybe (Double, Double)) -> Integer -> [String] -> <Proc> ()
\r
25 handlePipeEntry diagram coordinates id ["PIPE", id1, id2, pipeLength] = do
\r
26 name = "PI" + show id
\r
29 (x1,y1) = fromJust (coordinates id1)
\r
30 (x2,y2) = fromJust (coordinates id2)
\r
31 aadd diagram "PIPE" name (0.5*(x1+x2), 0.5*(y1+y2))
\r
32 amodi name "PI12_CONNECT_POINT_1" name1
\r
33 amodi name "PI12_CONNECT_POINT_2" name2
\r
34 amodi name "PI12_LENGTH" pipeLength
\r
36 processFile :: String -> String -> <Proc> ()
\r
37 processFile diagram fileName = do
\r
38 entries = map (flip splitString ";") $ loadAndPreprocess fileName
\r
41 pointEntries = filter isPointEntry entries
\r
42 iter (handlePointEntry diagram) pointEntries
\r
43 coordinates = index [(id, (read x, read y)) | [_,id,_,x,y] <- pointEntries]
\r
46 pipeEntries = filter isPipeEntry entries
\r
47 iterI (handlePipeEntry diagram coordinates) pipeEntries
\r