示例#1
0
main(int ac, char **av)
{
	FILE *fp;
	matrix prox=NULL,prepare_prox_mtx(),first_guess=NULL;
	matrix TMP=NULL,RES=NULL,mds2res();
	int dim ;


	if (ac != 3) {
		printf("USAGE: %s <data_file> <dimenssion> \n",av[0]);
		exit(1);
	}

	fp = fopen(av[1],"r");
	dim = atoi(av[2]);

	prox = prepare_prox_mtx(fp,dim);

	first_guess = generate_first_guess(dim,pnts,50);
	if (dim >1 ) TMP = metric_mds(dim,pnts,first_guess,prox,J_ee,DJ_ee);
	else  TMP = metric_mds(dim,pnts,first_guess,prox,OneJ_ee,DOneJ_ee);

	RES = mds2res(TMP,dim);
	compare_results(RES,prox,dim); 

	free_all_mtx(dim,&TMP,&prox,&first_guess);

        printf("Points coordinates are: \n \n");
        print_mtx(RES);   
	

}
示例#2
0
文件: benchxcomp.c 项目: hglm/benchx
int main(int argc, char *argv[]) {
    if (argc < 3) {
        usage();
        return 0;
    }
    FILE *f1 = fopen(argv[1], "r");
    if (f1 == NULL) {
        printf("Could open file %s.\n", argv[1]);
        return 1;
    }
    FILE *f2 = fopen(argv[2], "r");
    if (f2 == NULL) {
        printf("Could open file %s.\n", argv[2]);
        return 1;
    }
    BenchResults *results1 = malloc(sizeof(BenchResults));
    BenchResults *results2 = malloc(sizeof(BenchResults));
    process_file(f1, results1);
    printf("Processed %d results in %s.\n", results1->nu_results, argv[1]);
    process_file(f2, results2);
    printf("Processed %d results in %s.\n", results2->nu_results, argv[2]);
    compare_results(results1, results2);
    fclose(f1);
    fclose(f2);
}
示例#3
0
//--------------------------
// Send data thread
//-------------------------
void test_fft::send() {

    // Variables declaration
    int i=0;
    float  in_read_real, in_read_imag;

    //Reset routine
    in_file = fopen(INFILENAME, "rt");


    if(!in_file) {
        cout << "Could not open " << INFILENAME << "\n";
        sc_stop();
        exit(EXIT_FAILURE);
    }


    wait();

    while(true) {

        data_valid.write(false);  // start sending data to FFT module
        while(fscanf(in_file,"%f", &in_read_real) != EOF) {
            if(fscanf(in_file,"%f", &in_read_imag) == EOF)
                break;

            while(data_req.read() == false)
                wait();

            in_real.write(in_read_real);
            in_imag.write(in_read_imag);

            //	cout << "Input vector:" << in_read_real << "+i" << in_read_imag << endl;

            wait();
        }

        data_valid.write(true);

        fclose(in_file);


        cout << endl << "Starting comparing results " << endl;

        compare_results();
        sc_stop();

        wait();

    }//while_loop
}
示例#4
0
//----------------------
// Send data to Interpolation Filter
//----------------------------
void tb_interp::send(void){

  // Variables declarations
  float indata_var;
  float  infactor_var;
  int k;


   //Reset initialization
   in_file_data = fopen(IN_DATA, "r");
   in_file_factor = fopen( IN_FACTOR_DATA, "r");

   if(!in_file_data){
     cout<< endl << IN_DATA << " data file could not be opened " << endl;
     sc_stop();}

   if(!in_file_factor){
     cout<< endl << IN_FACTOR_DATA << " file could not be opened" << endl;
     sc_stop();

   }


  wait();

  while(true){

    while(fscanf(in_file_data,"%f",&indata_var) !=EOF &&  fscanf(in_file_factor,"%f", &infactor_var) != EOF){
     
      indata.write(indata_var);
      infactor.write(infactor_var);

      wait(); 
    }


    fclose(in_file_data);
    fclose(in_file_factor);
   
    cout << endl << "Start comparing results" << endl;
    compare_results();
    sc_stop();

    wait();
  }// end of while loop

 

}
示例#5
0
int main(int argc, char **argv)
{
    //allocate memory 16-byte aligned
    short *scalar_input = (short*) memalign(16, IDCT_SIZE*IDCT_SIZE*sizeof(short));
    short *scalar_output = (short *) memalign(16, IDCT_SIZE*IDCT_SIZE*sizeof(short));

    short *simd_input = (short*) memalign(16, IDCT_SIZE*IDCT_SIZE*sizeof(short));
    short *simd_output = (short *) memalign(16, IDCT_SIZE*IDCT_SIZE*sizeof(short));

    //initialize input
    printf("input array:\n");
    for(int j=0;j<IDCT_SIZE;j++){
        for(int i=0;i<IDCT_SIZE;i++){
            short value = rand()%2 ? (rand()%32768) : -(rand()%32768) ;
            scalar_input[j*IDCT_SIZE+i] = value;
            simd_input  [j*IDCT_SIZE+i] = value;
	    printf("%d\t", value);
        }
        printf("\n");
    }

    idct16_scalar(scalar_input, scalar_output);
    idct16_simd  (simd_input  , simd_output);

    //check for correctness
    compare_results (scalar_output, simd_output, "scalar and simd");

    printf("output array:\n");
    for(int j=0;j<IDCT_SIZE;j++){
        for(int i=0;i<IDCT_SIZE;i++){
	    printf("%d\t", scalar_output[j*IDCT_SIZE+i]);
        }
        printf("\n");
    }

    //Measure the performance of each kernel
    benchmark (idct16_scalar, scalar_input, scalar_output, "scalar");
    benchmark (idct16_simd, simd_input, simd_output, "simd");

    //cleanup
    free(scalar_input);    free(scalar_output);
    free(simd_input); free(simd_output);
}
int check_result(struct gameState myState, struct gameState copyState, int choice1, int choice2, int choice3, int myKingdomCards[10], int result, int handPos)
{
	int er_return = expected_result(&copyState, choice1, choice2, choice3, handPos, myKingdomCards);

	if( result == -1 && er_return == 0 )
	{
		printf("FAILURE: Test failed on valid inputs.\n");
		return 1;
	}
	else if(result == 0 && er_return == -1)
	{
		printf("FAILURE: Function did not fail on invalid input.\n");
		return 1;
	}
	else if(result == 0 && er_return == 0)
	{
		return compare_results(myState, copyState, choice1);
	}
	return 0;
}
示例#7
0
//-------------------
// Send data thread
//------------------
void test_adpcm::send()
{

  // Variables declaration
  int i=0;
  unsigned int  indata;

  //Reset routine
  in_file = fopen(INFILENAME, "rt");


  if(!in_file){
    cout << "Could not open " << INFILENAME << "\n";
    sc_stop();
    exit(EXIT_FAILURE);
  }

 
  wait();

  while(true){

   
    while(fscanf(in_file,"%f", &indata) != EOF){
      idata.write(indata);
      wait();
    }
  

    fclose(in_file);

    cout << endl << "Starting comparing results " << endl;
 
    compare_results();
    sc_stop();

    wait();

  }//while_loop
}
示例#8
0
static svn_error_t *
test_parse_date(const char **msg,
                svn_boolean_t msg_only,
                svn_test_opts_t *opts,
                apr_pool_t *pool)
{
  apr_time_t now, result;
  apr_time_exp_t nowexp, expt;
  svn_boolean_t matched;
  struct date_test *dt;
  const char **ft;

  *msg = "test svn_parse_date";

  if (msg_only)
    return SVN_NO_ERROR;

  now = apr_time_now();
  if (apr_time_exp_lt(&nowexp, now) != APR_SUCCESS)
    return svn_error_create(SVN_ERR_TEST_FAILED, NULL, "Can't expand time");

  for (dt = localtz_tests; dt->str; dt++)
    {
      SVN_ERR(svn_parse_date(&matched, &result, dt->str, now, pool));
      if (!matched)
        return svn_error_createf
          (SVN_ERR_TEST_FAILED, NULL, "Match failed for '%s'", dt->str);
      if (apr_time_exp_lt(&expt, result) != APR_SUCCESS)
        return svn_error_createf
          (SVN_ERR_TEST_FAILED, NULL, "Expand failed for '%s'", dt->str);
      SVN_ERR(compare_results(dt, &expt));
    }

  for (dt = gmt_tests; dt->str; dt++)
    {
      SVN_ERR(svn_parse_date(&matched, &result, dt->str, now, pool));
      if (!matched)
        return svn_error_createf
          (SVN_ERR_TEST_FAILED, NULL, "Match failed for '%s'", dt->str);
      if (apr_time_exp_gmt(&expt, result) != APR_SUCCESS)
        return svn_error_createf
          (SVN_ERR_TEST_FAILED, NULL, "Expand failed for '%s'", dt->str);
      SVN_ERR(compare_results(dt, &expt));
    }

  for (dt = daytime_tests; dt->str; dt++)
    {
      SVN_ERR(svn_parse_date(&matched, &result, dt->str, now, pool));
      if (!matched)
        return svn_error_createf
          (SVN_ERR_TEST_FAILED, NULL, "Match failed for '%s'", dt->str);
      if (apr_time_exp_lt(&expt, result) != APR_SUCCESS)
        return svn_error_createf
          (SVN_ERR_TEST_FAILED, NULL, "Expand failed for '%s'", dt->str);
      dt->year = nowexp.tm_year + 1900;
      dt->mon = nowexp.tm_mon + 1;
      dt->mday = nowexp.tm_mday;
      SVN_ERR(compare_results(dt, &expt));
    }

  for (ft = failure_tests; *ft; ft++)
    {
      SVN_ERR(svn_parse_date(&matched, &result, *ft, now, pool));
      if (matched)
        return svn_error_createf
          (SVN_ERR_TEST_FAILED, NULL, "Match succeeded for '%s'", *ft);
    }

  return SVN_NO_ERROR;
}
示例#9
0
int main()
{
	srand(time(NULL));


	float dt = 1.0/32.0;
	struct sAgentInit agent_init;
	agent_init.id = 0;
	agent_init.type = 0;
	agent_init.dt = dt;
	agent_init.gamma = 0.98;
	agent_init.alpha = 0.7;
	agent_init.k = 1.0;
	agent_init.function_type = 0;
	agent_init.inputs_count = 2;

	std::vector<float> action;
	std::vector<std::vector<float>> actions;

	action.push_back(0.0);
	action.push_back(0.0);

	action[0] = 1.0;
	action[1] = 0.0;
	actions.push_back(action);

	action[0] = -1.0;
	action[1] = 0.0;
	actions.push_back(action);

	action[0] = 0.0;
	action[1] = 1.0;
	actions.push_back(action);

	action[0] = 0.0;
	action[1] = -1.0;
	actions.push_back(action);


	action[0] = 1.0;
	action[1] = 1.0;
	actions.push_back(action);

	action[0] = 1.0;
	action[1] = -1.0;
	actions.push_back(action);

	action[0] = -1.0;
	action[1] = 1.0;
	actions.push_back(action);

	action[0] = -1.0;
	action[1] = -1.0;
	actions.push_back(action);



//	 create_maps(dt);

	u32 res, i;

	std::vector<class CMap*> maps;

	for (i = 0; i < MAPS_COUNT; i++)
	{
		char source_file_name[1024];
		char dest_file_name[1024];

		sprintf(source_file_name,"%s/%s%i/map.bin", S_RESULTS_PATH, S_MAP_PATH, i);
		sprintf(dest_file_name,"%s/%s%i/map_plot.log", S_RESULTS_PATH, S_MAP_PATH, i);


		maps.push_back(new CMap(dt, 0));
		res = maps[i]->load(source_file_name);
		maps[i]->save_plot(dest_file_name);

		printf("loading %s with %i\n", source_file_name, res);
	}


	u32 map_id, function_type;
	printf("\n processing experiment : \n");

	float error = 0.0;
	map_id = 2;
	i = 0;
	function_type = 3;

	for (map_id = 2; map_id < MAPS_COUNT; map_id++)
  for (function_type = 0; function_type <= 5; function_type++)
	{
		char file_name[1024];
		sprintf(file_name,"%s/map_%u/function_type_%u/summary_error_results.log",S_RESULTS_PATH, map_id, function_type);
		class CLog log(file_name, 2);

		for (i = 0; i < 20; i++)
		{
			float score;

			agent_init.function_type = function_type;
			class CEnvironment *environment = new CEnvironment(agent_init, actions, maps[map_id]);
			score = environment->process(map_id);

			error = compare_results(map_id, function_type);
			delete environment;

			printf("total error %f\n", error);

			log.add(0, i);
			log.add(1, error);

			log.save();
		}

		compare_all_results(map_id);
	}


	printf("program done\n");
	return 0;
}
示例#10
0
int main(int argc, char *argv[])
{
	int nchann, nsample, niter;
	int k, opt, ns;
	hfilter filt = NULL;
	void *buffin, *buffout;
	int filein = -1, fileout = -1;
	size_t samsize;
	uint32_t nchan32;
	uint32_t type;
	uint32_t r = 4;
	int retval = 1;
	int keepfiles = 0;


	// Process command-line options
	nchann = NCHANN;
	nsample = NSAMPLE;
	niter = NITER;
	type = TYPE_DEF;
	while ((opt = getopt(argc, argv, "hc:s:i:t:r:k:")) != -1) {
		switch (opt) {
		case 'c':
			nchann = atoi(optarg);
			break;
		case 's':
			nsample = atoi(optarg);
			break;
		case 'i':
			niter = atoi(optarg);
			break;
		case 'r':
			r = atoi(optarg);
			break;
		case 't':
			type = atoi(optarg);
			break;
		case 'k':
			keepfiles = atoi(optarg);
			break;
		case 'h':
		default:	/* '?' */
			fprintf(stderr, "Usage: %s [-c numchannel] [-s numsample] [-i numiteration] "
					"[-t (0 for float/1 for double)]\n",
				argv[0]);
			exit(EXIT_FAILURE);
		}
	}
	printf("\tnumber of channels: %i \t\tlength of batch: %i\n", nchann, nsample);
	samsize = sizeof_data(type) * nchann;
	nchan32 = nchann;

	// Allocate buffers
	buffin = align_alloc(16, nsample*samsize);
	buffout = align_alloc(16, nsample*samsize);
	if (!buffin || !buffout) {
		fprintf(stderr, "buffer allocation failed\n");
		goto out;
	}


	// Open files for writing
	filein = open(infilename, O_WRONLY|O_CREAT, S_IRWXU);
	fileout = open(outfilename, O_WRONLY|O_CREAT, S_IRWXU);
	if ((filein < 0) || (fileout < 0)) {
		fprintf(stderr, "File opening failed\n");
		goto out;
	}

	// write filter params on fileout
	if (write(filein, &type, sizeof(type)) == -1 ||
	    write(filein, &nchan32, sizeof(nchan32)) == -1 ||
	    write(fileout, &type, sizeof(type)) == -1 ||
	    write(fileout, &nchan32, sizeof(nchan32)) == -1  ||
	    write(fileout, &r, sizeof(r)) == -1)
		goto out;



	// create filters
	filt = rtf_create_downsampler(nchann, type, r);
	if (!filt) {
		fprintf(stderr,"Creation of filter failed\n");
		goto out;
	}

	// Filter chunks of data and write input and output on files
	for (k=0; k<niter; k++) {
		set_signals(nchann, nsample, type, buffin);
		ns = rtf_filter(filt, buffin, buffout, nsample);
		if ( write(filein, buffin, nsample*samsize) == -1
		     || write(fileout, buffout, ns*samsize) == -1 ) {
		        fprintf(stderr,"Error while writing file\n");
			break;
		}
	}
	retval = 0;

out:
	rtf_destroy_filter(filt);
	align_free(buffin);
	align_free(buffout);
	if (filein != -1)
		close(filein);
	if (fileout != -1)
		close(fileout);

#if HAVE_MATLAB
	if (retval == 0)
		retval = compare_results(0.02);
#endif
	if (!keepfiles) {
		unlink(infilename);
		unlink(outfilename);
	}

	return retval;
}
示例#11
0
文件: t_encrypt.c 项目: INNOAUS/krb5
int
main ()
{
    krb5_context context = 0;
    krb5_data  in, in2, out, out2, check, check2, state, signdata;
    krb5_crypto_iov iov[5];
    int i, j, pos;
    unsigned int dummy;
    size_t len;
    krb5_enc_data enc_out, enc_out2;
    krb5_keyblock *keyblock;
    krb5_key key;

    memset(iov, 0, sizeof(iov));

    in.data = "This is a test.\n";
    in.length = strlen (in.data);
    in2.data = "This is another test.\n";
    in2.length = strlen (in2.data);

    test ("Seeding random number generator",
          krb5_c_random_seed (context, &in));

    /* Set up output buffers. */
    out.data = malloc(2048);
    out2.data = malloc(2048);
    check.data = malloc(2048);
    check2.data = malloc(2048);
    if (out.data == NULL || out2.data == NULL
        || check.data == NULL || check2.data == NULL)
        abort();
    out.magic = KV5M_DATA;
    out.length = 2048;
    out2.magic = KV5M_DATA;
    out2.length = 2048;
    check.length = 2048;
    check2.length = 2048;

    for (i = 0; interesting_enctypes[i]; i++) {
        krb5_enctype enctype = interesting_enctypes [i];

        printf ("Testing enctype %d\n", enctype);
        test ("Initializing a keyblock",
              krb5_init_keyblock (context, enctype, 0, &keyblock));
        test ("Generating random keyblock",
              krb5_c_make_random_key (context, enctype, keyblock));
        test ("Creating opaque key from keyblock",
              krb5_k_create_key (context, keyblock, &key));

        enc_out.ciphertext = out;
        enc_out2.ciphertext = out2;
        /* We use an intermediate `len' because size_t may be different size
           than `int' */
        krb5_c_encrypt_length (context, keyblock->enctype, in.length, &len);
        enc_out.ciphertext.length = len;

        /* Encrypt, decrypt, and see if we got the plaintext back again. */
        test ("Encrypting (c)",
              krb5_c_encrypt (context, keyblock, 7, 0, &in, &enc_out));
        display ("Enc output", &enc_out.ciphertext);
        test ("Decrypting",
              krb5_c_decrypt (context, keyblock, 7, 0, &enc_out, &check));
        test ("Comparing", compare_results (&in, &check));

        /* Try again with the opaque-key-using variants. */
        memset(out.data, 0, out.length);
        test ("Encrypting (k)",
              krb5_k_encrypt (context, key, 7, 0, &in, &enc_out));
        display ("Enc output", &enc_out.ciphertext);
        test ("Decrypting",
              krb5_k_decrypt (context, key, 7, 0, &enc_out, &check));
        test ("Comparing", compare_results (&in, &check));

        /* Check if this enctype supports IOV encryption. */
        if ( krb5_c_crypto_length(context, keyblock->enctype,
                                  KRB5_CRYPTO_TYPE_HEADER, &dummy) == 0 ){
            /* Set up iovecs for stream decryption. */
            memcpy(out2.data, enc_out.ciphertext.data, enc_out.ciphertext.length);
            iov[0].flags= KRB5_CRYPTO_TYPE_STREAM;
            iov[0].data.data = out2.data;
            iov[0].data.length = enc_out.ciphertext.length;
            iov[1].flags = KRB5_CRYPTO_TYPE_DATA;

            /* Decrypt the encrypted data from above and check it. */
            test("IOV stream decrypting (c)",
                 krb5_c_decrypt_iov( context, keyblock, 7, 0, iov, 2));
            test("Comparing results",
                 compare_results(&in, &iov[1].data));

            /* Try again with the opaque-key-using variant. */
            memcpy(out2.data, enc_out.ciphertext.data, enc_out.ciphertext.length);
            test("IOV stream decrypting (k)",
                 krb5_k_decrypt_iov( context, key, 7, 0, iov, 2));
            test("Comparing results",
                 compare_results(&in, &iov[1].data));

            /* Set up iovecs for AEAD encryption. */
            signdata.magic = KV5M_DATA;
            signdata.data = (char *) "This should be signed";
            signdata.length = strlen(signdata.data);
            iov[0].flags = KRB5_CRYPTO_TYPE_HEADER;
            iov[1].flags = KRB5_CRYPTO_TYPE_DATA;
            iov[1].data = in; /*We'll need to copy memory before encrypt*/
            iov[2].flags = KRB5_CRYPTO_TYPE_SIGN_ONLY;
            iov[2].data = signdata;
            iov[3].flags = KRB5_CRYPTO_TYPE_PADDING;
            iov[4].flags = KRB5_CRYPTO_TYPE_TRAILER;

            /* "Allocate" data for the iovec buffers from the "out" buffer. */
            test("Setting up iov lengths",
                 krb5_c_crypto_length_iov(context, keyblock->enctype, iov, 5));
            for (j=0,pos=0; j <= 4; j++ ){
                if (iov[j].flags == KRB5_CRYPTO_TYPE_SIGN_ONLY)
                    continue;
                iov[j].data.data = &out.data[pos];
                pos += iov[j].data.length;
            }
            assert (iov[1].data.length == in.length);
            memcpy(iov[1].data.data, in.data, in.length);

            /* Encrypt and decrypt in place, and check the result. */
            test("iov encrypting (c)",
                 krb5_c_encrypt_iov(context, keyblock, 7, 0, iov, 5));
            assert(iov[1].data.length == in.length);
            display("Header", &iov[0].data);
            display("Data", &iov[1].data);
            display("Padding", &iov[3].data);
            display("Trailer", &iov[4].data);
            test("iov decrypting",
                 krb5_c_decrypt_iov(context, keyblock, 7, 0, iov, 5));
            test("Comparing results",
                 compare_results(&in, &iov[1].data));

            /* Try again with opaque-key-using variants. */
            test("iov encrypting (k)",
                 krb5_k_encrypt_iov(context, key, 7, 0, iov, 5));
            assert(iov[1].data.length == in.length);
            display("Header", &iov[0].data);
            display("Data", &iov[1].data);
            display("Padding", &iov[3].data);
            display("Trailer", &iov[4].data);
            test("iov decrypting",
                 krb5_k_decrypt_iov(context, key, 7, 0, iov, 5));
            test("Comparing results",
                 compare_results(&in, &iov[1].data));
        }

        enc_out.ciphertext.length = out.length;
        check.length = 2048;

        test ("init_state",
              krb5_c_init_state (context, keyblock, 7, &state));
        test ("Encrypting with state",
              krb5_c_encrypt (context, keyblock, 7, &state, &in, &enc_out));
        display ("Enc output", &enc_out.ciphertext);
        test ("Encrypting again with state",
              krb5_c_encrypt (context, keyblock, 7, &state, &in2, &enc_out2));
        display ("Enc output", &enc_out2.ciphertext);
        test ("free_state",
              krb5_c_free_state (context, keyblock, &state));
        test ("init_state",
              krb5_c_init_state (context, keyblock, 7, &state));
        test ("Decrypting with state",
              krb5_c_decrypt (context, keyblock, 7, &state, &enc_out, &check));
        test ("Decrypting again with state",
              krb5_c_decrypt (context, keyblock, 7, &state, &enc_out2, &check2));
        test ("free_state",
              krb5_c_free_state (context, keyblock, &state));
        test ("Comparing",
              compare_results (&in, &check));
        test ("Comparing",
              compare_results (&in2, &check2));

        krb5_free_keyblock (context, keyblock);
        krb5_k_free_key (context, key);
    }

    /* Test the RC4 decrypt fallback from key usage 9 to 8. */
    test ("Initializing an RC4 keyblock",
          krb5_init_keyblock (context, ENCTYPE_ARCFOUR_HMAC, 0, &keyblock));
    test ("Generating random RC4 key",
          krb5_c_make_random_key (context, ENCTYPE_ARCFOUR_HMAC, keyblock));
    enc_out.ciphertext = out;
    krb5_c_encrypt_length (context, keyblock->enctype, in.length, &len);
    enc_out.ciphertext.length = len;
    check.length = 2048;
    test ("Encrypting with RC4 key usage 8",
          krb5_c_encrypt (context, keyblock, 8, 0, &in, &enc_out));
    display ("Enc output", &enc_out.ciphertext);
    test ("Decrypting with RC4 key usage 9",
          krb5_c_decrypt (context, keyblock, 9, 0, &enc_out, &check));
    test ("Comparing", compare_results (&in, &check));

    krb5_free_keyblock (context, keyblock);
    free(out.data);
    free(out2.data);
    free(check.data);
    free(check2.data);
    return 0;
}
示例#12
0
int main(int argc, char *argv[])
{
	int dev, ret_val;
	unsigned int reg_val;

	// find and init FPGA device
	ret_val = fpga_init(argc, argv, &dev);
	if (ret_val<0) return -1;
	
	double dt_c[N];
	double dt_f[N];
	printf("N_d is %d\n",N_d);
	
	printf("N_d is %d\n",N_d);
	
	printf("size is %d\n",(int)SIZE_DWORD);

	try{
		

		x_1.resize(13);
		y_1.resize(13);
		t_1.resize(13);
		x_2.resize(13);
		y_2.resize(13);
		t_2.resize(13);
		for (int i = 0; i < 13; i++){
			x_1[i].resize(N_d);
			y_1[i].resize(N_d);
			t_1[i].resize(N_d);
			x_2[i].resize(N_d);
			y_2[i].resize(N_d);
			t_2[i].resize(N_d);
		}
		
	} catch (const  std::bad_alloc& ba){
		std::cout << "bad_alloc caught: " << ba.what() << std::endl;
	}	
	FILE  *f_p, *f_p1;

	int error = 0;
	if (flag_compare==1){
		f_p = fopen ("MT_coords_CPU.txt","w");
		if (f_p==NULL) {

			printf("Error opening file!\n");
			return -1;
		}
		
	}
	
	if (flag_file)		f_p1 = fopen (out_file,"w");
	else 				f_p1 = fopen ("MT_coords_FPGA.txt","w");
	
	if (f_p1==NULL) {

		printf("Error opening file!\n");
		return -1;
	}
	
	


	printf("TOTAL_STEPS = %d\nSTEPS_TO_WRITE = %d\n", TOTAL_STEPS, STEPS_TO_WRITE);



	// get golden results
	init_coords(x_1,y_1,t_1);
	init_coords(x_2,y_2,t_2);
	



	/*
	* в этом цикле проводим вычислени¤ и сравниваем результаты
	*
	* в данный момент чтобы проверить сравнение на каждом шаге вызываетс¤ функци¤ mt_cpu
	* с параметром load_coords = 1 (иначе состо¤ни¤ глобальных массивов координат будет все врем¤ мен¤тьс¤)
	*
	*  огда вместо mt_cpu будет реализаци¤ на OpenCL, то надо делать по-другому:
	*  перед циклом один раз вызываем mt_cpu (load_coords = 1), в цикле уменьшаем количество итераций на 1 и
	*  вызываем mt_cpu (load_coords = 0)
	*
	*/
	error = 0; 

	
	printf("\nFlag rand is SET, %d\n\n",flag_rand);
	
	if (flag_rand==1) 	  {
		
		srand (time(NULL));
		
		// set seed vals
		for (int i =0; i < NUM_SEEDS; i++){
#ifdef TEST_SEEDS
				seeds[i] = test_seeds[i];
#else
				seeds[i]=rand();
#endif
			unsigned int addr = SEED_REG + 4*i;
			RD_WriteDeviceReg32m(dev, CNTRL_BAR, addr, seeds[i]);	
		}		
		
		printf("\nFlag rand is SET\n\n");
		
		
		RD_ReadDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val);
	
		// deassert rand reset
		reg_val |= (1<<4);
		RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val);
		
		// set rand_enable flag
		reg_val |= (1<<7);
		RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val);

		// start rand core
		reg_val |= (1<<5);	
		RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val);		
		

		
		
	}
	
	
	printf("\n\nhereerereerere\n\n");
	
	

	for(int k=0; k<N; k++) {


		int err;
		struct timeval tt1, tt2;
		if (flag_compare==1){
			get_time(&tt1);
			if (mt_cpu(STEPS_TO_WRITE,1, flag_rand, flag_seed, seeds,  x_1,y_1,t_1,x_1,y_1, t_1)<0) { printf("Nan Error in cpu. Step is %d. Exitting....\n",k); break;}

			get_time(&tt2);
			calc_dt(&tt1,&tt2, &dt_c[k]);
		}
		
		get_time(&tt1);
		mt_fpga(dev,STEPS_TO_WRITE,1,x_2,y_2,t_2,x_2,y_2, t_2);
		get_time(&tt2);
		calc_dt(&tt1,&tt2, &dt_f[k]);

		flag_seed = 0; 
		
		printf("Step %d\n\t CPU Time = %f\n\t FPGA Time = %f\n",k,dt_c[k],dt_f[k] );

		if (flag_compare==1){
			err = compare_results(x_1,y_1,t_1,x_2,y_2,t_2);
			if (err) {
				error += err;
				printf("Compare results failed at step = %d, errors = %d\n", k, error);
			}
		}


		if (flag_compare==1)	print_coords(f_p, x_1, y_1, t_1);
		print_coords(f_p1, x_2, y_2, t_2);
		

	}
	if (flag_compare==1){
		if (!error)
		printf("Test OK!\n");
	}
	
	

	if (flag_compare==1) fclose(f_p);
	fclose(f_p1);


	RD_ReadDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val);
	
	// assert rand reset
	reg_val &= ~(1<<4);
	RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val);
		
	// reset rand_enable flag
	reg_val &= ~(1<<7);
	RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val);	
	


	free(wr_buf_free);
	free(rd_buf_free);


	RD_CloseDevice(pd_ptr);
	return 0; 

}
示例#13
0
//-------------------------
// Send data thread
//------------------------
void test_decim::send(){

  // Variables declaration
  int i=0;
  float coeff_read, in_filter_read;

  float incoef1_read[TAPS_STAGE1] ;
  float incoef2_read[TAPS_STAGE2] ;
  float incoef3_read[TAPS_STAGE3] ;
  float incoef4_read[TAPS_STAGE4] ;
  float incoef5_read[TAPS_STAGE5] ;



  //Reset routine
  in_filter_file = fopen(IN_DATA_FILENAME, "rt");
  in_coeff_file = fopen(IN_COEFF_FILENAME, "rt");


  if(!in_filter_file){
    cout << "Could not open " << IN_DATA_FILENAME << "\n";
    sc_stop();
    exit (-1);
  }


  if(!in_coeff_file){
    cout << "Could not open " << IN_COEFF_FILENAME << "\n";
    sc_stop();
    exit (-1);
  }


  for(i=0; i <TAPS_STAGE1; i ++){
    fscanf(in_coeff_file, "%f", &incoef1_read[i]);
  }
  
  for(i=0; i <TAPS_STAGE2; i ++){
    fscanf(in_coeff_file, "%f", &incoef2_read[i]);
  }

  for(i=0; i <TAPS_STAGE3; i ++){
    fscanf(in_coeff_file, "%f", &incoef3_read[i]);
  }  

  for(i=0; i <TAPS_STAGE4; i ++){
    fscanf(in_coeff_file, "%f", &incoef4_read[i]);
  } 
  for(i=0; i <TAPS_STAGE5; i ++){
    fscanf(in_coeff_file, "%f", &incoef5_read[i]);
  } 


  cout << endl << "Read coefficients from file " << endl;

  wait();

  while(true){

    load_coeff.write(true);
      for(i=0; i <TAPS_STAGE1; i ++)
        incoef1[i].write(incoef1_read[i]);

     for(i=0; i <TAPS_STAGE2; i ++)
      incoef2[i].write(incoef2_read[i]);

    for(i=0; i <TAPS_STAGE3; i ++)
      incoef3[i].write(incoef3_read[i]);

     for(i=0; i <TAPS_STAGE4; i ++)
       incoef4[i].write(incoef4_read[i]);

     for(i=0; i <TAPS_STAGE5; i ++)
       incoef5[i].write(incoef5_read[i]);


   wait();

   load_coeff.write(false);

    while(fscanf(in_filter_file,"%f", &in_filter_read) != EOF){
       	indata.write(in_filter_read);
   
	wait();
    }
  
   
    fclose(in_coeff_file);
    fclose(in_filter_file);

    cout << endl << "Starting comparing results " << endl;
 
    compare_results();
    sc_stop();

    wait();

  }//while_loop
}
示例#14
0
void verify_serial_generic(real_t * target_domain, Parameters p) {
  int male;
  // function pointer to select the reference stencil operator
  void (*std_kernel)( const int [],
      const real_t * restrict, real_t * restrict,
      const real_t * restrict, const real_t * restrict);

  real_t * restrict u, * restrict v, * restrict roc2, * restrict coef;
  uint64_t it, i, j , k, f, ax;
  int nnx = p.stencil_shape[0]+2*p.stencil.r;
  int nny = p.stencil_shape[1]+2*p.stencil.r;
  int nnz = p.stencil_shape[2]+2*p.stencil.r;
  uint64_t n_domain = ((uint64_t) 1)* nnx*nny*nnz;
  uint64_t domain_size;

  switch(p.stencil.type){
    case REGULAR:
      male = posix_memalign((void **)&(u),    p.alignment, sizeof(real_t)*n_domain); check_merr(male);
      male = posix_memalign((void **)&(v),    p.alignment, sizeof(real_t)*n_domain); check_merr(male);
    if(p.stencil.time_order == 2)
      male = posix_memalign((void **)&(roc2), p.alignment, sizeof(real_t)*n_domain); check_merr(male);
     break;

    case SOLAR:
      domain_size = n_domain*12lu*2lu;
      male = posix_memalign((void **)&(u), p.alignment, sizeof(real_t)*domain_size); check_merr(male);
      v = 0; 
      break;

   default:
    printf("ERROR: unknown type of stencil\n");
    exit(1);
    break;
  }


  // allocate the the coefficients according to the stencil type
  // initialize the coefficients
  // select the desired stencil operator function
  uint64_t coef_size, idx;
  switch(p.stencil.coeff){
  case CONSTANT_COEFFICIENT:
    coef_size = 11;
    male = posix_memalign((void **)&(coef), p.alignment, sizeof(real_t)*coef_size); check_merr(male);
    for(i=0;i<p.stencil.r+1;i++) coef[i] = p.g_coef[i];

    // select the stencil type
    switch(p.stencil.r){
    case 1:
      if(p.stencil.shape == STAR) 
        std_kernel = &std_kernel_2space_1time;
      else if(p.stencil.shape == BOX)
        std_kernel = &std_box_kernel_2space_1time;
      break;
    case 4:
      std_kernel = &std_kernel_8space_2time;
      break;
    default:
      printf("ERROR: unknown type of stencil\n");
      exit(1);
      break;
    }
    break;


  case VARIABLE_COEFFICIENT:
    coef_size = n_domain*(1 + p.stencil.r);
    male = posix_memalign((void **)&(coef), p.alignment, sizeof(real_t)*coef_size); check_merr(male);
    for(k=0; k <= p.stencil.r; k++){
      for(i=0; i<n_domain; i++){
        coef[i + k*n_domain] = p.g_coef[k];
      }
    }
    // select the stencil type
    switch(p.stencil.r){
    case 1:
      std_kernel = &std_kernel_2space_1time_var;
      break;
    default:
      printf("ERROR: unknown type of stencil\n");
      exit(1);
      break;
    }
    break;


  case VARIABLE_COEFFICIENT_AXSYM:
    coef_size = n_domain*(1 + 3*p.stencil.r);
    male = posix_memalign((void **)&(coef), p.alignment, sizeof(real_t)*coef_size); check_merr(male);

    // central point coeff
    for(i=0; i<n_domain; i++){
      coef[i] = p.g_coef[0];
    }
    for(k=0; k < p.stencil.r; k++){
      for(ax=0; ax<3; ax++){
        for(i=0; i<n_domain; i++){
          coef[i + n_domain + 3*k*n_domain + ax*n_domain] = p.g_coef[k+1];
        }
      }
    }

    // select the stencil type
    switch(p.stencil.r){
    case 1:
      std_kernel = &std_kernel_2space_1time_var_axsym;
      break;
    case 4:
      std_kernel = &std_kernel_8space_1time_var_axsym;
      break;
    default:
      printf("ERROR: unknown type of stencil\n");
      exit(1);
      break;
    }
    break;


  case VARIABLE_COEFFICIENT_NOSYM:
    coef_size = n_domain*(1 + 6*p.stencil.r);
    male = posix_memalign((void **)&(coef), p.alignment, sizeof(real_t)*coef_size); check_merr(male);

    // central point coeff
    for(i=0; i<n_domain; i++){
      coef[i] = p.g_coef[0];
    }
    for(k=0; k < p.stencil.r; k++){
      for(ax=0; ax<3; ax++){
        for(i=0; i<n_domain; i++){
          coef[i + n_domain + 6*k*n_domain +  2*ax   *n_domain] = p.g_coef[k+1];
          coef[i + n_domain + 6*k*n_domain + (2*ax+1)*n_domain] = p.g_coef[k+1];
        }
      }
    }

    // select the stencil type
    switch(p.stencil.r){
    case 1:
      std_kernel = &std_kernel_2space_1time_var_nosym;
      break;
    default:
      printf("ERROR: unknown type of stencil\n");
      exit(1);
      break;
    }
    break;


  case SOLAR_COEFFICIENT:
    std_kernel = &solar_kernel;
    coef_size = n_domain*28lu*2lu;
    male = posix_memalign((void **)&(coef), p.alignment, sizeof(real_t)*coef_size); check_merr(male); 
    for(f=0; f<28;f++){
      for(idx=0;idx<n_domain*2lu; idx++){
        coef[idx+f*n_domain*2lu] = p.g_coef[(idx+f*n_domain*2lu)%10];
      }
    }
    break;


  default:
    printf("ERROR: unknown type of stencil\n");
    exit(1);
    break;
  }


  switch(p.stencil.type){
    case REGULAR:
      //-- Initialize u,v,roc2
      // fill the array points according to their location in space and pad the boundary with zeroes
      for(i=0; i<n_domain;i++){
        u[i] = 0.0;
        v[i] = 0.0;
        if(p.stencil.time_order == 2)
          roc2[i]= 0.0;
      }
      real_t r;
      for(k=p.stencil.r; k<p.stencil_shape[2]+p.stencil.r; k++){
        for(j=p.stencil.r; j<p.stencil_shape[1]+p.stencil.r; j++){
          for(i=p.stencil.r; i<p.stencil_shape[0]+p.stencil.r; i++){
            r = 1.0/3 * (1.0*i/p.stencil_shape[0] + 1.0*j/p.stencil_shape[1]  + 1.0*k/p.stencil_shape[2]);
            U(i, j, k)    = r*1.845703;
            V(i, j, k)    = r*1.845703;

            if(p.stencil.time_order == 2)
              ROC2(i, j, k) = r*1.845703;
          }
        }
      }
    //   set source points at the boundary of the leading dimension
      for(k=0; k<nnz; k++){
        for(j=0; j<nny; j++){
          U(0, j, k) += BOUNDARY_SRC_VAL;
          V(0, j, k) += BOUNDARY_SRC_VAL;
          U(nnx-1, j, k) += BOUNDARY_SRC_VAL;
          V(nnx-1, j, k) += BOUNDARY_SRC_VAL;
        }
      }
      break;
  
    case SOLAR:
      for(i=0; i<n_domain*24lu;i++){
        u[i] = 0.0;
      }
      for(f=0; f<12; f++){
        for(k=0; k<nnz; k++){
          for(j=0; j<nny; j++){
            for(i=0; i<nnx; i++){
              idx = 2*((k*nny+j)*nnx + i +n_domain*f);
              r = 1.0/(3.0) * (1.0*i/p.stencil_shape[0] + 1.0*j/p.stencil_shape[1]  + 1.0*k/p.stencil_shape[2]);
              u[idx] = r*1.845703;
              u[idx+1] = r*1.845703/3.0;
            }
          }
        }
      }
      break;
    
   default:
    printf("ERROR: unknown type of stencil\n");
    exit(1);
    break;
  } 
  //-- Reference kernel Main Loop -
  int domain_shape[3];
  domain_shape[0] = nnx;
  domain_shape[1] = nny;
  domain_shape[2] = nnz;
  for(it=0; it<p.nt; it+=2){
    std_kernel(domain_shape, coef, u, v, roc2);
    std_kernel(domain_shape, coef, v, u, roc2);
  }
//  print_3Darray("u"   , u, nnx, nny, nnz, 0);
//  u[(p.stencil.r+1)*(nnx * nny + nny + 1)] += 100.1;

  // compare results
  compare_results(u, target_domain, p.alignment, p.stencil_shape[0], p.stencil_shape[1], p.stencil_shape[2], p.stencil.r, p);


  switch(p.stencil.type){
    case REGULAR:
      free(u);
      free(v);
      free(coef);
      if(p.stencil.time_order == 2)
        free(roc2);
      break;

    case SOLAR:
      free(u);
      free(coef);
      break;

   default:
    printf("ERROR: unknown type of stencil\n");
    exit(1);
    break;
  }

}
// MAIN  
main()
{
    int winning[SIZE] = {1,3,5,7,9,11};
    int choice[SIZE];
    static int numbers[42] = {0};
    char cont = 'n'; 
    int bonus, menu_option = 0, i;
    
    
    
    printf("Welcome to the Lotto game. You will pick your 6 numbers and a bonus number and win up to 500,000 Euro. Good luck!\n\n");
    
    //User choses numbers before menu is displayed
    scan_chosen_num(choice, &bonus);
    
    //Numbers are sorted in increasing order
    bubble_sort_chosen(choice);
    
    clrscr();
    
    while (cont == 'n')
    {
        
        printf("MENU\nPress 1 - 5 to choose options:\n1.Choose new numbers\n2.See your current chosen numbers\n3.See results"\
        "\n4.See frequency of chosen numbers\n5.Quit the Lotto game!");
        
        scanf("%d", &menu_option);
        
        //Each case calls a specific function which the user chooses
        switch(menu_option)
        {
            case 1:             //Choose new numbers
            {
                clrscr();
                scan_chosen_num(choice, &bonus);
                print_chosen(choice, &bonus);
                bubble_sort_chosen(choice);
                break;
            }
            
            case 2:             //Prints numbers
            {
                clrscr();
                
                print_chosen(choice, &bonus);
                break;
            }
            
            case 3:             //Compares chosen numbers to winning numbers and displays results
            {
                clrscr();
                
                compare_results(choice, winning, &bonus);
                break;
            }
            
            case 4:             //Displays the frequency of the numbers the user entered
            {
                clrscr();
                
                accumulator (choice, &bonus, numbers);
                break;
            }
            
            case 5:             //Quits program
            {
                clrscr();
                
                printf("Are you sure you want to quit? (y or n)\n\n");
                //If user chooses "n" the program will reiterate, if "y" exit while loop and end program
                scanf("%1s", &cont);
                clrscr();
                break;
            }
            
            default:
            {
                clrscr();
                printf("Invallid option!");
                break;
            }
        }
        
    }
    
    //Winning numbers are displayed when the user ends the program
    printf("The winning lotto numbers were:");
    
    for(i = 0; i < SIZE; i++)
    {
        printf(" %d", winning[i]);
    }

    getch();
    
}
示例#16
0
//-----------------------
// Send data thread
//----------------------
void test_kasumi::send(){

  // Variables declaration
  int x, y, ret1=0, ret2=0;
  unsigned int  in_read, in_k;

  //Reset routine

  in_file = fopen(INFILENAME, "rt");
  in_kfile = fopen(INFILEKEY, "rt");


  if(!in_file){
    cout << "Could not open " << INFILENAME << endl;
    sc_stop();
  }

  if(!in_kfile){
    cout << "Could not open " << INFILEKEY << endl;
    sc_stop();
  }


  wait();

  while(true){

    do{
      for(x=0; x< DEPTH; x++){
	for(y=0;y< WIDTH;y++){

	  ret1 = fscanf(in_file,"%d", &in_read);
	  if(ret1 == EOF){
	    x= DEPTH; break;
	  }
	    
	  indata[x][y].write(in_read);
	}
      }

      for(x=0; x< 8; x++){
	for(y=0;y< 2;y++){

	  ret2 = fscanf(in_kfile,"%d", &in_k);
	  if(ret2 == EOF){
	    x = 8;
	    break;
	  }

	  k[x][y].write(in_k);
	}
      }
  
    
      if(ret1 == EOF || ret2 == EOF)
	break;

    wait();
    
    }while(1);
 

    fclose(in_file);
    fclose(in_kfile);

    cout << endl << "Starting comparing results " << endl;
 
    compare_results();
    sc_stop();

    wait();

  }//while_loop
}
示例#17
0
int main(int argc, char *argv[])
{
	int nchann, nsample, niter, filtorder;
	int k, opt;
	hfilter filt = NULL;
	void *buffin, *buffout;
	int filein = -1, fileout = -1;
	float fc = FC_DEF;
	size_t buffinsize, buffoutsize;
	uint32_t nchan32, ntotsample32;
	int32_t datintype, datouttype;
	int retval = 1;
	int keepfiles = 0;


	// Process command-line options
	nchann = NCHANN;
	nsample = NSAMPLE;
	niter = NITER;
	filtorder = FILTORDER;
	datouttype = datintype = TYPE_DEF;
	while ((opt = getopt(argc, argv, "hc:s:i:o:f:d:p:k:")) != -1) {
		switch (opt) {
		case 'c':
			nchann = atoi(optarg);
			break;
		case 's':
			nsample = atoi(optarg);
			break;
		case 'i':
			niter = atoi(optarg);
			break;
		case 'o':
			filtorder = atoi(optarg);
			break;
		case 'f':
			fc = atof(optarg);
			break;
		case 'd':
			datintype = atoi(optarg);
			break;
		case 'p':
			ptype = atoi(optarg);
			break;
		case 'k':
			keepfiles = atoi(optarg);
			break;
		case 'h':
		default:	/* '?' */
			fprintf(stderr, "Usage: %s [-c numchannel] [-s numsample] [-i numiteration] "
					"[-o filterorder] [-f cutoff_freq] [-d (0 for float/1 for double)]\n",
				argv[0]);
			exit(EXIT_FAILURE);
		}
	}
	printf("\tfilter order: %i \tnumber of channels: %i \t\tlength of batch: %i\n",filtorder, nchann, nsample);
	set_param(ptype);
	datouttype = datintype;
	if (ptype & RTF_COMPLEX_MASK)
		datouttype |= RTF_COMPLEX_MASK;

	buffinsize = sizeof_data(datintype) * nchann * nsample;
	buffoutsize = sizeof_data(datouttype) * nchann * nsample;
	nchan32 = nchann;
	ntotsample32 = nsample*niter;

	// Allocate buffers
	buffin = align_alloc(16, buffinsize);
	buffout = align_alloc(16, buffoutsize);
	if (!buffin || !buffout) {
		fprintf(stderr, "buffer allocation failed\n");
		goto out;
	}


	// Open files for writing
	filein = open(infilename, O_WRONLY|O_CREAT, S_IRWXU);
	fileout = open(outfilename, O_WRONLY|O_CREAT, S_IRWXU);
	if ((filein < 0) || (fileout < 0)) {
		fprintf(stderr, "File opening failed\n");
		goto out;
	}

	fprintf(stdout, "datin=%i datout=%i ptype=%i\n", datintype, datouttype, ptype );
	// write filter params on fileout
	if (write(fileout, &ptype, sizeof(ptype)) == -1 ||
	    write(fileout, &numlen, sizeof(numlen)) == -1 ||
	    write(fileout, num, numlen*sizeof_data(ptype)) == -1 ||
	    write(fileout, &denumlen, sizeof(denumlen)) == -1 ||
	    write(fileout, denum, denumlen*sizeof_data(ptype)) == -1 ||
	    write(filein, &datintype, sizeof(datintype)) == -1 ||
	    write(filein, &nchan32, sizeof(nchan32)) == -1 ||
	    write(filein, &ntotsample32, sizeof(ntotsample32)) == -1 ||
	    write(fileout, &datouttype, sizeof(datouttype)) == -1 ||
	    write(fileout, &nchan32, sizeof(nchan32)) == -1 ||
	    write(fileout, &ntotsample32, sizeof(ntotsample32)) == -1)
		goto out;



	// set signals (ramps)
	set_signals(nchann, nsample, datintype, buffin);

	// create filters
	filt = rtf_create_filter(nchann, datintype, numlen, num, denumlen, denum, ptype);
	if (!filt) {
		fprintf(stderr,"Creation of filter failed\n");
		goto out;
	}

	// Test the type
	if (datintype != rtf_get_type(filt, 1)
	  || datouttype != rtf_get_type(filt, 0)) {
		fprintf(stderr, "Unexpected data type\n"
		                "expected: in=%i out=%i\n"
				"returned: in=%i out=%i\n",
				datintype, datouttype,
				rtf_get_type(filt, 1),
				rtf_get_type(filt, 0));
		goto out;
	}

	// Filter chunks of data and write input and output on files
	for (k=0; k<niter; k++) {
		rtf_filter(filt, buffin, buffout, nsample);
		if ( write(filein, buffin, buffinsize) == -1
		     || write(fileout, buffout, buffoutsize) == -1 ) {
		        fprintf(stderr,"Error while writing file\n");
			break;
		}
	}
	retval = 0;



out:
	rtf_destroy_filter(filt);
	align_free(buffin);
	align_free(buffout);
	if (filein != -1)
		close(filein);
	if (fileout != -1)
		close(fileout);

#if HAVE_MATLAB
	if (retval == 0)
		retval = compare_results( (datintype & RTF_PRECISION_MASK) ? 1e-12 : 1e-4);
#endif
	if (!keepfiles) {
		unlink(infilename);
		unlink(outfilename);
	}

	return retval;
}
示例#18
0
/*
** Send data thread
*/
void test_aes::send(){

  // Variables declaration
  int i=0;
  unsigned int  in_read, in_read_key;

  //Reset routine
  if (mode == 0) {
    in_file = fopen(INFILENAME, "rt");
  }
  else {
    in_file = fopen(INFILENAME_D, "rt");
  }

  if(!in_file){
    cout << "Could not open " << INFILENAME << "\n";
    sc_stop();
    exit (-1);
  }

  in_file_key = fopen(INFILENAME_KEY, "rt");

  if(!in_file_key){
    cout << "Could not open " << INFILENAME_KEY << "\n";
    sc_stop();
    exit (-1);
  }

  for(i=0; i < SIZE; i ++){
    idata[i].write(0); 
    fscanf(in_file_key, "%x", &in_read_key);
    input_key[i] = in_read_key;
  }
  i = 0;

//  wait();

  while(true){
   
    while(fscanf(in_file,"%x", &in_read) != EOF){
	idata[i].write(in_read);
	ikey[i].write(input_key[i]);
       	i++;
	
	if(i == SIZE){
	  i = 0;
	  wait();
	}
      }
  
  
  
    fclose(in_file);
    fclose(in_file_key);

    cout << endl << "Starting comparing results " << endl;
   
   wait();
   compare_results(); 
   exit(-1);

  }//while_loop
}