From: hackbard Date: Mon, 11 Feb 2008 10:12:22 +0000 (+0100) Subject: pair corr calc atom data offset correction X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19bf7f2ba36f79406db4efbf1201481a846762ac;p=physik%2Fposic.git pair corr calc atom data offset correction --- diff --git a/moldyn.c b/moldyn.c index 94beb04..e2c84a5 100644 --- a/moldyn.c +++ b/moldyn.c @@ -2223,6 +2223,8 @@ int moldyn_read_save_file(t_moldyn *moldyn,char *file) { int fd; int cnt,size; + int fsize; + int corr; fd=open(file,O_RDONLY); if(fd<0) { @@ -2230,6 +2232,9 @@ int moldyn_read_save_file(t_moldyn *moldyn,char *file) { return fd; } + fsize=lseek(fd,0,SEEK_END); + lseek(fd,0,SEEK_SET); + size=sizeof(t_moldyn); while(size) { @@ -2243,6 +2248,19 @@ int moldyn_read_save_file(t_moldyn *moldyn,char *file) { size=moldyn->count*sizeof(t_atom); + /* correcting possible atom data offset */ + corr=0; + if(fsize!=sizeof(t_moldyn)+size) { + corr=fsize-sizeof(t_moldyn)-size; + printf("[moldyn] WARNING: lsf (illegal file size)\n"); + printf(" moifying offset:\n"); + printf(" - current pos: %d\n",sizeof(t_moldyn)); + printf(" - atom size: %d\n",size); + printf(" - file size: %d\n",fsize); + printf(" => correction: %d\n",corr); + lseek(fd,corr,SEEK_CUR); + } + moldyn->atom=(t_atom *)malloc(size); if(moldyn->atom==NULL) { perror("[moldyn] load save file malloc (atoms)"); diff --git a/pair_correlation_calc.c b/pair_correlation_calc.c index b3386c7..f04c4e4 100644 --- a/pair_correlation_calc.c +++ b/pair_correlation_calc.c @@ -41,6 +41,7 @@ int main(int argc,char **argv) { memset(&moldyn,0,sizeof(t_moldyn)); + printf("[pair corr calc] reading save file ...\n"); ret=moldyn_read_save_file(&moldyn,argv[1]); if(ret) { printf("[pair corr calc] exit!\n");