コード例 #1
0
ファイル: matrix.c プロジェクト: iem-projects/pd-iemmatrix
static void *matrix_new(t_symbol *s, int argc, t_atom *argv)
{
  t_matrix *x = (t_matrix *)pd_new(matrix_class);
  int row, col;


  inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("matrix"), gensym(""));
  outlet_new(&x->x_obj, 0);

  x->atombuffer   = 0;
  x->x_canvas = canvas_getcurrent();

  switch (argc) {
  case 0:
    row = col = 0;
    break;
  case 1:
    if (argv->a_type == A_SYMBOL) {
      matrix_read(x, argv->a_w.w_symbol);
      return(x);
    }
    row = col = atom_getfloat(argv);
    break;
  default:
    row = atom_getfloat(argv++);
    col = atom_getfloat(argv++);
  }

  if(row*col) {
    adjustsize(x, row, col);
    matrix_set(x, 0);
  }

  return (x);
}
コード例 #2
0
ファイル: test.c プロジェクト: begun4ik/MSIS_lab1
void game_init(int argc, char *argv[]) {
    game_delay = (DELAY_MIN+DELAY_MAX)/2;
    stat = STAT_EDITING;
    running = true;

    int c;
    int x = 0;
    int y = 0;
    const char *path = NULL;
    while ((c = getopt(argc, argv, "hp:x:y:s:")) != -1) {
        switch (c) {
            case 'p': path = optarg; break;
            case 'x': x = atoi(optarg); break;
            case 'y': y = atoi(optarg); break;
            case 's': game_delay = DELAY_MAX - (atoi(optarg) - 1)*10; break;
            case 'h':
                usage(argv[0]);
                exit(-1);
                break;
        }
    }
    if (path) matrix_read(path, x, y);
    else matrix_init();

    initscr();

    noecho();
    cbreak();

    main_window = newwin(ROWS, COLS*2, 0, 0);
    panel_window = newwin(ROWS, COLS, 0, COLS*2+1);
    nodelay(main_window, true);
    nodelay(panel_window, true);
    panel_draw();
}
コード例 #3
0
ファイル: unweighted.c プロジェクト: mark123code/workout
void select_method (char **argv) {

	int x = 1;
	if (x==1) 
		matrix_read(argv[3], atoi(argv[2]));
	else if(!x)
		list_read(argv[3]);
	else
		exit(1);
}
コード例 #4
0
ファイル: practice_problems.c プロジェクト: gaibo/C
matrix* matrix_transpose(matrix* m) {
    matrix* mat_out = matrix_zero(m->n_cols, m->n_rows);
    int i_row, i_col;
    for (i_row = 0; i_row < m->n_rows; i_row++) {
        for (i_col = 0; i_col < m->n_cols; i_col++) {
            matrix_write(mat_out, i_col, i_row, matrix_read(m, i_row, i_col));
        }
    }
    return mat_out;
}
コード例 #5
0
ファイル: unweighted.c プロジェクト: mark123code/workout
void find_SP (char *path, int s, int size) {

	//table_node * T = initialize_data(size);
	s--;
	int * array = matrix_read(path, size);
	int i,j,k;
	int T[size];

	for (i=0;i<size;i++)
		T[i] = -1;

	T[s] = 0;
	struct head_ptr * Q = malloc(sizeof(struct head_ptr));
	Q->next = Q->last = malloc(sizeof(struct queue_node));


    // Queuing the first node onto the queue
	Q->next->v_no = s;
	Q->next->next = NULL;
	Q->last = Q->next;


    // Main BFS algo for shortest unweighted path
	while (Q->next) //while Q->next is not NULL
	{
		int vertex_no = dequeue(Q);
		

		/* Enter code for checking the adjacency method */
		/* for (all vertex w adjacent to vertex_no && T[w].distance == -1)
		   
		   {
 			T[w].distance = T[s].distance+1;
			queue(Q,w);
		   }
                */

		for (j=0;j<size;j++)
	 	{

			if (array[vertex_no][j]==1 && T[j] == -1 )
	
		   {
 			T[j] = T[vertex_no] + 1;
			queue(Q,j);
		   }
	
        	}	
       }

}
コード例 #6
0
ファイル: problem3.c プロジェクト: JordonPhillips/csse335
void master(char *a_fname, char *b_fname, char *out_fname) {
    Matrix a = matrix_read(a_fname);
    Matrix b = matrix_read(b_fname);

    if (a.width != a.height || b.width != b.height || a.width != b.width) {
        printf("Invalid inputs. Both matricies must be nxn. A was %dx%d. B was"
               " %dx%d", a.height, a.width, b.height, b.width);
        MPI_Abort(MPI_COMM_WORLD, -1);
    }

    MPI_Bcast(&(a.width), 1, MPI_INT, 0, MPI_COMM_WORLD);

    Matrix result = matrix_malloc(a.width, b.width);
    matrix_init(&result);
    MPI_matrix_multiply(&result, &a, &b, a.width, 0, MPI_COMM_WORLD);
    matrix_write(out_fname, result);

    if (result.width <= 20)
        matrix_print(result);

    free(result.data);
    free(a.data);
    free(b.data);
}
コード例 #7
0
ファイル: matrix_mult.c プロジェクト: Exceltior/dei-hpc
int main()
{
	long process_time;

	matrix_read(MATRICES_FILE, h_mat1, h_mat2, &n);

	fprintf(stderr, "Starting hard work.\n");

	process_time = matrix_mult_cpu_naive(h_mat1, h_mat2, h_out, n);
	fprintf(stderr, "Finished CPU naïve in %ld milliseconds\n", process_time);

	fprintf(stderr, "\n");

	process_time = matrix_mult_cpu_cache(h_mat1, h_mat2, h_out, n);
	fprintf(stderr, "Finished CPU with use of cache in %ld milliseconds\n", process_time);

	fprintf(stderr, "\n");

	matrix_mult_gpu(h_mat1, h_mat2, h_out, n);

	return 	0;
}
コード例 #8
0
ファイル: ambix-jrecord.c プロジェクト: sparrkli/ambix
int main(int argc, char *argv[])
{
  const char*filename = "jtest.caf";
  const char*myname=argv[0];
  observe_signals ();
  struct recorder d;

  ambix_matrix_t*matrix=NULL;
  int32_t order = -1;

  d.buffer_frames = 4096;
  d.minimal_frames = 32;
  d.channels = 2;
  d.timer_seconds = -1.0;
  d.timer_counter = 0;
  d.sample_format = AMBIX_SAMPLEFORMAT_FLOAT32;
  d.file_format   = AMBIX_BASIC;
  int c;
  while((c = getopt(argc, argv, "hVx:X:O:b:fhm:n:t:")) != -1) {
    switch(c) {
    case 'x':
      d.e_channels = (int) strtol(optarg, NULL, 0);
      d.file_format   = AMBIX_EXTENDED;
      break;
    case 'X':
      matrix=matrix_read(optarg, matrix);
      if(!matrix) {
        eprintf("%s: couldn't read matrix-file '%s'\n", myname, optarg);
        FAILURE;
      }
      d.file_format   = AMBIX_EXTENDED;
      break;
    case 'O':
      order = (uint32_t) strtol(optarg, NULL, 0);
      break;

    case 'b':
      d.buffer_frames = (int) strtol(optarg, NULL, 0);
      break;
#if 0
    case 'f':
      d.file_format = (int) strtol(optarg, NULL, 0);
      break;
#endif
    case 'V':
      version (myname);
      break;
    case 'h':
      usage (myname);
      break;
    case 'm':
      d.minimal_frames = (int) strtol(optarg, NULL, 0);
      break;
    case 't':
      d.timer_seconds = (float) strtod(optarg, NULL);
      break;
    default:
      eprintf("%s: illegal option, %c\n", myname, c);
      usage (myname);
      break;
    }
  }

  if(optind == argc - 1) {
    filename=argv[optind];
  } else {
    eprintf("opening default file '%s'\n", filename);
    //usage (myname);
  }

  /* Allocate channel based data. */
  if(matrix) {
    if(order<0) {
      d.a_channels = matrix->cols;
    } else {
      if(ambix_order2channels(order) != matrix->rows) {
        eprintf("%s: ambisonics order:%d cannot use [%dx%d] adaptor matrix.\n", myname, order, matrix->rows, matrix->cols);
        FAILURE;
      }
      d.a_channels = matrix->cols;
    }
  } else {
    if(order<0)
      order=1;

    d.a_channels=ambix_order2channels(order);
  }

  switch(d.file_format) {
  case AMBIX_BASIC:
    //d.a_channels;
    d.e_channels=0;
    break;
  case AMBIX_EXTENDED:
    //d.a_channels;
    //d.e_channels;
    break;
  case AMBIX_NONE: default:
    d.a_channels=0;
    //d.e_channels;
  }
  d.channels = d.a_channels+d.e_channels;


  if(d.channels < 1) {
    eprintf("%s: illegal number of channels: %d\n", myname, d.channels);
    FAILURE;
  }
  d.in = (float**)xmalloc(d.channels * sizeof(float *));
  d.input_port = (jack_port_t**)xmalloc(d.channels * sizeof(jack_port_t *));

  /* Connect to JACK. */
  
  jack_client_t *client = jack_client_unique_("ambix-jrecord");
  jack_set_error_function(jack_client_minimal_error_handler);
  jack_on_shutdown(client, jack_client_minimal_shutdown_handler, 0);
  jack_set_process_callback(client, process, &d);
  d.sample_rate = jack_get_sample_rate(client);

  /* Setup timer. */

  if(d.timer_seconds < 0.0) {
    d.timer_frames = -1;
  } else {
    d.timer_frames = d.timer_seconds * d.sample_rate;
  }

  /* Create sound file. */

  ambix_info_t sfinfo;
  memset(&sfinfo, 0, sizeof(sfinfo));
  sfinfo.samplerate = (int) d.sample_rate;
  sfinfo.frames = 0;
  sfinfo.fileformat = d.file_format;

  sfinfo.ambichannels  = d.a_channels;
  sfinfo.extrachannels = d.e_channels;

  d.sound_file = ambix_open(filename, AMBIX_WRITE, &sfinfo);

  if(matrix) {
    ambix_err_t aerr = ambix_set_adaptormatrix(d.sound_file, matrix);
    if(AMBIX_ERR_SUCCESS != aerr) {
      eprintf("setting [%dx%d] matrix returned %d.\n", matrix->rows, matrix->cols, aerr);
      FAILURE;
    }
  }

  /* Allocate buffers. */
  
  d.buffer_samples = d.buffer_frames * d.channels;
  d.buffer_bytes = d.buffer_samples * sizeof(float);

  d.a_buffer = (float32_t*)xmalloc(d.buffer_frames * d.a_channels * sizeof(float32_t));
  d.e_buffer = (float32_t*)xmalloc(d.buffer_frames * d.e_channels * sizeof(float32_t));

  d.d_buffer = (float*)xmalloc(d.buffer_bytes);
  d.j_buffer = (float*)xmalloc(d.buffer_bytes);
  d.u_buffer = (float*)xmalloc(d.buffer_bytes);
  d.ring_buffer = jack_ringbuffer_create(d.buffer_bytes);

  /* Create communication pipe. */

  xpipe(d.pipe);

  /* Start disk thread. */

  pthread_create (&(d.disk_thread),
		  NULL, 
		  disk_thread_procedure, 
		  &d);

  /* Create input ports and activate client. */

#if 0
  jack_port_make_standard(client, d.input_port, d.channels, false);
  jack_client_activate(client);
#else
  do {
    int i=0, a, e;
    const char*format=(sfinfo.fileformat == AMBIX_BASIC)?"ACN_%d":"ambisonics_%d";
    const int a_offset=(sfinfo.fileformat == AMBIX_BASIC)?0:1;
    for(a=0; a<d.a_channels; a++) {
      d.input_port[i] = _jack_port_register(client, JackPortIsInput, format, a+a_offset);
      i++;
    }
    for(e=0; e<d.e_channels; e++) {
      d.input_port[i] = _jack_port_register(client, JackPortIsInput, "in_%d", e+1);
      i++;
    }
  } while(0);

  if(jack_activate(client)) {
    eprintf("jack_activate() failed\n");
    FAILURE;
  }
#endif

  /* Wait for disk thread to end, which it does when it reaches the
     end of the file or is interrupted. */

  pthread_join(d.disk_thread, NULL);

  /* Close sound file, free ring buffer, close JACK connection, close
     pipe, free data buffers, indicate success. */

  jack_client_close(client);
  ambix_close(d.sound_file);
  jack_ringbuffer_free(d.ring_buffer);
  close(d.pipe[0]);
  close(d.pipe[1]);

  free(d.a_buffer);
  free(d.e_buffer);

  free(d.d_buffer);
  free(d.j_buffer);
  free(d.u_buffer);
  free(d.in);
  free(d.input_port);
  if(matrix)ambix_matrix_destroy(matrix);
  return EXIT_SUCCESS;
}
コード例 #9
0
ファイル: rwpics.c プロジェクト: chendong/ffpis_img
int main(int argc, char *argv[])
{
  char *rws_eg_seg, *outpics_dir, str[400], *desc;
  unsigned char pixval;
  static unsigned char *pic;
  int mode, iarg, i, ii, iis, iie, j, jj, jjs, jje;
  float *buf, *p, *pe, aval;
  float minval=9999.9, maxval=-9999.9, range, a=0.0, b=0.0, maxabs, c;
  int rw, rh;
  int pw, ph;

  if(argc < 4)
    usage("<rwfile_in[rwfile_in...]> <rws|eg|seg> <outpics_dir>");
  rws_eg_seg = argv[argc - 2];
  outpics_dir = argv[argc - 1];
  if(!strcmp(rws_eg_seg, "rws"))
    mode = RWS;
  else if(!strcmp(rws_eg_seg, "eg"))
    mode = EG;
  else if(!strcmp(rws_eg_seg, "seg"))
    mode = SEG;
  else
    fatalerr("the rws|eg|seg arg must be rws, eg, or seg", (char *)NULL,
             (char *)NULL);
  if(mode != SEG) {
    for(iarg = 1; iarg < argc - 2; iarg++) {
      matrix_read(argv[iarg], &desc, &rh, &rw, &buf);
      free(desc);
      for(pe = (p = buf) + rw*rh; p < pe; p++) {
	aval = *p;
	if(iarg == 1 && p == buf)
	  minval = maxval = aval;
	else if(aval < minval)
	  minval = aval;
	else if(aval > maxval)
	  maxval = aval;
      }
      free(buf);
    }
    if(mode == EG) {
      range = maxval - minval;
      if(range > 0.) {
	a = -255. / range;
	b = 255. * maxval / range;
      }
      else {
	a = 0.;
	b = 128.;
      }
    }
    else {
      maxabs = fabs((double)minval);
      if((c = fabs((double)maxval)) > maxabs)
	maxabs = c;
      if(maxabs > 0.) {
	a = 255. / maxabs;
	b = 0.;
      }
      else {
	a = 0.;
	b = 128.;
      }
    }
  }
  for(iarg = 1; iarg < argc - 2; iarg++) {
    matrix_read(argv[iarg], &desc, &rh, &rw, &buf);
    free(desc);
    pw = PWS * rw;
    ph = PWS * rh;
    malloc_uchar(&pic, pw*ph, "rwpics pic");
    for(i = iis = 0, iie = PWS, p = buf; i < rh; i++, iis += PWS,
      iie += PWS)
      for(j = jjs = 0, jje = PWS; j < rw; j++, jjs += PWS, jje += PWS,
        p++) {
	aval = *p;
	if(mode == EG)
	  pixval = a * aval + b + .5;
	else if(mode == SEG)
	  pixval = (aval < 0. ? 255 : 0);
	else
	  pixval = a * fabs((double)aval) + b + .5;
	for(ii = iis; ii < iie; ii++)
	  for(jj = jjs; jj < jje; jj++)
	    pic[ii*pw+jj] = pixval;
      }
    free(buf);
    sprintf(str, "%s/%s_%s.pct", outpics_dir, lastcomp(argv[iarg]),
      rws_eg_seg);
    write_ihdr_std(pic, pw, ph, 8, str);
    free(pic);
  }
  return 0;
}
コード例 #10
0
ファイル: asensor.cpp プロジェクト: anosnowhong/phantom
BOOL ASENSOR::Open( BOOL reset )
{
BOOL ok;
STRING file;
char *path;
int step,i;

    if( STR_null(ObjectName) )
    {
        ASENSOR_errorf("ASENSOR::Open() Sensor name not set.\n");
        return(FALSE);
    }

    for( ok=TRUE,step=ASENSOR_OPEN_CONFIGURATION; ((step <= ASENSOR_OPEN_VARIABLES) && ok); step++ )
    {
        switch( step )
        {
            case ASENSOR_OPEN_CONFIGURATION :
               strncpy(file,STR_stringf("%s.CFG",ObjectName),STRLEN);

               if( (path=FILE_Calibration(file)) == NULL )
               {
                   ASENSOR_errorf("ASENSOR::Open() Cannot find configuration file: %s\n",file);
                   ok = FALSE;
                   break;
               }

               strncpy(file,path,STRLEN);
               ok = ConfigLoad(file);
               break;

            case ASENSOR_OPEN_CALIBRATION :
               // Default identity calibration matrix for sensor.
               Calibration = I(DAQ_ChannelCount);

               if( !CalibrationFlags[ASENSOR_CALIBRATION_MTX] )
               {
                   break;
               }

               strncpy(file,STR_stringf("%s.MTX",ObjectName),STRLEN);
               if( (path=FILE_Calibration(file)) == NULL )
               {
                   ASENSOR_errorf("ASENSOR::Open() Cannot find calibration file: %s\n",file);
                   ok = FALSE;
                   break;
               }

               strncpy(file,path,STRLEN);
               if( !matrix_read(file,Calibration) )
               {
                   ASENSOR_errorf("ASENSOR::Open() Cannot load calibration file: %s\n",file);
                   ok = FALSE;
                   break;
               }

               // For some reason the ATI DAQ F/T sensor calibration matrix must be transposed.
               if( DeviceType == ASENSOR_DEVICE_DAQFT )
               {
                   Calibration.transpose();
               }
               break;

            case ASENSOR_OPEN_GAIN :
               Gain.dim(1,DAQ_ChannelCount);
               Gain.ones();

               if( !CalibrationFlags[ASENSOR_CALIBRATION_GAIN] )
               {
                   break;
               }

               strncpy(file,STR_stringf("%s.K",ObjectName),STRLEN);
               if( (path=FILE_Calibration(file)) == NULL )
               {
                   ASENSOR_errorf("ASENSOR::Open() Cannot find gain file: %s\n",file);
                   ok = FALSE;
                   break;
               }

               strncpy(file,path,STRLEN);
               if( !matrix_read(file,Gain) )
               {
                   ASENSOR_errorf("ASENSOR::Open() Cannot load gain file: %s\n",file);
                   ok = FALSE;
                   break;
               }

               MakeColumnVector(Gain);

               // For some reason the ATI DAQ F/T sensor gains must be inverted.
               if( DeviceType == ASENSOR_DEVICE_DAQFT )
               {
                   for( i=1; (i <= DAQ_ChannelCount); i++ )
                   {
                       if( Gain(1,i) != 0.0 )
                       {
                           Gain(1,i) = 1.0 / Gain(1,i);
                       }
                   }
               }
               break;

            case ASENSOR_OPEN_BIAS :
               BiasVolts.dim(1,DAQ_ChannelCount);
               BiasVolts.zeros();

               if( !CalibrationFlags[ASENSOR_CALIBRATION_BIAS] )
               {
                   break;
               }

               strncpy(file,STR_stringf("%s.B",ObjectName),STRLEN);

               if( (path=FILE_Calibration(file)) == NULL )
               {
                   ASENSOR_errorf("ASENSOR::Open() Cannot find bias file: %s\n",file);
                   ok = FALSE;
                   break;
               }

               strncpy(file,path,STRLEN);
               if( !matrix_read(file,BiasVolts) )
               {
                   ASENSOR_errorf("ASENSOR::Open() Cannot load bias file: %s\n",file);
                   ok = FALSE;
                   break;
               }

               strncpy(BiasFile,file,STRLEN);
               strncpy(BiasHistoryFile,STR_stringf("%sH",file),STRLEN);
               MakeColumnVector(BiasVolts);
               //disp(BiasVolts);
               break;

            case ASENSOR_OPEN_VARIABLES :
               SensorVolts.dim(1,DAQ_ChannelCount);
               SensorValues.dim(1,DAQ_ChannelCount);

               for( i=0; (i < DAQ_ChannelCount); i++ )
               {
                   BiasData[i] = new DATAPROC(STR_stringf("%s[%i]",ObjectName,i),BiasPoints,DATAPROC_FLAG_CIRCULAR);

                   if( VoltPoints > 0 )
                   {
                       VoltData[i] = new DATAPROC(STR_stringf("%s[%i]",ObjectName,i),VoltPoints,DATAPROC_FLAG_CIRCULAR);
                   }
               }

               if( WindowSize > 0 )
               {
                   Window = new WINFIT(ObjectName,WindowSize,DAQ_ChannelCount);
               }
               break;
        }

        STR_printf(ok,ASENSOR_debugf,ASENSOR_errorf,"ASENSOR::Open() %s[%d] %s.\n",ASENSOR_OpenText[step],step,STR_OkFailed(ok));
    }

    if( ok )
    {
        OpenFlag = TRUE;

        if( reset )
        {
            BiasResetAnterograde();
        }
    }

    return(ok);
}