Ejemplo n.º 1
0
void data_server(int argc, char *argv[])
{
	int np; 
	MPI_Comm_size(MPI_COMM_WORLD, &np);
	MPI_Status status;

	int num_comp_nodes = np -1;
	unsigned int num_bytes = sizeof(sAgents);
	sAgents h_agents_in, h_agents_out[num_comp_nodes];


	/* initialize input data */
	init_data(h_agents_in);

	#ifdef DEBUG 
	printf("Init data\n");
	display_data(h_agents_in);
	#endif

	/* send data to compute nodes */
	for(int process = 0; process < num_comp_nodes; process++)
		MPI_Send(&h_agents_in, num_bytes, MPI_BYTE, process, 0, MPI_COMM_WORLD);
		
	runDisplay(argc, argv);
	
	/* release resources */
	//free(&h_agents_in);
	//free(&h_agents_out); 
}
Ejemplo n.º 2
0
int main()    
{	
	InitData();	 					
	
	while(1) {

		ReadTimeAndJudgeAlarmArrival();

		switch (mainLoop) {
		case 0:
			display_time();
			break;
		case 1:
			display_data();
			break;
		case 2:
			display_alarm();
			break;
		case 3:
			display_sWatch();
			break;
		}
		KeyScan();
	}

	return 0;
}
Ejemplo n.º 3
0
void serial_process(void)
{
    uint8_t serial_channel = serial_readFrame();
    packet_t *packet;

    if( serial_channel == 0 ){
        return;
    }

    if( serial_channel == 0xFF ||
            serial_channel == 0xFE ){
        display_data(serial_channel,
                serial_getMessage(), serial_getMessageLen());
        return;
    }

    if( serial_getMessageLen() == 16 ){
        uint8_t *msg = serial_getMessage();
        if( serial_channel == '0' ){
            packet = (packet_t *) msg;

            if( packet_check_magic(packet) ){
                cmd_new(packet->cmd, packet->data);
            }
        }else if(serial_channel != 0) {
            bus_sendFrame(serial_channel, msg, 16);
        }
    }
}
Ejemplo n.º 4
0
/*! 
 * Init Display
 */
void display_init(void){
	shift_init();

	DISPLAY_DDR |= DISPLAY_OUT;		// Ausgänge
	DISPLAY_DDR &= ~DISPLAY_IN;		// Eingänge

	delay(30);		// Display steht erst 10ms nach dem Booten bereit
	
	// Register in 8-Bit-Modus 3x Übertragen, dazwischen warten
	shift_data_out(0x38,SHIFT_LATCH,SHIFT_REGISTER_DISPLAY);
	DISPLAY_PORT= DPC;
	delay(5);		
	shift_data_out(0x38,SHIFT_LATCH,SHIFT_REGISTER_DISPLAY);
	DISPLAY_PORT= DPC;
	delay(5);		
	shift_data_out(0x38,SHIFT_LATCH,SHIFT_REGISTER_DISPLAY);
	DISPLAY_PORT= DPC;
	delay(5);		
	
	display_cmd(0x0f);  		//Display On, Cursor On, Cursor Blink
	
	display_cmd(DISPLAY_CLEAR); // Display l�schen, Cursor Home
	
	display_data('i');
}
Ejemplo n.º 5
0
static void as_event(enum sys_message msg)
{


	if ( (msg & SYS_MSG_RTC_MINUTE) == SYS_MSG_RTC_MINUTE)
	{
		if(sAccel.mode == ACCEL_MODE_ON) sAccel.timeout--;
		//if timeout is over disable the accelerometer
		if(sAccel.timeout<1)
		{
			//disable accelerometer to save power			
			as_stop();
			//update the mode to remember
			sAccel.mode = ACCEL_MODE_OFF;
		}

	}
	if ( (msg & SYS_MSG_AS_INT) == SYS_MSG_AS_INT)
	{
		//Check the vti register for status information
		as_status.all_flags=as_get_status();
		//TODO For debugging only
		_printf(0, LCD_SEG_L1_1_0, "%1u", as_status.all_flags);	
		buzzer_play(smb);
		//if we were in free fall or motion detection mode check for the event
		if(as_status.int_status.falldet || as_status.int_status.motiondet){

			//if such an event is detected enable the symbol
			//display_symbol(0, LCD_ICON_ALARM , SEG_SET | BLINK_ON);
			
			//read the data
			as_get_data(sAccel.xyz);
			//display_data(0);
			/* update menu screen */
			lcd_screen_activate(0);

		}//if we were in measurment mode do a measurement and put it in the virtual screen
		else
		{

			//display_symbol(0, LCD_ICON_ALARM , SEG_SET | BLINK_OFF);
			display_data(1);
			/* refresh to accelerometer screen only if in that modality */
			if (submenu_state== VIEW_AXIS )lcd_screen_activate(1);

		}
	}
	/* The 1 Hz timer is used to refresh the menu screen */
	if ( (msg & SYS_MSG_RTC_SECOND) == SYS_MSG_RTC_SECOND)
	{
	/*check the status register for debugging purposes */
	_printf(0, LCD_SEG_L1_1_0, "%1u", as_read_register(ADDR_INT_STATUS));	
	/* update menu screen */
	lcd_screen_activate(0);
	}

}
Ejemplo n.º 6
0
void			actualize_data(t_vm *vm, t_proc **lproc)
{
  SDL_Rect		pos;
  SDL_Surface		*surface;

  pos.x = 50;
  pos.y = HEIGHT - SIDEBAR_SIZE;
  surface = SDL_CreateRGBSurface(SDL_HWSURFACE, 400,
				 SIDEBAR_SIZE - 15, 32, 0, 0, 0, 0);
  SDL_FillRect(surface, NULL, SDL_MapRGB(vm->sdl->screen->format, 0, 0, 0));
  SDL_BlitSurface(surface, NULL, vm->sdl->screen, &pos);
  SDL_FreeSurface(surface);
  display_data(vm->sdl->screen, vm->cycle, &display_cycle, "Cycle : ");
  display_data(vm->sdl->screen, vm->ctd, &display_ctd, "Cycle to die : ");
  display_data(vm->sdl->screen, vm->nb_proc, &display_nb_proc,
	       "Number of procs : ");
  display_data(vm->sdl->screen, vm->nb_live, &display_nb_live,
	       "Number of live : ");
}
Ejemplo n.º 7
0
int
main(void)
{
    /* Fill memory with pseudo-random data */
    init_data(LENGTH);

    /* Display unsorted */
    printf("\nUnsorted:\n");
    display_data(LENGTH);

    /* Sort */
    printf("\nSorting:\n");
    sort(LENGTH);

    /* Display sorted */
    printf("\nSorted:\n");
    display_data(LENGTH);
    printf("\n");

    return 0;
}
Ejemplo n.º 8
0
static int do_info(sc_card_t *card, const struct ef_name_map *map)
{
	int i;
	u8 buf[2048];

	for (i = 0; map[i].ef != NULL; i++) {
		sc_path_t path;
		sc_file_t *file;
		size_t count;
		int r;

		sc_format_path(map[i].ef, &path);
		r = sc_select_file(card, &path, &file);
		if (r) {
			util_error("failed to select EF %s: %s", map[i].ef, sc_strerror(r));
			return EXIT_FAILURE;
		}

		count = file->size;
		if (!count)
			continue;

		if (count > sizeof(buf) - 1) {
			util_error("too small buffer to read the OpenPGP map");
			return EXIT_FAILURE;
		}

		r = sc_read_binary(card, 0, buf, count, 0);
		if (r < 0) {
			util_error("failed to read %s: %s", map[i].ef, sc_strerror(r));
			return EXIT_FAILURE;
		}
		if (r != (signed) count || (size_t) r < map[i].offset + map[i].length) {
			util_error("%s: expecting %"SC_FORMAT_LEN_SIZE_T"d bytes, got only %d",
				map[i].ef, count, r);
			return EXIT_FAILURE;
		}
		if (map[i].offset > 0) {
			memmove(buf, buf + map[i].offset, map[i].length);
			count -= map[i].offset;
		}
		if (map[i].length > 0 && count > map[i].length)
			count = map[i].length;
		if (map[i].type == TYPE_STRING)
			buf[count] = '\0';

		display_data(&map[i], buf, count);
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
void run_memtop(void) {
    //TODO: initialization for read and select
    fd_set rd;
    struct timeval timeout;
    int bytes;
    char buf[BUFFER_SIZE];
    // Should I put this code insize FD_ISSET or where?
    // With
    if (fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK) == -1) {
                perror("fcntl()\n");
    }
    //to avoid unused variable warning. You may remove it once you use buf.
    buf[0] = 0;
    while(1) {
        //TODO: call select, read, and process_data
        FD_ZERO(&rd);               // Clear the fd set
        FD_SET(STDIN_FILENO,&rd);   // Fill the fd set
        timeout.tv_sec  = 0;        // Waiting time is 0
        timeout.tv_usec = 0;         
        if (select(1,&rd,NULL,NULL,&timeout) == -1) {
            perror("select()");
        }
        // Check if STDIN_FILENO ready or not 
        if (FD_ISSET(STDIN_FILENO,&rd)) {
            // read up to BUFFER_SIZE bytes
            
            if ((bytes = read(STDIN_FILENO,buf,BUFFER_SIZE)) == -1) {
                perror("read()\n");
            }
            if (process_input(buf,bytes) != 0) {
                break;
            }
        }

        //read proc filesystem
        int n_procs = 0;
        process_t *proc_arr = collect_data(&n_procs);

        if (proc_arr == NULL) {
            continue;
        }

        sort_data(proc_arr, n_procs);
        //update display
        display_data(proc_arr, n_procs);
                //free proc_data
        free(proc_arr);
    }
}
Ejemplo n.º 10
0
int main()
{
    /* Main variables */
    //t.start();
    CN0216 cn0216;
#ifdef SINGLE_CONVERSION
    cn0216.init(CAL_WEIGHT);
#elif defined CONTINOUS_CONVERSION
    cn0216.init(CAL_WEIGHT, 0x08, 0x07);
#else
#error define SINGLE_CONVERSION or CONTINOUS_CONVERSION, but not both
#endif
    /* Calibration sequence */

    pc.printf("\r\n Calibrating zero scale. Remove all weights from scale. Press any key to begin ..");
    while(!pc.readable());
    flush_serial_buffer();
    pc.printf("\r\n Calibrating . . . ");
    cn0216.calibrate(CN0216::ZERO_SCALE_CALIBRATION);
    pc.printf("done ! ");

    pc.printf("\r\n Calibrating full scale. Put calibration weight on scale. Press any key to begin ..");
    while(!pc.readable());
    flush_serial_buffer();
    pc.printf("\r\n Calibrating . . . ");
    cn0216.calibrate(CN0216::FULL_SCALE_CALIBRATION);
    pc.printf("done ! ");

    pc.printf("\r\n Calibration successful ");
    cn0216.calibrate(CN0216::COMPUTE_UNITS_PER_BIT);

    /* Infinite loop */
    uint64_t timer = 0;
    while (1) {
        wait_ms(1000);

        uint32_t data = cn0216.read_u32();
        float weight    = cn0216.compute_weight(data); //  Convert ADC data to voltage
        display_data(data, weight, timer); //  Display data thru UART

        timer++;
    }


    /* Infinite loop, never returns. */
}
Ejemplo n.º 11
0
static int do_userinfo(sc_card_t *card)
{
	int i;
	/* FIXME there are no length checks on buf. */
	unsigned char buf[2048];

	for (i = 0; openpgp_data[i].ef != NULL; i++) {
		sc_path_t path;
		sc_file_t *file;
		size_t count;
		int r;

		sc_format_path(openpgp_data[i].ef, &path);
		r = sc_select_file(card, &path, &file);
		if (r) {
			fprintf(stderr, "Failed to select EF %s: %s\n", openpgp_data[i].ef, sc_strerror(r));
			return EXIT_FAILURE;
		}

		count = file->size;
		if (!count)
			continue;

		if (count > sizeof(buf) - 1) {
			fprintf(stderr, "Too small buffer to read the OpenPGP data\n");
			return EXIT_FAILURE;
		}

		r = sc_read_binary(card, 0, buf, count, 0);
		if (r < 0) {
			fprintf(stderr, "%s: read failed - %s\n", openpgp_data[i].ef, sc_strerror(r));
			return EXIT_FAILURE;
		}
		if (r != (signed)count) {
			fprintf(stderr, "%s: expecting %"SC_FORMAT_LEN_SIZE_T"d, got only %d bytes\n",
				openpgp_data[i].ef, count, r);
			return EXIT_FAILURE;
		}

		buf[count] = '\0';

		display_data(openpgp_data + i, (char *) buf);
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 12
0
BK_U8B display_error_printf(const char * format, ...)
{
   char display_buf[DISPLAY_BUFFER_SIZE]; /*!< Pufferstring fuer Displayausgaben */
   va_list args;
   /* Sicher gehen, dass der zur Verfuegung stehende Puffer nicht ueberlaeuft */
   va_start(args, format);
   const BK_U8B len = (BK_U8B) vsnprintf(display_buf, DISPLAY_BUFFER_SIZE, format, args);
   va_end(args);
   /* Ausgeben bis Puffer leer ist */
   char * ptr = display_buf;
   BK_U8B i;
   for (i = len; i > 0; --i) {
      display_data(*ptr++);
   }
   /* Ausgeben bis Puffer leer ist */
   return len;
}
Ejemplo n.º 13
0
Archivo: fdf.c Proyecto: lgarczyn/fdf
int			main(int ac, char **av)
{
	int		fd;
	t_raw	raw;
	t_data	data;
	t_env	env;

	read_args(&env, ac, av);
	get_env(&env, av[1]);
	fd = xopen(av[1], O_RDONLY);
	raw = read_file(fd);
	close(fd);
	data = read_raw(raw);
	display_data(data, env);
	mlx_loop(env.mlx);
	return (1);
}
Ejemplo n.º 14
0
int main(int argc, char **argv)
{
   int            vc;                              /* argv: console number */
   Gpm_Connect    conn;                            /* connection to gpm    */
   fd_set         fds;

   /* select virtual console, 0 if not set */
   vc = (argc == 2) ? strtol(argv[1],NULL,10) : 0;

   conn.eventMask    =  GPM_MOVE; /* read only moves            */
   conn.defaultMask  = ~GPM_HARD; /* inverted GPM_HARD mask    */
   conn.minMod       =  0;
   conn.maxMod       = ~0;

   if(Gpm_Open(&conn,vc) == -1) {
      printf("Cannot connect to gpm!\n");
      return 1;
   }
   if(gpm_fd == -2) {
      printf("I must be run on the console\n");
      return 1;
   }
   

   while(1) { /* read data */
      FD_ZERO(&fds);
      FD_SET(gpm_fd, &fds);

      if (select(gpm_fd+1, &fds, 0, 0, 0) < 0 && errno == EINTR)
         continue;
      if (FD_ISSET(gpm_fd, &fds)) {
         Gpm_Event evt;
         if (Gpm_GetEvent(&evt) > 0) {
            display_data(&evt, NULL);
         } else {
            printf("Gpm_GetEvent failed\n");
         }
      }
   }

   Gpm_Close(); /* close connection */

   return 0;
}
Ejemplo n.º 15
0
/*!
 * Schreibt einen String auf das Display.
 * @param format Format, wie beim printf
 * @param ... Variable Argumentenliste, wie beim printf
 */
void display_printf(char *format, ...) {
	
	unsigned int run = 0;
	va_list	args;
	
	/* Sicher gehen, das der zur Verfuegung stehende Puffer nicht
	 * ueberschrieben wird.
	 */
	va_start(args, format);
	vsnprintf(display_buf, DISPLAY_BUFFER_SIZE, format, args);
	va_end(args);
	
	/* Ausgeben bis Puffer leer ist */
	while(display_buf[run] != '\0') {
		display_data(display_buf[run]);
		run++;
	}
	
	return;
}
Ejemplo n.º 16
0
void nlcall(struct sk_buff *__skb) 
{
	struct sk_buff *skb;
	struct nlmsghdr *nlh;
	char data[128];
	struct data_t *p;
	
	
	printk(KERN_ALERT "[+]netlink start\n");
	/*
	 * get true skb
	 */
	skb = skb_get(__skb);

	/*
	 * length of actual data must be bigger than
	 * NLMSG_LENTH
	 */
	if (skb->len >= NLMSG_SPACE(0)) {
		/*
		 * skb->data
		 */
		nlh = nlmsg_hdr(skb);	
		/*
		 * nlh + NLMSG_LENTH -->data
		 */
		memcpy(data, NLMSG_DATA(nlh), sizeof(data));
		
		p = (struct data_t *)data;	
		
		display_data(p->start, p->len);


		kfree_skb(skb);

	}
	else {
		printk(KERN_ALERT "data len is short!\n");

	}
}
Ejemplo n.º 17
0
void displayThread(void *args)
{
   BK_U8B *command;
   BK_S8B *data;
   BK_U8B len;
   while(1)
   {
      if(msgQueueMsgReadNoWait(commandMQ,&command,&len))
      {
         if(len == 1)
         {
            display_cmd(*command);
         }
         BK_free(command);
      }
      if(msgQueueMsgReadNoWait(dataMQ,&data,&len))
      {
         if(len > 2)
         {
            if(*data != -1)
            {
               display_cursor(data[0],data[1]);
               data ++;
               len  -=2;
            }
            data++;
            while(len > 0)
            {
               display_data(*data);
               len--;
               data++;
            }
         }
      }
      done();
   }
}
Ejemplo n.º 18
0
/*
 * 主要查询函数
 */
void consult()
{
    char word[MAX_WORD+1];
    char *data=NULL;
    long idx[MAX_KEYS];
    unsigned int offset, length;

    cache_idx(idx);

    while(1){
        printf("INPUT A WORD OR PHRASE: ");
        if(get_input(word, MAX_WORD)){
            fseek(pidx,locate_idx(word,idx),SEEK_SET);
            if(search_word(word,&offset,&length))
            {
                data=get_data(offset,length);
                display_data(data,length);
                free(data);
                data=NULL;
            }else fprintf(stderr,"SORRY, '%s' CANNOT BE FOUND!\n", word);
            printf("\n----------------------------------------\n\n");
        }else break;
    }
}
Ejemplo n.º 19
0
/*
 * process state machine
 */
void si7005_process(){
	U8 T[2], b;
	i2c_status st;
	if(state == RELAX) return;
	if(state == WAITFORP || state == WAITFORT){ // poll RDY
		if((st = i2c_7bit_send_onebyte(0, 0)) == I2C_OK){
			if(i2c_7bit_receive_onebyte(&b,0) == I2C_OK){
				if(b) return; // !RDY
				if((st = i2c_7bit_send_onebyte(1, 0)) == I2C_OK)
					if((st = i2c_7bit_receive_twobyte(T,0)) == I2C_OK)
						display_data(T);
				state = RELAX;
				if(st){
					uart_write("can't read value, err: ");
					printUHEX(st); UART_send_byte('\n');
				}
			}
		}else{
			error_msg("can't poll !RDY, err: ");
			printUHEX(st); UART_send_byte('\n');
			state = RELAX;
		}
	}
}
Ejemplo n.º 20
0
int main(int argc, char **argv){
	int c;
	int colouron = 0;

	char *fslist = NULL;

	time_t last_update = 0;

	extern int errno;

	int delay=2;

	sg_log_init("saidar", "SAIDAR_LOG_PROPERTIES", argc ? argv[0] : NULL);
	sg_init(1);
	if(sg_drop_privileges() != 0){
		fprintf(stderr, "Failed to drop setuid/setgid privileges\n");
		return 1;
	}

#ifdef COLOR_SUPPORT
	while ((c = getopt(argc, argv, "d:F:cvh")) != -1){
#else
	while ((c = getopt(argc, argv, "d:F:vh")) != -1){
#endif
		switch (c){
			case 'd':
				delay = atoi(optarg);
				if (delay < 1){
					fprintf(stderr, "Time must be 1 second or greater\n");
					exit(1);
				}
				break;
#ifdef COLOR_SUPPORT
			case 'c':
				colouron = 1;
				break;
#endif
			case 'v':
				version_num(argv[0]);
				break;
			case 'h':
			default:
				usage(argv[0]);
				return 1;
		}
	}

	if (fslist) {
		sg_error rc = set_valid_filesystems(fslist);
		if(rc != SG_ERROR_NONE)
			die(sg_str_error(rc));
		free(fslist);
	}
	else {
		sg_error rc = set_valid_filesystems("!nfs, nfs3, nfs4, cifs, smbfs, samba, autofs");
		if(rc != SG_ERROR_NONE)
			die(sg_str_error(rc));
	}

	signal(SIGWINCH, sig_winch_handler);
	initscr();
#ifdef COLOR_SUPPORT
	/* turn on colour */
	if (colouron) {
		if (has_colors()) {
			start_color();
			use_default_colors();
			init_pair(1,COLOR_RED,-1);
			init_pair(2,COLOR_GREEN,-1);
			init_pair(3,COLOR_YELLOW,-1);
			init_pair(4,COLOR_BLUE,-1);
			init_pair(5,COLOR_MAGENTA,-1);
			init_pair(6,COLOR_CYAN,-1);
		} else {
			fprintf(stderr, "Colour support disabled: your terminal does not support colour.");
			colouron = 0;
		}
	}
#endif
	nonl();
	curs_set(0);
	cbreak();
	noecho();
	timeout(delay * 1000);
	newwin(0, 0, 0, 0);
	clear();

	if(!get_stats()){
		fprintf(stderr, "Failed to get all the stats. Please check correct permissions\n");
		endwin();
		return 1;
	}

	display_headings();

	for(;;){
		time_t now;
		int ch = getch();

		if (ch == 'q'){
			break;
		}

		/* To keep the numbers slightly accurate we do not want them
		 * updating more frequently than once a second.
		 */
		now = time(NULL);
		if ((now - last_update) >= 1) {
			get_stats();
		}
		last_update = now;

		if(sig_winch_flag) {
			clear();
			display_headings();
			sig_winch_flag = 0;
		}

		display_data(colouron);
	}

	endwin();
	sg_shutdown();
	return 0;
}
Ejemplo n.º 21
0
int
Frame_data::load_data_oldformat(Gframe *gframe, char *dirpath, char *filename,
				int display_data_flag,
				int load_silently)

/*
 *  Load parameters and sisdata into a frame from a directory from
 *  <dir>/curpar, <dir>/datdir/phasefile.sis.
 *
 *  If there is no <dir>/datdir/phasefile.sis or it is out-of-data, it
 *  will convert <dir>/datdir/phasefile to <dir>/datdir/phasefile.sis.
 *
 *  Here are the steps for reading in data in the old format:
 *
 *  + Invoke Frame_data::load_params(gframe, exppath, curpar,...);
 *
 *      this creates the gframe->params structure
 *
 *  + Release the old gframe->imginfo (if it exists).
 *
 *  + Convert the phasefile into a SIS file (old format) if the SIS file
 *    is non-existent or if it is older than the phasefile.
 *
 *  + Invoke Frame_data::load_data(gframe, exppath, phasefile.sis, ...)
 *
 *  If any of the above steps fail, it is necessary to call
 *  PS_release(gframe->params) in order to deallocate the params structure
 *  
 */

{
  char exppath[256];   // path to the experiment being loaded
  char infile[256];    // filename for the phasefile
  char outfile[256];   // filename for the SIS format file
  char errmsg[128];	// error message buffer
  int temp_file_used = FALSE;
  struct stat buf;     // Holds status of phasefile
  double lpe, lro;	// field of view parameters
  char trace[4];   	// trace = "f1" or trace = "f2"
  Sisfile_info *sisfile;

  // Build experiment directory pathname
  (void)sprintf(exppath, "%s/%s", dirpath, filename);
  
  win_print_msg("Loading %s/%s/curpar.......", dirpath, filename);

  if (Frame_data::load_params(gframe, exppath, "curpar",
			      load_silently) == NOT_OK)    {    
    if (!load_silently) {
      msgerr_print("load_data: Error loading %scurpar", filename);
      win_print_msg("Loading %s/%sdatdir/phasefile.sis: ERROR",
		    dirpath, filename);
    }
    return NOT_OK;
  }

  // Build filenames for the convert routine
  (void)sprintf(infile, "%sdatdir/phasefile", exppath);
//  (void)sprintf(outfile, "%sdatdir/phasefile.sis", exppath);
  
  // First check status of phasefile and converted phasefile
  if (stat(infile, &buf) == -1)      {
    if (!load_silently) {
      msgerr_print("load_data:Couldn't find %s/%sdatdir/phasefile",
		   dirpath, filename);
      win_print_msg("Loading %s/%sdatdir/phasefile: ERROR",
		    dirpath, filename);
    }
    PS_release(gframe->params);
    gframe->params = NULL;	// So PS_read will allocate space next time
    return NOT_OK;
  }
  
    
    if (PS_get_string_value(gframe->params, "trace", 3, (char **)&trace)
	!= P_OK)
      (void)sprintf(trace, "f1"); 
    
    if (PS_get_real_value(gframe->params, "lpe", 1, &lpe) != P_OK)
      lpe = 1.0;
    if (PS_get_real_value(gframe->params, "lro", 1, &lro) != P_OK)
      lro = 1.0;
    
    if (strcmp(trace, "f1"))	  {
      if (!load_silently) {
	  msgerr_print(
	  "load_data:WARNING:phasefile with trace='f2' is not yet supported.");
      }
      double temp = lpe;
      lpe = lro;
      lro = temp;
    }    
    // release old image data before overwriting file
    if (gframe->imginfo) gframe->clear();
    detach_imginfo(gframe->imginfo);
    
    win_print_msg("Converting phasefile to SIS file format....");
    if (! (sisfile = Sisfile_info::sisdata_phase2sis(infile, 
			(float)lpe, (float)lro, errmsg) ) )
    {
	    if (!load_silently){
		msgerr_print(
		   "load_data:Can't convert %s/%sdatdir/phasefile to sisfile",
		   dirpath, filename);
		msgerr_print("  Reason:%s", errmsg);
		win_print_msg("Loading %s/ %sdatdir/phasefile.sis: ERROR",
			      dirpath, filename);
	    }
	    PS_release(gframe->params);
	    gframe->params = NULL; // So PS_read will allocate space next time
	    return NOT_OK;
    }
  
  win_print_msg("Loading %s/%sdatdir/phasefile.sis: .......",
		dirpath, filename);
  
  {
    char errmsg[128];	// Error message buffer
    double DEFAULT_VS = 4200.0;
    double vs = DEFAULT_VS;		// vertical scale

    // Release previous data; then allocate memory for new Imginfo
    detach_imginfo(gframe->imginfo);

    sisfile->SetDirpath(dirpath);
    sisfile->SetFilename(filename);


    if (sisfile->header.rank != RANK_2D){
	// Not a 2D data set--I can't handle this!
	msgerr_print("load_data_oldformat(): Not a 2D data set.");
	return NOT_OK;
    }

    gframe->imginfo = new Imginfo(sisfile->header.rank,
				  sisfile->header.bit,
				  sisfile->header.type,
				  sisfile->header.fast,
				  sisfile->header.medium,
				  sisfile->header.slow,
				  sisfile->header.hyperslow);

    // Copy data image from sisfile to st
    gframe->imginfo->st->SetData(sisfile->data, sisfile->DataLength());
    
    // Used gray-scale colormap
    gframe->imginfo->cmsindex = SISCMS_2;
    
    // Get the vertical scale.  Note that we retrieve a vertical scale value
    // from Vnmr, where its gray-leve is 64.  Now, we need to convert it to
    // the current gray-levels
    
    if (gframe->params && PS_exist(gframe->params, "vs"))   {
      if (PS_get_real_value(gframe->params, "vs", 1, &vs) == P_OK) {
	// From experience, we need to multiple the converted vs with 1.7
	// in order to obtain a good image
	vs *= (double) (G_Get_Sizecms2(gframe->gdev) / 64.0) * 1.7;
      } else {
	vs = DEFAULT_VS;
      }
    }
    
    DDLSymbolTable *st = gframe->imginfo->st;
    
    gframe->imginfo->vs = vs;
    st->SetValue("vs", vs);
//    st->SetValue("span", sisfile->header.ratio_fast, 0);
//    st->SetValue("span", sisfile->header.ratio_medium, 1);
    st->SetValue("span", (float)lpe, 0);
    st->SetValue("span", (float)lro, 1);
    st->SetValue("roi", (float)lpe, 0);
    st->SetValue("roi", (float)lro, 1);

    st->SetValue("dirpath", sisfile->GetDirpath());
    st->SetValue("filename", sisfile->GetFilename());
    

    // Display all the data
    if (display_data_flag) {
      display_data(gframe, 0, 0, sisfile->header.fast,
		   sisfile->header.medium,
		   vs);
    }

    win_print_msg("Loading %s/%sdatdir/phasefile: DONE",
		  dirpath, filename);

  }

  delete sisfile;
  return OK;
}
Ejemplo n.º 22
0
void data_server(int agents_total, int world_width, int world_height)
{
	int np; 
	MPI_Comm_size(MPI_COMM_WORLD, &np);

	/* create a type for struct agent */
	const int nitems=5;
   	int blocklengths[5] = {1,1,1,1,1};
   	MPI_Datatype types[5] = {MPI_INT, MPI_INT, MPI_INT, MPI_FLOAT, MPI_FLOAT};
	MPI_Datatype mpi_agent_type;
	MPI_Aint offsets[5];

	offsets[0] = offsetof(agent, id);
    	offsets[1] = offsetof(agent, x);
    	offsets[2] = offsetof(agent, y);
    	offsets[3] = offsetof(agent, z);
    	offsets[4] = offsetof(agent, w);

	MPI_Type_create_struct(nitems, blocklengths, offsets, types, &mpi_agent_type);
	MPI_Type_commit(&mpi_agent_type);


	int num_comp_nodes = np -1;
	unsigned int num_bytes = agents_total * sizeof(agent);
	agent *h_agents_in, *h_agents_out;

	/* allocate input data */
	h_agents_in = (agent *)malloc(num_bytes);
	h_agents_out = (agent *)malloc(num_bytes);
	if(h_agents_in == NULL || h_agents_out == NULL)
	{
		printf("server couldn't allocate memory\n");
		MPI_Abort(MPI_COMM_WORLD, 1);
	}

	/* initialize input data */
	init_data(h_agents_in, agents_total);

#ifdef DEBUG 
	printf("Init data\n");
	display_data(h_agents_in, agents_total);
#endif

	int world_height_node = world_height / num_comp_nodes;
//	printf("world_height: %d\n", world_height_node);
	agent h_agents_node_in[num_comp_nodes][agents_total], h_agents_node_out[num_comp_nodes][agents_total];
	for(int process = 0; process < num_comp_nodes; process++)
	{	
		for(int i = 0; i < agents_total; i++)
		{
			if(  ( h_agents_in[i].y >= (process * world_height_node) ) and ( h_agents_in[i].y < ( (process + 1) * world_height_node ) )  )
				h_agents_node_in[process][i] = h_agents_in[i];
		}
	}

/***	
	printf("copy data 0\n");
	display_data(h_agents_node_in[0], agents_total);
	printf("copy data 1\n");
	display_data(h_agents_node_in[1], agents_total);
	printf("copy data 2\n");
	display_data(h_agents_node_in[2], agents_total);
***/

	/* send data to compute nodes */
	for(int process = 0; process < num_comp_nodes; process++)
		MPI_Send(h_agents_node_in[process], agents_total, mpi_agent_type, process, 0, MPI_COMM_WORLD);

	/* Wait for nodes to compute */
	MPI_Barrier(MPI_COMM_WORLD);
	
	/* Collect output data */
	MPI_Status status;

	for(int process = 0; process < num_comp_nodes; process++)
		MPI_Recv(h_agents_node_out[process], agents_total, mpi_agent_type, process, DATA_COLLECT, MPI_COMM_WORLD, &status); 

#ifdef DEBUG
        printf("Final Data\n");	
	/* display output data */
//	display_data(h_agents_out, agents_total);
#endif
	
	/* release resources */
	free(h_agents_in);
	free(h_agents_out); 
//	free(h_agents_node_in); 
//	free(h_agents_node_out); 
}
Ejemplo n.º 23
0
void sig_winch_handler(int sig){
	clear();
	display_headings();
	display_data();
	signal(SIGWINCH, sig_winch_handler);
}
Ejemplo n.º 24
0
////////////////////////////////////////////////////////////////////////////////
//! Run the Cuda part of the computation
////////////////////////////////////////////////////////////////////////////////
void refreshData(struct cudaGraphicsResource **vbo_resource)
{
	int np; 
	MPI_Comm_size(MPI_COMM_WORLD, &np);
	MPI_Status status;

	int num_comp_nodes = np -1;
	unsigned int num_bytes = sizeof(sAgents);
	sAgents h_agents_in, h_agents_out[num_comp_nodes];
        size_t size_agents = agents_total * sizeof(float4);

        // map OpenGL buffer object for writing from CUDA
        float4 *d_agents;
        // Error code to check return values for CUDA calls
        cudaError_t err = cudaSuccess;

        checkCudaErrors(cudaGraphicsMapResources(1, vbo_resource, 0));
        size_t num_agents_bytes;
        checkCudaErrors(cudaGraphicsResourceGetMappedPointer((void **)&d_agents, &num_agents_bytes,
                                                         *vbo_resource));
		
	//for(int process = 0; process < num_comp_nodes; process++)
	//while(1)
	//{
		/* Wait for nodes to compute */
		MPI_Barrier(MPI_COMM_WORLD);

		for(int process = 0; process < num_comp_nodes; process++)
		{

			MPI_Recv(&h_agents_out[process], num_bytes, MPI_BYTE, process, DATA_COLLECT, MPI_COMM_WORLD, &status); 

			for( int i = 0; i < agents_total; i++)
			{
				if( h_agents_out[process].ids[i].y == 1 )
				{
					h_agents_in.pos[i] = h_agents_out[process].pos[i]; 
					h_agents_in.ids[i] = h_agents_out[process].ids[i];
					h_agents_in.pos[i].z = 0;
					h_agents_in.pos[i].w = 1;
				}
			}
	
		}
		#ifdef DEBUG
	        printf("Final Data:\n");	
		display_data(h_agents_in);
		#endif
		
		/***
		//pasar los valores al vbo
	        glBindBuffer(GL_ARRAY_BUFFER, vbo);
   	        unsigned int size = agent_width * agent_height * 4 * sizeof(float);    
	        glBufferSubData(GL_ARRAY_BUFFER, 0, size, &h_agents_in.pos);

	        glBindBuffer(GL_ARRAY_BUFFER, 0);
		***/

		// Copy the host pointer memory to the device memory
    		printf("Copy pointer from the host memory to the CUDA device\n");
    		err = cudaMemcpy(d_agents, h_agents_in.pos, size_agents, cudaMemcpyHostToDevice);

    		if (err != cudaSuccess)
    		{
    		    fprintf(stderr, "Failed to copy pointer from host to device (error code %s)!\n", cudaGetErrorString(err));
    		    exit(EXIT_FAILURE);
    		}
		//glutPostRedisplay();
	        printf("sale de refreshData:\n");	

	//}

    // unmap buffer object
    checkCudaErrors(cudaGraphicsUnmapResources(1, vbo_resource, 0));
	
	/* release resources */
	//free(&h_agents_in);
	//free(&h_agents_out); 
}
Ejemplo n.º 25
0
int main(int argc, char **argv)
{
	xmp_context ctx;
	struct xmp_module_info mi;
	struct xmp_frame_info fi;
	int row, pos, i;

	if (sound_init(44100, 2) < 0) {
		fprintf(stderr, "%s: can't initialize sound\n", argv[0]);
		exit(1);
	}

	ctx = xmp_create_context();

	for (i = 1; i < argc; i++) {
		if (xmp_load_module(ctx, argv[i]) < 0) {
			fprintf(stderr, "%s: error loading %s\n", argv[0],
				argv[i]);
			continue;
		}

		if (xmp_start_player(ctx, 44100, 0) == 0) {

			/* Show module data */

			xmp_get_module_info(ctx, &mi);
			printf("%s (%s)\n", mi.mod->name, mi.mod->type);

			/* Play module */

			row = pos = -1;
			while (xmp_play_frame(ctx) == 0) {
				xmp_get_frame_info(ctx, &fi);
				if (fi.loop_count > 0)
					break;

				sound_play(fi.buffer, fi.buffer_size);

				if (fi.pos != pos) {
					printf("\n%02x:%02x\n",
					       fi.pos, fi.pattern);
					pos = fi.pos;
					row = -1;
				}
				if (fi.row != row) {
					display_data(&mi, &fi);
					row = fi.row;
				}
			}
			xmp_end_player(ctx);
		}

		xmp_release_module(ctx);
		printf("\n");
	}

	xmp_free_context(ctx);
	sound_deinit();

	return 0;
}
Ejemplo n.º 26
0
int main(int argc, char **argv){

	extern char *optarg;
	int c;

	time_t last_update = 0;

	WINDOW *window;

	extern int errno;

	int delay=2;

	sg_init();
	if(sg_drop_privileges() != 0){
		fprintf(stderr, "Failed to drop setuid/setgid privileges\n");
		return 1;
	}
		
	while ((c = getopt(argc, argv, "vhd:")) != -1){
		switch (c){
			case 'd':
				delay = atoi(optarg);
				if (delay < 1){
					fprintf(stderr, "Time must be 1 second or greater\n");
					exit(1);
				}
				break;
			case 'v':
				version_num(argv[0]);	
				break;
			case 'h':
			default:
				usage(argv[0]);
				return 1;
				break;
		}
	}

	signal(SIGWINCH, sig_winch_handler);
	initscr();
	nonl();
	cbreak();
	noecho();
	timeout(delay * 1000);
	window=newwin(0, 0, 0, 0);
	clear();

	if(!get_stats()){
		fprintf(stderr, "Failed to get all the stats. Please check correct permissions\n");
		endwin();
		return 1;
	}

	display_headings();

	for(;;){
		time_t now;
		int ch = getch();

		if (ch == 'q'){
			break;
		}

		/* To keep the numbers slightly accurate we do not want them
		 * updating more frequently than once a second.
		 */
		now = time(NULL);
		if ((now - last_update) >= 1) {
			get_stats();
		}
		last_update = now;

		display_data();
	}	

	endwin();
	return 0;
}