/**************************************

           Code Template for:

           EECS 487  Winter 2004

           Programming Assignment #1

**************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Defined constants */
#define Winter
#define MAX_NAME_LEN 1023
#define N_ROWS       100
#define N_COLS       100
#define VIEWX0 	      15
#define VIEWY0        15
#define VIEWX1        85
#define VIEWY1        85

/* Subroutine Prototypes */

extern int WriteImage( char *outfilename, int rows, int cols, unsigned char *pixeldata );
extern int ReadInputData( char *infile, int *numpnts, float **x_pnts, float **y_pnts );
extern int ReadInputData3D( char *infile, int *numpnts, float **x_pnts, float **y_pnts, float **z_pnts);

int
main( int argc, char *argv[] )
{

/*w***************  Variable Declarations ********************4*/
        char            infilename[MAX_NAME_LEN] = "pa1-3D.dat";
        char            outfilename[MAX_NAME_LEN];
        unsigned char   pixeldata[N_ROWS * N_COLS];
        int             err_status = 0;

        int             numpnts;
        float           *x_pnts, *y_pnts, *z_pnts;

/****************** Main Code **********************************/

  if (argc != 3)
  {
     fprintf(stderr, "Usage:  pa1 <Input data filename> <Output image filename>\n");
     exit(1);
  }
 
  /* Initialize the error status */
  err_status = 0;

  /* Copy the input data filename to a local variable */
  if (strlen(argv[1]) >= MAX_NAME_LEN)
  {
     fprintf(stderr, "input data filename too long: %s\n", argv[1]);
     exit(1);
  }
  strcpy(infilename, argv[1]);
 
  /* Copy the output image filename to a local variable */
  if (strlen(argv[2]) >= MAX_NAME_LEN)
  {
     fprintf(stderr, "output image filename too long: %s\n", argv[2]);
     exit(1);
  }
  strcpy(outfilename, argv[2]);

  /* Init Image array to 0 */
  int n;
  for (n=0; n<N_ROWS*N_COLS; n++)
    pixeldata[n] = 0;

  /* For 2D data */
  err_status = ReadInputData( infilename, &numpnts, &x_pnts, &y_pnts );
  if (err_status == 0) {
     fprintf(stderr, "read %d points\n", numpnts);
  } else {
     fprintf(stderr, "error reading input data file %s\n", infilename);
     exit(1);
  }

  /* For 3D data  uncomment to use! */
  /* err_status = ReadInputData3D( infilename, &numpnts, &x_pnts, &y_pnts, &z_pnts); */

/******************** Your Code Goes Here ********************/




/*w****************** End of your code *********************4*/

  /* Write data array out to an image file */
  err_status = WriteImage( outfilename, N_ROWS, N_COLS, pixeldata ); 
  if (err_status == 0) {
     fprintf(stderr, "wrote output image file %s\n", outfilename);
  } else {
     fprintf(stderr, "error writing output image file %s\n", outfilename);
     exit(1);
  }

  return 0;
}
