NAMD
Macros | Functions
fixdcd.c File Reference
#include "largefiles.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

Go to the source code of this file.

Macros

#define MAP_FILE   0
 
#define SKIPFOUR   {d+=4;n-=4;}
 
#define SKIP(X)   {d+=(X);n-=(X);}
 
#define READINT(X)
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

#define MAP_FILE   0

Definition at line 17 of file fixdcd.c.

Referenced by main().

#define READINT (   X)
Value:
{ X=0; if (isbig) { for(j=0;j<4;++j,X<<8) X+=d[j]; } \
else { for(j=3;j>=0;--j,X<<8) X+=d[j]; } }
#define X
Definition: msm_defn.h:29
#define SKIP (   X)    {d+=(X);n-=(X);}

Referenced by main().

#define SKIPFOUR   {d+=4;n-=4;}

Referenced by main().

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 20 of file fixdcd.c.

References MAP_FILE, SKIP, and SKIPFOUR.

20  {
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 }
#define MAP_FILE
Definition: fixdcd.c:17
#define SKIPFOUR
#define SKIP(X)