fixdcd.c

Go to the documentation of this file.
00001 /********************************************************************/
00002 /*                                                                  */
00003 /*   Copyright 1999, Jim Phillips and the University of Illinois.   */
00004 /*                                                                  */
00005 /********************************************************************/
00006 
00007 #include "largefiles.h"  /* must be first! */
00008 
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <sys/mman.h>
00012 #include <fcntl.h>
00013 #include <stdio.h>
00014 
00015 #ifndef MAP_FILE
00016 #define MAP_FILE 0
00017 #endif
00018 
00019 int main(int argc, char *argv[]) {
00020 
00021 int fd;
00022 struct stat statbuf;
00023 int i, j, isbig, itmp;
00024 off_t n;
00025 double delta;
00026 float delta4;
00027 char b[8];
00028 char *d;
00029 
00030 if ( argc != 2 ) {
00031   fprintf(stderr,"This program fixes X-PLOR DCD files to work with CHARMM.\n");
00032   fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
00033   exit(-1);
00034 }
00035 
00036 if ( ( fd = open(argv[1], O_RDWR) ) < 0 ) {
00037   fprintf(stderr,"Can't open %s for updating.\n",argv[1]);
00038   exit(-1);
00039 }
00040 
00041 if ( fstat(fd,&statbuf) < 0 ) {
00042   fprintf(stderr,"Can't stat %s.\n",argv[1]);
00043   exit(-1);
00044 }
00045 
00046 n = statbuf.st_size;
00047 
00048 if ( n <= 104 ) {
00049   fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
00050   exit(-1);
00051 }
00052 
00053 if ( n % 4 ) {
00054   fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
00055   exit(-1);
00056 }
00057 
00058 if ( ( d = mmap(0,n,PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,fd,0) )
00059                                                         == (caddr_t) -1 ) {
00060   fprintf(stderr,"Can't mmap %s.\n",argv[1]);
00061   exit(-1);
00062 }
00063 
00064 #define SKIPFOUR {d+=4;n-=4;}
00065 #define SKIP(X) {d+=(X);n-=(X);}
00066 #define READINT(X) { X=0; if (isbig) { for(j=0;j<4;++j,X<<8) X+=d[j]; } \
00067         else { for(j=3;j>=0;--j,X<<8) X+=d[j]; } }
00068 
00069 SKIPFOUR;  /* 84 */
00070 SKIPFOUR;  /* "CORD" */
00071 SKIP(36);  /* First 9 elements of control array */
00072 
00073 for(j=0;j<8;++j) ((char*)(&delta))[j] = d[j];
00074 delta4 = delta;
00075 for(j=0;j<4;++j) d[j] = ((char*)(&delta4))[j];
00076 for(j=4;j<8;++j) d[j] = 0;
00077 
00078 }
00079 

Generated on Sat Nov 18 01:17:13 2017 for NAMD by  doxygen 1.4.7