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.

Defines

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

Functions

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

Define Documentation

#define READINT (  ) 
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 SKIP (  )     {d+=(X);n-=(X);}
#define SKIPFOUR   {d+=4;n-=4;}

Function Documentation

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

Definition at line 20 of file fixdcd.c.

References j, MAP_FILE, SKIP, and SKIPFOUR.

00020                                  {
00021 
00022 int fd;
00023 struct stat statbuf;
00024 int i, j, isbig, itmp;
00025 off_t n;
00026 double delta;
00027 float delta4;
00028 char b[8];
00029 char *d;
00030 
00031 if ( argc != 2 ) {
00032   fprintf(stderr,"This program fixes X-PLOR DCD files to work with CHARMM.\n");
00033   fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
00034   exit(-1);
00035 }
00036 
00037 if ( ( fd = open(argv[1], O_RDWR) ) < 0 ) {
00038   fprintf(stderr,"Can't open %s for updating.\n",argv[1]);
00039   exit(-1);
00040 }
00041 
00042 if ( fstat(fd,&statbuf) < 0 ) {
00043   fprintf(stderr,"Can't stat %s.\n",argv[1]);
00044   exit(-1);
00045 }
00046 
00047 n = statbuf.st_size;
00048 
00049 if ( n <= 104 ) {
00050   fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
00051   exit(-1);
00052 }
00053 
00054 if ( n % 4 ) {
00055   fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
00056   exit(-1);
00057 }
00058 
00059 if ( ( d = mmap(0,n,PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,fd,0) )
00060                                                         == (caddr_t) -1 ) {
00061   fprintf(stderr,"Can't mmap %s.\n",argv[1]);
00062   exit(-1);
00063 }
00064 
00065 #define SKIPFOUR {d+=4;n-=4;}
00066 #define SKIP(X) {d+=(X);n-=(X);}
00067 #define READINT(X) { X=0; if (isbig) { for(j=0;j<4;++j,X<<8) X+=d[j]; } \
00068         else { for(j=3;j>=0;--j,X<<8) X+=d[j]; } }
00069 
00070 SKIPFOUR;  /* 84 */
00071 SKIPFOUR;  /* "CORD" */
00072 SKIP(36);  /* First 9 elements of control array */
00073 
00074 for(j=0;j<8;++j) ((char*)(&delta))[j] = d[j];
00075 delta4 = delta;
00076 for(j=0;j<4;++j) d[j] = ((char*)(&delta4))[j];
00077 for(j=4;j<8;++j) d[j] = 0;
00078 
00079 }


Generated on 19 Sep 2019 for NAMD by  doxygen 1.6.1