NAMD
flipbinpdb.c
Go to the documentation of this file.
1 /********************************************************************/
2 /* */
3 /* Copyright 1998, Jim Phillips and the University of Illinois. */
4 /* */
5 /********************************************************************/
6 
7 #include "largefiles.h" /* must be first! */
8 
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <sys/mman.h>
12 #include <fcntl.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 
16 #ifndef MAP_FILE
17 #define MAP_FILE 0
18 #endif
19 
20 int main(int argc, char *argv[]) {
21 
22 int fd;
23 struct stat statbuf;
24 off_t i, j, n;
25 char b[8];
26 char *d;
27 
28 if ( argc != 2 ) {
29  fprintf(stderr,"This program flips byte-ordering of 8-byte doubles.\n");
30  fprintf(stderr,"Usage: %s <filename>\n",argv[0]);
31  exit(-1);
32 }
33 
34 if ( ( fd = open(argv[1], O_RDWR) ) < 0 ) {
35  fprintf(stderr,"Can't open %s for updating.\n",argv[1]);
36  exit(-1);
37 }
38 
39 if ( fstat(fd,&statbuf) < 0 ) {
40  fprintf(stderr,"Can't stat %s.\n",argv[1]);
41  exit(-1);
42 }
43 
44 n = statbuf.st_size;
45 
46 if ( (n < 4) || ((n-4) % 24) ) {
47  fprintf(stderr,"Size of %s is not 4 plus a multiple of 24.\n",argv[1]);
48  exit(-1);
49 }
50 
51 if ( ( d = mmap(0,n,PROT_READ|PROT_WRITE,MAP_FILE|MAP_SHARED,fd,0) )
52  == (caddr_t) -1 ) {
53  fprintf(stderr,"Can't mmap %s.\n",argv[1]);
54  exit(-1);
55 }
56 
57 for ( j = 0; j < 4; ++j ) b[j] = d[j];
58 for ( j = 3; j >= 0; --j, ++d ) *d = b[j];
59 
60 for ( i = 4; i < n; i += 8 ) {
61  for ( j = 0; j < 8; ++j ) b[j] = d[j];
62  for ( j = 7; j >= 0; --j, ++d ) *d = b[j];
63 }
64 
65 exit(0);
66 
67 }
68 
#define MAP_FILE
Definition: flipbinpdb.c:17
int main(int argc, char *argv[])
Definition: diffbinpdb.c:15