From 4f846bcb0d2027955d5bab4151dcfedf86347cd8 Mon Sep 17 00:00:00 2001 From: Daniel Spangberg Date: Sat, 25 May 2013 11:22:05 +0200 Subject: Add more tests for compression of frames that contain only zero data. Add input data sanity checks. tng_compress routines now return NULL if input data is too large compared to the precision. diff --git a/include/compression/tng_compress.h b/include/compression/tng_compress.h index 0858952..51597be 100644 --- a/include/compression/tng_compress.h +++ b/include/compression/tng_compress.h @@ -48,6 +48,8 @@ The compressed data is returned in a malloced pointer (so free can be called to free the memory), the number of chars in the compressed data is put into *nitems. + + If too large values are input (compared to the precision), NULL is returned. */ char DECLSPECDLLEXPORT *tng_compress_pos(double *pos, int natoms, int nframes, diff --git a/src/compression/tng_compress.c b/src/compression/tng_compress.c index 1219f6a..3fad3df 100644 --- a/src/compression/tng_compress.c +++ b/src/compression/tng_compress.c @@ -28,7 +28,49 @@ #define PRECISION(hi,lo) (Ptngc_i32x2_to_d(hi,lo)) -static void quantize(double *x, int natoms, int nframes, +#define MAX_FVAL 2147483647. + +static int verify_input_data(double *x, int natoms, int nframes, double precision) +{ + int iframe, i, j; + for (iframe=0; iframe=MAX_FVAL) + goto error; + return 0; + error: +#if 1 + for (iframe=0; iframe=MAX_FVAL) + printf("ERROR. Too large value: %d %d %d: %g %g %g\n",iframe,i,j,x[iframe*natoms*3+i*3+j],precision,x[iframe*natoms*3+i*3+j]/precision/MAX_FVAL); +#endif + return 1; +} + +static int verify_input_data_float(float *x, int natoms, int nframes, float precision) +{ + int iframe, i, j; + for (iframe=0; iframe=MAX_FVAL) + goto error; + return 0; + error: +#if 1 + for (iframe=0; iframe=MAX_FVAL) + printf("ERROR. Too large value: %d %d %d: %g %g %g\n",iframe,i,j,x[iframe*natoms*3+i*3+j],precision,x[iframe*natoms*3+i*3+j]/precision/MAX_FVAL); +#endif + return 1; +} + +static int quantize(double *x, int natoms, int nframes, double precision, int *quant) { @@ -37,9 +79,10 @@ static void quantize(double *x, int natoms, int nframes, for (i=0; itmp$$.h - echo "#define EXPECTED_FILESIZE" $(ls -l test$testnum.tng |awk '{print $5}'). >>tmp$$.h - mv tmp$$.h test$testnum.h - fi -done +if [ -z "$3" ]; then + echo $0 STARTTEST ENDTEST TNGFILEDIR +else + STARTTEST="$1" + ENDTEST="$2" + TNGFILEDIR="$3" + for testnum in $(seq $STARTTEST $ENDTEST); do + if [ -r $TNGFILEDIR/test$testnum.tng_compress ]; then + grep -v "EXPECTED_FILESIZE" test$testnum.h >tmp$$.h + echo "#define EXPECTED_FILESIZE" $(ls -l $TNGFILEDIR/test$testnum.tng_compress |awk '{print $5}'). >>tmp$$.h + mv tmp$$.h test$testnum.h + fi + done +fi \ No newline at end of file diff --git a/src/tests/compression/test4.h b/src/tests/compression/test4.h index dfda25d..5254a07 100644 --- a/src/tests/compression/test4.h +++ b/src/tests/compression/test4.h @@ -1,4 +1,4 @@ -#define TESTNAME "Initial coding. BWLZH one-to-one algorithm. Cubic cell." +#define TESTNAME "Initial coding. BWLZH intra algorithm. Cubic cell." #define FILENAME "test4.tng_compress" #define ALGOTEST #define NATOMS 1000 diff --git a/src/tests/compression/test65.h b/src/tests/compression/test65.h new file mode 100644 index 0000000..c7136ee --- /dev/null +++ b/src/tests/compression/test65.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. positions intra frame triple" +#define FILENAME "test65.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 0 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 3 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 6315. diff --git a/src/tests/compression/test66.h b/src/tests/compression/test66.h new file mode 100644 index 0000000..95597c8 --- /dev/null +++ b/src/tests/compression/test66.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. positions xtc2" +#define FILENAME "test66.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 0 +#define VELPRECISION 0.1 +#define INITIALCODING 5 +#define INITIALCODINGPARAMETER 0 +#define CODING 5 +#define CODINGPARAMETER 0 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 4465. diff --git a/src/tests/compression/test67.h b/src/tests/compression/test67.h new file mode 100644 index 0000000..ca8fe4b --- /dev/null +++ b/src/tests/compression/test67.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. positions triple one-to-one" +#define FILENAME "test67.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 0 +#define VELPRECISION 0.1 +#define INITIALCODING 7 +#define INITIALCODINGPARAMETER -1 +#define CODING 7 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 6315. diff --git a/src/tests/compression/test68.h b/src/tests/compression/test68.h new file mode 100644 index 0000000..00d8032 --- /dev/null +++ b/src/tests/compression/test68.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. positions BWLZH intra" +#define FILENAME "test68.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 0 +#define VELPRECISION 0.1 +#define INITIALCODING 9 +#define INITIALCODINGPARAMETER 0 +#define CODING 9 +#define CODINGPARAMETER 0 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 321. diff --git a/src/tests/compression/test69.h b/src/tests/compression/test69.h new file mode 100644 index 0000000..7ee385d --- /dev/null +++ b/src/tests/compression/test69.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. positions xtc3" +#define FILENAME "test69.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 0 +#define VELPRECISION 0.1 +#define INITIALCODING 10 +#define INITIALCODINGPARAMETER 0 +#define CODING 10 +#define CODINGPARAMETER 0 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 867. diff --git a/src/tests/compression/test70.h b/src/tests/compression/test70.h new file mode 100644 index 0000000..b3b4b25 --- /dev/null +++ b/src/tests/compression/test70.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. positions stopbit interframe" +#define FILENAME "test70.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 0 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 1 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 7548. diff --git a/src/tests/compression/test71.h b/src/tests/compression/test71.h new file mode 100644 index 0000000..c7d0673 --- /dev/null +++ b/src/tests/compression/test71.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. positions triple interframe" +#define FILENAME "test71.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 0 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 2 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 6315. diff --git a/src/tests/compression/test72.h b/src/tests/compression/test72.h new file mode 100644 index 0000000..633bb50 --- /dev/null +++ b/src/tests/compression/test72.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. positions BWLZH inter" +#define FILENAME "test72.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 0 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 8 +#define CODINGPARAMETER 0 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 257. diff --git a/src/tests/compression/test73.h b/src/tests/compression/test73.h new file mode 100644 index 0000000..e64af34 --- /dev/null +++ b/src/tests/compression/test73.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. velocities stopbits one-to-one" +#define FILENAME "test73.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 1 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 3 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 1 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 1 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 13863. diff --git a/src/tests/compression/test74.h b/src/tests/compression/test74.h new file mode 100644 index 0000000..73ada23 --- /dev/null +++ b/src/tests/compression/test74.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. velocities triplet one-to-one" +#define FILENAME "test74.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 1 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 3 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 3 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 3 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 12622. diff --git a/src/tests/compression/test75.h b/src/tests/compression/test75.h new file mode 100644 index 0000000..4fc004b --- /dev/null +++ b/src/tests/compression/test75.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. velocities BWLZH one-to-one" +#define FILENAME "test75.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 1 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 3 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 9 +#define INITIALVELCODINGPARAMETER 0 +#define VELCODING 9 +#define VELCODINGPARAMETER 0 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 6628. diff --git a/src/tests/compression/test76.h b/src/tests/compression/test76.h new file mode 100644 index 0000000..4a51ecb --- /dev/null +++ b/src/tests/compression/test76.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. velocities triplet inter" +#define FILENAME "test76.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 1 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 3 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 1 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 2 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 12630. diff --git a/src/tests/compression/test77.h b/src/tests/compression/test77.h new file mode 100644 index 0000000..d9394d8 --- /dev/null +++ b/src/tests/compression/test77.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. velocities stopbits inter" +#define FILENAME "test77.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 1 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 3 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 1 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 6 +#define VELCODINGPARAMETER -1 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 13863. diff --git a/src/tests/compression/test78.h b/src/tests/compression/test78.h new file mode 100644 index 0000000..f70592e --- /dev/null +++ b/src/tests/compression/test78.h @@ -0,0 +1,25 @@ +#define TESTNAME "Coding. Compress zeros test. velocities BWLZH inter" +#define FILENAME "test78.tng_compress" +#define ALGOTEST +#define NATOMS 100 +#define CHUNKY 100 +#define SCALE 0. +#define PRECISION 0.01 +#define WRITEVEL 1 +#define VELPRECISION 0.1 +#define INITIALCODING 3 +#define INITIALCODINGPARAMETER -1 +#define CODING 3 +#define CODINGPARAMETER -1 +#define INITIALVELCODING 1 +#define INITIALVELCODINGPARAMETER -1 +#define VELCODING 8 +#define VELCODINGPARAMETER 0 +#define INTMIN1 0 +#define INTMIN2 0 +#define INTMIN3 0 +#define INTMAX1 0 +#define INTMAX2 0 +#define INTMAX3 0 +#define NFRAMES 100 +#define EXPECTED_FILESIZE 6572. diff --git a/src/tests/compression/test_tng_compress_read.bat b/src/tests/compression/test_tng_compress_read.bat index 8bedeb4..b3e779b 100644 --- a/src/tests/compression/test_tng_compress_read.bat +++ b/src/tests/compression/test_tng_compress_read.bat @@ -4,7 +4,7 @@ SET /A I=0 :start SET /A I+=1 test_tng_compress_read%I% -IF "%I%" == "64" ( +IF "%I%" == "78" ( GOTO end ) ELSE ( GOTO start diff --git a/src/tests/compression/test_tng_compress_read.sh b/src/tests/compression/test_tng_compress_read.sh index 2d7a044..20f93f0 100755 --- a/src/tests/compression/test_tng_compress_read.sh +++ b/src/tests/compression/test_tng_compress_read.sh @@ -1,5 +1,5 @@ #!/bin/sh -numtests=64 +numtests=78 for x in $(seq 1 $numtests); do ./test_tng_compress_read$x done \ No newline at end of file diff --git a/src/tests/compression/test_tng_compress_write.bat b/src/tests/compression/test_tng_compress_write.bat index 7542fc8..2effa0e 100644 --- a/src/tests/compression/test_tng_compress_write.bat +++ b/src/tests/compression/test_tng_compress_write.bat @@ -4,7 +4,7 @@ SET /A I=0 :start SET /A I+=1 test_tng_compress_gen%I% -IF "%I%" == "64" ( +IF "%I%" == "78" ( GOTO end ) ELSE ( GOTO start diff --git a/src/tests/compression/test_tng_compress_write.sh b/src/tests/compression/test_tng_compress_write.sh index 1a5700b..4545991 100755 --- a/src/tests/compression/test_tng_compress_write.sh +++ b/src/tests/compression/test_tng_compress_write.sh @@ -1,5 +1,5 @@ #!/bin/sh -numtests=64 +numtests=78 for x in $(seq 1 $numtests); do ./test_tng_compress_gen$x done \ No newline at end of file -- cgit v0.10.1