#include "dcdlib.h"#include "Output.h"Go to the source code of this file.
Defines | |
| #define | NAMD_write NAMD_write64 |
| #define | O_LARGEFILE 0x0 |
| #define | CHECK_FREAD(X, msg) |
| #define | CHECK_FEOF(X, msg) |
| #define | NFILE_POS (off_t) 8 |
| #define | NPRIV_POS (off_t) 12 |
| #define | NSAVC_POS (off_t) 16 |
| #define | NSTEP_POS (off_t) 20 |
Functions | |
| void | NAMD_write (int fd, const char *buf, size_t count) |
| void | pad (char *s, int len) |
| int | open_dcd_read (char *filename) |
| int | open_dcd_write (char *dcdname) |
| int | open_dcd_write_par_slave (char *dcdname) |
| int | write_dcdstep (int fd, int N, float *X, float *Y, float *Z, double *cell) |
| 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 | write_dcdheader (int fd, char *filename, int N, int NFILE, int NPRIV, int NSAVC, int NSTEP, double DELTA, int with_unitcell) |
| int | get_dcdheader_size () |
| void | close_dcd_read (int fd, int num_fixed, int *indexes) |
| void | close_dcd_write (int fd) |
|
|
Value: if (X==0) \ { \ return(DCD_BADEOF); \ } |
|
|
Value: if (X==-1) \ { \ return(DCD_BADREAD); \ } |
|
|
Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by The Board of Trustees of the University of Illinois. All rights reserved. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 34 of file dcdlib.C. Referenced by open_dcd_read(), and open_dcd_write(). |
|
||||||||||||||||
|
Definition at line 1005 of file dcdlib.C. 01007 {
01008 #ifdef WIN32
01009 _close(fd);
01010 #else
01011 close(fd);
01012 #endif
01013
01014 if (num_fixed)
01015 {
01016 delete [] indexes;
01017 }
01018 }
|
|
|
Definition at line 1035 of file dcdlib.C. 01037 {
01038 #ifdef WIN32
01039 if ( _close(fd) )
01040 #else
01041 if ( fsync(fd) || close(fd) )
01042 #endif
01043 {
01044 NAMD_err("Error closing DCD file");
01045 }
01046 }
|
|
|
Definition at line 977 of file dcdlib.C. 00977 {
00978 int headersize = 0;
00979 int totalInt32s = 27; /* 27 writes from out_integer */
00980 int totalChars = 164; /* 3 writes from title_string */
00981 int totalFloats = 1; /* 1 write from out_float */
00982 headersize = sizeof(int32)*totalInt32s+totalChars+sizeof(float)*totalFloats;
00983 return headersize;
00984 }
|
|
||||||||||||||||
|
Definition at line 18 of file dcdlib.C. References NAMD_bug(), and NAMD_die(). 00018 {
00019 while ( count ) {
00020 #if defined(WIN32) && !defined(__CYGWIN__)
00021 long retval = _write(fd,buf,count);
00022 #else
00023 ssize_t retval = write(fd,buf,count);
00024 #endif
00025 if ( retval < 0 && errno == EINTR ) retval = 0;
00026 if ( retval < 0 ) NAMD_die(strerror(errno));
00027 if ( retval > count ) NAMD_bug("extra bytes written in NAMD_write64()");
00028 buf += retval;
00029 count -= retval;
00030 }
00031 }
|
|
|
Definition at line 115 of file dcdlib.C. References O_LARGEFILE. 00117 {
00118 struct stat stbuf; /* Stat structure to check file */
00119 int dcdfd; /* file descriptor for dcd file */
00120
00121 /* Do a stat just to see if the file really exists */
00122 if (stat(filename, &stbuf) != 0)
00123 {
00124 if (errno == ENOENT)
00125 {
00126 return(DCD_DNE);
00127 }
00128 }
00129
00130 /* Try and open the file */
00131 #ifdef WIN32
00132 dcdfd=_open(filename, O_RDONLY|O_BINARY|O_LARGEFILE);
00133 #else
00134 dcdfd=open(filename, O_RDONLY|O_LARGEFILE);
00135 #endif
00136
00137 if (dcdfd == -1)
00138 {
00139 return(DCD_OPENFAILED);
00140 }
00141
00142 return(dcdfd);
00143 }
|
|
|
Definition at line 629 of file dcdlib.C. References DCD_OPENFAILED, and O_LARGEFILE. 00631 {
00632 struct stat sbuf;
00633 int dcdfd;
00634 char *newdcdname = 0;
00635
00636 if (stat(dcdname, &sbuf) == 0)
00637 {
00638 newdcdname = new char[strlen(dcdname)+5];
00639 if(newdcdname == (char *) 0)
00640 return DCD_OPENFAILED;
00641 strcpy(newdcdname, dcdname);
00642 strcat(newdcdname, ".BAK");
00643 #if defined(WIN32) && !defined(__CYGWIN__)
00644 remove(newdcdname);
00645 #endif
00646 if(rename(dcdname, newdcdname))
00647 return(DCD_OPENFAILED);
00648 delete [] newdcdname;
00649 }
00650 #ifdef WIN32
00651 while ( (dcdfd = _open(dcdname, O_RDWR|O_CREAT|O_EXCL|O_BINARY|O_LARGEFILE,
00652 _S_IREAD|_S_IWRITE)) < 0)
00653 #else
00654 #ifdef NAMD_NO_O_EXCL
00655 while ( (dcdfd = open(dcdname, O_RDWR|O_CREAT|O_TRUNC|O_LARGEFILE,
00656 #else
00657 while ( (dcdfd = open(dcdname, O_RDWR|O_CREAT|O_EXCL|O_LARGEFILE,
00658 #endif
00659 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
00660 #endif
00661 {
00662 if ( errno != EINTR ) return(DCD_OPENFAILED);
00663 }
00664
00665 return(dcdfd);
00666 }
|
|
|
Definition at line 671 of file dcdlib.C. 00673 {
00674 #if OUTPUT_SINGLE_FILE
00675 //In the case of single file, the dcd output by slaves has been created
00676 //by the master, so the dcd file doesn't need to be created again and
00677 //backed up. --Chao Mei
00678 int dcdfd;
00679 #ifdef WIN32
00680 while ( (dcdfd = _open(dcdname, O_WRONLY|O_BINARY|O_LARGEFILE,
00681 _S_IREAD|_S_IWRITE)) < 0)
00682 #else
00683 while ( (dcdfd = open(dcdname, O_WRONLY|O_LARGEFILE,
00684 S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0)
00685 #endif
00686 {
00687 if ( errno != EINTR ) return(DCD_OPENFAILED);
00688 }
00689
00690 return(dcdfd);
00691 #else
00692 //In the case of multiple output files, each slave has its own output file and
00693 //it needs to be created. --Chao Mei
00694 return open_dcd_write(dcdname);
00695 #endif
00696 }
|
|
||||||||||||
|
Definition at line 75 of file dcdlib.C. 00076 {
00077 int curlen;
00078 int i;
00079
00080 curlen=strlen(s);
00081
00082 if (curlen>len)
00083 {
00084 s[len]='\0';
00085 return;
00086 }
00087
00088 for (i=curlen; i<len; i++)
00089 {
00090 s[i]=' ';
00091 }
00092
00093 s[i]='\0';
00094 }
|
|
|
Definition at line 811 of file dcdlib.C. 00812 {
00813 int32 NSAVC,NSTEP,NFILE;
00814 /* don't update header until after write succeeds */
00815 LSEEK(fd,NSAVC_POS,SEEK_SET);
00816 READ(fd,(void*) &NSAVC,sizeof(int32));
00817 LSEEK(fd,NSTEP_POS,SEEK_SET);
00818 READ(fd,(void*) &NSTEP,sizeof(int32));
00819 LSEEK(fd,NFILE_POS,SEEK_SET);
00820 READ(fd,(void*) &NFILE,sizeof(int32));
00821 NSTEP += NSAVC;
00822 NFILE += 1;
00823 LSEEK(fd,NSTEP_POS,SEEK_SET);
00824 NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00825 LSEEK(fd,NFILE_POS,SEEK_SET);
00826 NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00827 LSEEK(fd,0,SEEK_END);
00828
00829 return(0);
00830 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 887 of file dcdlib.C. 00889 {
00890 int32 out_integer;
00891 float out_float;
00892 char title_string[200];
00893 int user_id;
00894 #ifndef WIN32
00895 struct passwd *pwbuf;
00896 #endif
00897 time_t cur_time;
00898 struct tm *tmbuf;
00899 char time_str[11];
00900
00901 out_integer = 84;
00902 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00903 strcpy(title_string, "CORD");
00904 NAMD_write(fd, title_string, 4);
00905 out_integer = NFILE; /* located at fpos 8 */
00906 out_integer = 0; /* ignore the lies */
00907 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00908 out_integer = NPRIV; /* located at fpos 12 */
00909 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00910 out_integer = NSAVC; /* located at fpos 16 */
00911 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00912 out_integer = NSTEP; /* located at fpos 20 */
00913 out_integer = NPRIV - NSAVC; /* ignore the lies */
00914 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00915 out_integer=0;
00916 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00917 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00918 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00919 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00920 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00921 out_float = DELTA;
00922 NAMD_write(fd, (char *) &out_float, sizeof(float));
00923 out_integer = with_unitcell ? 1 : 0;
00924 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00925 out_integer = 0;
00926 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00927 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00928 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
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 out_integer = 24; // PRETEND TO BE CHARMM24 -JCP
00935 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00936 out_integer = 84;
00937 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00938
00939 out_integer = 164;
00940 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00941 out_integer = 2;
00942 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00943
00944 sprintf(title_string, "REMARKS FILENAME=%s CREATED BY NAMD", filename);
00945 pad(title_string, 80);
00946 NAMD_write(fd, title_string, 80);
00947
00948 char username[100];
00949 #if defined(WIN32) || defined(NO_GETPWUID)
00950 sprintf(username,"Win32");
00951 #else
00952 user_id= (int) getuid();
00953 pwbuf=getpwuid(user_id);
00954 if ( pwbuf ) sprintf(username,"%s",pwbuf->pw_name);
00955 else sprintf(username,"%d",user_id);
00956 #endif
00957 cur_time=time(NULL);
00958 tmbuf=localtime(&cur_time);
00959 strftime(time_str, 10, "%m/%d/%y", tmbuf);
00960
00961 sprintf(title_string, "REMARKS DATE: %s CREATED BY USER: %s",
00962 time_str, username);
00963 pad(title_string, 80);
00964 NAMD_write(fd, title_string, 80);
00965 out_integer = 164;
00966 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00967 out_integer = 4;
00968 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00969 out_integer = N;
00970 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00971 out_integer = 4;
00972 NAMD_write(fd, (char *) & out_integer, sizeof(int32));
00973
00974 return(0);
00975 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 718 of file dcdlib.C. 00720 {
00721 int32 NSAVC,NSTEP,NFILE;
00722 int32 out_integer;
00723
00724 /* Unit cell */
00725 if (cell) {
00726 out_integer = 48;
00727 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00728 NAMD_write(fd, (char *) cell, out_integer);
00729 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00730 }
00731
00732 /* Coordinates */
00733 out_integer = N*4;
00734 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00735 NAMD_write(fd, (char *) X, out_integer);
00736 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00737 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00738 NAMD_write(fd, (char *) Y, out_integer);
00739 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00740 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00741 NAMD_write(fd, (char *) Z, out_integer);
00742 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00743
00744 /* don't update header until after write succeeds */
00745 LSEEK(fd,NSAVC_POS,SEEK_SET);
00746 READ(fd,(void*) &NSAVC,sizeof(int32));
00747 LSEEK(fd,NSTEP_POS,SEEK_SET);
00748 READ(fd,(void*) &NSTEP,sizeof(int32));
00749 LSEEK(fd,NFILE_POS,SEEK_SET);
00750 READ(fd,(void*) &NFILE,sizeof(int32));
00751 NSTEP += NSAVC;
00752 NFILE += 1;
00753 LSEEK(fd,NSTEP_POS,SEEK_SET);
00754 NAMD_write(fd,(char*) &NSTEP,sizeof(int32));
00755 LSEEK(fd,NFILE_POS,SEEK_SET);
00756 NAMD_write(fd,(char*) &NFILE,sizeof(int32));
00757 LSEEK(fd,0,SEEK_END);
00758
00759 return(0);
00760 }
|
|
||||||||||||
|
Definition at line 762 of file dcdlib.C. 00762 {
00763 if (cell) {
00764 int32 out_integer = 48;
00765 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00766 NAMD_write(fd, (char *) cell, out_integer);
00767 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00768 }
00769 return 0;
00770 }
|
|
||||||||||||||||||||||||||||||||
|
Definition at line 835 of file dcdlib.C. 00835 {
00836
00837 int parN = parU-parL+1;
00838 int32 out_integer;
00839 /* Coordinates for the N elements handled by this writer */
00840 out_integer = parN*4;
00841
00842 /* x's 1st number of Xs */
00843 /* skip field for the bytes in X, and the first parL atoms in X*/
00844 off_t xoffset = sizeof(int)+sizeof(float)*((off_t)parL);
00845 LSEEK(fd, xoffset, SEEK_CUR);
00846 NAMD_write(fd, (char *) X, out_integer);
00847
00848 /* skip field for the bytes in X and Y; */
00849 /* skip the remaining atoms in X at number of (N-1)-(parU+1)+1
00850 * where N-1 is the last atom id, paru+1 is the next atom id. */
00851 /* skip the first parL atoms in Y; */
00852 off_t yoffset = 2*sizeof(int)+sizeof(float)*((off_t)(N-parU+parL-1));
00853 LSEEK(fd, yoffset, SEEK_CUR);
00854 NAMD_write(fd, (char *) Y, out_integer);
00855
00856 off_t zoffset = yoffset;
00857 LSEEK(fd, zoffset, SEEK_CUR);
00858 NAMD_write(fd, (char *) Z, out_integer);
00859 return(0);
00860 }
|
|
||||||||||||
|
Definition at line 787 of file dcdlib.C. 00788 {
00789 int32 out_integer;
00790
00791 // number of elements
00792 out_integer = N*sizeof(float);
00793 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00794 // seek to the end of each x y z block and write out the count
00795 LSEEK(fd, out_integer, SEEK_CUR);
00796 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00797
00798 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00799 LSEEK(fd, out_integer, SEEK_CUR);
00800 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00801
00802 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00803 LSEEK(fd, out_integer, SEEK_CUR);
00804 NAMD_write(fd, (char *) &out_integer, sizeof(int32));
00805
00806 return(0);
00807 }
|
1.3.9.1