home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
BoldtNew
/
LLVS
/
g0_dump_header.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-31
|
3KB
|
120 lines
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define HEADER_TYPE_LEN 16
#define HEADER_INFO_LEN 120
#define INT_STRING_LEN 10
#define BYTESIZE 8
#define IU_TESTBED_TYPE "SRI TB01IMGHDR"
void copy_substring(char* dest, char* src, int begin, int end)
{
strncpy(dest,&src[begin],end-begin);
dest[end-begin] = '\0';
return;
}
int read_int_from_string(char* src, int begin, int end)
{
char tmpstr[INT_STRING_LEN];
copy_substring(tmpstr,src,begin,end);
return((int)(atoi(tmpstr)));
}
int string_equal(char* string, char* strptr) /* string must end with '\0' */
{ /* but strptr doesn't have to */
return(!strncmp(string,strptr,strlen(string)));
}
int ceiling(int a, int b)
{
return((int)(ceil( ((float)a) / ((float)b) )));
}
void main(int argc, char *argv[])
{
char *infilename;
FILE *infile;
char headerString[HEADER_INFO_LEN+1];
char elementType[40-32+1];
int imageXdim, imageYdim, elementSize, elementBytes, headerLen;
int blockXdim, blockYdim, blockSize, numXblocks, numYblocks;
int dx = 1, dy = 1;
int i, itmp, jtmp;
infilename = argv[1];
if ((infile = fopen(infilename,"r")) == NULL) {
perror("error opening input file");
perror(infilename);
return;
}
for (i=0 ; i < HEADER_TYPE_LEN; i++)
headerString[i] = getc(infile);
headerString[HEADER_TYPE_LEN] = '\0';
printf("Header string: \"%s\"\n",headerString);
rewind(infile);
for (i=0 ; i < HEADER_INFO_LEN; i++)
headerString[i] = getc(infile);
headerString[HEADER_INFO_LEN] = '\0';
printf("Header Info...\n");
printf("%s>\n", headerString);
copy_substring(elementType,headerString,32,40);
printf("Element type: <%s>\n", elementType);
elementSize = read_int_from_string(headerString,56,64);
printf("Element size: %d\n", elementSize);
elementBytes = (int)(elementSize / BYTESIZE);
printf("Bytes per element: %d\n", elementBytes);
imageXdim = read_int_from_string(headerString,64,72);
printf("X dimension: %d\n", imageXdim);
imageYdim = read_int_from_string(headerString,72,80);
printf("Y dimension: %d\n", imageYdim);
/*;; testbed format gives the number of BYTES horizontally in block */
itmp = read_int_from_string(headerString,80,88);
blockXdim = (int) ((itmp * BYTESIZE) / elementSize);
if (string_equal("RL",&headerString[24]))
dx = (- dx);
printf("X blocksize: %d\n", (dx * blockXdim));
blockYdim = read_int_from_string(headerString,88,96);
if (string_equal("TB",&headerString[26]))
dy = (- dy);
printf("Y blocksize: %d\n", (dy * blockYdim));
numXblocks = ceiling(imageXdim,blockXdim);
numYblocks = ceiling(imageYdim,blockYdim);
printf("Num X blocks: %d\n", numXblocks);
printf("Num Y blocks: %d\n", numYblocks);
itmp = read_int_from_string(headerString,112,120);
jtmp = blockXdim * blockYdim;
blockSize = ((itmp < jtmp) ? jtmp : itmp);
printf("Block size: %d\n", blockSize);
headerLen = read_int_from_string(headerString,16,24);
printf("Header length: %d\n", headerLen);
fclose(infile);
return;
}