NAMD
Macros | Typedefs | Functions
loaddcd.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>
#include <limits.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)
 

Typedefs

typedef short int32
 

Functions

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

Macro Definition Documentation

#define MAP_FILE   0

Definition at line 18 of file loaddcd.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);}
#define SKIPFOUR   {d+=4;n-=4;}

Referenced by main().

Typedef Documentation

typedef short int32

Definition at line 24 of file loaddcd.c.

Function Documentation

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

Definition at line 27 of file loaddcd.c.

References MAP_FILE, and SKIPFOUR.

27  {
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 writes the ICNTRL array to 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_RDWR) ) < 0 ) {
47  fprintf(stderr,"Can't open %s for updating.\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|PROT_WRITE,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 for(j=0;j<9;++j) {
83  scanf("%d",&itmp);
84  icntrl[j] = itmp;
85 }
86 
87 scanf("%f\n",((float*)(icntrl+9)));
88 
89 for(j=10;j<20;++j) {
90  scanf("%d",&itmp);
91  icntrl[j] = itmp;
92 }
93 
94 ccntrl = (char*)(&(icntrl[0]));
95 
96 for(j=0;j<80;++j) {
97  d[j] = ccntrl[j];
98 }
99 
100 }
short int32
Definition: dumpdcd.c:24
#define SKIPFOUR
#define MAP_FILE
Definition: loaddcd.c:18