Beispiel #1
0
bool City::load_data(std::istream& data)
{
  clear_data();

  data >> uid;
  std::string tmpstr;
  while (tmpstr != "!") {
    data >> tmpstr;
    if (tmpstr != "!") {
      if (!name.empty()) {
        name = name + " ";
      }
      name = name + tmpstr;
    }
  }
  int tmptype, tmprace;
  data >> tmptype >> tmprace;
  if (tmptype >= CITY_TYPE_MAX || tmptype <= 0) {
    debugmsg("City '%s' has type value of %d (range is 1 - %d)!",
             name.c_str(), tmptype, CITY_TYPE_MAX - 1);
    return false;
  }
  if (tmprace >= RACE_MAX || tmptype <= 0) {
    debugmsg("City '%s' has race value of %d (range is 1 - %d)!",
             name.c_str(), tmprace, RACE_MAX - 1);
    return false;
  }
  type = City_type(tmptype);
  race = Race(tmprace);

  data >> location.x >> location.y;

  if (!map.load_data(data)) {
    debugmsg("City '%s' failed to load map.", name.c_str());
    return false;
  }

  int num_routes;
  data >> num_routes;
  for (int i = 0; i < num_routes; i++) {
    int tmpuid;
    Trade_route tmproute;
    data >> tmpuid;
    if (!tmproute.load_data(data)) {
      debugmsg("City '%s' failed to load trade route to City %d.",
               name.c_str(), tmpuid);
      return false;
    }
    trade_routes[tmpuid] = tmproute;
  }

  for (int i = 0; i < CIT_MAX; i++) {
    if (!population[i].load_data(data)) {
      debugmsg("City '%s' failed to load %s data.",
               name.c_str(), citizen_type_name(Citizen_type(i), true).c_str());
      return false;
    }
  }

  for (int i = 0; i < RES_MAX; i++) {
    data >> resources[i];
  }

  for (int i = 0; i < MINERAL_MAX; i++) {
    data >> minerals[i];
  }

  int num_animals;
  data >> num_animals;
  for (int i = 0; i < num_animals; i++) {
    int tmpanimal, tmpnum;
    data >> tmpanimal >> tmpnum;
    if (tmpanimal <= 0 || tmpanimal >= ANIMAL_MAX) {
      debugmsg("City '%s' had animal of index %d (Range is 1 to %d)",
               name.c_str(), tmpanimal, ANIMAL_MAX - 1);
      return false;
    }
    livestock[ Animal(tmpanimal) ] = tmpnum;
  }

  return true;
}
Beispiel #2
0
 void clear_rek()
  {
   for(int i=0; i < KOLENTER; i++)
     gtk_entry_set_text(GTK_ENTRY(entry[i]),"");
   zap_zaktaxi.clear_data();
  }
Beispiel #3
0
Info_tab::Info_tab(QWidget *parent_P, const char *name_P) : Info_tab_ui(parent_P, name_P)
{
    clear_data();
}
void start_a_diagonal_homotopy(int myid, int numbprocs, char *name_1, 
                               char *name_2, char *outfile, WSET *ws,
                               int num_group, int stages, int cnt_stage, 
                               int cnt_step,
                               IDLE_ELEMENT **ie, LISTELEMENT **listpointer,
                               int *TaskCount, int NUM_GROUP, int NUM_VARS, 
                               int *cnt_index, int *expected,
                               int *dim, int update_flag)                           
{
   int n, deg, n1, n2, dim1, dim2, deg1, deg2, cd, nbsols,
       fail, i, slv, count;
   double vcp[34];
  
   if(myid==0)
   {
     printf("manager is in inside of start_a_diagonal_homotopy\n"); 
                           
     fail = read_two_witness_sets_from_file(&n1,&n2,&dim1,&dim2,
                                            &deg1,&deg2,name_1,name_2,&cd);
     n = cd; /* dimension */
     nbsols = deg1*deg2;
     printf("#paths to track: %d\n", nbsols);
     
     fail = define_output_file_with_string ((int)strlen(outfile), outfile);
     
     fail = standard_diagonal_homotopy(dim1,dim2);
     if(fail == 0)
     {
      fail = write_standard_target_system();
      fail = write_standard_start_system();
     }
     /*fail = tune_continuation_parameters(); printf("\n");*/
     fail = retrieve_continuation_parameters(vcp);
     write_solution_banner_to_defined_output_file(nbsols,n);
     printf("\nSee the output file %s for results...\n\n", outfile);  
     *expected = dim1+dim2-NUM_VARS;  
     printf("expected dimension=%d\n", *expected);
   }       
   
   dimension_broadcast(myid,&n);
  
   MPI_Bcast(&nbsols,1,MPI_INT,0,MPI_COMM_WORLD);
   MPI_Bcast(vcp,34,MPI_DOUBLE,0,MPI_COMM_WORLD);
   
   if(myid != 0) 
   {
      fail = set_continuation_parameters(vcp);
   }
   
   fail = homotopy_broadcast(myid,n);
   fail = create_homotopy_with_given_gamma
                (-0.824263733224601,0.566206056211557);
   
   if(myid == 0)
   {
     send_collect(ws, num_group, stages, cnt_stage, numbprocs, cnt_step, 
                  ie, listpointer, TaskCount, NUM_GROUP,
                  cnt_index, update_flag, 
                  n1, n2, cd);
   
     if(v>3)
     {   
     printf("after send_collect \n");
     printf("%d JOBs in listpointer. \n", length(*listpointer));
     printf("%d idles\n", num_idle(*ie));
     printf("indexing........ with cnt_index=%d\n", *cnt_index);    
     }                 
   }
   else
   {   
     if(v>3) printf("node %d will run run_slave \n", myid); fflush;
     run_slave(myid); 
   }
   
   MPI_Barrier(MPI_COMM_WORLD);
                            
   if(myid == 0)
   { 
     if(v>3) printf("manager clear data \n"); 
     fail = clear_data(); 
     if(fail>0) printf("manager fail to clear data.\n"); 
     fail = clear_homotopy(); 
     if(fail>0) printf("manager fail to clear homotopy.\n"); 
     fail = solcon_close_solution_input_file(1);
     if(fail>0) printf("fail to close witness set 1.\n");
     fail = solcon_close_solution_input_file(2); 
     if(fail>0) printf("fail to close witness set 2.\n");
     fail = solcon_clear_standard_solutions( );  
     if(fail>0) printf("fail to clear solution container.\n");
     fail = close_output_file();
     if(fail>0) printf("fail to close output file. \n"); 
     fail = read_witness_set_from_file((int)strlen(outfile),
                                       outfile,&n,dim,&deg); 
     fail = solcon_clear_standard_solutions();
     fail = syscon_clear_standard_system( );
     printf("end of start_a_diagonal_homotopy\n");
     fflush;
   }
   else 
   {
     if(v>3) printf("node %d clear data.\n", myid); 
     fail = clear_data();
     if(fail>0) printf("node %d fail to clear data.\n", myid);
     fail = clear_homotopy();
     if(fail>0) printf("node %d fail to clear homotopy.\n", myid);
   }
}
void cascade_one_level_down(int myid, int numbprocs, char *infile, 
                            char *outfile, WSET *ws, int num_group, 
                            int stages, int cnt_stage, int cnt_step, IDLE_ELEMENT **ie, 
                            LISTELEMENT **listpointer, int *TaskCount,
                            int NUM_GROUP, int *dimension, int *cnt_index, 
                            int update_flag)
{
   int n,/* dimension */
       nbsols, dim, deg, fail, i,
       n1, n2, cd;   
   double vcp[34];
  
   if(myid == 0)
   {
     printf("manager is in inside of cascade_one_level_down\n");        
     read_dimension_of_system((int)strlen(infile),infile,&n);
   }
   
   dimension_broadcast(myid,&n);
   
   if(myid == 0)
   {
     fail = syscon_clear_symbol_table();
     fail = read_named_start_without_solutions((int)strlen(infile),infile);  
     /*fail = copy_start_system_to_container();*/
     fail = copy_start_system_to_container();
     fail = syscon_sort_embed_symbols(&dim);
     printf("the top dimension is %d\n",dim);
     fail = copy_container_to_start_system();
      
     fail = solcon_scan_solution_banner();
     fail = solcon_read_solution_dimensions(&nbsols,dimension); 
   }
   else
     /* initialize system container */
     fail = syscon_initialize_number_of_standard_polynomials(n);
   
   monomials_broadcast(myid,n);            /* broadcast container */

   if(myid != 0)                           /* copy result of broadcast */
   {
      fail = copy_container_to_start_system();
      fail = syscon_clear_standard_system();  /* clear system container */
   }
   
   fail = create_cascade_homotopy(); 
   
   MPI_Barrier(MPI_COMM_WORLD);
   if(myid == 0)
   {
      if(v>3) printf("# paths to track : %d\n",nbsols);
      fail = define_output_file_with_string ((int)strlen(outfile), outfile);
      
      fail = write_standard_target_system();
      fail = write_standard_start_system(); 
      /*fail = tune_continuation_parameters(); printf("\n");*/
      fail = retrieve_continuation_parameters(vcp);     
      write_solution_banner_to_defined_output_file(nbsols,n);
      printf("\nSee the output file for results...\n\n");
   }
   
   MPI_Bcast(&nbsols,1,MPI_INT,0,MPI_COMM_WORLD);
   MPI_Bcast(vcp,34,MPI_DOUBLE,0,MPI_COMM_WORLD);
    
   if(myid != 0) 
   {
      fail = set_continuation_parameters(vcp); 
   } 
   if(myid == 0)
   {
      n1=0; n2=0; cd=n;
      send_collect(ws, num_group, stages, cnt_stage, numbprocs, cnt_step, 
                   ie, listpointer, TaskCount, NUM_GROUP,
                   cnt_index, update_flag, 
                   n1, n2, cd);  
      if(update_flag) *cnt_index=*cnt_index+1;
      
      if(v>3)
      {                         
       printf("after send_collect \n");
       printf("%d JOBs in listpointer. \n", length(*listpointer));
       printf("%d idles\n", num_idle(*ie));
       printf("indexing........ with cnt_index=%d\n", *cnt_index);  
      }                             
   }
   else
   {  
      if(v>3) printf("node %d will run run_slave \n", myid); fflush;
      run_slave(myid); 
   }
      
   MPI_Barrier(MPI_COMM_WORLD);
                          
   if(myid == 0)
   { 
      if(v>3) printf("manager clear data \n"); 
      fail = clear_data(); 
      if(fail>0) printf("manager fail to clear data.\n"); fflush;
      fail = solcon_close_solution_input_file(0);
      if(fail>0) printf("fail to close solution input file.\n");
      fail = solcon_clear_standard_solutions( );  
      if(fail>0) printf("fail to clear solution container.\n");
      fail = close_output_file();
      if(fail>0) printf("fail to close output file. \n");
      fflush;	 
   } 
   else 
   {
      if(v>3) printf("node %d clear data \n", myid); 
      fail = clear_data(); 
      if(fail>0) printf("node %d fail to clear data.\n", myid); 
      fflush; 
   }
}
RTChatBuffStreamPool::~RTChatBuffStreamPool()
{
    clear_data();
}
void MainWindow::choose_file_button_clicked()
{   try {
        QString fileName = QFileDialog::getOpenFileName(this,QString::fromUtf8("Choose File"),QDir::currentPath(),"Text(*.txt)");
        if (fileName.length() != 0) {
            // ДАЛЕЕ ОЧИСТКА ЗНАЧЕНИЙ!!!
            clear_data();
            clear_lines();

            ui->fileName->setText(fileName);
            QFile my_file(fileName);
            my_file.open(QIODevice::ReadOnly);
            if (my_file.isOpen())
                while (!my_file.atEnd()) {
                    QString exmpl = changeOnDoTA(my_file.readLine());
                    double obj = exmpl.toDouble();
                    started_data.push_back(obj);
                }

            try {

                set_average_data();

               // qDebug() << max_x << " " << min_x;
                set_square_deviation();
                set_Sx();
    //            for (int i = 0; i < started_data.size(); i++)
    //                qDebug() << started_data[i];
                set_r(); //  КИДАЕТ ВНУТРЕННИЙ ЭКСЕПШЕН!
                set_h();

                fill_intervals();
                set_f();
                set_middle_value();
                set_middle_value2();
                set_average_of_intervals();
                set_si();
                set_n_i();
                set_xi_sq();

                choose_quantile();

//                qDebug() << "BEgin";
//                for (int i = 0;i < started_data.size();i++)
//                    qDebug() << started_data[i];
//                qDebug() << "END";

                set_lines();
                for (int i = 0; i < intervals.size();i++) {
                    for (int j = 0; j < intervals[i].size();j++)
                        qDebug() << intervals[i][j];
                    qDebug() << "end_line";
                }

              //  check_result();

                is_chButton_clicked_flag = true;
                my_file.close();
            } catch(std::exception &e){
                clear_data();
                clear_lines();
                is_chButton_clicked_flag = false;
                QMessageBox::critical(this,"Not Valid!!!",e.what());
            }
        }
        else {
            throw (std::invalid_argument("Choose txt File!"));
        }
    } catch(std::exception& e) {
        clear_data();
        clear_lines();
        is_chButton_clicked_flag = false;
       // QMessageBox::critical(this, "Error!",e.what());
    }

}
static int verify_eraseblock(int ebnum)
{
	size_t read = 0;
	int err = 0;
	loff_t addr = ebnum * mtd->erasesize;

	set_random_data(writebuf, subpgsize);
	clear_data(readbuf, subpgsize);
	read = 0;
	err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
	if (unlikely(err || read != subpgsize)) {
		if (err == -EUCLEAN && read == subpgsize) {
			printk(PRINT_PREF "ECC correction at %#llx\n",
			       (long long)addr);
			err = 0;
		} else {
			printk(PRINT_PREF "error: read failed at %#llx\n",
			       (long long)addr);
			return err ? err : -1;
		}
	}
	if (unlikely(memcmp(readbuf, writebuf, subpgsize))) {
		printk(PRINT_PREF "error: verify failed at %#llx\n",
		       (long long)addr);
		printk(PRINT_PREF "------------- written----------------\n");
		print_subpage(writebuf);
		printk(PRINT_PREF "------------- read ------------------\n");
		print_subpage(readbuf);
		printk(PRINT_PREF "-------------------------------------\n");
		errcnt += 1;
	}

	addr += subpgsize;

	set_random_data(writebuf, subpgsize);
	clear_data(readbuf, subpgsize);
	read = 0;
	err = mtd->read(mtd, addr, subpgsize, &read, readbuf);
	if (unlikely(err || read != subpgsize)) {
		if (err == -EUCLEAN && read == subpgsize) {
			printk(PRINT_PREF "ECC correction at %#llx\n",
			       (long long)addr);
			err = 0;
		} else {
			printk(PRINT_PREF "error: read failed at %#llx\n",
			       (long long)addr);
			return err ? err : -1;
		}
	}
	if (unlikely(memcmp(readbuf, writebuf, subpgsize))) {
		printk(PRINT_PREF "error: verify failed at %#llx\n",
		       (long long)addr);
		printk(PRINT_PREF "------------- written----------------\n");
		print_subpage(writebuf);
		printk(PRINT_PREF "------------- read ------------------\n");
		print_subpage(readbuf);
		printk(PRINT_PREF "-------------------------------------\n");
		errcnt += 1;
	}

	return err;
}
int main(int argc, char *argv[])
{
	char str_to_write[1024];
	int i0 = 0;
	int  fd_read;
	int  fd;
	int  ret = 0;

	char sn_header[16];
	char serial_number[SN_MAX_LEN];
	char *str_sn;
	char str_slip[] = "-";
	char arg_val[8][64];
	CARD_INFO *card_data;
	CARD_INFO *card_tmp;
	char *str_read;

	int fd0;
	char buf[sizeof(char)+1];
	char str_storeu[2048];
	int read_flag = 0;
#ifdef DEBUG_IN_LINUX
	char m_data[2048];
#endif

	char cmd_buf[256];
	CARD_INFO *card_store[MAX_CARD_NUMBER];

	memset(str_to_write  , 0x0 , sizeof(str_to_write));
	memset(sn_header     , 0x0 , sizeof(sn_header));
	memset(serial_number , 0x0 , sizeof(serial_number));
	memset(cmd_buf       , 0x0 , sizeof(cmd_buf));
#ifdef DEBUG_IN_LINUX
	memset(m_data        , 0x0 , sizeof(m_data));
#endif
	#ifdef ENABLE_STRUCT
	i0 = 0;
	while(i0 < sizeof(card_store)/sizeof(CARD_INFO))
	{
		memset(card_store,0x0,sizeof(CARD_INFO));
		i0++;
	}
	#endif
	prepare_env();

	//read_file_from_mmc();
	/* go out if argument less than 2 */
	if(argc < 2)
	{
#ifdef DEBUG_IN_LINUX
		//testRSAGen();
		//encrypt_write_data("test data!",0);
		//decrypt_read_data(m_data);
		//JCG("read -->\n%s\n",m_data);
#endif
		JCG("bad args, should be ./q YCT-000000123455; ./q read; ./q write etc.");
		ret = -1;
		goto RET_ERR;
	}
	JCG("argv[0]:%s, argv[1]:%s.\n",argv[0],argv[1]);

	if(strcasecmp(argv[1],"clear") == 0)
	{
		clear_data();
		JCG("clear");
		ret = 0;
		goto RET_SUCC;
	}

	#ifdef MAC_WRITER_SUPPORT
	else if(strncasecmp(argv[1],"mac",sizeof("mac")) == 0)
	{
		ret = main_mac(argc,argv);
		JCG(" MAC Writer!!");
		goto RET_SUCC;
	}
	#endif

	else if(strcasecmp(argv[1],"read") == 0)
	{
#if 0
		char str_store[2048];

		char cmd_buf[256];
		char data_buf[256];

		memset(cmd_buf       , 0x0 , sizeof(cmd_buf));
		memset(data_buf      , 0x0 , sizeof(data_buf));

		/* read data from flash*/
		read_data(NULL, str_store);
		JCG("get read data:%s\n",str_store);
#else
		char get_read_data[2048];
		/* read data from flash*/
		read_file_from_mmc();
		#ifdef ENABLE_STRUCT
		card_data = (CARD_INFO*) malloc(sizeof(CARD_INFO));
		read_data(card_data, NULL);
		card_tmp = card_data->next;
		print_card_info(card_data);
		free(card_data);
		#else	//not ENABLE_STRUCT
		memset(get_read_data,0x0,sizeof(get_read_data));
		read_data(NULL, get_read_data);
		JCG("get data -->\n%s\n",get_read_data);
		#endif
#endif
 		JCG("read");
		ret = 0;
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"del",3) == 0)
	{
		/* read data from flash*/
		delete_data(argv[1], NULL);
 		JCG("delete");
		ret = 0;
		write_file_to_mmc();
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"search",strlen("search")) == 0)
	{
		search_data(NULL);
		ret = 0;
		goto RET_SUCC;
	}

	else if(strncasecmp(argv[1],"mmcread",strlen("mmcread")) == 0)
	{
		read_file_from_mmc();
		ret = 0;
		goto RET_SUCC;
	}
	else if(strncasecmp(argv[1],"mmcwrite",strlen("mmcwrite")) == 0)
	{
		write_file_to_mmc();
		ret = 0;
		goto RET_SUCC;
	}
	else if(strncasecmp(argv[1],"rmda",strlen("rmda")) == 0)
	{
		delete_data_file();
		ret = 0;
		goto RET_SUCC;
	}

	JCG("-------- format: ./mac_writer YHK-000000123455 ---------------------------");
	write_data(argv[1], NULL);
	JCG("-----------------------------------");
	ret = 0;
	write_file_to_mmc();
	goto RET_SUCC;

RET_SUCC:
#ifdef DEBUG_IN_ANDROID
	property_set("persist.sys.mac_writer.proc" ,"done");
#else
#endif
	destroye_env();

	return ret;
RET_ERR:
	destroye_env();
	return ret;

}
Beispiel #10
0
void signal_callback_handler()
{
	printf("signal callback handler\n");
	clear_data(&data_RP);
	exit(0);//must exit whereas it return into main
}
Beispiel #11
0
int main ( int argc, char ** argv )
{
	// Parse command line options
    //
    int use_gpu = 1;
    int use_interop = 0;
    for(int i = 0; i < argc && argv; i++)
    {
        if(!argv[i])
            continue;
            
        if(strstr(argv[i], "cpu"))
            use_gpu = 0;        

        else if(strstr(argv[i], "gpu"))
            use_gpu = 1;

        else if(strstr(argv[i], "interop"))
            use_interop = 1;
    }

    printf("Parameter detect %s device (%s)\n",use_gpu==1?"GPU":"CPU",use_interop==1?"Share OpenGL":"Not Sharing OpenGL");

	OPENCL_SHARE_WITH_OPENGL = use_interop;

  	//testCG();
  	win_x = 512;
	win_y = 512;
  
  
	glutInit ( &argc, argv );
  
	open_glut_window ();
 
  //test_opencl_opengl_interop();
  
  
  dt = 0.1f;
  force = 10.0f;
  source = 10.0f;
	

	printf ( "\n\nHow to use this demo:\n\n" );
	printf ( "\t Add densities with the left mouse button\n" );
	printf ( "\t Add velocities with the left mouse button and dragging the mouse\n" );
	printf ( "\t Toggle density/velocity display with the 'v' key\n" );
	printf ( "\t Clear the simulation by pressing the 'x' key\n" );
  printf ( "\t switch poisson solvers from jacobi to conjugate gradient by pressing the 'c' key\n" );
  printf ( "\t switch advection scheme from RK2 to MacCormack by pressing the 'm' key\n" );
  printf ( "\t toggle vorticity confinement by pressing the 'o' key\n" );
  
	printf ( "\t Quit by pressing the 'q' key\n" );

	dvel = 0;

	step = 0;
	maccormack = 0;
	vorticity = 0;
  useCG = 0;
	
	if ( !allocate_data () ) exit ( 1 );
	clear_data ();
  

  
  //setupMatrix(g_laplacian_matrix);

//	FOR_EACH_FACE
//	{
//		//if(i < NX - NX*0.4 && i > NX*0.4 
//		//	&&
//		//   j < NY - NY*0.4 && j > NY*0.4 )
//		{
//			g_u_prev[IX(i,j,0)] =  -0.01 * cosf(3.14159 * 2.0 * i/NX);
//			g_v_prev[IX(i,j,0)] =  0.01 * sinf(3.14159 * 2.0 * j/NY);
//		}
//	}

#if RUN_TIMINGS
  runTimings(use_gpu);
  exit(0);
#endif
  
	copy_grid(g_u_prev, g_u);
	copy_grid(g_v_prev, g_v);
  
  g_dens_prev[IX(16,3,0)] = 10.0f;
  //g_u_prev[IX(16,3,0)] = 10.0f;
  
	/*
	calculate_divergence(g_divergence, g_u_prev, g_v_prev, g_w_prev, dt);
	pressure_solve(g_pressure,g_pressure_prev, g_divergence, dt);
	pressure_apply(g_u_prev, g_v_prev, g_w_prev, g_pressure, dt);
	//project(dt,g_u_prev,g_v_prev, g_w_prev, g_divergence, g_pressure, g_pressure_prev);
	SWAP(g_u_prev,g_u);
	SWAP(g_v_prev,g_v);
	SWAP(g_w_prev,g_w);

	if(!check_divergence(g_u_prev, g_v_prev, g_w_prev))
	{
		printf("Initial field wasn't divergence free!\n");
	}
	*/


//print_platforms_devices();
//  run_opencl_test(use_gpu);
  
//	run_tests();
   
  
#if USE_OPENCL
   init_opencl(use_gpu);
   load_cl_kernels(&clData);
   allocate_cl_buffers(&clData);
  
  
   transfer_buffers_to_gpu();
   
   flush_cl_queue();
#endif
   
   
  

	glutMainLoop ();

#if USE_OPENCL
   cleanup_cl(&clData);
#endif
  
	exit ( 0 );
}
 /*
 * Destructor. Clear any present data.
 */
Superpixel::~Superpixel() 
{
    clear_data();
}
MeshSubWindow::~MeshSubWindow(void)
{
	clear_data();
}
Beispiel #14
0
		void exit(){
            clear_data();
			cout<<"exit and clear!"<<endl;
		}