/* gpixnfo.c: print info of a gridpix */

/*
 * usage: gpxinfo file
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

#include "gridpix.h"
#include "utils.h"

/* #define DEBUG 1 */

int main(int argc, char **argv)
{
    char *progname ;
    char *filename ;
    FILE *fp ;
    struct gridpix gp ;
    int gpxtype, i ;

    progname = argv[0] ;
    
    if (argc != 2) {
	fprintf(stderr, "usage: %s file\n", progname) ;
	exit(1) ;
    }

    filename = argv[1] ;

    if ((fp = fopen(filename, "r")) == NULL) {
	fprintf(stderr, "\"%s\"", filename) ;
	perror("") ;
	exit(1) ;
    }

    if ((gpxtype = readheader(&gp, fp)) == 0) {
	fprintf(stderr, "\"%s\"", filename) ;
	perror("") ;
	exit(1) ;
    }

    printf("type=%d\n", gpxtype) ;
    printf("headersize=%qd\n", gp.header.headersize) ;
    printf("width=%qd\n", gp.header.width) ;
    printf("height=%qd\n", gp.header.height) ;
    printf("layers=%qd\n", gp.header.layers) ;
    printf("tilewidth=%qd\n", gp.header.tilewidth) ;
    printf("tileheight=%qd\n", gp.header.tileheight) ;
    printf("ratio=%f\n", (double)gp.header.ratio) ;
    printf("numtiles=%qd\n", gp.header.numfiles) ;

    for (i = 0 ; i < gp.header.layers ; i++)
	printf("layer[%d]=%qd\n", i, gp.header.layersize[i]) ;

    exit(0) ;
}
