00001
00002
00003
00004
00005
00006
00007 #include "largefiles.h"
00008
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <sys/mman.h>
00012 #include <fcntl.h>
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015 #include <limits.h>
00016
00017 #ifndef MAP_FILE
00018 #define MAP_FILE 0
00019 #endif
00020
00021 #if ( INT_MAX == 2147483647 )
00022 typedef int int32;
00023 #else
00024 typedef short int32;
00025 #endif
00026
00027 int main(int argc, char *argv[]) {
00028
00029 int fd;
00030 struct stat statbuf;
00031 int i, j, isbig, itmp;
00032 off_t n;
00033 double delta;
00034 float delta4;
00035 int32 icntrl[20];
00036 char *ccntrl;
00037 char b[8];
00038 char *d;
00039
00040 if ( argc != 2 ) {
00041 fprintf(stderr,"This program reads the ICNTRL array from DCD files.\n");
00042 fprintf(stderr,"Usage: %s <filename> > <data>\n",argv[0]);
00043 exit(-1);
00044 }
00045
00046 if ( ( fd = open(argv[1], O_RDONLY) ) < 0 ) {
00047 fprintf(stderr,"Can't open %s for reading.\n",argv[1]);
00048 exit(-1);
00049 }
00050
00051 if ( fstat(fd,&statbuf) < 0 ) {
00052 fprintf(stderr,"Can't stat %s.\n",argv[1]);
00053 exit(-1);
00054 }
00055
00056 n = statbuf.st_size;
00057
00058 if ( n <= 104 ) {
00059 fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
00060 exit(-1);
00061 }
00062
00063 if ( n % 4 ) {
00064 fprintf(stderr,"%s is not in DCD format.\n",argv[1]);
00065 exit(-1);
00066 }
00067
00068 if ( ( d = mmap(0,n,PROT_READ,MAP_FILE|MAP_SHARED,fd,0) )
00069 == (caddr_t) -1 ) {
00070 fprintf(stderr,"Can't mmap %s.\n",argv[1]);
00071 exit(-1);
00072 }
00073
00074 #define SKIPFOUR {d+=4;n-=4;}
00075 #define SKIP(X) {d+=(X);n-=(X);}
00076 #define READINT(X) { X=0; if (isbig) { for(j=0;j<4;++j,X<<8) X+=d[j]; } \
00077 else { for(j=3;j>=0;--j,X<<8) X+=d[j]; } }
00078
00079 SKIPFOUR;
00080 SKIPFOUR;
00081
00082 ccntrl = (char*)(&(icntrl[0]));
00083
00084 for(j=0;j<80;++j) {
00085 ccntrl[j] = d[j];
00086 }
00087
00088 for(j=0;j<9;++j) {
00089 itmp = icntrl[j];
00090 printf("%d\n",itmp);
00091 }
00092
00093 printf("%f\n",*((float*)(icntrl+9)));
00094
00095 for(j=10;j<20;++j) {
00096 itmp = icntrl[j];
00097 printf("%d\n",itmp);
00098 }
00099
00100 }
00101