/*
Copyright (C) 1999 E. H. Haley
 */

#include <stdio.h>
#include <stdlib.h>
#include <jpeglib.h>
#include "lib/tile.h"
#include "lib/loadj.h"
#include "lib/color.h"


int main(int aardc, char **aardv)
{
  FILE *fd;
  tfile curimg;
  res *tree;
  int i,j;

  if (aardc<2) { printf("Usage: \"./test tilefile.dat\"\n"); exit(0); }
  fd=fopen(*++aardv,"r");

  while(1)
    {
      if (fread(&curimg,sizeof(tfile),1,fd)==0) { fclose(fd); exit(0); }
      tree=(res *)calloc(curimg.nnodes,sizeof(res));
      fread(tree,curimg.nnodes*sizeof(res),1,fd);
      
      printf("%s\t%d\t%d\n\n",curimg.fname, curimg.side, curimg.nnodes);
      
      for(i=0; i<curimg.nnodes; i++)
	{
	  printf("side=%d\tavgY=%f\n",tree[i].side, tree[i].avgy);

	  for(j=0; j<40; j++)
	    printf("(%d,%d,%d) %f\t",
		   tree[i].entry[j].index[0],
		   tree[i].entry[j].index[1],
		   tree[i].entry[j].index[2],
		   tree[i].entry[j].val);
	  printf("\n\n");
	}
    }
  fclose(fd);
  exit(0);
}
