pair corr calc atom data offset correction
authorhackbard <hackbard@sage.physik.uni-augsburg.de>
Mon, 11 Feb 2008 10:12:22 +0000 (11:12 +0100)
committerhackbard <hackbard@sage.physik.uni-augsburg.de>
Mon, 11 Feb 2008 10:12:22 +0000 (11:12 +0100)
moldyn.c
pair_correlation_calc.c

index 94beb04..e2c84a5 100644 (file)
--- 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)");
index b3386c7..f04c4e4 100644 (file)
@@ -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");