summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Spangberg <daniels@kemi.uu.se>2013-05-17 16:54:01 (GMT)
committerDaniel Spangberg <daniels@kemi.uu.se>2013-05-17 16:54:01 (GMT)
commitecf039adfd38ba1a95b94f1bdc22f01928cb81c5 (patch)
treeeb3ee60ed08cc65fe02b103e4bf9fe34750c63b1
parent6ae393dbe7ffda9c2340503c82d062cb8d7c6f41 (diff)
Added conversion from unpacked integers to float/double.
Added tests for recompression (uncompress to int, compress int) Added tests for conversion from unpacked integers to float/double.
-rw-r--r--include/compression/tng_compress.h16
-rw-r--r--src/compression/tng_compress.c14
-rw-r--r--src/tests/compression/CMakeLists.txt2
-rw-r--r--src/tests/compression/test61.h4
-rw-r--r--src/tests/compression/test62.h22
-rw-r--r--src/tests/compression/test63.h26
-rw-r--r--src/tests/compression/test64.h27
-rw-r--r--src/tests/compression/testsuite.c200
8 files changed, 258 insertions, 53 deletions
diff --git a/include/compression/tng_compress.h b/include/compression/tng_compress.h
index 14786d1..5d43ffc 100644
--- a/include/compression/tng_compress.h
+++ b/include/compression/tng_compress.h
@@ -166,11 +166,21 @@ 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);
+/* This converts a block of integers, as obtained from tng_compress_uncompress_int, to floating point values
+ either double precision or single precision. */
+void DECLSPECDLLEXPORT tng_compress_int_to_double(int *posvel_int,unsigned long prec_hi, unsigned long prec_lo,
+ int natoms,int nframes,
+ double *posvel_double);
- /* Compression algorithms (matching the original trajng
- assignments) The compression backends require that some of the
- algorithms must have the same value. */
+void DECLSPECDLLEXPORT tng_compress_int_to_float(int *posvel_int,unsigned long prec_hi, unsigned long prec_lo,
+ int natoms,int nframes,
+ float *posvel_float);
+
+/* Compression algorithms (matching the original trajng
+ assignments) The compression backends require that some of the
+ algorithms must have the same value. */
+
#define TNG_COMPRESS_ALGO_STOPBIT 1
#define TNG_COMPRESS_ALGO_TRIPLET 2
#define TNG_COMPRESS_ALGO_BWLZH1 8
diff --git a/src/compression/tng_compress.c b/src/compression/tng_compress.c
index ed3fca9..1219f6a 100644
--- a/src/compression/tng_compress.c
+++ b/src/compression/tng_compress.c
@@ -1764,6 +1764,20 @@ int DECLSPECDLLEXPORT tng_compress_uncompress_int(char *data,int *posvel, unsign
return 1;
}
+void DECLSPECDLLEXPORT tng_compress_int_to_double(int *posvel_int,unsigned long prec_hi, unsigned long prec_lo,
+ int natoms,int nframes,
+ double *posvel_double)
+{
+ unquantize(posvel_double,natoms,nframes,PRECISION(prec_hi,prec_lo),posvel_int);
+}
+
+void DECLSPECDLLEXPORT tng_compress_int_to_float(int *posvel_int,unsigned long prec_hi, unsigned long prec_lo,
+ int natoms,int nframes,
+ float *posvel_float)
+{
+ unquantize_float(posvel_float,natoms,nframes,(float)PRECISION(prec_hi,prec_lo),posvel_int);
+}
+
static char *compress_algo_pos[TNG_COMPRESS_ALGO_MAX]={
"Positions invalid algorithm",
"Positions stopbits interframe",
diff --git a/src/tests/compression/CMakeLists.txt b/src/tests/compression/CMakeLists.txt
index 39c2078..694d27b 100644
--- a/src/tests/compression/CMakeLists.txt
+++ b/src/tests/compression/CMakeLists.txt
@@ -9,7 +9,7 @@ include_directories(${CMAKE_SOURCE_DIR}/include/compression)
include_directories(${CMAKE_BINARY_DIR}/generated/)
set(number 0)
-set(numtests 62)
+set(numtests 64)
while( number LESS ${numtests})
diff --git a/src/tests/compression/test61.h b/src/tests/compression/test61.h
index 2b71cc8..373456d 100644
--- a/src/tests/compression/test61.h
+++ b/src/tests/compression/test61.h
@@ -21,5 +21,5 @@
#define INTMAX1 10000
#define INTMAX2 10000
#define INTMAX3 10000
-#define NFRAMES 1000
-#define EXPECTED_FILESIZE 6986313.
+#define NFRAMES 100
+#define EXPECTED_FILESIZE 698801.
diff --git a/src/tests/compression/test62.h b/src/tests/compression/test62.h
index 4b9e122..c8a2b48 100644
--- a/src/tests/compression/test62.h
+++ b/src/tests/compression/test62.h
@@ -4,23 +4,23 @@
#define ALGOTEST
#define NATOMS 1000
#define CHUNKY 100
-#define SCALE 0.01 /* Changed on purpose. */
+#define SCALE 0.1
#define PRECISION 0.01
#define WRITEVEL 1
#define VELPRECISION 0.1
-#define INITIALCODING -1
-#define INITIALCODINGPARAMETER -1
-#define CODING -1
-#define CODINGPARAMETER -1
-#define INITIALVELCODING -1
-#define INITIALVELCODINGPARAMETER -1
-#define VELCODING -1
-#define VELCODINGPARAMETER -1
+#define INITIALCODING 10
+#define INITIALCODINGPARAMETER 0
+#define CODING 10
+#define CODINGPARAMETER 0
+#define INITIALVELCODING 3
+#define INITIALVELCODINGPARAMETER 0
+#define VELCODING 8
+#define VELCODINGPARAMETER 0
#define INTMIN1 0
#define INTMIN2 0
#define INTMIN3 0
#define INTMAX1 10000
#define INTMAX2 10000
#define INTMAX3 10000
-#define NFRAMES 1000
-#define EXPECTED_FILESIZE 6986313.
+#define NFRAMES 100
+#define EXPECTED_FILESIZE 151226.
diff --git a/src/tests/compression/test63.h b/src/tests/compression/test63.h
new file mode 100644
index 0000000..65a4768
--- /dev/null
+++ b/src/tests/compression/test63.h
@@ -0,0 +1,26 @@
+#define TESTNAME "Coding. Read int and convert to double."
+#define FILENAME "test63.tng_compress"
+#define ALGOTEST
+#define NATOMS 1000
+#define CHUNKY 100
+#define SCALE 0.1
+#define PRECISION 0.01
+#define WRITEVEL 1
+#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 10000
+#define INTMAX2 10000
+#define INTMAX3 10000
+#define NFRAMES 100
+#define INTTODOUBLE
+#define EXPECTED_FILESIZE 698801.
diff --git a/src/tests/compression/test64.h b/src/tests/compression/test64.h
new file mode 100644
index 0000000..02f99b5
--- /dev/null
+++ b/src/tests/compression/test64.h
@@ -0,0 +1,27 @@
+#define TESTNAME "Coding. Read int and convert to float."
+#define FILENAME "test64.tng_compress"
+#define ALGOTEST
+#define NATOMS 1000
+#define CHUNKY 100
+#define SCALE 0.1
+#define PRECISION 0.01
+#define WRITEVEL 1
+#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 10000
+#define INTMAX2 10000
+#define INTMAX3 10000
+#define NFRAMES 100
+#define INTTOFLOAT
+#define TEST_FLOAT
+#define EXPECTED_FILESIZE 698801.
diff --git a/src/tests/compression/testsuite.c b/src/tests/compression/testsuite.c
index e1b9710..3ed9f32 100644
--- a/src/tests/compression/testsuite.c
+++ b/src/tests/compression/testsuite.c
@@ -286,6 +286,8 @@ struct tng_file
REAL *vel;
int *ipos;
int *ivel;
+ unsigned int prec_hi, prec_lo;
+ unsigned int velprec_hi, velprec_lo;
};
static size_t fwrite_int_le(int *x,FILE *f)
@@ -357,9 +359,7 @@ static struct tng_file *open_tng_file_write(char *filename,
static struct tng_file *open_tng_file_write_int(char *filename,
int natoms,int chunky,
- unsigned long prec_hi, unsigned long prec_lo,
int writevel,
- unsigned long velprec_hi, unsigned long velprec_lo,
int initial_coding,
int initial_coding_parameter,
int coding,
@@ -377,10 +377,8 @@ static struct tng_file *open_tng_file_write_int(char *filename,
tng_file->ivel=NULL;
tng_file->nframes=0;
tng_file->chunky=chunky;
- tng_file->precision=precision;
tng_file->natoms=natoms;
tng_file->writevel=writevel;
- tng_file->velprecision=velprecision;
tng_file->initial_coding=initial_coding;
tng_file->initial_coding_parameter=initial_coding_parameter;
tng_file->coding=coding;
@@ -390,15 +388,17 @@ static struct tng_file *open_tng_file_write_int(char *filename,
tng_file->velcoding=velcoding;
tng_file->velcoding_parameter=velcoding_parameter;
tng_file->speed=speed;
- tng_file->pos=malloc(natoms*chunky*3*sizeof *tng_file->pos);
+ tng_file->ipos=malloc(natoms*chunky*3*sizeof *tng_file->ipos);
tng_file->f=fopen(filename,"wb");
if (writevel)
- tng_file->vel=malloc(natoms*chunky*3*sizeof *tng_file->vel);
+ tng_file->ivel=malloc(natoms*chunky*3*sizeof *tng_file->ivel);
fwrite_int_le(&natoms,tng_file->f);
return tng_file;
}
-static void flush_tng_frames(struct tng_file *tng_file)
+static void flush_tng_frames(struct tng_file *tng_file,
+ unsigned long prec_hi, unsigned long prec_lo,
+ unsigned long velprec_hi, unsigned long velprec_lo)
{
int algo[4];
char *buf;
@@ -408,19 +408,27 @@ static void flush_tng_frames(struct tng_file *tng_file)
algo[1]=tng_file->initial_coding_parameter;
algo[2]=tng_file->coding;
algo[3]=tng_file->coding_parameter;
+#ifdef RECOMPRESS
+ buf=tng_compress_pos_int(tng_file->ipos,
+ tng_file->natoms,
+ tng_file->nframes,
+ prec_hi,prec_lo,
+ tng_file->speed,algo,&nitems);
+#else /* RECOMPRESS */
#ifdef TEST_FLOAT
buf=tng_compress_pos_float(tng_file->pos,
tng_file->natoms,
tng_file->nframes,
tng_file->precision,
tng_file->speed,algo,&nitems);
-#else
+#else /* TEST_FLOAT */
buf=tng_compress_pos(tng_file->pos,
tng_file->natoms,
tng_file->nframes,
tng_file->precision,
tng_file->speed,algo,&nitems);
-#endif
+#endif /* TEST_FLOAT */
+#endif /* RECOMPRESS */
tng_file->initial_coding=algo[0];
tng_file->initial_coding_parameter=algo[1];
tng_file->coding=algo[2];
@@ -434,19 +442,27 @@ static void flush_tng_frames(struct tng_file *tng_file)
algo[1]=tng_file->initial_velcoding_parameter;
algo[2]=tng_file->velcoding;
algo[3]=tng_file->velcoding_parameter;
+#ifdef RECOMPRESS
+ buf=tng_compress_vel_int(tng_file->ivel,
+ tng_file->natoms,
+ tng_file->nframes,
+ velprec_hi,velprec_lo,
+ tng_file->speed,algo,&nitems);
+#else /* RECOMPRESS */
#ifdef TEST_FLOAT
buf=tng_compress_vel_float(tng_file->vel,
tng_file->natoms,
tng_file->nframes,
tng_file->velprecision,
tng_file->speed,algo,&nitems);
-#else
+#else /* TEST_FLOAT */
buf=tng_compress_vel(tng_file->vel,
tng_file->natoms,
tng_file->nframes,
tng_file->velprecision,
tng_file->speed,algo,&nitems);
-#endif
+#endif /* TEST_FLOAT */
+#endif /* RECOMPRESS */
tng_file->initial_velcoding=algo[0];
tng_file->initial_velcoding_parameter=algo[1];
tng_file->velcoding=algo[2];
@@ -466,16 +482,35 @@ static void write_tng_file(struct tng_file *tng_file,
memcpy(tng_file->vel+tng_file->nframes*tng_file->natoms*3,vel,tng_file->natoms*3*sizeof *tng_file->vel);
tng_file->nframes++;
if (tng_file->nframes==tng_file->chunky)
- flush_tng_frames(tng_file);
+ flush_tng_frames(tng_file,0,0,0,0);
+}
+
+static void write_tng_file_int(struct tng_file *tng_file,
+ int *ipos,int *ivel,
+ unsigned long prec_hi, unsigned long prec_lo,
+ unsigned long velprec_hi, unsigned long velprec_lo)
+{
+ memcpy(tng_file->ipos+tng_file->nframes*tng_file->natoms*3,ipos,tng_file->natoms*3*sizeof *tng_file->ipos);
+ if (tng_file->writevel)
+ memcpy(tng_file->ivel+tng_file->nframes*tng_file->natoms*3,ivel,tng_file->natoms*3*sizeof *tng_file->ivel);
+ tng_file->nframes++;
+ if (tng_file->nframes==tng_file->chunky)
+ flush_tng_frames(tng_file,prec_hi,prec_lo,velprec_hi,velprec_lo);
+ tng_file->prec_hi=prec_hi;
+ tng_file->prec_lo=prec_lo;
+ tng_file->velprec_hi=velprec_hi;
+ tng_file->velprec_lo=velprec_lo;
}
static void close_tng_file_write(struct tng_file *tng_file)
{
if (tng_file->nframes)
- flush_tng_frames(tng_file);
+ flush_tng_frames(tng_file,tng_file->prec_hi,tng_file->prec_lo,tng_file->velprec_hi,tng_file->velprec_lo);
fclose(tng_file->f);
free(tng_file->pos);
free(tng_file->vel);
+ free(tng_file->ipos);
+ free(tng_file->ivel);
free(tng_file);
}
@@ -500,6 +535,27 @@ static struct tng_file *open_tng_file_read(char *filename, int writevel)
return tng_file;
}
+static struct tng_file *open_tng_file_read_int(char *filename, int writevel)
+{
+ struct tng_file *tng_file=malloc(sizeof *tng_file);
+ tng_file->pos=NULL;
+ tng_file->vel=NULL;
+ tng_file->ipos=NULL;
+ tng_file->ivel=NULL;
+ tng_file->f=fopen(filename,"rb");
+ tng_file->nframes=0;
+ tng_file->nframes_delivered=0;
+ tng_file->writevel=writevel;
+ if (tng_file->f)
+ fread_int_le(&tng_file->natoms,tng_file->f);
+ else
+ {
+ free(tng_file);
+ tng_file=NULL;
+ }
+ return tng_file;
+}
+
static int read_tng_file(struct tng_file *tng_file,
REAL *pos,
REAL *vel)
@@ -573,10 +629,55 @@ static int read_tng_file(struct tng_file *tng_file,
return 0;
}
+static int read_tng_file_int(struct tng_file *tng_file,
+ int *ipos,
+ int *ivel,
+ unsigned long *prec_hi, unsigned long *prec_lo,
+ unsigned long *velprec_hi, unsigned long *velprec_lo)
+{
+ if (tng_file->nframes==tng_file->nframes_delivered)
+ {
+ int nitems;
+ char *buf;
+ free(tng_file->ipos);
+ free(tng_file->ivel);
+ if (!fread_int_le(&tng_file->nframes,tng_file->f))
+ return 1;
+ if (!fread_int_le(&nitems,tng_file->f))
+ return 1;
+ buf=malloc(nitems);
+ if (!fread(buf,1,nitems,tng_file->f))
+ return 1;
+ tng_file->ipos=malloc(tng_file->natoms*tng_file->nframes*3*sizeof *tng_file->ipos);
+ if (tng_file->writevel)
+ tng_file->ivel=malloc(tng_file->natoms*tng_file->nframes*3*sizeof *tng_file->ivel);
+ tng_compress_uncompress_int(buf,tng_file->ipos,prec_hi,prec_lo);
+ free(buf);
+ if (tng_file->writevel)
+ {
+ if (!fread_int_le(&nitems,tng_file->f))
+ return 1;
+ buf=malloc(nitems);
+ if (!fread(buf,1,nitems,tng_file->f))
+ return 1;
+ tng_compress_uncompress_int(buf,tng_file->ivel,velprec_hi,velprec_lo);
+ free(buf);
+ }
+ tng_file->nframes_delivered=0;
+ }
+ memcpy(ipos,tng_file->ipos+tng_file->nframes_delivered*tng_file->natoms*3,tng_file->natoms*3*sizeof *ipos);
+ if (tng_file->writevel)
+ memcpy(ivel,tng_file->ivel+tng_file->nframes_delivered*tng_file->natoms*3,tng_file->natoms*3*sizeof *ivel);
+ tng_file->nframes_delivered++;
+ return 0;
+}
+
static void close_tng_file_read(struct tng_file *tng_file)
{
free(tng_file->vel);
free(tng_file->pos);
+ free(tng_file->ivel);
+ free(tng_file->ipos);
fclose(tng_file->f);
free(tng_file);
}
@@ -631,6 +732,17 @@ static int algotest()
REAL *box2=malloc(NATOMS*STRIDE2*sizeof *box2);
REAL *velbox2=malloc(NATOMS*STRIDE2*sizeof *velbox2);
#endif
+#ifdef RECOMPRESS
+ void *dumpfile=open_tng_file_write_int(TNG_COMPRESS_FILES_DIR FILENAME,NATOMS,CHUNKY,
+ WRITEVEL,
+ INITIALCODING,
+ INITIALCODINGPARAMETER,CODING,CODINGPARAMETER,
+ INITIALVELCODING,INITIALVELCODINGPARAMETER,
+ VELCODING,VELCODINGPARAMETER,SPEED);
+ void *dumpfile_recompress=open_tng_file_read_int(TNG_COMPRESS_FILES_DIR RECOMPRESS,WRITEVEL);
+ if (!dumpfile_recompress)
+ return 1;
+#else /* RECOMPRESS */
#ifdef GEN
void *dumpfile=open_tng_file_write(TNG_COMPRESS_FILES_DIR FILENAME,NATOMS,CHUNKY,
PRECISION,WRITEVEL,VELPRECISION,
@@ -641,11 +753,7 @@ static int algotest()
#else
void *dumpfile=open_tng_file_read(TNG_COMPRESS_FILES_DIR FILENAME,WRITEVEL);
#endif
-#ifdef RECOMPRESS
- void *dumpfile_recompress=open_tng_file_read_int(TNG_COMPRESS_FILES_DIR RECOMPRESS,WRITEVEL);
- if (!dumpfile_recompress)
- return 1;
-#endif
+#endif /* RECOMPRESS */
if (!dumpfile)
return 1;
for (i=0; i<9; i++)
@@ -655,35 +763,54 @@ static int algotest()
H1[8]=INTMAX3*PRECISION*SCALE;
for (i=startframe; i<endframe; i++)
{
-#ifndef RECOMPRES
+#ifdef RECOMPRESS
+ unsigned long prec_hi, prec_lo;
+ unsigned long velprec_hi, velprec_lo;
+ if (read_tng_file_int(dumpfile_recompress,intbox,intvelbox,&prec_hi,&prec_lo,&velprec_hi,&velprec_lo))
+ return 1;
+ write_tng_file_int(dumpfile,intbox,intvelbox,prec_hi,prec_lo,velprec_hi,velprec_lo);
+#else /* RECOMPRESS */
genibox(intbox,i);
realbox(intbox,box1,STRIDE1);
#if WRITEVEL
genivelbox(intvelbox,i);
realvelbox(intvelbox,velbox1,STRIDE1);
#endif
-#else
-#ifdef GEN
- if (read_tng_file_int(dumpfile_recompress,intbox,intvelbox))
- return 1;
-#else
- if (read_tng_file(dumpfile_recompress,box1,velbox1))
- return 1;
-#endif
-#endif
time1=(REAL)i;
lambda1=(REAL)(i+100);
#ifdef GEN
-#ifdef RECOMPRESS
- write_tng_file_int(dumpfile,intbox,intvelbox);
-#else
write_tng_file(dumpfile,box1,velbox1);
+#else /* GEN */
+#ifdef INTTOFLOAT
+ unsigned long prec_hi, prec_lo;
+ unsigned long velprec_hi, velprec_lo;
+ readreturn=read_tng_file_int(dumpfile,intbox,intvelbox,&prec_hi,&prec_lo,&velprec_hi,&velprec_lo);
+ if (!readreturn)
+ {
+ tng_compress_int_to_float(intbox,prec_hi,prec_lo,NATOMS,1,box2);
+#if WRITEVEL
+ tng_compress_int_to_float(intvelbox,velprec_hi,velprec_lo,NATOMS,1,velbox2);
#endif
-#else
+ }
+#else /* INTTOFLOAT */
+#ifdef INTTODOUBLE
+ unsigned long prec_hi, prec_lo;
+ unsigned long velprec_hi, velprec_lo;
+ readreturn=read_tng_file_int(dumpfile,intbox,intvelbox,&prec_hi,&prec_lo,&velprec_hi,&velprec_lo);
+ if (!readreturn)
+ {
+ tng_compress_int_to_double(intbox,prec_hi,prec_lo,NATOMS,1,box2);
+#if WRITEVEL
+ tng_compress_int_to_double(intvelbox,velprec_hi,velprec_lo,NATOMS,1,velbox2);
+#endif
+ }
+#else /* INTTODOUBLE */
readreturn=read_tng_file(dumpfile,box2,velbox2);
+#endif /* INTTODOUBLE */
+#endif /* INTTOFLOAT */
if (readreturn==1) /* general read error */
return 1;
-#endif
+#endif /* GEN */
#ifndef GEN
/* Check for equality of boxes. */
if (!equalarr(box1,box2,(REAL)PRECISION,NATOMS,3,STRIDE1,STRIDE2))
@@ -692,7 +819,8 @@ static int algotest()
if (!equalarr(velbox1,velbox2,(REAL)VELPRECISION,NATOMS,3,STRIDE1,STRIDE2))
return 5;
#endif
-#endif
+#endif /* GEN */
+#endif /* RECOMPRESS */
}
#ifdef GEN
close_tng_file_write(dumpfile);
@@ -736,9 +864,9 @@ int main()
exit(EXIT_FAILURE);
}
#ifdef GEN
- printf("Tng compress testsuite generating test: %s\n",TESTNAME);
+ printf("Tng compress testsuite generating (writing) test: %s\n",TESTNAME);
#else
- printf("Tng compress testsuite running test: %s\n",TESTNAME);
+ printf("Tng compress testsuite running (reading) test: %s\n",TESTNAME);
#endif
testval=algotest();
if (testval==0)
contact: Jan Huwald // Impressum