Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
70
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 myarray = myarray // [(2,show fixp),(3,show fixy),(4,show fixroll),(7,show fixspeed),(8,show fixaccel)]
  31.     where   pitch = read $ myarray ! 2
  32.         yaw = read $ myarray ! 3
  33.         roll = read $ myarray ! 4
  34.         speed = read $ myarray ! 7
  35.         accel = read $ myarray ! 8
  36.         normalize num mid factor = num + (mid - num) / factor
  37.         fixp = normalize pitch 1 5
  38.         fixy = normalize yaw 1 5
  39.         fixroll = normalize roll 1 5
  40.         fixspeed = normalize speed 500000 15
  41.         fixaccel = normalize (2 * accel) 200000 15
  42.        
  43. preprocess myarray
  44.     | tunings > 15 = fixarray myarray
  45.     | otherwise = myarray
  46.     where   tunings = read $ myarray ! 26
  47.         fixarray passedarray = passedarray // [(7, show fixedspeed),(8, show fixedaccel),(26, "15")]
  48.         fixedspeed = originalspeed * ( 1 + (tunings - 15) * 0.1)
  49.         fixedaccel =  originalaccel * ( 1 + originalspeed / (fixedspeed - originalspeed))
  50.         originalspeed = read $ myarray ! 7
  51.         originalaccel = read $ myarray ! 8
  52.  
  53. [1 of 1] Compiling Main             ( new  2.hs, new  2.o )
  54.  
  55. new  2.hs:16:20:
  56.     No instance for (IArray a String)
  57.       arising from a use of `mklist' at new  2.hs:16:20-25
  58.    Possible fix: add an instance declaration for (IArray a String)
  59.    In the first argument of `map', namely `mklist'
  60.    In the expression: map mklist finallist
  61.    In the definition of `listedfinal':
  62.         listedfinal = map mklist finallist
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement