pair corr calc atom data offset correction
[physik/posic.git] / moldyn.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)");