NAMD
fixdcd.c
Go to the documentation of this file.
1 /********************************************************************/
2 /* */
3 /* Copyright 1999, Jim Phillips and the University of Illinois. */
4 /* */
5 /********************************************************************/
6 
7 #include "largefiles.h" /* must be first! */
8 
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <sys/mman.h>
12 #include <fcntl.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 #ifndef MAP_FILE
17 #define MAP_FILE 0
18 #endif
19 
20 int main(int argc, char *argv[]) {
21 
22 int fd;
23 struct stat statbuf;
24 int i, j, isbig, itmp;
25 off_t n;
26 double delta;
27 float delta4;
28 char b[8];
29 char *d;
30 
31 if ( argc != 2 ) {
32  fprintf(stderr,"This program fixes X-PLOR DCD files to work with CHARMM.\n");
33  fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
34  exit(-1);
35 }
36 
37 if ( ( fd = open(argv[1], O_RDWR) ) < 0 ) {
38  fprintf(stderr,"Can't open %s for updating.\n",argv[1]);
39  exit(-1);
40 }
41 
42 if ( fstat(fd,&statbuf) < 0 ) {
43  fprintf(stderr,"Can't stat %s.\n",argv[1]);
44  exit(-1);
45 }
46 
47 n = statbuf.st_size;
48 
49 if ( n <= 104 ) {
50  fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
51  exit(-1);
52 }
53 
54 if ( n % 4 ) {
55  fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
56  exit(-1);
57 }
58 
59 if ( ( d = mmap(0,n,PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,fd,0) )
60  == (caddr_t) -1 ) {
61  fprintf(stderr,"Can't mmap %s.\n",argv[1]);
62  exit(-1);
63 }
64 
65 #define SKIPFOUR {d+=4;n-=4;}
66 #define SKIP(X) {d+=(X);n-=(X);}
67 #define READINT(X) { X=0; if (isbig) { for(j=0;j<4;++j,X<<8) X+=d[j]; } \
68  else { for(j=3;j>=0;--j,X<<8) X+=d[j]; } }
69 
70 SKIPFOUR; /* 84 */
71 SKIPFOUR; /* "CORD" */
72 SKIP(36); /* First 9 elements of control array */
73 
74 for(j=0;j<8;++j) ((char*)(&delta))[j] = d[j];
75 delta4 = delta;
76 for(j=0;j<4;++j) d[j] = ((char*)(&delta4))[j];
77 for(j=4;j<8;++j) d[j] = 0;
78 
79 }
80 
#define MAP_FILE
Definition: fixdcd.c:17
int main(int argc, char *argv[])
Definition: diffbinpdb.c:15
#define SKIPFOUR
#define SKIP(X)