TWiki> DROrg Web>ProjectPage>FortranBase64 (revision 1)EditAttach

Fortran 90 base64 encoding of Reals

To store big amounts of reals encoding the IEEE754 bit pattern in big endian order to base64 is a good solution.

This encodes 6 bits (64 values) in one char (8 bits) using "A-Za-z0-9+/", which means that it is 1/3 larger than binary encoding. If done well it is fully portable, and doable in fortran without external libraries.

So I tried to implement it, and it was much harder than I thought to do it in a portable way across compilers.

This code has the ability to encode and decode reals to/from base64 even across precision (i.e. decode single precision to double and double precision to single), and to handle infinity and NAN consistently.

In base64 an array of reals is represented like this: Y4jImSka/AEAAAAAAAAA4AAAAAAAAA9NAAAAAAAAQgD ...

Bit mantissa and exponent are stored so that the precision of the model is known and transfer between precisions is possible.

CompilerWoes

I wrote a small utility to convert to/from base64, so that you can get the data in/out cp2k easily. You can find it in cp2k/tools/convertBase64.F90 (define __NAG, __XLF with the nag or xlf compilers). There is also a python script cp2k/tools/testBase64.py that if you feed the executable tests it. I would like to know the results on other architectures/compilers.

I think that the code is close to optimal from the feature point of view.

-- FawziMohamed - 24 May 2006

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r1 - 24 May 2006 - FawziMohamed
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback