/* BBFILE.C /* /* Written by Gary Glassmoyer /* /* Machine independent reader of GEOS binary data files /* /* Modified 23-OCT-1997 /* corrects optimization errors /* corrects (long) casts in real header block /* displays data blocks /* Modified 21-JAN-1998 /* use FILE *GEOS_file /* Modified 23-JAN-1998 /* handle files without I[032] /* Modified 22-APR-2014 /* compile with Microsoft C 10.0 to allow long filenames /* change fopen to "rb" in order to read read-only files /* de-clutter output by removing "Data block: " from output /* and change /t to /n for single column /* /* Compiled with Microsoft C 10.0 using: /* cl BBFILE.C /* /* */ #include #define _BLOCK_SIZE (unsigned int)512 FILE *GEOS_file; main(argc, argv) int argc; char *argv[]; { int i, block_number, number_of_blocks, index_of_last_datum, f1; short e; long l, lnull; short I[1+_BLOCK_SIZE/2]; float R[1+_BLOCK_SIZE/4]; char fname[128], buffer[_BLOCK_SIZE]; /* get filename */ printf("Name of file: "); if (argc == 2) { i = 0; while (fname[i] = toupper(argv[1][i])) i++; printf("%s\n", fname); } else gets(fname); /* open file */ /* if ((f1 = open (fname, 0)) == -1) {*/ /*2014 if ((GEOS_file = fopen(fname, "r+b")) == NULL) {*/ if ((GEOS_file = fopen(fname, "rb")) == NULL) { printf("ERROR: %s cannot be opened.\n", fname); exit(1); } /* integer header */ /* i = read (f1, buffer, _BLOCK_SIZE);*/ i = fread (buffer, 1, _BLOCK_SIZE, GEOS_file); printf("\nInteger header\n"); for (i = 1; i <= _BLOCK_SIZE / 2; i++) { I[i] = (buffer[2*i-2] & 0xFF) << 000 | (buffer[2*i-1] & 0xFF) << 010; if (i <= 3 || I[i] != I[3]) printf("I(%03.3d) %6d\n", i, I[i]); } number_of_blocks = I[31]; if (I[32] != I[3]) { index_of_last_datum = I[32]; } else { if (I[256] != I[3]) { index_of_last_datum = I[256] & 0xFF; } else { index_of_last_datum = 256; } } /* real header */ /* i = read (f1, buffer, _BLOCK_SIZE);*/ i = fread (buffer, 1, _BLOCK_SIZE, GEOS_file); printf("\nReal header\n"); for (i = 1; i <= 128; i++) { l = (long) (buffer[4*i-4] & 0xFF) << 020 | (long) (buffer[4*i-3] & 0xFF) << 030 | (long) (buffer[4*i-2] & 0xFF) << 000 | (long) (buffer[4*i-1] & 0xFF) << 010; if (i <= 2 || l != lnull) { if (i == 2) lnull = l; if (l == 0) R[i] = 0; else { e = (l >> 23 & 0xFF) - 152; R[i] = (long) 1 << 23 | l & 0x007FFFFF; if (l >> 31) R[i] *= -1; while (e++ < 0) R[i] /= 2; while (e-- > 1) R[i] *= 2; } printf("R(%03.3d) %14.6g\n", i, R[i]); } else R[i] = R[2]; } //2014 printf("\nData\n"); /* integer data block */ for (block_number = 1; block_number <= number_of_blocks; block_number++) { /* i = read (f1, buffer, _BLOCK_SIZE);*/ i = fread (buffer, 1, _BLOCK_SIZE, GEOS_file); //2014 printf("\nData block #%05.5d\n", block_number); for (i = 1; i <= 256; i++) { if (block_number < number_of_blocks || i <= index_of_last_datum) { I[i] = (buffer[2*i-2] & 0xFF) << 000 | (buffer[2*i-1] & 0xFF) << 010; //2014 printf("%6d\t", I[i]); printf("%6d\n", I[i]); } } } /* */ /* close file */ /* close (f1);*/ if (GEOS_file != NULL) fclose (GEOS_file); }