Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import qualified Data.List as L
  2. import System.Environment
  3. import Data.Array.IArray
  4. import Data.Function
  5.  
  6. main = do
  7.     (sourcefile:_) <- getArgs
  8.     sourcedata <- readFile sourcefile
  9.     let tships = lines sourcedata
  10.         header = take 3 tships
  11.         rest = drop 3 $ tships
  12.         parsedlist = map split rest
  13.         arrayedlist = map mkarray parsedlist
  14.         processedlist = map preprocess arrayedlist
  15.         finallist = map process processedlist
  16.         listedfinal = map mklist finallist
  17.         stuff = unlines . map unsplit $ listedfinal
  18.     writeFile "done.txt" stuff
  19.  
  20. mkarray list = listArray (0, (length list - 1)) list
  21. mklist myarray = elems myarray
  22.  
  23. split :: String -> [String]
  24. split = filter (not . L.any (== ';')) . L.groupBy (on (==) (== ';')) -- like words, but for ;. Also like Data.ByteString split, but partially applied with ';'
  25.  
  26.  
  27. unsplit :: [String] -> String
  28. unsplit = L.intercalate ";"
  29.  
  30. process :: Array -> Array
  31. process myarray = myarray // [(2,show fixp),(3,show fixy),(4,show fixroll),(7,show fixspeed),(8,show fixaccel)]
  32.     where   pitch = read $ myarray ! 2
  33.         yaw = read $ myarray ! 3
  34.         roll = read $ myarray ! 4
  35.         speed = read $ myarray ! 7
  36.         accel = read $ myarray ! 8
  37.         normalize num mid factor = num + (mid - num) / factor
  38.         fixp = normalize pitch 1 5
  39.         fixy = normalize yaw 1 5
  40.         fixroll = normalize roll 1 5
  41.         fixspeed = normalize speed 500000 15
  42.         fixaccel = normalize (2 * accel) 200000 15
  43.        
  44. preprocess :: Array -> Array
  45. preprocess myarray
  46.     | tunings > 15 = fixarray myarray
  47.     | otherwise = myarray
  48.     where   tunings = read $ myarray ! 26
  49.         fixarray passedarray = passedarray // [(7, show fixedspeed),(8, show fixedaccel),(26, "15")]
  50.         fixedspeed = originalspeed * ( 1 + (tunings - 15) * 0.1)
  51.         fixedaccel =  originalaccel * ( 1 + originalspeed / (fixedspeed - originalspeed))
  52.         originalspeed = read $ myarray ! 7
  53.         originalaccel = read $ myarray ! 8
  54.  
  55. [1 of 1] Compiling Main             ( new  2.hs, new  2.o )
  56.  
  57. new  2.hs:30:11:
  58.     `Array' is not applied to enough type arguments
  59.    Expected kind `??', but `Array' has kind `* -> * -> *'
  60.     In the type signature for `process': process :: Array -> Array
  61.  
  62. new  2.hs:44:14:
  63.    `Array' is not applied to enough type arguments
  64.     Expected kind `??', but `Array' has kind `* -> * -> *'
  65.    In the type signature for `preprocess':
  66.       preprocess :: Array -> Array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement