diffbinpdb.c File Reference

#include "largefiles.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])


Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 13 of file diffbinpdb.c.

References j.

00013                                  {
00014 
00015 int fd1, fd2;
00016 struct stat statbuf;
00017 int i, j, n1, n2;
00018 off_t s1, s2;
00019 int imax, usetol;
00020 double dmax, dtol;
00021 
00022 if ( argc < 3 || argc > 4 ) {
00023   fprintf(stderr,"Returns the maximum distance between two binary pdb files.\n");
00024   fprintf(stderr,"Optionally lists all differences greater than [tolerance].\n");
00025   fprintf(stderr,"Usage: %s <filename1> <filename2> [tolerance]\n",argv[0]);
00026   exit(-1);
00027 }
00028 
00029 if ( ( fd1 = open(argv[1], O_RDONLY) ) < 0 ) {
00030   fprintf(stderr,"Can't open %s for reading.\n",argv[1]);
00031   exit(-1);
00032 }
00033 
00034 if ( fstat(fd1,&statbuf) < 0 ) {
00035   fprintf(stderr,"Can't stat %s.\n",argv[1]);
00036   exit(-1);
00037 }
00038 
00039 s1 = statbuf.st_size;
00040 
00041 if ( (s1 < 4) || ((s1-4) % 24) ) {
00042   fprintf(stderr,"Size %ld of %s is not 4 plus a multiple of 24.\n",s1,argv[1]);
00043   exit(-1);
00044 }
00045 
00046 read(fd1,&n1,4);
00047 
00048 if ( s1 != 4 + (off_t)n1 * 24 ) {
00049   fprintf(stderr,"Size %ld of %s is not 4 plus %d times 24.\n",s1,argv[1],n1);
00050   exit(-1);
00051 }
00052 
00053 if ( ( fd2 = open(argv[2], O_RDONLY) ) < 0 ) {
00054   fprintf(stderr,"Can't open %s for reading.\n",argv[2]);
00055   exit(-1);
00056 }
00057 
00058 if ( fstat(fd2,&statbuf) < 0 ) {
00059   fprintf(stderr,"Can't stat %s.\n",argv[2]);
00060   exit(-1);
00061 }
00062 
00063 s2 = statbuf.st_size;
00064 
00065 if ( (s2 < 4) || ((s2-4) % 24) ) {
00066   fprintf(stderr,"Size %ld of %s is not 4 plus a multiple of 24.\n",s2,argv[2]);
00067   exit(-1);
00068 }
00069 
00070 read(fd2,&n2,4);
00071 
00072 if ( s2 != 4 + (off_t)n2 * 24 ) {
00073   fprintf(stderr,"Size %ld of %s is not 4 plus %d times 24.\n",s2,argv[2],n2);
00074   exit(-1);
00075 }
00076 
00077 if ( n1 != n2 ) {
00078   fprintf(stderr,"%s atomcount %d does not match %s atomcount %d..\n",
00079           argv[1],n1,argv[2],n2);
00080   exit(-1);
00081 }
00082 
00083 usetol = 0;
00084 dtol = 0;
00085 
00086 if ( argc == 4 ) {
00087   if ( sscanf(argv[3],"%lf",&dtol) != 1 ) {
00088     fprintf(stderr,"Unable to parse tolerance argument %s\n",argv[3]);
00089     fprintf(stderr,"Usage: %s <filename1> <filename2> [tolerance]\n",argv[0]);
00090     exit(-1);
00091   }
00092   usetol = 1;
00093   if ( dtol > 0. ) dtol *= dtol;  /* preserve negative values */
00094 }
00095 
00096 imax = 0;
00097 dmax = 0;
00098 
00099 for ( i=0; i<n1; ++i ) {
00100   double c1[3];
00101   double c2[3];
00102   double d;
00103   read(fd1,c1,24);
00104   read(fd2,c2,24);
00105 
00106   d = 0;
00107   for ( j=0; j<3; ++j ) {
00108     double dj;
00109     dj = c1[j] - c2[j];
00110     d += dj*dj;
00111   }
00112   if ( d > dmax ) { imax = i; dmax = d; }
00113   if ( usetol && d > dtol ) {
00114     printf("%lg at %d\n",sqrt(d),i);
00115   }
00116 }
00117 
00118 dmax = sqrt(dmax);
00119 
00120 if ( dtol ) printf("MAX: ");
00121 printf("%lg at %d\n",dmax,imax);
00122 
00123 exit(0);
00124 
00125 }


Generated on Sat Nov 18 01:17:17 2017 for NAMD by  doxygen 1.4.7