From e70cadd9f3f6494ad55efa5e917a12cf18c60d26 Mon Sep 17 00:00:00 2001 From: Daniel Spangberg Date: Thu, 16 May 2013 10:55:44 +0200 Subject: Separated quantization and compression/uncompression more, to allow compression/uncompression of float data. Also added compression/uncompression of integer data, which will allow for recompression. diff --git a/include/compression/tng_compress.h b/include/compression/tng_compress.h index eefcfaa..14786d1 100644 --- a/include/compression/tng_compress.h +++ b/include/compression/tng_compress.h @@ -52,7 +52,16 @@ char DECLSPECDLLEXPORT *tng_compress_pos(double *pos, int natoms, int nframes, double desired_precision, int speed, int *algo, int *nitems); + +char DECLSPECDLLEXPORT *tng_compress_pos_float(float *pos, int natoms, int nframes, + float desired_precision, + int speed, int *algo, + int *nitems); +char DECLSPECDLLEXPORT *tng_compress_pos_int(int *pos, int natoms, int nframes, + unsigned long prec_hi, unsigned long prec_lo, + int speed,int *algo, + int *nitems); /* The tng_compress_pos_find_algo works the same as tng_compress_pos, but it performs benchmarking to find the algorithms with the best @@ -84,6 +93,17 @@ char DECLSPECDLLEXPORT *tng_compress_pos_find_algo(double *pos, int natoms, int int speed, int *algo, int *nitems); + +char DECLSPECDLLEXPORT *tng_compress_pos_float_find_algo(float *pos, int natoms, int nframes, + float desired_precision, + int speed, + int *algo, + int *nitems); + +char DECLSPECDLLEXPORT *tng_compress_pos_int_find_algo(int *pos, int natoms, int nframes, + unsigned long prec_hi, unsigned long prec_lo, + int speed,int *algo, + int *nitems); /* This returns the number of integers required for the storage of the algorithm with the best compression ratio. */ @@ -98,6 +118,16 @@ char DECLSPECDLLEXPORT *tng_compress_vel(double *vel, int natoms, int nframes, double desired_precision, int speed, int *algo, int *nitems); + +char DECLSPECDLLEXPORT *tng_compress_vel_float(float *vel, int natoms, int nframes, + float desired_precision, + int speed, int *algo, + int *nitems); + +char DECLSPECDLLEXPORT *tng_compress_vel_int(int *vel, int natoms, int nframes, + unsigned long prec_hi, unsigned long prec_lo, + int speed, int *algo, + int *nitems); char DECLSPECDLLEXPORT *tng_compress_vel_find_algo(double *vel, int natoms, int nframes, double desired_precision, @@ -105,6 +135,18 @@ char DECLSPECDLLEXPORT *tng_compress_vel_find_algo(double *vel, int natoms, int int *algo, int *nitems); +char DECLSPECDLLEXPORT *tng_compress_vel_float_find_algo(float *vel, int natoms, int nframes, + float desired_precision, + int speed, + int *algo, + int *nitems); + +char DECLSPECDLLEXPORT *tng_compress_vel_int_find_algo(int *vel, int natoms, int nframes, + unsigned long prec_hi, unsigned long prec_lo, + int speed, + int *algo, + int *nitems); + /* From a compressed block, obtain information about whether it is a position or velocity block: *vel=1 means velocity block, *vel=0 means position block. @@ -120,6 +162,10 @@ int DECLSPECDLLEXPORT tng_compress_inquire(char *data,int *vel, int *natoms, */ int DECLSPECDLLEXPORT tng_compress_uncompress(char *data,double *posvel); +int DECLSPECDLLEXPORT tng_compress_uncompress_float(char *data,float *posvel); + +int DECLSPECDLLEXPORT tng_compress_uncompress_int(char *data,int *posvel, unsigned long *prec_hi, unsigned long *prec_lo); + /* Compression algorithms (matching the original trajng assignments) The compression backends require that some of the diff --git a/src/compression/tng_compress.c b/src/compression/tng_compress.c index e92f24d..ed3fca9 100644 --- a/src/compression/tng_compress.c +++ b/src/compression/tng_compress.c @@ -37,13 +37,17 @@ static void quantize(double *x, int natoms, int nframes, for (i=0; i1) @@ -1447,14 +1684,24 @@ static int tng_compress_uncompress_vel(char *data,double *vel) (coding==TNG_COMPRESS_ALGO_VEL_BWLZH_INTER)) { /* This requires that the first frame is already in one-to-one format. */ - unquantize_inter_differences(vel,natoms,nframes,PRECISION(prec_hi,prec_lo),quant); + if (veld) + unquantize_inter_differences(veld,natoms,nframes,PRECISION(*prec_hi,*prec_lo),quant); + else if (velf) + unquantize_inter_differences_float(velf,natoms,nframes,(float)PRECISION(*prec_hi,*prec_lo),quant); + else if (veli) + unquantize_inter_differences_int(veli,natoms,nframes,quant); } /* One-to-one compression? */ else if ((coding==TNG_COMPRESS_ALGO_VEL_STOPBIT_ONETOONE) || (coding==TNG_COMPRESS_ALGO_VEL_TRIPLET_ONETOONE) || (coding==TNG_COMPRESS_ALGO_VEL_BWLZH_ONETOONE)) { - unquantize(vel+natoms*3,natoms,nframes-1,PRECISION(prec_hi,prec_lo),quant+natoms*3); + if (veld) + unquantize(veld+natoms*3,natoms,nframes-1,PRECISION(*prec_hi,*prec_lo),quant+natoms*3); + else if (velf) + unquantize_float(velf+natoms*3,natoms,nframes-1,(float)PRECISION(*prec_hi,*prec_lo),quant+natoms*3); + else if (veli) + memcpy(veli+natoms*3,quant+natoms*3,natoms*3*(nframes-1)*sizeof *veli); } } error: @@ -1462,6 +1709,23 @@ static int tng_compress_uncompress_vel(char *data,double *vel) return rval; } +static int tng_compress_uncompress_vel(char *data,double *vel) +{ + unsigned long prec_hi, prec_lo; + return tng_compress_uncompress_vel_gen(data,vel,NULL,NULL,&prec_hi,&prec_lo); +} + +static int tng_compress_uncompress_vel_float(char *data,float *vel) +{ + unsigned long prec_hi, prec_lo; + return tng_compress_uncompress_vel_gen(data,NULL,vel,NULL,&prec_hi,&prec_lo); +} + +static int tng_compress_uncompress_vel_int(char *data,int *vel, unsigned long *prec_hi, unsigned long *prec_lo) +{ + return tng_compress_uncompress_vel_gen(data,NULL,NULL,vel,prec_hi,prec_lo); +} + /* Uncompresses any tng compress block, positions or velocities. It determines whether it is positions or velocities from the data buffer. The return value is 0 if ok, and 1 if not. */ int DECLSPECDLLEXPORT tng_compress_uncompress(char *data,double *posvel) @@ -1476,6 +1740,30 @@ int DECLSPECDLLEXPORT tng_compress_uncompress(char *data,double *posvel) return 1; } +int DECLSPECDLLEXPORT tng_compress_uncompress_float(char *data,float *posvel) +{ + int magic_int; + magic_int=(int)readbufferfix((unsigned char *)data,4); + if (magic_int==MAGIC_INT_POS) + return tng_compress_uncompress_pos_float(data,posvel); + else if (magic_int==MAGIC_INT_VEL) + return tng_compress_uncompress_vel_float(data,posvel); + else + return 1; +} + +int DECLSPECDLLEXPORT tng_compress_uncompress_int(char *data,int *posvel, unsigned long *prec_hi, unsigned long *prec_lo) +{ + int magic_int; + magic_int=(int)readbufferfix((unsigned char *)data,4); + if (magic_int==MAGIC_INT_POS) + return tng_compress_uncompress_pos_int(data,posvel,prec_hi,prec_lo); + else if (magic_int==MAGIC_INT_VEL) + return tng_compress_uncompress_vel_int(data,posvel,prec_hi,prec_lo); + else + return 1; +} + static char *compress_algo_pos[TNG_COMPRESS_ALGO_MAX]={ "Positions invalid algorithm", "Positions stopbits interframe", -- cgit v0.10.1