#include "avg.h"
#include <stdlib.h>

#define dbg() fprintf(stderr, "debug: %s %s %d\n",  __FILE__,__FUNCTION__,__LINE__)

void
averageprog_1( char* host, int argc, char *argv[])
{
   CLIENT *clnt;
   double  *result_1, *dp, f;
   char *endptr;
   int i;
   input_data  average_1_arg;
   average_1_arg.input_data.input_data_val = (double*) malloc(MAXAVGSIZE*sizeof(double));
   dp = average_1_arg.input_data.input_data_val;
   average_1_arg.input_data.input_data_len = argc - 2;
   for (i=1;i<=(argc - 2);i++) {
     f = strtod(argv[i+1],&endptr);
     printf("value   = %e\n",f);
     *dp = f;
     dp++;
   }

/*
CLIENT *clnt_create(char *host, unsigned long prog,
                   unsigned long vers, char *proto);

      Generic client creation routine.  host identifies  the  name  of
      the  remote  host  where the server is located.  proto indicates
      which kind of transport protocol to  use.   The  currently  
			supported values for this field are "udp" and "tcp".  Default 
			timeouts are set, but can be modified using clnt_control(). 
 */
   clnt = clnt_create(host, AVERAGEPROG,
   AVERAGEVERS, "udp");
   if (clnt == NULL) {
      clnt_pcreateerror(host);
      exit(1);
   }
   result_1 = average_1(&average_1_arg, clnt);
   if (result_1 == NULL) {
      clnt_perror(clnt, "call failed:");
   }
   clnt_destroy( clnt );
   printf("average = %e\n",*result_1);
}


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

   if(argc < 3) {
     printf(
      "usage: %s server_host value ...\n",
      argv[0]);
      exit(1);
   }
   if(argc > MAXAVGSIZE + 2) {
      printf("Too many input values\n");
      exit(2);
   }
   host = argv[1];
   averageprog_1( host, argc, argv);
}
