+ if(!strcmp(outfile,"")) {
+ printf("no outfile specified!\n");
+ return -1;
+ }
+ printf("outfile -> %s\n",outfile);
+
+ outfd=open(outfile,O_WRONLY|O_CREAT);
+ if(outfd<3) {
+ perror("outfile");
+ return outfd;
+ }
+
+ /* read in data */
+
+ size=sizeof(t_moldyn);
+ ret=0;
+ while(size-ret)
+ ret+=read(infd,&md,size-ret);
+ printf("read %d bytes moldyn struct data\n",size);
+
+ /* allocate memory for atoms */
+ size=md.count*sizeof(t_atom);
+ md.atom=malloc(size);
+ if(md.atom==NULL) {
+ perror("malloc");
+ goto end;
+ }
+
+ /* read in atom data */
+
+ ret=0;
+ atom=md.atom;
+ while(size-ret)
+ ret+=read(infd,atom,size-ret);
+ printf("read %d bytes atom data\n",size);
+
+ /* postprocess ... */
+ dprintf(outfd,"%d\n",md.count+8);
+ dprintf(outfd,"atoms at time %f\n",md.time);
+ for(i=0;i<md.count;i++) {
+printf("%d ",i);
+ dprintf(outfd,"%s %f %f %f",pse[atom[i].element],
+ atom[i].r.x,atom[i].r.y,atom[i].r.z);
+ if(mode&DISPLACEMENT) {
+ v3_sub(&dist,&(atom[i].r),&(atom[i].r_0));
+ check_per_bound(&md,&dist);
+ dprintf(outfd," %f",v3_norm(&dist));
+ }
+ if(mode&VELOCITY) {
+ dprintf(outfd," %f",atom[i].ekin);
+ }
+ dprintf(outfd,"\n");
+ }
+
+ /* free memory & close file descriptors */
+
+end:
+ free(md.atom);
+ close(infd);
+ close(outfd);