예제 #1
0
파일: planet.c 프로젝트: dezgeg/PlanetSim
/* load a solar system specification from file, return NULL on failure */
System* load_system(FILE* file)
{
	int nplanets;
	long long steps_to_write;
	Float duration, time_step;
	fscanf(file, "%d " FLOAT_SCANF_FORMAT " " FLOAT_SCANF_FORMAT " %lld",
			&nplanets, &duration, &time_step, &steps_to_write);
	System* sys = alloc_system(nplanets);
	if(!sys || duration < time_step)
	{
		free(sys);
		return NULL;
	}

	sys->time_step = time_step;
	sys->nplanets = nplanets;
	sys->cur_step = 0;
	sys->nsteps = ceil(duration / time_step);
	if(steps_to_write > sys->nsteps)
		steps_to_write = sys->nsteps;
	sys->print_period = (long long)((double)sys->nsteps / steps_to_write);

	for(int i = 0; i < nplanets; i++)
	{
		fscanf(file, FLOAT_SCANF_FORMAT, &sys->planets[i].mass);
		read_vector(file, sys->planets[i].position);
		read_vector(file, sys->planets[i].velocity);
	}
	return sys;
}
// Read binary ROM data for basis functions and coefficients
static int load_data(const char dir[], gsl_vector *cvec_amp, gsl_vector *cvec_phi, gsl_matrix *Bamp, gsl_matrix *Bphi, gsl_vector *cvec_amp_pre) {
  // Load binary data for amplitude and phase spline coefficients as computed in Mathematica
  int ret = XLAL_SUCCESS;
  ret |= read_vector(dir, "SEOBNRv1ROM_SS_Amp_ciall.dat", cvec_amp);
  ret |= read_vector(dir, "SEOBNRv1ROM_SS_Phase_ciall.dat", cvec_phi);
  ret |= read_matrix(dir, "SEOBNRv1ROM_SS_Bamp_bin.dat", Bamp);
  ret |= read_matrix(dir, "SEOBNRv1ROM_SS_Bphase_bin.dat", Bphi);
  ret |= read_vector(dir, "SEOBNRv1ROM_SS_AmpPrefac_ci.dat", cvec_amp_pre);
  return(ret);
}
예제 #3
0
static bool decodeRig(fsMsgRig &_msg, const std::string &buffer, Size &start) {
    bool success = true;
    success &= read_vector(_msg.mesh().m_quads,buffer,start);                 // read quads
    success &= read_vector(_msg.mesh().m_tris,buffer,start);                  // read triangles
    success &= read_vector(_msg.mesh().m_vertex_data.m_vertices,buffer,start);// read neutral vertices
    success &= read_small_vector(_msg.blendshape_names(),buffer,start);       // read names
    uint16_t bsize = 0;
    success &= read_pod(bsize,buffer,start);
    _msg.blendshapes().resize(bsize);
    for(uint16_t i = 0;i < bsize; i++)
        success &= read_vector(_msg.blendshapes()[i].m_vertices,buffer,start);                  // read blendshapes
    return success;
}
예제 #4
0
int f_plane(ULONG *arg)
{
	rsiVECTOR vec;
	void *plane,*surf,*actor;
	rsiResult err;

	if (!arg[0])
		return ERROR_SURFACE;
		
	surf = FindSurfListItem((char*)arg[0]);
	if (!surf)
		return rsiERR_SURFACE;

	err = rsiCreatePlane(&plane,surf);
	if (err)
		return err;

	if (arg[1])
	{
		if (!read_vector(&vec,(char*)arg[1]))
			return ERROR_VECTOR;
		err = rsiSetPlane(plane, rsiTPlanePos, &vec, rsiTDone);
		if (err)
			return err;
	}

	if (arg[2])
	{
		if (!read_vector(&vec,(char*)arg[2]))
			return ERROR_VECTOR;
		err = rsiSetPlane(plane, rsiTPlaneNorm, &vec, rsiTDone);
		if (err)
			return err;
	}

	if (arg[3])
	{
		actor = FindActorListItem((char*)arg[3]);
		if (!actor)
			return rsiERR_ACTOR;

		err = rsiSetPlane(plane,rsiTPlaneActor,actor,rsiTDone);
		if (err)
			return err;
	}

	return rsiERR_NONE;
}
예제 #5
0
TEST(rust, MP4Metadata)
{
  FILE* f = fopen("street.mp4", "rb");
  ASSERT_TRUE(f != nullptr);
  // Read just the moov header to work around the parser
  // treating mid-box eof as an error.
  //read_vector reader = read_vector(f, 1061);
  struct stat s;
  ASSERT_EQ(0, fstat(fileno(f), &s));
  read_vector reader = read_vector(f, s.st_size);
  fclose(f);

  mp4parse_io io = { vector_reader, &reader };
  mp4parse_parser* context = mp4parse_new(&io);
  ASSERT_NE(nullptr, context);

  mp4parse_error rv = mp4parse_read(context);
  EXPECT_EQ(MP4PARSE_OK, rv);

  uint32_t tracks = 0;
  rv = mp4parse_get_track_count(context, &tracks);
  EXPECT_EQ(MP4PARSE_OK, rv);
  EXPECT_EQ(2U, tracks);

  mp4parse_free(context);
}
예제 #6
0
파일: read.c 프로젝트: troter/thesis
/* R5RS library procedure read
 *   (read)
 *   (read [port])
 */
SCM scm_proc_read(FILE *file)
{
    int c = skip_comment_and_space(file);

    switch (c) {
    case '(':
        return read_list(file);
    case ')': /* List end */
        scheme_error("symtax error");
    case '[':
    case ']':
        scheme_error("unsupport bracket");
    case '{':
    case '}':
        scheme_error("unsupport brace");
    case '|':
        scheme_error("unsupport bar");
    case '#':
        c = fgetc(file);
        if ('(' == c) {
            return read_vector(file);
        } else {
            ungetc(c, file);
            return read_simple_datum(file, '#');
        }
    case '\'': /* Quotation */
        return new_cons(SCM_SYMBOL_QUOTE, new_cons(scm_proc_read(file), SCM_NULL));
    case '`':  /* Quasiquotation */
        scheme_error("unsupport quasiquotation");
    case ',':  /* (Splicing) Uuquotation */
        scheme_error("unsupport (splicing) unquotation");
    default:
        return read_simple_datum(file, c);
    }
}
예제 #7
0
ULONG sphere(ULONG *arg)
{
	rsiVECTOR vec;
	float fnum;
	void *sphere,*surf,*actor;
	rsiResult err;

	surf = FindSurfListItem((char*)arg[0]);
	if(!surf)
		return rsiERR_SURFACE;

	err = rsiCreateSphere(CTXT, &sphere,surf);
	if(err)
		return err;

	if(!read_vector(&vec,(char*)arg[1]))
		return ERROR_VECTOR;
	err = rsiSetSphere(CTXT, sphere,rsiTSpherePos,&vec,rsiTDone);
	if(err)
		return err;

	fnum = (float)atof((char*)arg[2]);
	err = rsiSetSphere(CTXT, sphere,rsiTSphereRadius,fnum,rsiTDone);
	if(err)
		return err;

	if(arg[3])
	{
		actor = FindActorListItem((char*)arg[3]);
		if(!actor)
			return rsiERR_ACTOR;

		err = rsiSetSphere(CTXT, sphere,rsiTSphereActor,actor,rsiTDone);
		if(err)
			return err;
	}

	if(arg[4])
	{
		fnum = (float)atof((char*)arg[4]);
		err = rsiSetSphere(CTXT, sphere,rsiTSphereFuzzy,fnum,rsiTDone);
		if(err)
			return err;
	}

	if(arg[5])
	{
		err = rsiSetSphere(CTXT, sphere,rsiTSphereFlags,rsiFSphereInverted,rsiTDone);
		if(err)
			return err;
	}

	if(insideCSG > 0)
	{
		SetCSGObject(sphere);
		insideCSG--;
	}

	return rsiERR_NONE;
}
예제 #8
0
void GameObjectMessage::read_object_points() {
  char point_count;
  socket_->read_buffer(&point_count, sizeof(char));
  for (char i = 0; i < point_count; i++) {
    points_.push_back(read_vector(socket_));
  }
}
예제 #9
0
void GameObjectMessage::read() {
  object_id_ = read_uint32(socket_);
  position_ = read_vector(socket_);
  object_type_ = read_char(socket_);
  read_object_points();
  alive_ = read_bool(socket_);
}
예제 #10
0
ULONG size(ULONG *arg)
{
	rsiVECTOR vec;
	float begin,end;
	int flags = rsiFActionLinear;

	if(!actor)
		return rsiERR_ACTOR;

	begin = (float)atof((char*)arg[0]);
	end = (float)atof((char*)arg[1]);

	if(!read_vector(&vec,(char*)arg[2]))
		return ERROR_VECTOR;

	if(arg[3])
	{
		if(KEYWORD((char*)arg[3], "LINEAR"))
			flags |= rsiFActionLinear;
		else
			if(KEYWORD((char*)arg[3], "SPLINE"))
				flags |= rsiFActionSpline;
			else
				return ERROR_INTERPOL;
	}

	return rsiSize(CTXT, actor->item,begin,end,&vec,/*rsiTSizeFlags,flags,*/rsiTDone);
}
예제 #11
0
int f_alignment(ULONG *arg)
{
	rsiVECTOR vec;
	float begin,end;
	int flags = rsiFActionLinear;

	if (!actor)
		return rsiERR_ACTOR;

	begin = end = 0;

	if (arg[0])
		begin = (float)atof((char*)arg[0]);

	if (arg[1])
	end = (float)atof((char*)arg[1]);

	if (!read_vector(&vec,(char*)arg[2]))
		return ERROR_VECTOR;

	if (arg[3])
	{
		if (!stricmp((char*)arg[3], "LINEAR"))
			flags |= rsiFActionLinear;
		else
			if (!stricmp((char*)arg[3], "SPLINE"))
				flags |= rsiFActionSpline;
			else
				return ERROR_INTERPOL;
	}

	return rsiAlignment(actor->item,begin,end,&vec,rsiTAlignFlags,flags,rsiTDone);
}
NurbsOverAdaptedGrid::NurbsOverAdaptedGrid(int depth) {
	string d = to_string(depth);
	string grid_file = "grid-" + d + ".dat";
	string cmd = "./generate --knots " + d + " > " + grid_file;
	system(cmd.c_str());
	ifstream fin(grid_file);

	int N; // number of elements
	fin >> N;
	for (int i = 0; i < N; i++) {
		Bounds b;
		fin >> b.left >> b.right >> b.up >> b.down;
	}

	int M; // number of B-splines
	fin >> M;
	for (int i = 0; i < M; i++) {
		string type;
		// Regular or Gnomon
		fin >> type;
		if (type == "Regular") {
			vector<double> x_knots, y_knots;
			read_vector(fin, &x_knots, 4);
			read_vector(fin, &y_knots, 4);
			Bspline* regular = new Bspline(x_knots, y_knots);
			unscaled_bsplines.push_back(regular);
		} else {  // type == "Gnomon"
			double x_mid, y_mid, shift_x, shift_y;
			fin >> x_mid >> y_mid >> shift_x >> shift_y;
			GnomonBspline* gnomon = new GnomonBspline(x_mid, y_mid, shift_x, shift_y);
			unscaled_bsplines.push_back(gnomon);
		}
	}

	LinearCombination* sum_of_unscaled = new LinearCombination(unscaled_bsplines);
	for (const Function2D* unscaled_bspline: unscaled_bsplines) {
		const GnomonBspline* gb = dynamic_cast<const GnomonBspline*>(unscaled_bspline);
		Quotient* scaled_bspline;
		if (gb != nullptr)
			scaled_bspline = new GnomonNurbs(*gb, *sum_of_unscaled);
		else
			scaled_bspline = new Quotient(*unscaled_bspline, *sum_of_unscaled);
		scaled_bsplines.push_back(scaled_bspline);
	}
}
예제 #13
0
bool read_vector(const std::string& filename, boost::numeric::ublas::vector<T>& v) {
  FILE* file = fopen(filename.c_str(), "rb");
  if (!file)
    return false;
  bool res = read_vector(file, v);
  fclose(file);

  return res;
}
예제 #14
0
파일: 1.c 프로젝트: harababurel/homework
void option_b() {
    /* Method solves the second subproblem:
     * Given a vector of numbers, find the longest increasing contiguous subsequence.
     */

    vector v = read_vector();
    printf("Longest increasing contiguous subsequence: ");
    print_vector(get_longest_increasing_subsequence(v));
}
예제 #15
0
ULONG triangle(ULONG *arg)
{
	void *surf,*actor=NULL;
	int i;
	rsiVECTOR v[3];
	rsiVECTOR n[3];

	surf = FindSurfListItem((char*)arg[0]);
	if(!surf)
		return rsiERR_SURFACE;

	for(i=0; i<3; i++)
	{
		if(!read_vector(&v[i],(char*)arg[i+1]))
			return ERROR_VECTOR;
	}

	if(arg[7])
	{
		actor = FindActorListItem((char*)arg[7]);
		if(!actor)
			return rsiERR_ACTOR;
	}

	if(arg[4])
	{
		for(i=0; i<3; i++)
		{
			if(arg[i+4])
			{
				if(!read_vector(&n[i],(char*)arg[i+4]))
					return ERROR_VECTOR;
			}
		}
		return rsiCreateTriangle(CTXT, surf, &v[0], &v[1], &v[2],
			rsiTTriangleActor, actor,
			rsiTTriangleNorm1, &n[0],
			rsiTTriangleNorm2, &n[1],
			rsiTTriangleNorm3, &n[2], rsiTDone);
	}
	else
		return rsiCreateTriangle(CTXT, surf, &v[0], &v[1], &v[2],
			rsiTTriangleActor, actor, rsiTDone);
}
예제 #16
0
파일: matrix.c 프로젝트: DaniCF93/studia
int main(int argc, char * args[]){
    int i,j,it;
    unsigned long long counter, stop;
    char a[256], b[256];
    FILE * f;
    f = fopen("results.txt","w");
    

    
    
    
    for(it=2; it<=13; it++){
        fprintf(f,"%d ",it);
        sprintf(a,"mat_%d_a.mat",it);
        sprintf(b,"mat_%d_b.mat",it);
        int a_row = (int)pow(2,it), a_column = (int)pow(2,it), b_row = (int)pow(2,it), b_column = 1;
        
        
        //alokacja pamięci na macierze
        float ** m1 = read_matrix(a,a_row,a_column);
        float * m2 = read_vector(b,b_row);
        float * mw1 = (float*)malloc(a_row* sizeof(float));
		
		
		
		for(i=0; i<a_row; i++)
                mw1[i] = 0;
        counter = rdtsc(); 
        mul(mw1,m1,m2,a_row);
        stop = rdtsc() - counter;
        fprintf(f,"%llu ",stop / (int)pow(2,2*it));
        printf("%d\n",it);
		
		
		for(i=0; i<a_row; i++)
                mw1[i] = 0;
        counter = rdtsc(); 
        mul6(mw1,m1,m2,a_row);
        stop = rdtsc() - counter;
        fprintf(f,"%llu ",stop / (int)pow(2,2*it));
        printf("%d\n",it);
        
        
//print_matrix(mw1,a_row);

        //zwalnianie pamięci
        for(i=0; i<a_row; i++)
		    free(m1[i]);
	    free(m1); 
	    free(m2);
	    free(mw1);
	    fprintf(f,"\n");
	}
	fclose(f);
	return 0;
}
예제 #17
0
파일: util2.c 프로젝트: kolyuchiy/slau-mpi
double* read_matrix(double *a, int n, int m)
{
	int j;

	for (j=0; j<n; j++) {
		read_vector(a+j*m, m);
	}

	return a;
}
예제 #18
0
int f_newactor(ULONG *arg)
{
	rsiVECTOR vec;
	void *act;
	rsiResult err;

	err = rsiCreateActor(&act);
	if (err)
		return err;

	if (!arg[0])
		return ERROR_STRINGEXP;

	actor = AddActorList((char*)arg[0],act);
	if (!actor)
		return rsiERR_MEM;

	if (arg[1])
	{
		if (!read_vector(&vec,(char*)arg[1]))
			return ERROR_VECTOR;
		err = rsiSetActor(act,rsiTActorPos,&vec,rsiTDone);
		if (err)
			return err;
	}
	if (arg[2])
	{
		if (!read_vector(&vec,(char*)arg[2]))
			return ERROR_VECTOR;
		err = rsiSetActor(act,rsiTActorAlign,&vec,rsiTDone);
		if (err)
			return err;
	}
	if (arg[3])
	{
		if (!read_vector(&vec,(char*)arg[3]))
			return ERROR_VECTOR;
		err = rsiSetActor(act,rsiTActorSize,&vec,rsiTDone);
		if (err)
			return err;
	}
	return rsiERR_NONE;
}
예제 #19
0
ULONG loadobj(ULONG *arg)
{
	rsiVECTOR pos = {0.,0.,0.}, align = {0.,0.,0.}, scale = {1.,1.,1.};
	void *surf=NULL,*actor=NULL;

	if(arg[1])
	{
		if(!read_vector(&pos,(char*)arg[1]))
			return ERROR_VECTOR;
	}
	if(arg[2])
	{
		if(!read_vector(&align,(char*)arg[2]))
			return ERROR_VECTOR;
	}
	if(arg[3])
	{
		if(!read_vector(&scale,(char*)arg[3]))
			return ERROR_VECTOR;
	}
	if(arg[4])
	{
		actor = FindActorListItem((char*)arg[4]);
		if(!actor)
			return rsiERR_ACTOR;
	}
	if(arg[5])
	{
		surf = FindSurfListItem((char*)arg[5]);
		if(!surf)
			return rsiERR_SURFACE;
	}

	return rsiLoadObject(CTXT, (char*)arg[0],
		rsiTObjPos,&pos,
		rsiTObjAlign,&align,
		rsiTObjScale,&scale,
		rsiTObjActor,actor,
		rsiTObjSurface,surf,
		rsiTDone);
}
예제 #20
0
파일: g_save.c 프로젝트: Jenco420/q2pro
static void read_field(FILE *f, const save_field_t *field, void *base)
{
    void *p = (byte *)base + field->ofs;
    int i;

    switch (field->type) {
    case F_BYTE:
        read_data(p, field->size, f);
        break;
    case F_SHORT:
        for (i = 0; i < field->size; i++) {
            ((short *)p)[i] = read_short(f);
        }
        break;
    case F_INT:
        for (i = 0; i < field->size; i++) {
            ((int *)p)[i] = read_int(f);
        }
        break;
    case F_FLOAT:
        for (i = 0; i < field->size; i++) {
            ((float *)p)[i] = read_float(f);
        }
        break;
    case F_VECTOR:
        read_vector(f, (vec_t *)p);
        break;

    case F_LSTRING:
        *(char **)p = read_string(f);
        break;
    case F_ZSTRING:
        read_zstring(f, (char *)p, field->size);
        break;

    case F_EDICT:
        *(edict_t **)p = read_index(f, sizeof(edict_t), g_edicts, game.maxentities - 1);
        break;
    case F_CLIENT:
        *(gclient_t **)p = read_index(f, sizeof(gclient_t), game.clients, game.maxclients - 1);
        break;
    case F_ITEM:
        *(gitem_t **)p = read_index(f, sizeof(gitem_t), itemlist, game.num_items - 1);
        break;

    case F_POINTER:
        *(void **)p = read_pointer(f, field->size);
        break;

    default:
        gi.error("%s: unknown field type", __func__);
    }
}
예제 #21
0
파일: lab.cpp 프로젝트: cscenter/hpcourse
int run_threads() {
    pthread_t consumer;
    pthread_t producer;
    pthread_t interruptor;
    std::vector<int> v = read_vector();
    int sum = 0;
    pthread_create(&consumer, NULL, consumer_routine, &sum);
    pthread_create(&producer, NULL, producer_routine, &v);
    pthread_create(&interruptor, NULL, consumer_interruptor_routine, &consumer);
    pthread_join(consumer, NULL);
    pthread_join(producer, NULL);
    pthread_join(interruptor, NULL);
    return sum;
}
예제 #22
0
Volume* load_volume(tinyxml2::XMLElement *elem, VolumeCache &cache, const std::string &scene_file){
	if (!elem->Attribute("name")){
		std::cout << "Scene error: Volumes require a name" << std::endl;
		return nullptr;
	}
	if (!elem->Attribute("type")){
		std::cout << "Scene error: Volumes require a type" << std::endl;
		return nullptr;
	}

	std::string name = elem->Attribute("name");
	std::string type = elem->Attribute("type");

	Volume *vol = cache.get(name);
	if (vol){
		return vol;
	}
	Colorf sig_a, sig_s, emit;
	float phase_asym;
	read_color(elem->FirstChildElement("absorption"), sig_a);
	read_color(elem->FirstChildElement("scattering"), sig_s);
	read_color(elem->FirstChildElement("emission"), emit);
	read_float(elem->FirstChildElement("phase_asymmetry"), phase_asym);

	if (type == "homogeneous"){
		Point min, max;
		read_point(elem->FirstChildElement("min"), min);
		read_point(elem->FirstChildElement("max"), max);
		return cache.add(name, std::make_unique<HomogeneousVolume>(sig_a, sig_s, emit, phase_asym, BBox{min, max}));
	}
	if (type == "exponential"){
		float a = 0, b = 0;
		Vector up;
		Point min, max;
		read_float(elem->FirstChildElement("a"), a);
		read_float(elem->FirstChildElement("b"), b);
		read_vector(elem->FirstChildElement("up"), up);
		read_point(elem->FirstChildElement("min"), min);
		read_point(elem->FirstChildElement("max"), max);
		return cache.add(name, std::make_unique<ExponentialVolume>(sig_a, sig_s, emit, phase_asym, BBox{min, max}, a, b, up));
	}
	if (type == "vol"){
		std::string file = scene_file.substr(0, scene_file.rfind(PATH_SEP) + 1) + elem->Attribute("file");
		float density_scale = 1;
		read_float(elem->FirstChildElement("density_scale"), density_scale);
		return cache.add(name, std::make_unique<GridVolume>(sig_a, sig_s, emit, phase_asym, file, density_scale));
	}
	std::cout << "Scene error: Unrecognized volume type " << type << std::endl;
	return nullptr;
}
		/*!
		* \brief Initializes node to get parameters, subscribe and publish to topics.
		*/
		bool init()
		{
			// implementation of topics to publish
 
			nh_.param("dsadevicestring", dsadevicestring_, std::string(""));
			if (dsadevicestring_.empty()) return false;

			nh_.param("dsadevicenum", dsadevicenum_, 0);
			nh_.param("maxerror", maxerror_, 8);
			
 			double publish_frequency, diag_frequency;
			
			nh_.param("debug", debug_, false);
			nh_.param("polling", polling_, false);
			nh_.param("use_rle", use_rle_, true);
			nh_.param("diag_frequency", diag_frequency, 5.0);
			frequency_ = 30.0;
			if(polling_) nh_.param("poll_frequency", frequency_, 5.0);
			nh_.param("publish_frequency", publish_frequency, 0.0);
			
			auto_publish_ = true;

				
			if(polling_){
			    timer_dsa = nh_.createTimer(ros::Rate(frequency_).expectedCycleTime(),boost::bind(&DsaNode::pollDsa,  this));
 			}else{
			    timer_dsa = nh_.createTimer(ros::Rate(frequency_*2.0).expectedCycleTime(),boost::bind(&DsaNode::readDsaFrame,  this));
			    if(publish_frequency > 0.0){
				auto_publish_ = false;
				timer_publish = nh_.createTimer(ros::Rate(publish_frequency).expectedCycleTime(),boost::bind(&DsaNode::publishTactileData, this));
			    }
			}

			timer_diag = nh_.createTimer(ros::Rate(diag_frequency).expectedCycleTime(),boost::bind(&DsaNode::publishDiagnostics, this));
			
			if(!read_vector(nh_, "dsa_reorder", dsa_reorder_)){
			    dsa_reorder_.resize(6);
			    dsa_reorder_[0] = 2; // t1
			    dsa_reorder_[1] = 3; // t2
			    dsa_reorder_[2] = 4; // f11
			    dsa_reorder_[3] = 5; // f12
			    dsa_reorder_[4] = 0; // f21
			    dsa_reorder_[5] = 1; // f22
			}
			
			return true;
		}
예제 #24
0
floatingtype_t read_floatingtype(hid_t loc_id, const char *path)
{
    floatingtype_t ft;

    ft.floatingtype = get_type_ft(loc_id, path);
    if (ft.floatingtype == E_SINGLE_REAL)
        ft.singlereal = read_singlereal(loc_id, path);
    else if (ft.floatingtype == E_SINGLE_COMPLEX)
        ft.singlecomplex = read_singlecomplex(loc_id, path);
    else if (ft.floatingtype == E_VECTOR)
        ft.vector = read_vector(loc_id, path);
    else if (ft.floatingtype == E_DATA_SET)
        ft.dataset = read_dataset(loc_id, path);
    else if (ft.floatingtype == E_ARRAY_SET)
        ft.arrayset = read_arrayset(loc_id, path);
    return ft;
}
예제 #25
0
inline value read_value(scanner& sc) {
    if (sc.peek_token().is_char('{')) {
        return value(read_group(sc, true));
    } else if (sc.peek_token().is_char('[')) {
        return value(read_vector(sc));
    } else {
        switch (sc.peek_token().type) {
        case token_type::identifier_token: {
            std::string ident = sc.expect_identifier();
            if (ident == "true") {
                return value(true);
            } else if (ident == "false") {
                return value(false);
            } else {
                sc.fail("unexpected identifier", sc.peek_token().line, sc.peek_token().col);
            }
            break;
        }
        case token_type::string_token: {
            std::string str = sc.expect_string();
            return value(str);
        }
        case token_type::number_token: {
            double dbl = sc.expect_number();
            return value(dbl);
        }
        case token_type::char_token: {
            sc.fail("unexpected '" + std::string(1, sc.peek_token().char_value) + "'",
                sc.peek_token().line, sc.peek_token().col);
            break;
        }
        default: {
            sc.fail("unexpected token", sc.peek_token().line, sc.peek_token().col);
            break;
        }

        }
    }
    return value();
}
예제 #26
0
void indexed_force_tri_3D::load(std::ifstream& in, point_cloud* pPC)
{
	// read the label in and set it
	LABEL label = read_label(in);
	set_label(label);
	if (in.eof())
		return;

	// set the point cloud
	ppoint_cloud_instance = pPC;
	// read the point cloud indices for each vertex
	for (int t=0; t<3; t++)
		p[t] = read_int(in);
	// calculate the centroid
	calculate_centroid();
	// read the target index
	ds_index = read_int(in);
	// read the length of index list in
	int n_idx = read_int(in);
	for (int i=0; i<n_idx; i++)
	{
		grid_index gr_idx;
		gr_idx.i = read_int(in);
		gr_idx.j = read_int(in);
		gr_idx.cart_coord = read_vector(in);
		grid_indices.push_back(gr_idx);
	}
	// read the point and adjacency list
	for (int a=0; a<2; a++)
	{
		// get the size first
		int s = read_int(in);
		for (int i=0; i<s; i++)
			adjacency[a].push_back(read_label(in));
	}
}
예제 #27
0
파일: read.c 프로젝트: GlenHertz/julia
// label is the backreference we'd like to fix up with this read
static value_t do_read_sexpr(value_t label)
{
    value_t v, sym, oldtokval, *head;
    value_t *pv;
    u_int32_t t;
    char c;

    t = peek();
    take();
    switch (t) {
    case TOK_CLOSE:
        lerror(ParseError, "read: unexpected ')'");
    case TOK_CLOSEB:
        lerror(ParseError, "read: unexpected ']'");
    case TOK_DOT:
        lerror(ParseError, "read: unexpected '.'");
    case TOK_SYM:
    case TOK_NUM:
        return tokval;
    case TOK_COMMA:
        head = &COMMA; goto listwith;
    case TOK_COMMAAT:
        head = &COMMAAT; goto listwith;
    case TOK_COMMADOT:
        head = &COMMADOT; goto listwith;
    case TOK_BQ:
        head = &BACKQUOTE; goto listwith;
    case TOK_QUOTE:
        head = &QUOTE;
    listwith:
        v = cons_reserve(2);
        car_(v) = *head;
        cdr_(v) = tagptr(((cons_t*)ptr(v))+1, TAG_CONS);
        car_(cdr_(v)) = cdr_(cdr_(v)) = NIL;
        PUSH(v);
        if (label != UNBOUND)
            ptrhash_put(&readstate->backrefs, (void*)label, (void*)v);
        v = do_read_sexpr(UNBOUND);
        car_(cdr_(Stack[SP-1])) = v;
        return POP();
    case TOK_SHARPQUOTE:
        // femtoLisp doesn't need symbol-function, so #' does nothing
        return do_read_sexpr(label);
    case TOK_OPEN:
        PUSH(NIL);
        read_list(&Stack[SP-1], label);
        return POP();
    case TOK_SHARPSYM:
        sym = tokval;
        if (sym == tsym || sym == Tsym)
            return FL_T;
        else if (sym == fsym || sym == Fsym)
            return FL_F;
        // constructor notation
        c = nextchar();
        if (c != '(') {
            take();
            lerrorf(ParseError, "read: expected argument list for %s",
                    symbol_name(tokval));
        }
        PUSH(NIL);
        read_list(&Stack[SP-1], UNBOUND);
        if (sym == vu8sym) {
            sym = arraysym;
            Stack[SP-1] = fl_cons(uint8sym, Stack[SP-1]);
        }
        else if (sym == fnsym) {
            sym = FUNCTION;
        }
        v = symbol_value(sym);
        if (v == UNBOUND)
            fl_raise(fl_list2(UnboundError, sym));
        return fl_apply(v, POP());
    case TOK_OPENB:
        return read_vector(label, TOK_CLOSEB);
    case TOK_SHARPOPEN:
        return read_vector(label, TOK_CLOSE);
    case TOK_SHARPDOT:
        // eval-when-read
        // evaluated expressions can refer to existing backreferences, but they
        // cannot see pending labels. in other words:
        // (... #2=#.#0# ... )    OK
        // (... #2=#.(#2#) ... )  DO NOT WANT
        sym = do_read_sexpr(UNBOUND);
        if (issymbol(sym)) {
            v = symbol_value(sym);
            if (v == UNBOUND)
                fl_raise(fl_list2(UnboundError, sym));
            return v;
        }
        return fl_toplevel_eval(sym);
    case TOK_LABEL:
        // create backreference label
        if (ptrhash_has(&readstate->backrefs, (void*)tokval))
            lerrorf(ParseError, "read: label %ld redefined", numval(tokval));
        oldtokval = tokval;
        v = do_read_sexpr(tokval);
        ptrhash_put(&readstate->backrefs, (void*)oldtokval, (void*)v);
        return v;
    case TOK_BACKREF:
        // look up backreference
        v = (value_t)ptrhash_get(&readstate->backrefs, (void*)tokval);
        if (v == (value_t)HT_NOTFOUND)
            lerrorf(ParseError, "read: undefined label %ld", numval(tokval));
        return v;
    case TOK_GENSYM:
        pv = (value_t*)ptrhash_bp(&readstate->gensyms, (void*)tokval);
        if (*pv == (value_t)HT_NOTFOUND)
            *pv = fl_gensym(NULL, 0);
        return *pv;
    case TOK_DOUBLEQUOTE:
        return read_string();
    }
    return FL_UNSPECIFIED;
}
예제 #28
0
static bool decodeBlendshapes(fsTrackingData & _trackingData, const std::string &buffer, Size &start) {
    return read_vector(_trackingData.m_coeffs, buffer, start);
}
예제 #29
0
/*
 * Main function used to plot save vectors
 */
int main(int argc, char const *argv[])
{
	// variables declaration
	int i, j;
	int nb_curves;
	int size_vector, cur_size_vector;
	int init_t_sec, init_t_usec;

	double last_tsim;
	double cur_value, cur_min, cur_max;
	double y_min_init, y_max_init;

	char *generic_vec_file;
	char **vec_names;
	char t_file[PATH_MAX_LENGTH];
	char cur_vec_file[PATH_MAX_LENGTH];

	double *vec_t;
	double **vec_out;
	double *y_tab_min, *y_tab_max;

	Screen_sdl *screen_sdl;
	Simu_real_time *real_time;

	// vectors to plot
	vec_names = get_vec_names(&nb_curves);

	// vectors initialization
	generic_vec_file = CUR_PROJECT_ABS_PATH"/vectors";

	sprintf (t_file, "%s/vectors/%s", CUR_PROJECT_ABS_PATH, vec_names[0]);	

	vec_t = read_vector(t_file, &size_vector);

	vec_out = (double**) malloc (nb_curves*sizeof(double*));

	for (i=0; i<nb_curves; i++)
	{
		sprintf (cur_vec_file, "%s/%s", generic_vec_file, vec_names[i+1]);

		vec_out[i] = read_vector(cur_vec_file, &cur_size_vector);

		if (cur_size_vector != size_vector)
		{
			printf("Problem: all vectors do not have the same size !\n");
			printf("Time vector size: %d\n", size_vector);
			printf("Vector %s size: %d\n", cur_vec_file, cur_size_vector);
			exit(1);
		}
	}

	// max and min tabulars
	y_tab_min = (double*) malloc(nb_curves*sizeof(double));
	y_tab_max = (double*) malloc(nb_curves*sizeof(double));

	// compute minimal and maximal values
	cur_value  = vec_out[0][0];
	y_min_init = cur_value;
	y_max_init = cur_value;

	for (i=0; i<nb_curves; i++)
	{
		cur_value = vec_out[i][0];
		cur_min   = cur_value;
		cur_max   = cur_value;

		for (j=1; j<size_vector; j++)
		{
			cur_value = vec_out[i][j];

			if (cur_value < cur_min)
			{
				cur_min = cur_value;
			}

			if (cur_value > cur_max)
			{
				cur_max = cur_value;
			}
		}

		y_tab_min[i] = cur_min;
		y_tab_max[i] = cur_max;

		if (cur_min < y_min_init)
		{
			y_min_init = cur_min;
		}

		if (cur_max > y_max_init)
		{
			y_max_init = cur_max;
		}
	}

	// absolute time before starting loop
	time_get(&init_t_sec, &init_t_usec);

	// real time structure initialization
	real_time = init_real_time(init_t_sec, init_t_usec);

	// init screen SDL
	screen_sdl = configure_screen_sdl_plot_save(init_t_sec, init_t_usec, y_min_init, y_max_init, size_vector, nb_curves);

	// fill screen SDL
	for (i=0; i<nb_curves; i++)
	{
		for (j=1; j<size_vector; j++)
		{
			screen_sdl->y_vectors[i][j] = vec_out[i][j];
		}
	}

	for (i=0; i<size_vector; i++)
	{
		screen_sdl->tsim_vec[i] = vec_t[i];
	}

	for (i=0; i<nb_curves; i++)
	{
		screen_sdl->y_tab_min[i] = y_tab_min[i];
		screen_sdl->y_tab_max[i] = y_tab_max[i];
	}

	// special values
	real_time->simu_break  = 1;
	screen_sdl->index_simu = size_vector-1;
	last_tsim              = vec_t[size_vector-1];

	// plot main loop
	break_gestion_plot_save(screen_sdl, real_time, init_t_sec, init_t_usec, last_tsim);

	// release memory
	for (i=0; i<nb_curves; i++)
	{
		free(vec_out[i]);
	}

	free(vec_out);
	free(vec_t);
	free(y_tab_min);
	free(y_tab_max);
	
	free_screen_sdl(screen_sdl);
	free_simu_real_time(real_time);
	free_char_tab(vec_names);

	return 0;
}
예제 #30
0
int main()
{
    int n = 0;
    char filename[256];
    double** matrixA;
    clock_t time;
    double* vectorB;

    n = read_dimension();
    printf("Dimensio n=%d\n", n);

    printf("Arxiu matriu A? (buit per matriu random) ");
    fgets(filename, 255, stdin);

    if (filename[0] != '\n') {
        if (filename[strlen(filename) - 1] == '\n') {
            filename[strlen(filename) - 1] = '\0';
        }

        printf("\nMatriu de l'arxiu %s\n", filename);
        matrixA = read_matrix(filename, n);
    } else {
        printf("\nMatriu random\n");
        matrixA = generate_random_matrix(n);
    }

    printf("Arxiu vector b? (buit per vector random) ");
    fgets(filename, 255, stdin);

    if (filename[0] != '\n') {
        if (filename[strlen(filename) - 1] == '\n') {
            filename[strlen(filename) - 1] = '\0';
        }

        printf("\nVector de l'arxiu %s\n", filename);
        vectorB = read_vector(filename, n);
    } else {
        printf("\n Vector random\n");
        vectorB = generate_random_vector(n);
    }

    printf("Començant calcul LUx = b...\n");
    time = clock();

    /*******/
    solveLU(n, matrixA, vectorB);
    /*******/
    time = clock() - time;
    printf("Calcul finalitzat.\n");

    printf("S'escriura el vector X a l'arxiu output2.txt\n");

    write_vector("output2.txt", vectorB, n);

    printf("n = %d, t = %.6f, t/n = %.6f\n",
           n, ((float)time)/CLOCKS_PER_SEC,
           (((float)time) / CLOCKS_PER_SEC)/n
          );

    free_matrix(matrixA, n);
    free(vectorB);
    return 0;
}