--- /dev/null
+## Pipelines solution\r
+\r
+~~~\r
+import "StringIO"\r
+import "Apros/Legacy"\r
+\r
+isNonemptyString :: String -> Boolean\r
+isNonemptyString = (!= "")\r
+\r
+removeComment :: String -> String\r
+removeComment text = (splitString text "!")!0\r
+\r
+loadAndPreprocess :: String -> <Proc> [String]\r
+loadAndPreprocess = filter isNonemptyString . map (trim . removeComment) . readLines\r
+\r
+isPointEntry entry = (entry!0) == "POINT"\r
+isPipeEntry entry = (entry!0) == "PIPE"\r
+\r
+handlePointEntry diagram ["POINT", id, pointElevation, x, y] = do\r
+ name = "PO" + id\r
+ aadd diagram "POINT" name (read x, read y)\r
+ amodi name "PO11_ELEV" pointElevation\r
+ \r
+handlePipeEntry :: String -> (String -> Maybe (Double, Double)) -> Integer -> [String] -> <Proc> ()\r
+handlePipeEntry diagram coordinates id ["PIPE", id1, id2, pipeLength] = do\r
+ name = "PI" + show id\r
+ name1 = "PO" + id1\r
+ name2 = "PO" + id2\r
+ (x1,y1) = fromJust (coordinates id1)\r
+ (x2,y2) = fromJust (coordinates id2)\r
+ aadd diagram "PIPE" name (0.5*(x1+x2), 0.5*(y1+y2))\r
+ amodi name "PI12_CONNECT_POINT_1" name1\r
+ amodi name "PI12_CONNECT_POINT_2" name2\r
+ amodi name "PI12_LENGTH" pipeLength\r
+\r
+processFile :: String -> String -> <Proc> ()\r
+processFile diagram fileName = do\r
+ entries = map (flip splitString ";") $ loadAndPreprocess fileName\r
+ \r
+ // Points\r
+ pointEntries = filter isPointEntry entries\r
+ iter (handlePointEntry diagram) pointEntries\r
+ coordinates = index [(id, (read x, read y)) | [_,id,_,x,y] <- pointEntries]\r
+ \r
+ // Pipes \r
+ pipeEntries = filter isPipeEntry entries\r
+ iterI (handlePipeEntry diagram coordinates) pipeEntries\r
+~~~
\ No newline at end of file