/*
   xy.c
   création :
     May 21 03:07:47 CEST 2004 par whygee@f-cpu.org

   compilation :
     gcc -lm -o xy xy.c

   invocation :
     xy nom_du_fichier.raw
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

unsigned long int xy[512][512];
  /* pour l'initialiser à 0 */

int main(int argc, char *argv[]) {
  FILE *file_in, *file_out;
  signed short int droite, gauche;
  int i, j;

  file_in=fopen(argv[1], "rb");
  if (file_in!=NULL) {
    file_out=fopen("xy.bin", "wb");
    if (file_out!=NULL) {
      while (
        ( fread(&gauche, 1, sizeof(gauche), file_in)
        + fread(&droite, 1, sizeof(droite), file_in))
              == (sizeof(gauche) * 2 )) {
        xy[(gauche>>7)+256][(droite>>7)+256]++;
      }

      for (i=0; i<512; i++)
        for (j=0; j<512; j++)
          fputc(15.0*log(1+xy[i][j]), file_out);
    }
  }
  exit(EXIT_SUCCESS);
}

