NAMD
dumpdcd.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 #include <limits.h>
16 
17 #ifndef MAP_FILE
18 #define MAP_FILE 0
19 #endif
20 
21 #if ( INT_MAX == 2147483647 )
22 typedef int int32;
23 #else
24 typedef short int32;
25 #endif
26 
27 int main(int argc, char *argv[]) {
28 
29 int fd;
30 struct stat statbuf;
31 int i, j, isbig, itmp;
32 off_t n;
33 double delta;
34 float delta4;
35 int32 icntrl[20];
36 char *ccntrl;
37 char b[8];
38 char *d;
39 
40 if ( argc != 2 ) {
41  fprintf(stderr,"This program reads the ICNTRL array from DCD files.\n");
42  fprintf(stderr,"Usage: %s <filename> > <data>\n",argv[0]);
43  exit(-1);
44 }
45 
46 if ( ( fd = open(argv[1], O_RDONLY) ) < 0 ) {
47  fprintf(stderr,"Can't open %s for reading.\n",argv[1]);
48  exit(-1);
49 }
50 
51 if ( fstat(fd,&statbuf) < 0 ) {
52  fprintf(stderr,"Can't stat %s.\n",argv[1]);
53  exit(-1);
54 }
55 
56 n = statbuf.st_size;
57 
58 if ( n <= 104 ) {
59  fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
60  exit(-1);
61 }
62 
63 if ( n % 4 ) {
64  fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
65  exit(-1);
66 }
67 
68 if ( ( d = mmap(0,n,PROT_READ,MAP_FILE|MAP_SHARED,fd,0) )
69  == (caddr_t) -1 ) {
70  fprintf(stderr,"Can't mmap %s.\n",argv[1]);
71  exit(-1);
72 }
73 
74 #define SKIPFOUR {d+=4;n-=4;}
75 #define SKIP(X) {d+=(X);n-=(X);}
76 #define READINT(X) { X=0; if (isbig) { for(j=0;j<4;++j,X<<8) X+=d[j]; } \
77  else { for(j=3;j>=0;--j,X<<8) X+=d[j]; } }
78 
79 SKIPFOUR; /* 84 */
80 SKIPFOUR; /* "CORD" */
81 
82 ccntrl = (char*)(&(icntrl[0]));
83 
84 for(j=0;j<80;++j) {
85  ccntrl[j] = d[j];
86 }
87 
88 for(j=0;j<9;++j) {
89  itmp = icntrl[j];
90  printf("%d\n",itmp);
91 }
92 
93 printf("%f\n",*((float*)(icntrl+9)));
94 
95 for(j=10;j<20;++j) {
96  itmp = icntrl[j];
97  printf("%d\n",itmp);
98 }
99 
100 }
101 
short int32
Definition: dumpdcd.c:24
#define SKIPFOUR
int main(int argc, char *argv[])
Definition: diffbinpdb.c:15
#define MAP_FILE
Definition: dumpdcd.c:18