/* Kurt Schwehr - NASA Ames Research Center - 8/25/94         */
/* schwehr@cs.stanford.edu                                    */
/* Compute the average value in a 1-byte integer grass raster */

/* 1 Byte Integer Format ONLY!! */

/*
   I want the average value from a map.  I couldn't figure how
   to get the value from grass so I'm writting my own.
*/

#include <stdio.h>


void main() {

  char infile[255];
  FILE *InFile;
  int count=0;
  int lines,samples;
  int cur_line;
  int buffer;
  int cells;
  double sum;

  printf ("Compute the average value in a 1 byte integer raster\n"); 
  printf ("Input File:");
  scanf ("%s",infile);
/*  printf ("LINES:");
  scanf ("%d",&lines);
  printf ("LINE_SAMPLES:");
  scanf ("%d",&samples);
*/
  InFile = fopen (infile,"r");
/*  cells = lines*samples; */

  sum=0;
  while ( (buffer=getc(InFile))!=EOF ) {
    sum+= buffer;
    count++;
  }

  printf ("The average for %d cells is %3.2f\n",count, sum/count);

  fclose (InFile);
  printf ("Have a nice day!\n");
}
