summaryrefslogtreecommitdiff
path: root/src/tests/compression/testsuite.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/compression/testsuite.c')
-rw-r--r--src/tests/compression/testsuite.c200
1 files changed, 164 insertions, 36 deletions
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