Exemplo n.º 1
0
 virtual void SetUp() {
     read_data_file("140712_003331.txt", m_X);
     read_data_file("140712_064332.txt", m_Y);
     read_data_file("140712_064332_rigid.txt", m_Y_rigid);
     read_data_file("140712_064332_nonrigid_lowrank.txt",
                    m_Y_nonrigid_lowrank);
 }
Exemplo n.º 2
0
Arquivo: data.c Projeto: amumu/nokuno
void
verify_results(vector_t x[], vector_t v[], const char lang[])
{
    char fname[256], qx[256], qv[256], verif[256];
    vector_t xT[N], vT[N];
    data_t m[N], ex, ev;

    if (pid != 0)  return;

    sprintf(fname, "%s/%d/%s/result%d.dat", data_dir, N, lang, prob_no);
    if ((!random_flag || fixed_flag) && read_data_file(fname, m, xT, vT)) {
        ex = quality_index(xT, x);
        ev = quality_index(vT, v);

        sprintf(qx, "%.1e", ex);
        sprintf(qv, "%.1e", ev);
        strcpy(verif,
               finite_func(ex) && ex < epsilon &&
               finite_func(ev) && ev < epsilon ? "Successful" : "FAILED");
    }
    else {
        strcpy(qx, "N/A");
        strcpy(qv, "N/A");
        strcpy(verif, "not performed");
    }

    printf("\n*** Overall results ***\n"
           "# of processes: %d\n"
           "Quality index (2-norm) of x: %s\n"
           "Quality index (2-norm) of v: %s\n"
           "Verification: %s\n",
           nprocs, qx, qv, verif);
}
static void
read_autodetect_file(const char * filename)
{
	int binary = 0, c;
	FILE *file;

	file = fopen (filename, "r");
	if (file == NULL) {
		fprintf (stderr, "Failed to open %s: %s\n",
			 filename, strerror (errno));
		exit (1);
	}

	while ((c = fgetc(file)) != EOF) {
		/* totally lazy binary detector */
		if (c < 10) {
			binary = 1;
			break;
		}
	}

	fclose(file);

	if (binary == 1)
		read_bin_file(filename);
	else
		read_data_file(filename);

}
int main(int argc,char *argv[]) {
  double value;
  int i_start,n_points;

  if (argc != 3) {
    fprintf(stderr,"%s <input file> <value>\n",argv[0]);
    exit(1);
  }
  n_points = read_data_file(argv[1],&data);
  fprintf(stderr,"Read %d points from data file %s\n",n_points,argv[1]);
  value = atof(argv[2]);
  i_start = 0;
  while (i_start < n_points - 3) {
    if ((data[i_start + 1].y - value) * (data[i_start + 2].y - value) < 0.0) {
#ifdef NEWTON
      find_newton_inverse_coeffs(4,data + i_start);
#endif
#ifdef LAGRANGE
      printf("%.8g %.8g\n",lagrange_inverse(4,data + i_start,value),value);
#endif
#ifdef NEWTON
      printf("%.8g %.8g\n",newton_inverse(4,data + i_start,value),value);
#endif
    }
    i_start++;
  }
  exit(0);
}
Exemplo n.º 5
0
 /**
 * 주어진 argv를 이용해서 config파일을 오픈하는 함수입니다.
 */
void file_open(char **argv)
{
	char* file_name;
	file_name = strdup(argv[1]);
	
	argv_file = fopen(file_name,"r");

	if (argv_file == NULL)
	{
		fprintf(stderr,"failed to load data file ‘%s’\n",file_name);
		return;
	}

	//먼저 data파일의 줄 갯수를 셉니다.
	read_new_line_letter(argv_file);
	
	//data파일의 내용을 읽고 적절하게 파싱해서 실행하고 스케쥴링할 프로그램의 데이터를 구합니다.
	read_data_file();
	
	//이제 각 알고리즘마다 한번씩 검사합니다.
	printf("\n[SJF]\n");
	process_run(SJF);
	printf("\n[SRT]\n");
	process_run(SRT);
	printf("\n[RR]\n");
	process_run(RR);
	printf("\n[PR]\n");
	process_run(PR);
}
Exemplo n.º 6
0
int main(int argc, char** argv)
{
    vector<string> feats;
    vector<string> data;
    size_t min_samples;
    read_feature_file(argv[1], feats);
    read_data_file(argv[2], data);
    min_samples = atoi(argv[2]);
    cart dc(feats, data, min_samples);
    tree_node* root = dc.gen_subtree();
    traverse(root, feats);
    return 0;
}
Exemplo n.º 7
0
int main(){

	int menu=0;

	List* user_list = (List*)malloc(sizeof(List));
	tweetList* word_list = (tweetList*)malloc(sizeof(tweetList));


	//list_init(user_list);

	while(menu!=99){

			puts("\t***************\t Menu \t*****************");
			puts("\t0. Read data files");
			puts("\t1. display statistics");
			puts("\t2. Top 5 most tweeted words");
			puts("\t3. Top 5 most tweeted users");
			puts("\t4. Find users who tweeted a word (e.g., ’연세대’)");
			puts("\t5. Find all people who are friends of the above users");
			puts("\t6. Delete all mentions of a word");
			puts("\t7. Delete all users who mentioned a word");
			puts("\t8. Find strongly connected components");
			puts("\t9. Find shortest path from a given user");
			printf("\t99. Quit\n");
			puts("\t********************************************");
			printf("Select menu : ");

			scanf("%d", &menu);

			switch(menu){
	
			case 0:
				read_data_file(user_list, word_list);
				break;
			case 1:
				display_stats(user_list, word_list);
				break;


			case 99:
				printf("Quit this program.\n");
				return;

			default:
				puts("Wrong Input!\n. Select menu again.");
			}
	}
	
	return 0;
}
Exemplo n.º 8
0
Arquivo: data.c Projeto: amumu/nokuno
void
load_data(data_t m[], vector_t x[], vector_t v[])
{
    char fname[256], pname[256];

#ifdef USE_RANDOM_DATA
    random_flag = 1;
#endif
#ifdef USE_FIXED_DATA
    fixed_flag = 1;
#endif
    set_seed();

    if (!random_flag) {
        if (!fixed_flag)  prob_no = rand_func()%nprobs;
        sprintf(fname, "%s/%d/prob%d.dat", data_dir, N, prob_no);
        if (!read_data_file(fname, m, x, v))  random_flag = 1;
    }
    if (random_flag) {
        if (fixed_flag)  prob_no = nprobs;
        generate_mass_array(m);
        generate_vector_array(x);
        generate_vector_array(v);
    }

    if (pid == 0) {
        if (!random_flag || fixed_flag)
            sprintf(pname, "%d", prob_no);
        else
            strcpy(pname, "random");

        printf("\n*** Simulation parameters ***\n"
               "Number of particles: %d\n"
               "Number of time steps: %d\n"
               "Interval of time steps: %.1g\n"
               "Data set No.: %s\n",
               N, T, DT, pname);
    }
}
int
main (int argc, char *argv[])
{
	uint32_t devid = 0xa011;
	char *devid_str = NULL;
	int i, c;
	int option_index = 0;
	int binary = -1;

	static struct option long_options[] = {
		{"devid", 1, 0, 'd'},
		{"ascii", 0, 0, 'a'},
		{"binary", 0, 0, 'b'},
		{ 0 }
	};

	devid_str = getenv("INTEL_DEVID_OVERRIDE");

	while((c = getopt_long(argc, argv, "ad:b",
			       long_options, &option_index)) != -1) {
		switch(c) {
		case 'd':
			devid_str = optarg;
			break;
		case 'b':
			binary = 1;
			break;
		case 'a':
			binary = 0;
			break;
		default:
			printf("unkown command options\n");
			break;
		}
	}

	if (devid_str)
		devid = strtoul(devid_str, NULL, 0);

	ctx = drm_intel_decode_context_alloc(devid);

	if (optind == argc) {
		fprintf(stderr, "no input file given\n");
		exit(-1);
	}

	for (i = optind; i < argc; i++) {
		/* For stdin input, let's read as data file */
		if (!strcmp(argv[i], "-")) {
			read_data_file(argv[i]);
			continue;
		}
		if (binary == 1)
			read_bin_file(argv[i]);
		else if (binary == 0)
			read_data_file(argv[i]);
		else
			read_autodetect_file(argv[i]);
	}

	return 0;
}
Exemplo n.º 10
0
int main(int argc, char *argv[]) {
    int c;
    
    static struct option long_options[] = {
        { "help", no_argument, 0, 'h'},
        { "file", required_argument, 0, 'f'},	
        { "layout", required_argument, 0, 'l'},	
        { "bsize", required_argument, 0, 'b'},	
        { "chunk", required_argument, 0, 'c'},	
        { "blockNumber", required_argument, 0, 'n'},	
        { 0, 0, 0, 0}
    };

    // Get utility name
    utility_name = basename(argv[0]);   

    rozofs_layout_initialize();
   
    while (1) {

        int option_index = 0;
        c = getopt_long(argc, argv, "hH:f:l:b:c:n:", long_options, &option_index);

        if (c == -1)
            break;

        switch (c) {

            case 'h':
                usage();
                exit(EXIT_SUCCESS);
                break;
                break;
            case 'f':
	        filename[nb_file++] = optarg;
                break;	
            case 'l':
	        {
		  int ret;
                  ret = sscanf(optarg,"%d", &layout);
                  if (ret <= 0) { 
                      fprintf(stderr, "dataReader failed. Bad layout: %s %s\n", optarg,
                              strerror(errno));
                      exit(EXIT_FAILURE);
                  }
		}
		break;
            case 'c':
	        {
		  int ret;
                  ret = sscanf(optarg,"%d", &firstBlock);
                  if (ret <= 0) { 
                      fprintf(stderr, "dataReader failed. Bad chunk number: %s %s\n", optarg,
                              strerror(errno));
                      exit(EXIT_FAILURE);
                  }
		}
		break;		
            case 'n':
	        {
		  int ret;
                  ret = sscanf(optarg,"%d", &block_number);
                  if (ret < 0) { 
                      fprintf(stderr, "dataReader failed. Bad block number: %s %s\n", optarg,
                              strerror(errno));
                      exit(EXIT_FAILURE);
                  }
		}	
		break;	
            case 'b':
	        {
		  int ret;
                  ret = sscanf(optarg,"%d", &bsize);
                  if (ret < 0) { 
                      fprintf(stderr, "dataReader failed. Bad block size: %s %s\n", optarg,
                              strerror(errno));
                      exit(EXIT_FAILURE);
                  }
		}	
		break;				
	    case '?':
                usage();
                exit(EXIT_SUCCESS);
                break;
            default:
                usage();
                exit(EXIT_FAILURE);
                break;
        }
    }
    openlog("dataReader", LOG_PID, LOG_DAEMON);
    
    
    /*
    ** Check parameter consistency
    */
    if (nb_file == 0){
        fprintf(stderr, "dataReader failed. Missing --file option.\n");
        exit(EXIT_FAILURE);
    }  
 
    bbytes = ROZOFS_BSIZE_BYTES(bsize);
    if (bbytes < 0) {
        fprintf(stderr, "bad block size: %d\n", bsize);
        exit(EXIT_FAILURE);
    }
    firstBlock *= ROZOFS_STORAGE_NB_BLOCK_PER_CHUNK(bsize);

    // Start rebuild storage   
    if (read_data_file() != 0) goto error;
    exit(EXIT_SUCCESS);
    
error:
    exit(EXIT_FAILURE);
}
Exemplo n.º 11
0
int main(void)
{
    FILE *config,*data;
    if(!(config = fopen(CONFIG_FILE,"r")))
    {
        printf("error while reading config file\n");
        exit(-1);
    }
    //todo:create init function
    MAC* mac_p = (MAC*)malloc(sizeof(*mac_p));
    MAC* mac_head = mac_p;                              //head(the first) node does not store data
    mac_head->next = NULL;
    mac_p = mac_head;

    if(!read_config(config,&mac_p))
    {
        printf("error while reading config\n");
        exit(-1);
    }
    fclose(config);
    //here you should sort mac address!!!


    //this is the mac_address link test
    printf("%s\n",mac_head->next->next->next->mac_address );
    //mac_p = mac_head->next->next;
    //sort_mac_address(&mac_p);
    //print_config_to_file(mac_head);
    //test end

    if(!(data = fopen(DATA_FILE,"r+")))
    {
        printf("error while reading data file\n");
        exit(-1);
    }
    STUDENT_INFO* info_p = (STUDENT_INFO*)malloc(sizeof(*info_p));
    STUDENT_INFO* info_head = info_p;
    info_head->next = NULL;
    info_p = info_head;
    read_data_file(data, &info_p);

    //this is the stu_info link test
    /*STUDENT_INFO* test2 = info_head->next;
    printf("link test2!\n");
    while(test2!=NULL)
    {
        printf("student info faculty is %s\n",test2->faculty);
        printf("student info id is %s\n",test2->id);
        printf("student info name is %s\n",test2->name);
        test2 = test2->next;
    }*/
    //test end

    //begin handle data(struct slice):
    //todo:init func
    SESSION* session_head = (SESSION*)malloc(sizeof(*session_head));
    session_head->next = NULL;
    SESSION* session_p = session_head;




    return 0;
}
Exemplo n.º 12
0
int main(int argc, char **argv){
    size_t num_resampled_elements = PFA_NOUT_AZIMUTH * PFA_NOUT_RANGE;

    complex **resampled      = new complex*[PFA_NOUT_AZIMUTH];
    complex **data           = new complex*[N_PULSES];
    double  **input_coords   = new double*[PFA_NOUT_RANGE];

    for(int p=0;p<N_PULSES;p++){
      *(data+p)           = new complex[PFA_NOUT_RANGE];
    }
    for(int p=0;p<PFA_NOUT_AZIMUTH;p++){
      *(resampled+p)      = new complex[PFA_NOUT_RANGE];   
    }
    for(int p=0;p<PFA_NOUT_RANGE;p++){
      *(input_coords+p)   = new double[N_PULSES];
    }

    float  *window               = new float[T_PFA];
    double *output_coords        = new double[PFA_NOUT_AZIMUTH];
    complex *gold_resampled      = new complex[num_resampled_elements];

    size_t num_sw = PFA_NOUT_AZIMUTH/WIN_SIZE;

    read_kern2_data_file(
      data,
      input_coords,
      output_coords,
      window);   
    fprintf(stderr,"end read in input data\n");   
 
    read_data_file(
        (char *) gold_resampled,
        sizeof(complex)*num_resampled_elements);

  struct timeval tim1,tim2;
#ifdef serial
  fprintf(stderr,"serial version start\n");  
gettimeofday(&tim1, NULL);  
    
  for(size_t col=0;col<PFA_NOUT_RANGE;col++){
    sar_interp2_col(
        col,
        num_sw,
        resampled,
        data,
        window,
        input_coords,
        output_coords);     
  }

gettimeofday(&tim2, NULL);
  fprintf(stderr,"serial version end\n");  
#endif

#ifdef parallel
  fprintf(stderr,"parallel version start\n");  
gettimeofday(&tim1, NULL);
    ar::simt_tau::par_for(PFA_NOUT_RANGE, [&](size_t col) {
      sar_interp2_col(col,num_sw,resampled,data,window,input_coords,output_coords); 
    });   
gettimeofday(&tim2, NULL);
  fprintf(stderr,"parallel version end\n");     
#endif

double t1=tim1.tv_sec+(tim1.tv_usec/1000000.0);
double t2=tim2.tv_sec+(tim2.tv_usec/1000000.0); 

fprintf(stderr,"interp1@@@ %f seconds elapsed\n", t2-t1);

#ifdef WRITEtoFILE
  FILE *wbfp=fopen("interp2.wb","wb");
  for(size_t p=0;p<PFA_NOUT_AZIMUTH;p++)
    fwrite(*(resampled+p), sizeof(complex), PFA_NOUT_RANGE, wbfp);

  fclose(wbfp);
#endif  


  double snr = calculate_snr((complex *) gold_resampled,resampled);
  fprintf(stderr,"snr=%f\n",snr);     


  for(int p=0;p<N_PULSES;p++){
    delete[] *(data+p);
  }

  for(int p=0;p<PFA_NOUT_AZIMUTH;p++){
    delete[] *(resampled+p);
  }

  for(int p=0;p<PFA_NOUT_RANGE;p++){
    delete[] *(input_coords+p);
  }

  delete[] data;
  delete[] resampled;
  delete[] window;
  delete[] input_coords;
  delete[] output_coords;
  delete[] gold_resampled;

}
Exemplo n.º 13
0
/*read the data contain in the file
*/
int32_t macsim_read(GenericReader_T* genreader,glu_item_t* item)
{
	char  	      data_var[LG_MAX_STRING_MACSIM];
	uint32_t      indice_data=0,
	              rep=EOF,
	              dimension=0;
	uint8_t       continuer=1;
	

	TSP_sample_symbol_info_list_t  ssi_list;

	ssi_list=*genreader->ssi_list;

	
	if(NULL!=genreader->handler->file)
	{

	  /*TYPE_CHAR or TYPE_UCHAR is a  string of  LG_MAX_STRING_MACSIM length */
	  if( (TSP_TYPE_CHAR==ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].type)
	      || (TSP_TYPE_UCHAR==ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].type) )
	  {
	    item->size=ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].dimension;
	    /*calculate the real dimension for the string symbol*/
	    dimension=ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].dimension/LG_MAX_STRING_MACSIM;
	  }
	  else
	  {
	    item->size=ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].dimension;
	    dimension=ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].dimension;
	      
	  }
	  
	  item->size*=tsp_type_size[ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].type];

	    
	  while( continuer  && 
                (indice_data<dimension))
	  {

	    memset(data_var,'\0',LG_MAX_STRING_MACSIM);

	    /*read one data of the file*/
	    rep=read_data_file(genreader->handler->file,data_var);
              
	    if(EOF!=rep)
	    {
	      /*end of line*/
	      if(END_SAMPLE_SET==rep)
	      {
		continuer=0;
	      }

	      /*load retrieve data in the raw value*/
	      switch(ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].type) 
	      {

	        case TSP_TYPE_DOUBLE :
		  load_double(data_var,item->raw_value,indice_data);
		  break;
				       
	        case TSP_TYPE_FLOAT :
		  load_float(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_INT8 :
		  load_int8(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_INT16:
		  load_int16(data_var,item->raw_value,indice_data);
		  break;

	        case TSP_TYPE_INT32 :
		  load_int32(data_var,item->raw_value,indice_data);
		  break;
      
	        case TSP_TYPE_INT64 :
		  load_int64(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_UINT8:
		  load_uint8(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_UINT16:
		  load_uint16(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_UINT32:
		  load_uint32(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_UINT64:
		  load_uint64(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_CHAR:
		  load_char(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_UCHAR:
		  load_uchar(data_var,item->raw_value,indice_data);
		  break;
    
	        case TSP_TYPE_RAW:
		  load_type_raw(data_var,item->raw_value,indice_data);
		  break;
    
	        default:
		  break;
	      }

	      ++indice_data;
	    
	    }
	    else
	    {
	      continuer=0;
	    }

	  }
   
	}
         return(rep);
}
Exemplo n.º 14
0
int main(int argc, char **argv)
{
    float (*mu)[WAMI_GMM_IMG_NUM_COLS][WAMI_GMM_NUM_MODELS] = NULL;
    float (*sigma)[WAMI_GMM_IMG_NUM_COLS][WAMI_GMM_NUM_MODELS] = NULL;
    float (*weights)[WAMI_GMM_IMG_NUM_COLS][WAMI_GMM_NUM_MODELS] = NULL;
    u8 (*foreground)[WAMI_GMM_IMG_NUM_ROWS][WAMI_GMM_IMG_NUM_COLS] = NULL;
#ifdef ENABLE_CORRECTNESS_CHECKING
    u8 (*golden_foreground)[WAMI_GMM_IMG_NUM_ROWS][WAMI_GMM_IMG_NUM_COLS] = NULL;
    u8 (*golden_eroded)[WAMI_GMM_IMG_NUM_COLS] = NULL;
    u8 (*eroded)[WAMI_GMM_IMG_NUM_COLS] = NULL;
#endif
    u8 (*morph)[WAMI_GMM_IMG_NUM_COLS] = NULL;
    u16 (*frames)[WAMI_GMM_IMG_NUM_ROWS][WAMI_GMM_IMG_NUM_COLS] = NULL;
    int i;

    char *input_directory = NULL;

    const size_t num_pixels = WAMI_GMM_IMG_NUM_ROWS * WAMI_GMM_IMG_NUM_COLS;

    if (argc != 2)
    {
        fprintf(stderr, "%s <directory-containing-input-files>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    input_directory = argv[1];

    mu = XMALLOC(sizeof(float) * num_pixels * WAMI_GMM_NUM_MODELS);
    sigma = XMALLOC(sizeof(float) * num_pixels * WAMI_GMM_NUM_MODELS);
    weights = XMALLOC(sizeof(float) * num_pixels * WAMI_GMM_NUM_MODELS);
    foreground = XMALLOC(sizeof(u8) * num_pixels * WAMI_GMM_NUM_FRAMES);
#ifdef ENABLE_CORRECTNESS_CHECKING
    golden_foreground = XMALLOC(sizeof(u8) * num_pixels * WAMI_GMM_NUM_FRAMES);
    eroded = XMALLOC(sizeof(u8) * num_pixels);
    golden_eroded = XMALLOC(sizeof(u8) * num_pixels);
#endif
    morph = XMALLOC(sizeof(u8) * num_pixels);
    frames = XMALLOC(sizeof(u16) * num_pixels * WAMI_GMM_NUM_FRAMES);

    memset(mu, 0, sizeof(float) * num_pixels * WAMI_GMM_NUM_MODELS);
    memset(sigma, 0, sizeof(float) * num_pixels * WAMI_GMM_NUM_MODELS);
    memset(weights, 0, sizeof(float) * num_pixels * WAMI_GMM_NUM_MODELS);
    memset(foreground, 0, sizeof(u8) * num_pixels * WAMI_GMM_NUM_FRAMES);
    memset(morph, 0, sizeof(u8) * num_pixels);
    memset(frames, 0, sizeof(u16) * num_pixels * WAMI_GMM_NUM_FRAMES);

    read_gmm_input_data(
        mu, sigma, weights, frames, input_filename, input_directory);

#ifdef ENABLE_CORRECTNESS_CHECKING
    read_data_file(
        (char *) golden_foreground,
        golden_output_filename,
        input_directory,
        sizeof(u8) * num_pixels * WAMI_GMM_NUM_FRAMES);
#endif

    printf("WAMI kernel 2 parameters:\n\n");
    printf("Image width = %d pixels\n", WAMI_DEBAYER_IMG_NUM_COLS);
    printf("Image height = %d pixels\n", WAMI_DEBAYER_IMG_NUM_ROWS);
    printf("Number of input frames = %d\n", WAMI_GMM_NUM_FRAMES);

    printf("\nStarting WAMI kernel 3 (Gaussian Mixture Model / Change Detection).\n\n");
    tic();
    accept_roi_begin();
    for (i = 0; i < WAMI_GMM_NUM_FRAMES; ++i)
    {
        wami_gmm(
            (u8 (*)[WAMI_GMM_IMG_NUM_COLS]) &foreground[i][0][0],
            mu,
            sigma,
            weights,
            (u16 (*)[WAMI_GMM_IMG_NUM_COLS]) &frames[i][0][0]);
    }
    accept_roi_end();
    PRINT_STAT_DOUBLE("CPU time using func toc - ", toc());
    printf ("\n");
#ifdef ENABLE_CORRECTNESS_CHECKING
    {
      int j, k, validation_warning = 0;
      double err;
        for (i = 0; i < WAMI_GMM_NUM_FRAMES; ++i)
        {
            int num_misclassified = 0, num_foreground = 0;
            double misclassification_rate = 0;

            wami_morpho_erode(
                eroded, (u8 (*)[WAMI_GMM_IMG_NUM_COLS]) &foreground[i][0][0]);
            wami_morpho_erode(
                golden_eroded, (u8 (*)[WAMI_GMM_IMG_NUM_COLS]) &golden_foreground[i][0][0]);

            printf("\nValidating frame %d output...\n", i);

            for (j = 0; j < WAMI_GMM_IMG_NUM_ROWS; ++j)
            {
                for (k = 0; k < WAMI_GMM_IMG_NUM_COLS; ++k)
                {
                    if (eroded[j][k] != golden_eroded[j][k])
                    {
                        ++num_misclassified;
                    }
                    if (golden_eroded[j][k] != 0)
                    {
                        ++num_foreground;
                    }
                }
            }
            misclassification_rate = (100.0*num_misclassified)/num_foreground;
	    err += (((double) num_misclassified) / ((double) num_foreground)) / ((double) WAMI_GMM_NUM_FRAMES);
            printf("\tMisclassified pixels: %d\n", num_misclassified);
            printf("\tGolden foreground pixels (after erosion): %d\n", num_foreground);
            printf("\tMisclassification rate relative to foreground: %f%%\n",
                misclassification_rate);
            if (misclassification_rate > 0.1)
            {
                validation_warning = 1;
            }
        }
	
	FILE *fp = fopen("err.txt", "wb");
	assert(fp != NULL);
	fprintf(fp, "%.2f\n", err);
	fclose(fp);

        if (validation_warning)
        {
            printf("\nValidation warning: Misclassification rate appears high; check images.\n\n");
        }
        else
        {
            printf("\nValidation checks passed.\n\n");
        }
    }
#endif
    
#ifdef WRITE_OUTPUT_TO_DISK
    printf("Writing output to %s.\n", output_filename);
    {
        FILE *fp = fopen(output_filename, "wb");
        assert(fp != NULL);
        assert(fwrite(foreground, sizeof(u8), num_pixels * WAMI_GMM_NUM_FRAMES, fp) ==
            num_pixels * WAMI_GMM_NUM_FRAMES);
        fclose(fp);
    }
#endif

    FREE_AND_NULL(mu);
    FREE_AND_NULL(sigma);
    FREE_AND_NULL(weights);
    FREE_AND_NULL(foreground);
#ifdef ENABLE_CORRECTNESS_CHECKING
    FREE_AND_NULL(golden_foreground);
    FREE_AND_NULL(eroded);
    FREE_AND_NULL(golden_eroded);
#endif
    FREE_AND_NULL(morph);
    FREE_AND_NULL(frames);

    return 0;
}