#include "binfile.h" #include inline void binfile::order2(char *point) { short test=258; char i,j,*testp=(char *) &test; for(i=0; i<2; i++) for(j=1; j<=2; j++) if (testp[i]==j) point[i]=j-1; } inline void binfile::order4(char *point) { long test=16909060; char i,j,*testp=(char *) &test; for(i=0; i<4; i++) for(j=1; j<=4; j++) if (testp[i]==j) point[i]=j-1; } inline void binfile::order8(char *point) { double test=1212121212121212.; char i,*testp=(char *) &test; for(i=0; i<8; i++) switch(testp[i]) { case -16: point[i]=7; break; case -63: point[i]=6; break; case 23: point[i]=5; break; case -39: point[i]=4; break; case -85: point[i]=3; break; case 57: point[i]=2; break; case 17: point[i]=1; break; case 67: point[i]=0; break; default: point[i]=-1; } for(i=0; i<8; i++) if (point[i]<0) { printf("%d: ",i); printf("Fatal Error: Unknown double precision format!\n"); exit(1); } } // 08-FEB-2008 added by y.t. extern "C" { void findfile(char *, char *, char *, char *, int); } binfile::binfile(const char *name,char mode) { char allmode[]=" b"; order2(offset); order4(offset+2); order8(offset+6); allmode[0]=mode; // 08-FEB-2008 modified by y.t. //char file_name[1024]; //findfile(file_name, name, "SKPATH", ConstDirC, 1024); //fp=fopen(file_name,allmode); fp=fopen(name,allmode); if (fp==NULL) { printf("Unable to open file %s as %s!\n",name,allmode); exit(1); } } binfile::binfile(FILE *f) { fp=f; } binfile::~binfile(void) { fclose(fp); } int binfile::read(int *&sizes,int *&numbers,void **&starts) { char primer[900]; int narray,i,j,k; char *datp=NULL,*buffp; buffp=primer; for(narray=0; narray<300; narray++,buffp+=3) { if (fread(buffp,1,3,fp)!=3) return(-1); if (*buffp & 0x80) break; } *buffp=*buffp & 0x7f; narray++; sizes=new int[narray]; numbers=new int[narray]; starts=new void *[narray]; buffp=primer; for(i=0; i=0; i++) { if (numbers[i]>2097151) numbers[i]=2097151; if (numbers[i]<0) numbers[i]=0; switch(sizes[i]) { case 1: case 2: case 4: case 8: break; default: sizes[i]=4; } } if ((narray=i)==0) return; for(i=1,totsize=*sizes*(*numbers); i