diff options
author | Daniel Spangberg <daniels@kemi.uu.se> | 2013-05-15 12:31:28 (GMT) |
---|---|---|
committer | Daniel Spangberg <daniels@kemi.uu.se> | 2013-05-15 12:31:28 (GMT) |
commit | 2882416b599514f5a7e60b07c6a20b53a32f9027 (patch) | |
tree | fe8fd58b5023c7835af4096f32389e7cb8aaa6bb /src/compression/vals16.c | |
parent | 43f0748e4a4335e0eb9f81cc8a4728616ac08cf1 (diff) |
Added tng_compress trajectory compression algorithms
Diffstat (limited to 'src/compression/vals16.c')
-rw-r--r-- | src/compression/vals16.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/compression/vals16.c b/src/compression/vals16.c new file mode 100644 index 0000000..6a8e7e7 --- /dev/null +++ b/src/compression/vals16.c @@ -0,0 +1,73 @@ +/* This code is part of the tng compression routines. + * + * Written by Daniel Spangberg + * Copyright (c) 2010, 2013, The GROMACS development team. + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + */ + + +#include "vals16.h" + +/* Coding 32 bit ints in sequences of 16 bit ints. Worst case + the output is 3*nvals long. */ +void Ptngc_comp_conv_to_vals16(unsigned int *vals,int nvals, + unsigned int *vals16, int *nvals16) +{ + int i; + int j=0; + for (i=0; i<nvals; i++) + { + if (vals[i]<=0x7FFFU) + vals16[j++]=vals[i]; + else + { + unsigned int lo=(vals[i]&0x7FFFU)|0x8000U; + unsigned int hi=vals[i]>>15; + vals16[j++]=lo; + if (hi<=0x7FFFU) + vals16[j++]=hi; + else + { + unsigned int lohi=(hi&0x7FFFU)|0x8000U; + unsigned int hihi=hi>>15; + vals16[j++]=lohi; + vals16[j++]=hihi; + } + } + } +#if 0 + /* Test that things that detect that this is bad really works. */ + vals16[0]=0; +#endif + *nvals16=j; +} + +void Ptngc_comp_conv_from_vals16(unsigned int *vals16,int nvals16, + unsigned int *vals, int *nvals) +{ + int i=0; + int j=0; + while (i<nvals16) + { + if (vals16[i]<=0x7FFFU) + vals[j++]=vals16[i++]; + else + { + unsigned int lo=vals16[i++]; + unsigned int hi=vals16[i++]; + if (hi<=0x7FFFU) + vals[j++]=(lo&0x7FFFU)|(hi<<15); + else + { + unsigned int hihi=vals16[i++]; + vals[j++]=(lo&0x7FFFU)|((hi&0x7FFFU)<<15)|(hihi<<30); + } + } + } + *nvals=j; +} |