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 OFF_T   off_t
#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 (const char *)
int write_dcdstep (int, int, float *, float *, float *, double *unitcell)
int write_dcdheader (int, const 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)
OFF_T NAMD_seek (int file, OFF_T offset, int whence)


Define Documentation

#define DCD_BADEOF   -5

Definition at line 50 of file dcdlib.h.

#define DCD_BADFORMAT   -6

Definition at line 51 of file dcdlib.h.

#define DCD_BADMALLOC   -8

Definition at line 53 of file dcdlib.h.

#define DCD_BADREAD   -4

Definition at line 49 of file dcdlib.h.

#define DCD_DNE   -2

Definition at line 47 of file dcdlib.h.

Referenced by open_dcd_read().

#define DCD_FILEEXISTS   -7

Definition at line 52 of file dcdlib.h.

Referenced by ComputeQMMgr::recvPartQM(), and Output::recvReplicaDcdData().

#define DCD_OPENFAILED   -3

Definition at line 48 of file dcdlib.h.

Referenced by open_dcd_read(), open_dcd_write(), and open_dcd_write_par_slave().

#define OFF_T   off_t

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

Definition at line 42 of file dcdlib.h.

Referenced by NAMD_seek(), update_dcdstep_par_header(), write_dcdstep(), and write_dcdstep_par_slave().


Function Documentation

void close_dcd_read ( int  ,
int  ,
int *   
)

Definition at line 1025 of file dcdlib.C.

01027 {
01028 #ifdef WIN32
01029         _close(fd);
01030 #else
01031         close(fd);
01032 #endif
01033 
01034         if (num_fixed)
01035         {
01036                 delete [] indexes;
01037         }
01038 }

void close_dcd_write ( int   ) 

Definition at line 1055 of file dcdlib.C.

References NAMD_err().

Referenced by Output::recvReplicaDcdInit(), and ComputeQMMgr::~ComputeQMMgr().

01057 {
01058 #ifdef WIN32
01059   if ( _close(fd) )
01060 #else
01061   if ( fsync(fd) || close(fd) )
01062 #endif
01063   {
01064     NAMD_err("Error closing DCD file");
01065   }
01066 }

int get_dcdheader_size (  ) 

Definition at line 997 of file dcdlib.C.

00997                         {
00998         int headersize = 0;
00999         int totalInt32s = 27; /* 27 writes from out_integer */
01000         int totalChars = 164; /* 3 writes from title_string */
01001         int totalFloats = 1; /* 1 write from out_float */
01002         headersize = sizeof(int32)*totalInt32s+totalChars+sizeof(float)*totalFloats;
01003         return headersize;
01004 }

OFF_T NAMD_seek ( int  file,
OFF_T  offset,
int  whence 
)

Definition at line 49 of file dcdlib.C.

References LSEEK, NAMD_die(), NAMD_err(), and OFF_T.

00049                                                     {
00050   OFF_T retval = LSEEK(file, offset, whence);
00051   if ( retval < 0 ) NAMD_err("seek failed while writing DCD file");
00052   if ( whence == SEEK_SET && retval != offset ) {
00053     char buf[256];
00054     sprintf(buf, "seek failed while writing DCD file: SEEK_SET %lld returned %lld\n", offset, retval);
00055     NAMD_die(buf);
00056   }
00057   return retval;
00058 }

int open_dcd_read ( char *   ) 

Definition at line 145 of file dcdlib.C.

References DCD_DNE, DCD_OPENFAILED, and O_LARGEFILE.

00147 {
00148         int dcdfd;              /*  file descriptor for dcd file        */
00149 
00150         /*  Do a stat just to see if the file really exists     */
00151         if (access(filename, F_OK) != 0)
00152         {
00153                 if (errno == ENOENT)
00154                 {
00155                         return(DCD_DNE);
00156                 }
00157         }
00158 
00159         /*  Try and open the file                               */
00160 #ifdef WIN32
00161         dcdfd=_open(filename, O_RDONLY|O_BINARY|O_LARGEFILE);
00162 #else
00163         dcdfd=open(filename, O_RDONLY|O_LARGEFILE);
00164 #endif
00165 
00166         if (dcdfd == -1)
00167         {
00168                 return(DCD_OPENFAILED);
00169         }
00170 
00171         return(dcdfd);
00172 }

int open_dcd_write ( const char *   ) 

Definition at line 662 of file dcdlib.C.

References DCD_OPENFAILED, NAMD_backup_file(), and O_LARGEFILE.

Referenced by open_dcd_write_par_slave(), ComputeQMMgr::recvPartQM(), and Output::recvReplicaDcdData().

00664 {
00665         int dcdfd;
00666         NAMD_backup_file(dcdname,".BAK");
00667 
00668 #ifdef WIN32
00669         while ( (dcdfd = _open(dcdname, O_RDWR|O_CREAT|O_EXCL|O_BINARY|O_LARGEFILE,
00670                                 _S_IREAD|_S_IWRITE)) < 0)
00671 #else
00672 #ifdef NAMD_NO_O_EXCL
00673         while ( (dcdfd = open(dcdname, O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE,
00674 #else
00675         while ( (dcdfd = open(dcdname, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE,
00676 #endif
00677                                 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
00678 #endif
00679         {
00680                 if ( errno != EINTR ) return(DCD_OPENFAILED);
00681         }
00682 
00683         return(dcdfd);
00684 }

int open_dcd_write_par_slave ( char *  dcdname  ) 

Definition at line 689 of file dcdlib.C.

References DCD_OPENFAILED, O_LARGEFILE, and open_dcd_write().

00691 {
00692 #if OUTPUT_SINGLE_FILE
00693         //In the case of single file, the dcd output by slaves has been created
00694         //by the master, so the dcd file doesn't need to be created again and
00695         //backed up. --Chao Mei
00696         int dcdfd;
00697 #ifdef WIN32
00698         while ( (dcdfd = _open(dcdname, O_WRONLY|O_BINARY|O_LARGEFILE,
00699                                 _S_IREAD|_S_IWRITE)) < 0)
00700 #else
00701         while ( (dcdfd = open(dcdname, O_WRONLY|O_LARGEFILE,
00702                                 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
00703 #endif
00704         {
00705                 if ( errno != EINTR ) return(DCD_OPENFAILED);
00706         }
00707 
00708         return(dcdfd);
00709 #else
00710         //In the case of multiple output files, each slave has its own output file and
00711         //it needs to be created. --Chao Mei
00712         return open_dcd_write(dcdname);
00713 #endif
00714 }

int read_dcdheader ( int  ,
int *  ,
int *  ,
int *  ,
int *  ,
double *  ,
int *  ,
int **   
)

int read_dcdstep ( int  ,
int  ,
float *  ,
float *  ,
float *  ,
int  ,
int  ,
int *   
)

int update_dcdstep_par_header ( int  fd  ) 

Definition at line 830 of file dcdlib.C.

References LSEEK, NAMD_write, NFILE_POS, NSAVC_POS, NSTEP_POS, OFF_T, and READ.

00831 {
00832         int32 NSAVC,NSTEP,NFILE;
00833         /* don't update header until after write succeeds */
00834         OFF_T end = LSEEK(fd,0,SEEK_CUR);
00835         LSEEK(fd,NSAVC_POS,SEEK_SET);
00836         READ(fd,(void*) &NSAVC,sizeof(int32));
00837         LSEEK(fd,NSTEP_POS,SEEK_SET);
00838         READ(fd,(void*) &NSTEP,sizeof(int32));
00839         LSEEK(fd,NFILE_POS,SEEK_SET);
00840         READ(fd,(void*) &NFILE,sizeof(int32));
00841         NSTEP += NSAVC;
00842         NFILE += 1;
00843         LSEEK(fd,NSTEP_POS,SEEK_SET);
00844         NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00845         LSEEK(fd,NFILE_POS,SEEK_SET);
00846         NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00847         LSEEK(fd,end,SEEK_SET);
00848 
00849         return(0);
00850 }

int write_dcdheader ( int  ,
const char *  ,
int  ,
int  ,
int  ,
int  ,
int  ,
double  ,
int   
)

Definition at line 907 of file dcdlib.C.

References NAMD_write, and pad().

Referenced by ComputeQMMgr::recvPartQM(), and Output::recvReplicaDcdData().

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

int write_dcdstep ( int  ,
int  ,
float *  ,
float *  ,
float *  ,
double *  unitcell 
)

Definition at line 736 of file dcdlib.C.

References LSEEK, NAMD_write, NFILE_POS, NSAVC_POS, NSTEP_POS, OFF_T, and READ.

Referenced by ComputeQMMgr::procQMRes(), and Output::recvReplicaDcdData().

00738 {
00739         int32 NSAVC,NSTEP,NFILE;
00740         int32 out_integer;
00741 
00742   /* Unit cell */
00743   if (cell) {
00744     out_integer = 48;
00745     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00746     NAMD_write(fd, (char *) cell, out_integer);
00747     NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00748   }
00749 
00750   /* Coordinates */
00751         out_integer = N*4;
00752         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00753         NAMD_write(fd, (char *) X, out_integer);
00754         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00755         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00756         NAMD_write(fd, (char *) Y, out_integer);
00757         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00758         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00759         NAMD_write(fd, (char *) Z, out_integer);
00760         NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00761 
00762         /* don't update header until after write succeeds */
00763         OFF_T end = LSEEK(fd,0,SEEK_CUR);
00764         LSEEK(fd,NSAVC_POS,SEEK_SET);
00765         READ(fd,(void*) &NSAVC,sizeof(int32));
00766         LSEEK(fd,NSTEP_POS,SEEK_SET);
00767         READ(fd,(void*) &NSTEP,sizeof(int32));
00768         LSEEK(fd,NFILE_POS,SEEK_SET);
00769         READ(fd,(void*) &NFILE,sizeof(int32));
00770         NSTEP += NSAVC;
00771         NFILE += 1;
00772         LSEEK(fd,NSTEP_POS,SEEK_SET);
00773         NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00774         LSEEK(fd,NFILE_POS,SEEK_SET);
00775         NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00776         LSEEK(fd,end,SEEK_SET);
00777 
00778         return(0);
00779 }

int write_dcdstep_par_cell ( int  fd,
double *  cell 
)

Definition at line 781 of file dcdlib.C.

References NAMD_write.

00781                                                 {
00782         if (cell) {
00783           int32 out_integer = 48;
00784           NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00785           NAMD_write(fd, (char *) cell, out_integer);
00786           NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00787         }
00788         return 0;
00789 }

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

Definition at line 855 of file dcdlib.C.

References LSEEK, NAMD_write, and OFF_T.

00855                                                                                             {
00856 
00857         int parN = parU-parL+1;
00858         int32 out_integer;
00859   /* Coordinates for the N elements handled by this writer */
00860         out_integer = parN*4;
00861 
00862         /* x's 1st number of Xs */
00863         /* skip field for the bytes in X, and the first parL atoms in X*/
00864         OFF_T xoffset = sizeof(int)+sizeof(float)*((OFF_T)parL);
00865         LSEEK(fd, xoffset, SEEK_CUR);
00866         NAMD_write(fd, (char *) X, out_integer);
00867 
00868         /* skip field for the bytes in X and Y; */
00869         /* skip the remaining atoms in X at number of (N-1)-(parU+1)+1
00870          * where N-1 is the last atom id, paru+1 is the next atom id. */
00871         /* skip the first parL atoms in Y; */
00872         OFF_T yoffset = 2*sizeof(int)+sizeof(float)*((OFF_T)(N-parU+parL-1));
00873         LSEEK(fd, yoffset, SEEK_CUR);
00874         NAMD_write(fd, (char *) Y, out_integer);
00875 
00876         OFF_T zoffset = yoffset;
00877         LSEEK(fd, zoffset, SEEK_CUR);
00878         NAMD_write(fd, (char *) Z, out_integer);
00879         return(0);
00880 }

int write_dcdstep_par_XYZUnits ( int  fd,
int  N 
)

Definition at line 806 of file dcdlib.C.

References LSEEK, and NAMD_write.

00807 {
00808   int32 out_integer;
00809 
00810   // number of elements
00811   out_integer = N*sizeof(float);
00812   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00813   // seek to the end of each x y z block and write out the count
00814   LSEEK(fd, out_integer, SEEK_CUR);
00815   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00816 
00817   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00818   LSEEK(fd, out_integer, SEEK_CUR);
00819   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00820 
00821   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00822   LSEEK(fd, out_integer, SEEK_CUR);
00823   NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00824 
00825   return(0);
00826 }


Generated on Fri Sep 22 01:17:15 2017 for NAMD by  doxygen 1.4.7