Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import qualified Data.List as L
- import System.Environment
- import Data.Array.IArray
- import Data.Function
- main = do
- (sourcefile:_) <- getArgs
- sourcedata <- readFile sourcefile
- let tships = lines sourcedata
- header = take 3 tships
- rest = drop 3 $ tships
- parsedlist = map split rest
- arrayedlist = map mkarray parsedlist
- processedlist = map preprocess arrayedlist
- finallist = map process processedlist
- listedfinal = map mklist finallist
- stuff = unlines . map unsplit $ listedfinal
- writeFile "done.txt" stuff
- mkarray list = listArray (0, (length list - 1)) list
- mklist myarray = elems myarray
- split :: String -> [String]
- split = filter (not . L.any (== ';')) . L.groupBy (on (==) (== ';')) -- like words, but for ;. Also like Data.ByteString split, but partially applied with ';'
- unsplit :: [String] -> String
- unsplit = L.intercalate ";"
- process myarray = myarray // [(2,show fixp),(3,show fixy),(4,show fixroll),(7,show fixspeed),(8,show fixaccel)]
- where pitch = read $ myarray ! 2
- yaw = read $ myarray ! 3
- roll = read $ myarray ! 4
- speed = read $ myarray ! 7
- accel = read $ myarray ! 8
- normalize num mid factor = num + (mid - num) / factor
- fixp = normalize pitch 1 5
- fixy = normalize yaw 1 5
- fixroll = normalize roll 1 5
- fixspeed = normalize speed 500000 15
- fixaccel = normalize (2 * accel) 200000 15
- preprocess myarray
- | tunings > 15 = fixarray myarray
- | otherwise = myarray
- where tunings = read $ myarray ! 26
- fixarray passedarray = passedarray // [(7, show fixedspeed),(8, show fixedaccel),(26, "15")]
- fixedspeed = originalspeed * ( 1 + (tunings - 15) * 0.1)
- fixedaccel = originalaccel * ( 1 + originalspeed / (fixedspeed - originalspeed))
- originalspeed = read $ myarray ! 7
- originalaccel = read $ myarray ! 8
- [1 of 1] Compiling Main ( new 2.hs, new 2.o )
- new 2.hs:16:20:
- No instance for (IArray a String)
- arising from a use of `mklist' at new 2.hs:16:20-25
- Possible fix: add an instance declaration for (IArray a String)
- In the first argument of `map', namely `mklist'
- In the expression: map mklist finallist
- In the definition of `listedfinal':
- listedfinal = map mklist finallist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement