<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">&lt;<a href="mailto:bartek@sudety.it">bartek@sudety.it</a>&gt;</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&#39;ve created simply program using ByteString.<br>
Generally I&#39;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 &gt;&gt;= myPrint . myConcat . B.unpack<br>
<br>
myConcat = myConcat&#39; 0<br>
<br>
myConcat&#39; :: (Integral a) =&gt; Integer -&gt; [a] -&gt; [Integer]<br>
myConcat&#39;  _  [] = []<br>
myConcat&#39; acc (x:xs) = case x `mod` 16 of<br>
                12 -&gt; (10*acc + (restOf . fromIntegral) x) : myConcat&#39; 0 xs<br>
                13 -&gt; ((-10)*acc + (restOf . fromIntegral) x) : myConcat&#39; 0 xs<br>
                15 -&gt; (10*acc + (restOf . fromIntegral) x) : myConcat&#39; 0 xs<br>
                10 -&gt; fail $ show acc<br>
                11 -&gt; fail $ show acc<br>
                14 -&gt; fail $ show acc<br>
                 v  -&gt; myConcat&#39; (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) &gt;&gt; putStrLn &quot;&quot; &gt;&gt; myPrint (drop 14 xs)<br>
<br>
myShow x = (putStr . show) x &gt;&gt; putStr &quot;;&quot;<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>