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 $ header ++ map unsplit listedfinal
- writeFile "done.txt" stuff
- mkarray list = listArray (0, (length list - 1)) list
- mklist :: Array Int String-> [String]
- 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 = floor $ normalize speed 500000 15
- fixaccel = floor $ 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 = floor $ originalspeed * ( 1 + (tunings - 15) * 0.1)
- fixedaccel = floor $ 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:49:15:
- Ambiguous type variable `a' in the constraints:
- `Integral a' arising from a use of `floor' at new 2.hs:49:15-19
- `RealFrac a' arising from a use of `floor' at new 2.hs:50:16-20
- `Read a' arising from a use of `read' at new 2.hs:47:17-20
- Probable fix: add a type signature that fixes these type variable(s)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement