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

dcdlib.h File Reference

#include "largefiles.h"
#include "common.h"
#include "Vector.h"
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <pwd.h>
#include <time.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
#define LSEEK   lseek
#define READ   read

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 write_dcdstep (int, int, float *, float *, float *, double *unitcell)
int write_dcdheader (int, char *, int, int, int, int, int, double, int)
int get_dcdheader_size ()
void close_dcd_read (int, int, int *)
void close_dcd_write (int)
int open_dcd_write_par_slave (char *dcdname)
int write_dcdstep_par_cell (int fd, double *cell)
int write_dcdstep_par_XYZUnits (int fd, int N)
int update_dcdstep_par_header (int fd)
int write_dcdstep_par_slave (int fd, int parL, int parU, int N, float *X, float *Y, float *Z)
int seek_dcdfile (int fd, off_t offset, int whence)


Define Documentation

#define DCD_BADEOF   -5
 

Definition at line 43 of file dcdlib.h.

#define DCD_BADFORMAT   -6
 

Definition at line 44 of file dcdlib.h.

#define DCD_BADMALLOC   -8
 

Definition at line 46 of file dcdlib.h.

#define DCD_BADREAD   -4
 

Definition at line 42 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 40 of file dcdlib.h.

#define DCD_FILEEXISTS   -7
 

Definition at line 45 of file dcdlib.h.

#define DCD_OPENFAILED   -3
 

Definition at line 41 of file dcdlib.h.

Referenced by open_dcd_write().

#define LSEEK   lseek
 

Definition at line 52 of file dcdlib.h.

Referenced by seek_dcdfile().

#define READ   read
 

Definition at line 53 of file dcdlib.h.


Function Documentation

void close_dcd_read int  ,
int  ,
int * 
 

Definition at line 1008 of file dcdlib.C.

01010 {
01011 #ifdef WIN32
01012         _close(fd);
01013 #else
01014         close(fd);
01015 #endif
01016 
01017         if (num_fixed)
01018         {
01019                 delete [] indexes;
01020         }
01021 }

void close_dcd_write int   ) 
 

Definition at line 1038 of file dcdlib.C.

01040 {
01041 #ifdef WIN32
01042   if ( _close(fd) )
01043 #else
01044   if ( fsync(fd) || close(fd) )
01045 #endif
01046   {
01047     NAMD_err("Error closing DCD file");
01048   }
01049 }

int get_dcdheader_size  ) 
 

Definition at line 980 of file dcdlib.C.

00980                         {
00981         int headersize = 0;
00982         int totalInt32s = 27; /* 27 writes from out_integer */
00983         int totalChars = 164; /* 3 writes from title_string */
00984         int totalFloats = 1; /* 1 write from out_float */
00985         headersize = sizeof(int32)*totalInt32s+totalChars+sizeof(float)*totalFloats;
00986         return headersize;
00987 }

int open_dcd_read char *   ) 
 

Definition at line 118 of file dcdlib.C.

References O_LARGEFILE.

00120 {
00121         int dcdfd;              /*  file descriptor for dcd file        */
00122 
00123         /*  Do a stat just to see if the file really exists     */
00124         if (access(filename, F_OK) != 0)
00125         {
00126                 if (errno == ENOENT)
00127                 {
00128                         return(DCD_DNE);
00129                 }
00130         }
00131 
00132         /*  Try and open the file                               */
00133 #ifdef WIN32
00134         dcdfd=_open(filename, O_RDONLY|O_BINARY|O_LARGEFILE);
00135 #else
00136         dcdfd=open(filename, O_RDONLY|O_LARGEFILE);
00137 #endif
00138 
00139         if (dcdfd == -1)
00140         {
00141                 return(DCD_OPENFAILED);
00142         }
00143 
00144         return(dcdfd);
00145 }

int open_dcd_write char *   ) 
 

Definition at line 631 of file dcdlib.C.

References DCD_OPENFAILED, and O_LARGEFILE.

00633 {
00634         int dcdfd;
00635         char *newdcdname = 0;
00636 
00637         if (access(dcdname, F_OK) == 0) 
00638         {
00639            newdcdname = new char[strlen(dcdname)+5];
00640            if(newdcdname == (char *) 0)
00641              return DCD_OPENFAILED;
00642            strcpy(newdcdname, dcdname);
00643            strcat(newdcdname, ".BAK");
00644 #if defined(WIN32) && !defined(__CYGWIN__)
00645            remove(newdcdname);
00646 #endif
00647            if(rename(dcdname, newdcdname))
00648                 return(DCD_OPENFAILED);
00649            delete [] newdcdname;
00650         } 
00651 #ifdef WIN32
00652         while ( (dcdfd = _open(dcdname, O_RDWR|O_CREAT|O_EXCL|O_BINARY|O_LARGEFILE,
00653                                 _S_IREAD|_S_IWRITE)) < 0)
00654 #else
00655 #ifdef NAMD_NO_O_EXCL
00656         while ( (dcdfd = open(dcdname, O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE,
00657 #else
00658         while ( (dcdfd = open(dcdname, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE,
00659 #endif
00660                                 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
00661 #endif
00662         {
00663                 if ( errno != EINTR ) return(DCD_OPENFAILED);
00664         }
00665 
00666         return(dcdfd);
00667 }

int open_dcd_write_par_slave char *  dcdname  ) 
 

Definition at line 672 of file dcdlib.C.

00674 {
00675 #if OUTPUT_SINGLE_FILE
00676         //In the case of single file, the dcd output by slaves has been created
00677         //by the master, so the dcd file doesn't need to be created again and
00678         //backed up. --Chao Mei
00679         int dcdfd;
00680 #ifdef WIN32
00681         while ( (dcdfd = _open(dcdname, O_WRONLY|O_BINARY|O_LARGEFILE,
00682                                 _S_IREAD|_S_IWRITE)) < 0)
00683 #else
00684         while ( (dcdfd = open(dcdname, O_WRONLY|O_LARGEFILE,
00685                                 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
00686 #endif
00687         {
00688                 if ( errno != EINTR ) return(DCD_OPENFAILED);
00689         }
00690 
00691         return(dcdfd);
00692 #else
00693         //In the case of multiple output files, each slave has its own output file and
00694         //it needs to be created. --Chao Mei
00695         return open_dcd_write(dcdname);
00696 #endif
00697 }

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

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

int seek_dcdfile int  fd,
off_t  offset,
int  whence
[inline]
 

Definition at line 86 of file dcdlib.h.

References LSEEK.

00086                                                          {
00087     return LSEEK(fd, offset, whence);
00088 }

int update_dcdstep_par_header int  fd  ) 
 

Definition at line 813 of file dcdlib.C.

00814 {
00815         int32 NSAVC,NSTEP,NFILE;
00816         /* don't update header until after write succeeds */
00817         off_t end = LSEEK(fd,0,SEEK_CUR);
00818         LSEEK(fd,NSAVC_POS,SEEK_SET);
00819         READ(fd,(void*) &NSAVC,sizeof(int32));
00820         LSEEK(fd,NSTEP_POS,SEEK_SET);
00821         READ(fd,(void*) &NSTEP,sizeof(int32));
00822         LSEEK(fd,NFILE_POS,SEEK_SET);
00823         READ(fd,(void*) &NFILE,sizeof(int32));
00824         NSTEP += NSAVC;
00825         NFILE += 1;
00826         LSEEK(fd,NSTEP_POS,SEEK_SET);
00827         NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00828         LSEEK(fd,NFILE_POS,SEEK_SET);
00829         NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00830         LSEEK(fd,end,SEEK_SET);
00831 
00832         return(0);
00833 }

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

Definition at line 890 of file dcdlib.C.

00892 {
00893         int32   out_integer;
00894         float   out_float;
00895         char    title_string[200];
00896         int     user_id;
00897 #ifndef WIN32
00898         struct  passwd *pwbuf;
00899 #endif
00900         time_t  cur_time;
00901         struct  tm *tmbuf;
00902         char    time_str[11];
00903 
00904         out_integer = 84;
00905         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00906         strcpy(title_string, "CORD");
00907         NAMD_write(fd, title_string, 4);
00908         out_integer = NFILE;  /* located at fpos 8 */
00909         out_integer = 0;  /* ignore the lies */
00910         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00911         out_integer = NPRIV;  /* located at fpos 12 */
00912         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00913         out_integer = NSAVC;  /* located at fpos 16 */
00914         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00915         out_integer = NSTEP;  /* located at fpos 20 */
00916         out_integer = NPRIV - NSAVC;  /* ignore the lies */
00917         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00918         out_integer=0;
00919         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00920         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00921         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00922         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00923         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00924         out_float = DELTA;
00925         NAMD_write(fd, (char *) &out_float, sizeof(float));
00926   out_integer = with_unitcell ? 1 : 0;
00927         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00928   out_integer = 0;
00929         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00930         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00931         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00932         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00933         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00934         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00935         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00936         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00937         out_integer = 24;  // PRETEND TO BE CHARMM24 -JCP
00938         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00939         out_integer = 84;
00940         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00941 
00942         out_integer = 164;
00943         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00944         out_integer = 2;
00945         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00946 
00947         sprintf(title_string, "REMARKS FILENAME=%s CREATED BY NAMD", filename);
00948         pad(title_string, 80);
00949         NAMD_write(fd, title_string, 80);
00950 
00951         char username[100];
00952 #if defined(WIN32) || defined(NO_GETPWUID)
00953         sprintf(username,"Win32");
00954 #else
00955         user_id= (int) getuid();
00956         pwbuf=getpwuid(user_id);
00957         if ( pwbuf ) sprintf(username,"%s",pwbuf->pw_name);
00958         else sprintf(username,"%d",user_id);
00959 #endif
00960         cur_time=time(NULL);
00961         tmbuf=localtime(&cur_time);
00962         strftime(time_str, 10, "%m/%d/%y", tmbuf);
00963 
00964         sprintf(title_string, "REMARKS DATE: %s CREATED BY USER: %s",
00965            time_str, username);
00966         pad(title_string, 80);
00967         NAMD_write(fd, title_string, 80);
00968         out_integer = 164;
00969         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00970         out_integer = 4;
00971         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00972         out_integer = N;
00973         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00974         out_integer = 4;
00975         NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00976 
00977         return(0);
00978 }

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

Definition at line 719 of file dcdlib.C.

00721 {
00722         int32 NSAVC,NSTEP,NFILE;
00723         int32 out_integer;
00724 
00725   /* Unit cell */
00726   if (cell) {
00727     out_integer = 48;
00728     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00729     NAMD_write(fd, (char *) cell, out_integer);
00730     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00731   }
00732 
00733   /* Coordinates */
00734         out_integer = N*4;
00735         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00736         NAMD_write(fd, (char *) X, out_integer);
00737         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00738         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00739         NAMD_write(fd, (char *) Y, out_integer);
00740         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00741         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00742         NAMD_write(fd, (char *) Z, out_integer);
00743         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00744 
00745         /* don't update header until after write succeeds */
00746         off_t end = LSEEK(fd,0,SEEK_CUR);
00747         LSEEK(fd,NSAVC_POS,SEEK_SET);
00748         READ(fd,(void*) &NSAVC,sizeof(int32));
00749         LSEEK(fd,NSTEP_POS,SEEK_SET);
00750         READ(fd,(void*) &NSTEP,sizeof(int32));
00751         LSEEK(fd,NFILE_POS,SEEK_SET);
00752         READ(fd,(void*) &NFILE,sizeof(int32));
00753         NSTEP += NSAVC;
00754         NFILE += 1;
00755         LSEEK(fd,NSTEP_POS,SEEK_SET);
00756         NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00757         LSEEK(fd,NFILE_POS,SEEK_SET);
00758         NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00759         LSEEK(fd,end,SEEK_SET);
00760 
00761         return(0);
00762 }

int write_dcdstep_par_cell int  fd,
double *  cell
 

Definition at line 764 of file dcdlib.C.

00764                                                 {
00765         if (cell) {
00766           int32 out_integer = 48;
00767           NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00768           NAMD_write(fd, (char *) cell, out_integer);
00769           NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00770         }
00771         return 0;
00772 }

int write_dcdstep_par_slave int  fd,
int  parL,
int  parU,
int  N,
float *  X,
float *  Y,
float *  Z
 

Definition at line 838 of file dcdlib.C.

00838                                                                                             {
00839 
00840         int parN = parU-parL+1;
00841         int32 out_integer;
00842   /* Coordinates for the N elements handled by this writer */
00843         out_integer = parN*4;
00844 
00845         /* x's 1st number of Xs */
00846         /* skip field for the bytes in X, and the first parL atoms in X*/
00847         off_t xoffset = sizeof(int)+sizeof(float)*((off_t)parL);
00848         LSEEK(fd, xoffset, SEEK_CUR);
00849         NAMD_write(fd, (char *) X, out_integer);
00850 
00851         /* skip field for the bytes in X and Y; */
00852         /* skip the remaining atoms in X at number of (N-1)-(parU+1)+1
00853          * where N-1 is the last atom id, paru+1 is the next atom id. */
00854         /* skip the first parL atoms in Y; */
00855         off_t yoffset = 2*sizeof(int)+sizeof(float)*((off_t)(N-parU+parL-1));
00856         LSEEK(fd, yoffset, SEEK_CUR);
00857         NAMD_write(fd, (char *) Y, out_integer);
00858 
00859         off_t zoffset = yoffset;
00860         LSEEK(fd, zoffset, SEEK_CUR);
00861         NAMD_write(fd, (char *) Z, out_integer);
00862         return(0);
00863 }

int write_dcdstep_par_XYZUnits int  fd,
int  N
 

Definition at line 789 of file dcdlib.C.

00790 {
00791   int32 out_integer;
00792 
00793   // number of elements
00794   out_integer = N*sizeof(float);
00795   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00796   // seek to the end of each x y z block and write out the count
00797   LSEEK(fd, out_integer, SEEK_CUR);
00798   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00799 
00800   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00801   LSEEK(fd, out_integer, SEEK_CUR);
00802   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00803 
00804   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00805   LSEEK(fd, out_integer, SEEK_CUR);
00806   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00807 
00808   return(0);
00809 }


Generated on Thu May 23 04:07:19 2013 for NAMD by  doxygen 1.3.9.1