Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

dcdlib.h File Reference

#include "Vector.h"

Go to the source code of this file.

Defines

#define DCD_DNE   -2
#define DCD_OPENFAILED   -3
#define DCD_BADREAD   -4
#define DCD_BADEOF   -5
#define DCD_BADFORMAT   -6
#define DCD_FILEEXISTS   -7
#define DCD_BADMALLOC   -8

Functions

int open_dcd_read (char *)
int read_dcdheader (int, int *, int *, int *, int *, double *, int *, int **)
int read_dcdstep (int, int, float *, float *, float *, int, int, int *)
int open_dcd_write (char *)
int open_dcd_write_par_slave (char *dcdname)
int write_dcdstep (int, int, float *, float *, float *, double *unitcell)
int write_dcdstep (int, int, FloatVector *, double *unitcell)
int write_dcdstep_par_units (int fd, int N, float *X, float *Y, float *Z, double *cell, int unitoffset)
int write_dcdstep_par_header (int fd, int N, float *X, float *Y, float *Z, double *cell)
int write_dcdstep_par_slave (int fd, int N, float *X, float *Y, float *Z, double *cell, int xoffset, int yoffset, int zoffset)
int write_dcdheader (int, char *, int, int, int, int, int, double, int)
void close_dcd_read (int, int, int *)
void close_dcd_write (int)


Define Documentation

#define DCD_BADEOF   -5
 

Definition at line 22 of file dcdlib.h.

#define DCD_BADFORMAT   -6
 

Definition at line 23 of file dcdlib.h.

#define DCD_BADMALLOC   -8
 

Definition at line 25 of file dcdlib.h.

#define DCD_BADREAD   -4
 

Definition at line 21 of file dcdlib.h.

#define DCD_DNE   -2
 

Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved.

Definition at line 19 of file dcdlib.h.

#define DCD_FILEEXISTS   -7
 

Definition at line 24 of file dcdlib.h.

#define DCD_OPENFAILED   -3
 

Definition at line 20 of file dcdlib.h.

Referenced by open_dcd_write().


Function Documentation

void close_dcd_read int  ,
int  ,
int * 
 

Definition at line 1082 of file dcdlib.C.

01084 {
01085 #ifdef WIN32
01086         _close(fd);
01087 #else
01088         close(fd);
01089 #endif
01090 
01091         if (num_fixed)
01092         {
01093                 delete [] indexes;
01094         }
01095 }

void close_dcd_write int   ) 
 

Definition at line 1112 of file dcdlib.C.

01114 {
01115 #ifdef WIN32
01116         _close(fd);
01117 #else
01118         close(fd);
01119 #endif
01120 }

int open_dcd_read char *   ) 
 

Definition at line 136 of file dcdlib.C.

References O_LARGEFILE.

00138 {
00139         struct stat stbuf;      /*  Stat structure to check file        */
00140         int dcdfd;              /*  file descriptor for dcd file        */
00141 
00142         /*  Do a stat just to see if the file really exists     */
00143         if (stat(filename, &stbuf) != 0)
00144         {
00145                 if (errno == ENOENT)
00146                 {
00147                         return(DCD_DNE);
00148                 }
00149         }
00150 
00151         /*  Try and open the file                               */
00152 #ifdef WIN32
00153         dcdfd=_open(filename, O_RDONLY|O_BINARY|O_LARGEFILE);
00154 #else
00155         dcdfd=open(filename, O_RDONLY|O_LARGEFILE);
00156 #endif
00157 
00158         if (dcdfd == -1)
00159         {
00160                 return(DCD_OPENFAILED);
00161         }
00162 
00163         return(dcdfd);
00164 }

int open_dcd_write char *   ) 
 

Definition at line 638 of file dcdlib.C.

References DCD_OPENFAILED, and O_LARGEFILE.

00640 {
00641         struct stat sbuf;
00642         int dcdfd;
00643         char *newdcdname = 0;
00644 
00645         if (stat(dcdname, &sbuf) == 0) 
00646         {
00647            newdcdname = new char[strlen(dcdname)+5];
00648            if(newdcdname == (char *) 0)
00649              return DCD_OPENFAILED;
00650            strcpy(newdcdname, dcdname);
00651            strcat(newdcdname, ".BAK");
00652 #if defined(WIN32) && !defined(__CYGWIN__)
00653            remove(newdcdname);
00654 #endif
00655            if(rename(dcdname, newdcdname))
00656                 return(DCD_OPENFAILED);
00657            delete [] newdcdname;
00658         } 
00659 #ifdef WIN32
00660         if ( (dcdfd = _open(dcdname, O_RDWR|O_CREAT|O_EXCL|O_BINARY|O_LARGEFILE,
00661                                 _S_IREAD|_S_IWRITE)) < 0)
00662 #else
00663 #ifdef NAMD_NO_O_EXCL
00664         if ( (dcdfd = open(dcdname, O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE,
00665 #else
00666         if ( (dcdfd = open(dcdname, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE,
00667 #endif
00668                                 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
00669 #endif
00670         {
00671                 return(DCD_OPENFAILED);
00672         }
00673 
00674         return(dcdfd);
00675 }

int open_dcd_write_par_slave char *  dcdname  ) 
 

Definition at line 680 of file dcdlib.C.

00682 {
00683         struct stat sbuf;
00684         int dcdfd;
00685 #ifdef WIN32
00686         if ( (dcdfd = _open(dcdname, O_RDWR|O_BINARY|O_LARGEFILE,
00687                                 _S_IREAD|_S_IWRITE)) < 0)
00688 #else
00689 
00690         if ( (dcdfd = open(dcdname, O_RDWR|O_LARGEFILE,
00691                                 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
00692 #endif
00693         {
00694                 return(DCD_OPENFAILED);
00695         }
00696 
00697         return(dcdfd);
00698 }

int read_dcdheader int  ,
int *  ,
int *  ,
int *  ,
int *  ,
double *  ,
int *  ,
int ** 
 

int read_dcdstep int  ,
int  ,
float *  ,
float *  ,
float *  ,
int  ,
int  ,
int * 
 

int write_dcdheader int  ,
char *  ,
int  ,
int  ,
int  ,
int  ,
int  ,
double  ,
int 
 

Definition at line 973 of file dcdlib.C.

00975 {
00976         int32   out_integer;
00977         float   out_float;
00978         char    title_string[200];
00979         int     user_id;
00980 #ifndef WIN32
00981         struct  passwd *pwbuf;
00982 #endif
00983         time_t  cur_time;
00984         struct  tm *tmbuf;
00985         char    time_str[11];
00986 
00987         out_integer = 84;
00988         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00989         strcpy(title_string, "CORD");
00990         NAMD_write(fd, title_string, 4);
00991         out_integer = NFILE;  /* located at fpos 8 */
00992         out_integer = 0;  /* ignore the lies */
00993         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00994         out_integer = NPRIV;  /* located at fpos 12 */
00995         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00996         out_integer = NSAVC;  /* located at fpos 16 */
00997         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00998         out_integer = NSTEP;  /* located at fpos 20 */
00999         out_integer = NPRIV - NSAVC;  /* ignore the lies */
01000         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01001         out_integer=0;
01002         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01003         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01004         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01005         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01006         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01007         out_float = DELTA;
01008         NAMD_write(fd, (char *) &out_float, sizeof(float));
01009   out_integer = with_unitcell ? 1 : 0;
01010         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01011   out_integer = 0;
01012         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01013         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01014         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01015         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01016         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01017         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01018         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01019         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01020         out_integer = 24;  // PRETEND TO BE CHARMM24 -JCP
01021         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
01022         out_integer = 84;
01023         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
01024 
01025         out_integer = 164;
01026         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
01027         out_integer = 2;
01028         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
01029 
01030         sprintf(title_string, "REMARKS FILENAME=%s CREATED BY NAMD", filename);
01031         pad(title_string, 80);
01032         NAMD_write(fd, title_string, 80);
01033 
01034         char username[100];
01035 #if defined(WIN32) || defined(NO_GETPWUID)
01036         sprintf(username,"Win32");
01037 #else
01038         user_id= (int) getuid();
01039         pwbuf=getpwuid(user_id);
01040         if ( pwbuf ) sprintf(username,"%s",pwbuf->pw_name);
01041         else sprintf(username,"%d",user_id);
01042 #endif
01043         cur_time=time(NULL);
01044         tmbuf=localtime(&cur_time);
01045         strftime(time_str, 10, "%m/%d/%y", tmbuf);
01046 
01047         sprintf(title_string, "REMARKS DATE: %s CREATED BY USER: %s",
01048            time_str, username);
01049         pad(title_string, 80);
01050         NAMD_write(fd, title_string, 80);
01051         out_integer = 164;
01052         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
01053         out_integer = 4;
01054         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
01055         out_integer = N;
01056         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
01057         out_integer = 4;
01058         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
01059 
01060         return(0);
01061 }

int write_dcdstep int  ,
int  ,
FloatVector ,
double *  unitcell
 

Definition at line 842 of file dcdlib.C.

References LSEEK, and READ.

00844 {
00845         int32 NSAVC,NSTEP,NFILE;
00846         int32 out_integer;
00847 
00848   /* Unit cell */
00849   if (cell) {
00850     out_integer = 48;
00851     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00852     NAMD_write(fd, (char *) cell, out_integer);
00853     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00854   }
00855 
00856   /* Coordinates */
00857 #define FBUFSIZE 4096
00858     float fBuf[FBUFSIZE];
00859 
00860     int32 remains = N;
00861     int32 coorstart = 0;
00862 
00863         out_integer = N*4;
00864         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00865     //writing X-coor in batch mode
00866     while(remains>0){
00867         int32 writesize = FBUFSIZE;
00868         if(remains<FBUFSIZE) writesize=remains;
00869         for(int i=0; i<writesize; i++)
00870             fBuf[i] = coor[i+coorstart].x;
00871         NAMD_write(fd, (char *)fBuf, writesize*4);
00872         coorstart += writesize;
00873         remains -= FBUFSIZE;
00874     }    
00875         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00876 
00877         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00878     //writing Y-coor in batch mode
00879     remains = N;
00880     coorstart = 0;
00881     while(remains>0){
00882         int32 writesize = FBUFSIZE;
00883         if(remains<FBUFSIZE) writesize=remains;
00884         for(int i=0; i<writesize; i++)
00885             fBuf[i] = coor[i+coorstart].y;
00886         NAMD_write(fd, (char *)fBuf, writesize*4);
00887         coorstart += writesize;
00888         remains -= FBUFSIZE;
00889     }    
00890         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00891 
00892         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00893     //writing Z-coor in batch mode
00894     remains = N;
00895     coorstart = 0;
00896     while(remains>0){
00897         int32 writesize = FBUFSIZE;
00898         if(remains<FBUFSIZE) writesize=remains;
00899         for(int i=0; i<writesize; i++)
00900             fBuf[i] = coor[i+coorstart].z;
00901         NAMD_write(fd, (char *)fBuf, writesize*4);
00902         coorstart += writesize;
00903         remains -= FBUFSIZE;
00904     }   
00905         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00906 
00907 #ifdef WIN32
00908 #define LSEEK _lseek
00909 #define READ _read
00910 #else
00911 #define LSEEK lseek
00912 #define READ read
00913 #endif
00914 
00915         /* don't update header until after write succeeds */
00916 
00917         LSEEK(fd,NSAVC_POS,SEEK_SET);
00918         READ(fd,(void*) &NSAVC,sizeof(int32));
00919         LSEEK(fd,NSTEP_POS,SEEK_SET);
00920         READ(fd,(void*) &NSTEP,sizeof(int32));
00921         LSEEK(fd,NFILE_POS,SEEK_SET);
00922         READ(fd,(void*) &NFILE,sizeof(int32));
00923         NSTEP += NSAVC;
00924         NFILE += 1;
00925         LSEEK(fd,NSTEP_POS,SEEK_SET);
00926         NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00927         LSEEK(fd,NFILE_POS,SEEK_SET);
00928         NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00929         LSEEK(fd,0,SEEK_END);
00930         return(0);
00931 }

int write_dcdstep int  ,
int  ,
float *  ,
float *  ,
float *  ,
double *  unitcell
 

Definition at line 720 of file dcdlib.C.

References LSEEK, and READ.

00722 {
00723         int32 NSAVC,NSTEP,NFILE;
00724         int32 out_integer;
00725 
00726   /* Unit cell */
00727   if (cell) {
00728     out_integer = 48;
00729     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00730     NAMD_write(fd, (char *) cell, out_integer);
00731     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00732   }
00733 
00734   /* Coordinates */
00735         out_integer = N*4;
00736         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00737         NAMD_write(fd, (char *) X, out_integer);
00738         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00739         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00740         NAMD_write(fd, (char *) Y, out_integer);
00741         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00742         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00743         NAMD_write(fd, (char *) Z, out_integer);
00744         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00745 
00746 #ifdef WIN32
00747 #define LSEEK _lseek
00748 #define READ _read
00749 #else
00750 #define LSEEK lseek
00751 #define READ read
00752 #endif
00753 
00754         /* don't update header until after write succeeds */
00755         LSEEK(fd,NSAVC_POS,SEEK_SET);
00756         READ(fd,(void*) &NSAVC,sizeof(int32));
00757         LSEEK(fd,NSTEP_POS,SEEK_SET);
00758         READ(fd,(void*) &NSTEP,sizeof(int32));
00759         LSEEK(fd,NFILE_POS,SEEK_SET);
00760         READ(fd,(void*) &NFILE,sizeof(int32));
00761         NSTEP += NSAVC;
00762         NFILE += 1;
00763         LSEEK(fd,NSTEP_POS,SEEK_SET);
00764         NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00765         LSEEK(fd,NFILE_POS,SEEK_SET);
00766         NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00767         LSEEK(fd,0,SEEK_END);
00768 
00769         return(0);
00770 }

int write_dcdstep_par_header int  fd,
int  N,
float *  X,
float *  Y,
float *  Z,
double *  cell
 

Definition at line 820 of file dcdlib.C.

References LSEEK, and READ.

00821 {
00822         int32 NSAVC,NSTEP,NFILE;
00823         /* don't update header until after write succeeds */
00824         LSEEK(fd,NSAVC_POS,SEEK_SET);
00825         READ(fd,(void*) &NSAVC,sizeof(int32));
00826         LSEEK(fd,NSTEP_POS,SEEK_SET);
00827         READ(fd,(void*) &NSTEP,sizeof(int32));
00828         LSEEK(fd,NFILE_POS,SEEK_SET);
00829         READ(fd,(void*) &NFILE,sizeof(int32));
00830         NSTEP += NSAVC;
00831         NFILE += 1;
00832         LSEEK(fd,NSTEP_POS,SEEK_SET);
00833         NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00834         LSEEK(fd,NFILE_POS,SEEK_SET);
00835         NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00836         LSEEK(fd,0,SEEK_END);
00837 
00838         return(0);
00839 }

int write_dcdstep_par_slave int  fd,
int  N,
float *  X,
float *  Y,
float *  Z,
double *  cell,
int  xoffset,
int  yoffset,
int  zoffset
 

Definition at line 934 of file dcdlib.C.

References LSEEK.

00936 {
00937         int32 out_integer;
00938   /* Coordinates for the N elements handled by this writer */
00939         out_integer = N*4;
00940         LSEEK(fd, xoffset, SEEK_SET);
00941         NAMD_write(fd, (char *) X, out_integer);
00942         LSEEK(fd, yoffset, SEEK_SET);
00943         NAMD_write(fd, (char *) Y, out_integer);
00944         LSEEK(fd, zoffset, SEEK_SET);
00945         NAMD_write(fd, (char *) Z, out_integer);
00946         return(0);
00947 }

int write_dcdstep_par_units int  fd,
int  N,
float *  X,
float *  Y,
float *  Z,
double *  cell,
int  unitoffset
 

Definition at line 789 of file dcdlib.C.

References LSEEK.

00791 {
00792         int32 NSAVC,NSTEP,NFILE;
00793         int32 out_integer;
00794 
00795   /* Unit cell */
00796   if (cell) {
00797     LSEEK(fd, unitoffset, SEEK_SET);
00798     out_integer = 48;
00799     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00800     NAMD_write(fd, (char *) cell, out_integer);
00801     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00802   }
00803   // number of elements
00804   out_integer = N*4;
00805   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00806   // seek to the end of each x y z block and write out the count
00807   LSEEK(fd, out_integer, SEEK_SET);
00808   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00809   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00810   LSEEK(fd, out_integer, SEEK_SET);
00811   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00812   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00813   LSEEK(fd, out_integer, SEEK_SET);
00814   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00815   return(0);
00816 }


Generated on Sat Aug 30 04:07:41 2008 for NAMD by  doxygen 1.3.9.1