<div dir="ltr">I *do* know what Packed Decimal is; at my previous job, I actually had a whole Haskell library for parsing them. The only immediate suggestion that pops to mind is to use Int instead of Integer (Int uses regular 32- or 64-bit integers, Integer uses arbitrary precision integers). If you send me a sample Packed Decimal file, I can test out your code and get a better feel for it that way.<br>
<br>Good luck with those mainframes, they can be beasts sometimes. Have you had to parse EBCDIC yet? *That* was fun, manually copying all those character codes from some IBM web page... ;)<br><br>Michael<br><br><div class="gmail_quote">
On Fri, Jun 5, 2009 at 2:31 AM, Bartosz Wójcik <span dir="ltr"><<a href="mailto:bartek@sudety.it">bartek@sudety.it</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi Folks,<br>
<br>
I had to transform Packed Decimal file into csv format (does anybody here know<br>
what this Mainframe format is?). Because of the file size I could not do<br>
this on mainframe directly. So I've created simply program using ByteString.<br>
Generally I'm happy with my solution: pgm processes arroud 2MB/s on my pc, so<br>
my 3GB file was transformed in reasonable 30 min time.<br>
<br>
My question is: how to do this faster?<br>
<br>
{code}<br>
module Main<br>
where<br>
<br>
import qualified Data.ByteString.Lazy as B<br>
<br>
main = B.getContents >>= myPrint . myConcat . B.unpack<br>
<br>
myConcat = myConcat' 0<br>
<br>
myConcat' :: (Integral a) => Integer -> [a] -> [Integer]<br>
myConcat' _ [] = []<br>
myConcat' acc (x:xs) = case x `mod` 16 of<br>
12 -> (10*acc + (restOf . fromIntegral) x) : myConcat' 0 xs<br>
13 -> ((-10)*acc + (restOf . fromIntegral) x) : myConcat' 0 xs<br>
15 -> (10*acc + (restOf . fromIntegral) x) : myConcat' 0 xs<br>
10 -> fail $ show acc<br>
11 -> fail $ show acc<br>
14 -> fail $ show acc<br>
v -> myConcat' (100*acc + (numberOf . fromIntegral) x) xs<br>
where restOf n = (n - 12) `div` 16<br>
numberOf n = n - 6 * (n `div` 16)<br>
<br>
myPrint [] = return ()<br>
myPrint xs = mapM_ myShow (take 14 xs) >> putStrLn "" >> myPrint (drop 14 xs)<br>
<br>
myShow x = (putStr . show) x >> putStr ";"<br>
{code}<br>
<br>
I knew that csv output had to be 14 fields per line.<br>
<br>
Best,<br>
Bartek<br>
<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br></div>