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