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.

Defines

#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[])

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;}

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 j, MAP_FILE, and SKIPFOUR.

00027                                  {
00028 
00029 int fd;
00030 struct stat statbuf;
00031 int i, j, isbig, itmp;
00032 off_t n;
00033 double delta;
00034 float delta4;
00035 int32 icntrl[20];
00036 char *ccntrl;
00037 char b[8];
00038 char *d;
00039 
00040 if ( argc != 2 ) {
00041   fprintf(stderr,"This program writes the ICNTRL array to DCD files.\n");
00042   fprintf(stderr,"Usage: %s <filename> < <data>\n",argv[0]);
00043   exit(-1);
00044 }
00045 
00046 if ( ( fd = open(argv[1], O_RDWR) ) < 0 ) {
00047   fprintf(stderr,"Can't open %s for updating.\n",argv[1]);
00048   exit(-1);
00049 }
00050 
00051 if ( fstat(fd,&statbuf) < 0 ) {
00052   fprintf(stderr,"Can't stat %s.\n",argv[1]);
00053   exit(-1);
00054 }
00055 
00056 n = statbuf.st_size;
00057 
00058 if ( n <= 104 ) {
00059   fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
00060   exit(-1);
00061 }
00062 
00063 if ( n % 4 ) {
00064   fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
00065   exit(-1);
00066 }
00067 
00068 if ( ( d = mmap(0,n,PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,fd,0) )
00069                                                         == (caddr_t) -1 ) {
00070   fprintf(stderr,"Can't mmap %s.\n",argv[1]);
00071   exit(-1);
00072 }
00073 
00074 #define SKIPFOUR {d+=4;n-=4;}
00075 #define SKIP(X) {d+=(X);n-=(X);}
00076 #define READINT(X) { X=0; if (isbig) { for(j=0;j<4;++j,X<<8) X+=d[j]; } \
00077         else { for(j=3;j>=0;--j,X<<8) X+=d[j]; } }
00078 
00079 SKIPFOUR;  /* 84 */
00080 SKIPFOUR;  /* "CORD" */
00081 
00082 for(j=0;j<9;++j) {
00083   scanf("%d",&itmp);
00084   icntrl[j] = itmp;
00085 }
00086 
00087 scanf("%f\n",((float*)(icntrl+9)));
00088 
00089 for(j=10;j<20;++j) {
00090   scanf("%d",&itmp);
00091   icntrl[j] = itmp;
00092 }
00093 
00094 ccntrl = (char*)(&(icntrl[0]));
00095 
00096 for(j=0;j<80;++j) {
00097   d[j] = ccntrl[j];
00098 }
00099 
00100 }


Generated on 20 Nov 2019 for NAMD by  doxygen 1.6.1