void receive_file(struct packet* hp, struct packet* data, int sfd, FILE* f)
{
	int x;
	int i = 0, j = 0;
	if((x = recv(sfd, data, size_packet, 0)) <= 0)
		er("recv()", x);
	j++;
	hp = ntohp(data);
	printpacket(hp, HP);
	// 当在数据传输的时候 type字段会用来标示是否
	while(hp->type == DATA)
	{
		// 将收到的数据写入文件,二进制写入方式
		i += fwrite(hp->buffer, 1, hp->datalen, f);
		if((x = recv(sfd, data, size_packet, 0)) <= 0)
			er("recv()", x);
		j++;
		hp = ntohp(data);
		printpacket(hp, HP);
	}
	fprintf(stderr, "\t%d data packet(s) received.\n", --j);	// j decremented because the last packet is EOT.
	fprintf(stderr, "\t%d byte(s) written.\n", i);
	if(hp->type == EOT)
		return;
	else
	{
		fprintf(stderr, "Error occured while downloading remote file.\n");
		exit(2);
	}
	fflush(stderr);
}
Esempio n. 2
0
void command_rput(int sfd_client, struct packet* chp)
{
	static char lpwd[LENBUFFER];
	if(!getcwd(lpwd, sizeof lpwd))
		er("getcwd()", 0);
	DIR* d = opendir(lpwd);
	if(!d)
		er("opendir()", (int) d);
	struct dirent* e;
	struct command* cmd = (struct command*) malloc(sizeof(struct command));
	cmd->id = RPUT;
	cmd->npaths = 0;
	cmd->paths = NULL;
	while((e = readdir(d)) != NULL)
		if(e->d_type == 8)
			append_path(cmd, e->d_name);
		else if(e->d_type == 4 && strcmp(e->d_name, ".") && strcmp(e->d_name, ".."))
		{
			command_mkdir(sfd_client, chp, e->d_name);
			
			command_cd(sfd_client, chp, e->d_name);
			command_lcd(e->d_name);
			
			command_rput(sfd_client, chp);
			
			command_cd(sfd_client, chp, "..");
			command_lcd("..");
		}
	closedir(d);
	command_mput(sfd_client, chp, cmd->npaths, cmd->paths);
}
// the opration of DIR command
void command_dir(struct packet* shp, struct packet* data, int sfd_client, char* lpwd)
{
    int x;
    shp->type = DATA;
    DIR* d = opendir(lpwd);
    if(!d)
    {
        er("opendir()", (int) d);
        sprintf(shp->buffer, "ER: could not get the dir info!\n");
        data = htonp(shp);
        if( (x = send(sfd_server_data, data, size_packet,0)) != size_packet)
            er("send()",x);
    }
    else
    {
        sprintf(shp->buffer, "OK: get the dir info.\n");
        data = htonp(shp);
        if(( x = send(sfd_server_data, data, size_packet, 0)) != size_packet)
            er("send()",x);
    }
    struct dirent* e;

    while(e = readdir(d))
    {
        sprintf(shp->buffer, "%s\t%s", e->d_type == 4 ? "DIR:" : e->d_type == 8 ? "FILE:" : "UNDEF:" , e->d_name);
        data = htonp(shp);
        //if(( x = send(sfd_client, data, size_packet, 0)) != size_packet)
        if(( x = send(sfd_server_data, data, size_packet, 0)) != size_packet)    
            er("send()", x);
    }
    send_EOT(shp, data, sfd_server_data);
    //send_EOT(shp, data, sfd_client);
}
Esempio n. 4
0
void DifBufferBase::zombify( Element* orig, const Cinfo* zClass, 
			     Id hsolve )
{
  if ( orig->cinfo() == zClass )
    return;
  unsigned int start = orig->localDataStart();
  unsigned int num = orig->numLocalData();
  if ( num == 0 )
    return;
  unsigned int len = 14;
  vector< double > data( num * len );

  unsigned int j = 0;
	
  for ( unsigned int i = 0; i < num; ++i ) {
    Eref er( orig, i + start );
    const DifBufferBase* ds = 
      reinterpret_cast< const DifBufferBase* >( er.data() );
    data[j + 0] = ds->getActivation( er );
    data[j + 1] = ds->getBFree( er );
    data[j + 2] = ds->getBBound( er );
    data[j + 3] = ds->getBTot( er );
    data[j + 4] = ds->getKf( er );
    data[j + 5] = ds->getKb( er );
    data[j + 6] = ds->getD( er );
    data[j + 7] = ds->getShapeMode( er );
    data[j + 8] = ds->getLength( er );
    data[j + 9] = ds->getDiameter( er );
    data[j + 10] = ds->getThickness( er );
    data[j + 11] = ds->getVolume( er );
    data[j + 12] = ds->getOuterArea( er );
    data[j + 13] = ds->getInnerArea( er );
    j += len;
  }
  orig->zombieSwap( zClass );
  j = 0;
  for ( unsigned int i = 0; i < num; ++i ) {
    Eref er( orig, i + start );
    DifBufferBase* ds = 
      reinterpret_cast< DifBufferBase* >( er.data() );
    ds->vSetSolver(er,hsolve);
    ds->setActivation(er, data[j+0]);
    ds->setBFree(er, data[j + 1]);
    ds->setBBound(er, data[j + 2]);
    ds->setBTot(er, data[j + 3]);
    ds->setKf(er, data[j + 4]);
    ds->setKb(er, data[j + 5]);
    ds->setD(er, data[j + 6]);
    ds->setShapeMode(er, data[j + 7]);
    ds->setLength(er, data[j + 8]);
    ds->setDiameter(er, data[j + 9]);
    ds->setThickness(er, data[j + 10]);
    ds->setVolume(er, data[j + 11]);
    ds->setOuterArea(er, data[j + 12]);
    ds->setInnerArea(er, data[j + 13]);
    j += len; //??
  }
	
}
Esempio n. 5
0
/*
 * A tadpole with a full propagator and with 1 LV vertex
 */
main()
{
  page                   pg;
  FeynDiagram            fd(pg);

#define RAD    2.5

  fd.line_thickness.set(0.15);
  fd.vertex_thickness.set(0.15);
  /* define the left and the right external points */
  xy                     el(-TADPOLELEG, 0), er(6, 0);
  /* the LV vertex */
  xy                     arcpt1(RAD, 0);
  xy                     arcpt2(0, -RAD);
  /* the ordinary SQED vertex */
  vertex_circlecross     v1(fd, -RAD, 0);
  vertex                 v2(fd,  RAD, 0);
  vertex                 fict(fd, -RAD - 0.5, 0);   /* for a nicer picture */
  /* photon line propagators */
  line_wiggle            ph1(fd, el, fict);

  line_plain             f1(fd, v1, v1);
  f1.thickness.set(FULLPROPTHICK);
  f1.arrowon.setfalse();
  //  line_plain             f2(fd, v2, v1);

  /* stretch it to be an arc */

  f1.arcthru(arcpt1);
  //  f2.arcthru(arcpt2);

  pg.output();
  return 0;
}
Esempio n. 6
0
vector< ObjId > Element::getMsgTargets( DataId srcDataId,
				const SrcFinfo* finfo  ) const
{
	assert( finfo ); // would like to check that finfo is on this.
	assert( srcDataId < this->numData() );

	vector< ObjId > ret;
	Eref er( const_cast< Element* >( this ), srcDataId );

	const vector< MsgDigest >&md = er.msgDigest( finfo->getBindIndex() );
	for ( vector< MsgDigest >::const_iterator
		i = md.begin(); i != md.end(); ++i ) {
		for ( vector< Eref >::const_iterator
			j = i->targets.begin(); j != i->targets.end(); ++j ) {
				if ( j->dataIndex() == ALLDATA ) {
					for ( unsigned int k = 0; 
									k < j->element()->numData(); ++k )
						ret.push_back( ObjId( j->id(), k ) );
				} else {
					ret.push_back( j->objId() );
				}
		}
	}
	return ret;
}
Esempio n. 7
0
bd_result banco::executaQuery(const string& q)
{
	MYSQL_ROW linha;
	MYSQL_FIELD* colunas;
	unsigned int i;
	string col;
	bd_result R;
	map <string, string> RES;
	
	if(mysql_query(sock,q.c_str())) {
		ostringstream er("");
		er << mysql_error(sock);
		throw queryErro(er.str().c_str(), q,  mysql_errno(sock));
	} else {
//		cout << "Query executada!" << endl;
		result = mysql_store_result(sock);
		if (result)
		{
			colunas = mysql_fetch_fields(result);
			while ((linha=mysql_fetch_row(result)) != NULL)
			{
				for (i=0; i<mysql_num_fields(result); i++) {
					col = colunas[i].name;
					RES[col] = linha[i];
				}
				R.push_back(RES);
			}
		}
	}
	mysql_free_result(result);
	return R;
}
Esempio n. 8
0
  /*! This method employs the static method matrix3x3::jacobi(...)
    to find the eigenvalues and eigenvectors of a symmetric
    matrix. On entry it is checked if the matrix really is
    symmetric: if isSymmetric() returns 'false', an OBError is
    thrown.
 
    \note The jacobi algorithm is should work great for all
    symmetric 3x3 matrices. If you need to find the eigenvectors
    of a non-symmetric matrix, you might want to resort to the
    sophisticated routines of LAPACK.
 
    @param eigenvals a reference to a vector3 where the
    eigenvalues will be stored. The eigenvalues are ordered so
    that eigenvals[0] <= eigenvals[1] <= eigenvals[2].
 
    @return an orthogonal matrix whose ith column is an
    eigenvector for the eigenvalue eigenvals[i]. Here 'orthogonal'
    means that all eigenvectors have length one and are mutually
    orthogonal. The ith eigenvector can thus be conveniently
    accessed by the GetColumn() method, as in the following
    example.
    \code
    // Calculate eigenvectors and -values
    vector3 eigenvals;
    matrix3x3 eigenmatrix = somematrix.findEigenvectorsIfSymmetric(eigenvals);
  
    // Print the 2nd eigenvector
    cout << eigenmatrix.GetColumn(1) << endl;
    \endcode
    With these conventions, a matrix is diagonalized in the following way:
    \code
    // Diagonalize the matrix
    matrix3x3 diagonalMatrix = eigenmatrix.inverse() * somematrix * eigenmatrix;
    \endcode
  
  */
  matrix3x3 matrix3x3::findEigenvectorsIfSymmetric(vector3 &eigenvals) const
#ifdef OB_OLD_MATH_CHECKS
  throw(OBError)
#endif
  {
    matrix3x3 result;

#ifdef OB_OLD_MATH_CHECKS
    if (!isSymmetric())
      {
        OBError er("matrix3x3::findEigenvectorsIfSymmetric(vector3 &eigenvals) const throw(OBError)",
                   "The method was called on a matrix that was not symmetric, i.e. where isSymetric() == false.",
                   "This is a runtime or a programming error in your application.");
        throw er;
      }
#endif

    double d[3];
    matrix3x3 copyOfThis = *this;

    jacobi(3, copyOfThis.ele[0], d, result.ele[0]);
    eigenvals.Set(d);

    return result;
  }
Esempio n. 9
0
int main(int argc, char** argv)
{
    // Get user parameters.
    Opm::parameter::ParameterGroup param(argc, argv, false);

    // Create the Equelle runtime.
    EquelleRuntimeCPU er(param);

    ensureRequirements(er);

    // ============= Generated code starts here ================

    const CollOfScalar a = er.operatorExtend(double(1), er.allCells());
    const CollOfScalar b = er.operatorExtend(double(2), er.interiorCells());
    const CollOfScalar c = er.operatorExtend(double(3), er.boundaryCells());
    const CollOfScalar d = ((a + er.operatorExtend(b, er.interiorCells(), er.allCells())) + er.operatorExtend(c, er.boundaryCells(), er.allCells()));
    er.output("a", a);
    er.output("b", b);
    er.output("c", c);
    er.output("d", d);

    // ============= Generated code ends here ================

    return 0;
}
Esempio n. 10
0
  /*! This method checks if the absolute value of the determinant is smaller than 1e-6. If
    so, nothing is done and an exception is thrown. Otherwise, the
    inverse matrix is calculated and returned. *this is not changed.
	
    \warning If the determinant is close to zero, but not == 0.0,
    this method may behave in unexpected ways and return almost
    random results; details may depend on your particular floating
    point implementation. The use of this method is therefore highly
    discouraged, unless you are certain that the determinant is in a
    reasonable range, away from 0.0 (Stefan Kebekus)
  */
  matrix3x3 matrix3x3::inverse(void) const
#ifdef OB_OLD_MATH_CHECKS
  throw(OBError)
#endif
  {
    double det = determinant();

#ifdef OB_OLD_MATH_CHECKS
    if (fabs(det) <= 1e-6)
      {
        OBError er("matrix3x3::invert(void)",
                   "The method was called on a matrix with |determinant| <= 1e-6.",
                   "This is a runtime or a programming error in your application.");
        throw er;
      }
#endif

    matrix3x3 returnValue;
    returnValue.ele[0][0] = ele[1][1]*ele[2][2] - ele[1][2]*ele[2][1];
    returnValue.ele[1][0] = ele[1][2]*ele[2][0] - ele[1][0]*ele[2][2];
    returnValue.ele[2][0] = ele[1][0]*ele[2][1] - ele[1][1]*ele[2][0];
    returnValue.ele[0][1] = ele[2][1]*ele[0][2] - ele[2][2]*ele[0][1];
    returnValue.ele[1][1] = ele[2][2]*ele[0][0] - ele[2][0]*ele[0][2];
    returnValue.ele[2][1] = ele[2][0]*ele[0][1] - ele[2][1]*ele[0][0];
    returnValue.ele[0][2] = ele[0][1]*ele[1][2] - ele[0][2]*ele[1][1];
    returnValue.ele[1][2] = ele[0][2]*ele[1][0] - ele[0][0]*ele[1][2];
    returnValue.ele[2][2] = ele[0][0]*ele[1][1] - ele[0][1]*ele[1][0];

    returnValue /= det;

    return(returnValue);
  }
Esempio n. 11
0
/*
 * Diagram "F", SQED, unbroken SUSY,
 * Gauge sector.
 */
main()
{
  page                   pg;
  FeynDiagram            fd(pg);

#define RAD    2.5

  fd.line_thickness.set(0.15);
  fd.vertex_thickness.set(0.15);
  /* define the left and the right external points */
  xy                     el(-6, 0), er(6, 0);

  xy              arcpt1(RAD, 0);    arcpt1.rotate(90); arcpt1 += xy(0,RAD);

  arcpt1 += xy(0, GAUGE_LIFT1);

  /* the LV vertex */
  xy                     lv_coord(0, GAUGE_LIFT1);
  vertex_circlecross     v1(fd, lv_coord);        

  /* photon line propagators */
  line_wiggle            ph1(fd, el, er); ph1.width.scale(0.7);

  line_plain             f1(fd, v1, v1);

  /* stretch it to be an arc */

  f1.arcthru(arcpt1);

  pg.output();
  return 0;
}
Esempio n. 12
0
void tst_expr_arith(unsigned num_files) {
    ast_manager m;
    reg_decl_plugins(m);

    expr_rand er(m);    
    er.seed(rand_seed);
    er.initialize_arith(20);

    family_id fid = m.mk_family_id("arith");
    sort* int_ty  = m.mk_sort(fid, INT_SORT, 0, 0);
    sort* real_ty = m.mk_sort(fid, REAL_SORT, 0, 0);

    er.initialize_array(3, int_ty, int_ty);
    er.initialize_array(3, int_ty, real_ty);

    er.initialize_basic(20);

    for (unsigned i = 0; i < num_files; ++i) {
        expr_ref e(m);
        er.get_next(m.mk_bool_sort(), e);
        ast_smt_pp pp(m);

        pp.set_logic(symbol("QF_AUFLIA"));
        std::ostringstream buffer;
        buffer << "random_arith_" << i << ".smt";
        std::cout << buffer.str() << "\n";
        std::ofstream file(buffer.str().c_str());
        pp.display(file, e.get());
        file.close();
    }
    
}
Esempio n. 13
0
int main(int argc, char** argv)
{
    // Get user parameters.
    Opm::parameter::ParameterGroup param(argc, argv, false);

    // Create the Equelle runtime.
    EquelleRuntimeCPU er(param);

    ensureRequirements(er);

    // ============= Generated code starts here ================

    const Scalar k = er.inputScalarWithDefault("k", double(0.3));
    const CollOfScalar u_initial = er.inputCollectionOfScalar("u_initial", er.allCells());
    const CollOfFace dirichlet_boundary = er.inputDomainSubsetOf("dirichlet_boundary", er.boundaryFaces());
    const CollOfScalar dirichlet_val = er.inputCollectionOfScalar("dirichlet_val", dirichlet_boundary);
    const CollOfScalar vol = er.norm(er.allCells());
    const CollOfFace interior_faces = er.interiorFaces();
    const CollOfCell first = er.firstCell(interior_faces);
    const CollOfCell second = er.secondCell(interior_faces);
    const CollOfScalar itrans = (k * (er.norm(interior_faces) / er.norm((er.centroid(first) - er.centroid(second)))));
    const CollOfFace bf = er.boundaryFaces();
    const CollOfCell bf_cells = er.trinaryIf(er.isEmpty(er.firstCell(bf)), er.secondCell(bf), er.firstCell(bf));
    const CollOfScalar bf_sign = er.trinaryIf(er.isEmpty(er.firstCell(bf)), er.operatorExtend(-double(1), bf), er.operatorExtend(double(1), bf));
    const CollOfScalar btrans = (k * (er.norm(bf) / er.norm((er.centroid(bf) - er.centroid(bf_cells)))));
    const CollOfScalar dir_sign = er.operatorOn(bf_sign, er.boundaryFaces(), dirichlet_boundary);
    std::function<CollOfScalar(const CollOfScalar&)> computeInteriorFlux = [&](const CollOfScalar& u) -> CollOfScalar {
        return (-itrans * er.gradient(u));
    };
    std::function<CollOfScalar(const CollOfScalar&)> computeBoundaryFlux = [&](const CollOfScalar& u) -> CollOfScalar {
        const CollOfScalar u_dirbdycells = er.operatorOn(u, er.allCells(), er.operatorOn(bf_cells, er.boundaryFaces(), dirichlet_boundary));
        const CollOfScalar dir_fluxes = ((er.operatorOn(btrans, er.boundaryFaces(), dirichlet_boundary) * dir_sign) * (u_dirbdycells - dirichlet_val));
        return er.operatorExtend(dir_fluxes, dirichlet_boundary, er.boundaryFaces());
    };
    std::function<CollOfScalar(const CollOfScalar&, const CollOfScalar&, const Scalar&)> computeResidual = [&](const CollOfScalar& u, const CollOfScalar& u0, const Scalar& dt) -> CollOfScalar {
        const CollOfScalar ifluxes = computeInteriorFlux(u);
        const CollOfScalar bfluxes = computeBoundaryFlux(u);
        const CollOfScalar fluxes = (er.operatorExtend(ifluxes, er.interiorFaces(), er.allFaces()) + er.operatorExtend(bfluxes, er.boundaryFaces(), er.allFaces()));
        const CollOfScalar residual = ((u - u0) + ((dt / vol) * er.divergence(fluxes)));
        return residual;
    };
    const SeqOfScalar timesteps = er.inputSequenceOfScalar("timesteps");
    CollOfScalar u0;
    u0 = u_initial;
    for (const Scalar& dt : timesteps) {
        std::function<CollOfScalar(const CollOfScalar&)> computeResidualLocal = [&](const CollOfScalar& u) -> CollOfScalar {
            return computeResidual(u, u0, dt);
        };
        const CollOfScalar u_guess = u0;
        const CollOfScalar u = er.newtonSolve(computeResidualLocal, u_guess);
        er.output("u", u);
        er.output("maximum of u", er.maxReduce(u));
        u0 = u;
    }

    // ============= Generated code ends here ================

    return 0;
}
void send_EOT(struct packet* hp, struct packet* data, int sfd)
{
	int x;
	hp->type = EOT;
	data = htonp(hp);
	if((x = send(sfd, data, size_packet, 0)) != size_packet)
		er("send()", x);
}
Esempio n. 15
0
// static func
void CaConcBase::zombify( Element* orig, const Cinfo* zClass, 
			  Id hsolve )
{
  if ( orig->cinfo() == zClass )
    return;
  unsigned int start = orig->localDataStart();
  unsigned int num = orig->numLocalData();
  if ( num == 0 )
    return;
  vector< double > data( num * 9 );

  unsigned int j = 0;
  for ( unsigned int i = 0; i < num; ++i ) {
    Eref er( orig, i + start );
    const CaConcBase* cb = 
      reinterpret_cast< const CaConcBase* >( er.data() );
    data[j + 0] = cb->getCa( er );
    data[j + 1] = cb->getCaBasal( er );
    data[j + 2] = cb->getTau( er );
    data[j + 3] = cb->getB( er );
    data[j + 4] = cb->getCeiling( er );
    data[j + 5] = cb->getFloor( er );
    data[j + 6] = cb->getThickness( er );
    data[j + 7] = cb->getLength( er );
    data[j + 8] = cb->getDiameter( er );
    j += 9;
  }
  orig->zombieSwap( zClass );
  j = 0;
  for ( unsigned int i = 0; i < num; ++i ) {
    Eref er( orig, i + start );
    CaConcBase* cb = reinterpret_cast< CaConcBase* >( er.data() );
    cb->vSetSolver( er, hsolve );
    cb->setCa( er, data[j + 0] );
    cb->setCaBasal( er, data[j + 1] );
    cb->setTau( er, data[j + 2] );
    cb->setB( er, data[j + 3] );
    cb->setCeiling( er, data[j + 4] );
    cb->setFloor( er, data[j + 5] );
    cb->setThickness( er, data[j + 6] );
    cb->setLength( er, data[j + 7] );
    cb->setDiameter( er, data[j + 8] );
    j += 9; //was 7?
  }
}
Esempio n. 16
0
//Arthur says he doesn't use malloc or free. Andrei Moutchkine claims smallest unit is vm page (his truss says no malloc + add pages one at a time).
//Arthur not using malloc is probably true. No strdup & related functions in binary's strings. Note: Skelton references "different allocator" not in \w report
//This source would be improved by getting ridding of remaing malloc/calloc/realloc
K cd(K a)
{
  #ifdef DEBUG
  if(a && a->c <=0 ) { er(Tried to cd() already freed item) dd(tests) dd(a) dd(a->c) dd(a->t) dd(a->n) show(a); }
  #endif 
  if(!a || --a->c) R a;
  #ifdef DEBUG
  DO(kreci, if(a==krec[i]){krec[i]=0; break; })
  #endif 
  if(7==a->t){ DO(-2+TYPE_SEVEN_SIZE,cd(kV(a)[2+i]))} //-4 special trick: don't recurse on V members. assumes sizeof S==K==V.  (don't free CONTEXT or DEPTH)
Esempio n. 17
0
void send_EOT(struct packet* hp, struct packet* data, int sfd)
{
	int x;
	hp->type = EOT;
    hp->datalen = 0;
    memset(hp->buffer, '\0', sizeof(char) *LENBUFFER);
	data = htonp(hp);
	if((x = send(sfd, data, size_packet, 0)) != size_packet)
		er("send()", x);
}
Esempio n. 18
0
void command_lls(char* lpwd)
{
	DIR* d = opendir(lpwd);
	if(!d)
		er("opendir()", (int) d);
	struct dirent* e;
	while((e = readdir(d)) != NULL)
		printf("\t%s\t%s\n", e->d_type == 4 ? "DIR:" : e->d_type == 8 ? "FILE:" : "UNDEF", e->d_name);
	closedir(d);
}
void HHChannelBase::zombify( Element* orig, const Cinfo* zClass, Id hsolve )
{
	if ( orig->cinfo() == zClass )
		return;
	unsigned int start = orig->localDataStart();
	unsigned int num = orig->numLocalData();
	if ( num == 0 )
		return;
	// Parameters are Gbar, Ek, Xpower, Ypower, Zpower, useConcentration
	// We also want to haul the original gates over, this is done earlier
	// in the HSolve building process. So just six terms.
	vector< double > chandata( num * 6, 0.0 );
	vector< double >::iterator j = chandata.begin();

	for ( unsigned int i = 0; i < num; ++i ) {
		Eref er( orig, i + start );
		const HHChannelBase* hb = 
			reinterpret_cast< const HHChannelBase* >( er.data() );
		*j = hb->vGetGbar( er );
		*(j+1) = hb->vGetEk( er);
		*(j+2) = hb->getXpower( er );
		*(j+3) = hb->getYpower( er );
		*(j+4) = hb->getZpower( er );
		*(j+5) = hb->getUseConcentration( er );
		j+= 6;
	}
	orig->zombieSwap( zClass );
	j = chandata.begin();
	for ( unsigned int i = 0; i < num; ++i ) {
		Eref er( orig, i + start );
		HHChannelBase* hb = reinterpret_cast< HHChannelBase* >( er.data() );
		hb->vSetSolver( er, hsolve );
		hb->vSetGbar( er, *j );
		hb->vSetEk( er, *(j+1) );
		hb->vSetXpower( er, *(j+2) );
		hb->vSetYpower( er, *(j+3) );
		hb->vSetZpower( er, *(j+4) );
		// hb->vSetUseConcentration( er, *(j+5) > 0.5 );
		// Disable this assignment because the Solver already reads the 
		// value, and it triggers an error msg.
		j+= 6;
	}
}
Esempio n. 20
0
int main(void)
{
//BEGIN: initialization
struct sockaddr_in sin_server, sin_client;
int sfd_server, sfd_client, x;
short int connection_id = 0;

if((x = sfd_server = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
er("socket()", x);

memset((char*) &sin_server, 0, sizeof(struct sockaddr_in));
sin_server.sin_family = AF_INET;
sin_server.sin_port = htons(PORTSERVER);
sin_server.sin_addr.s_addr = htonl(INADDR_ANY);

if((x = bind(sfd_server, (struct sockaddr*) &sin_server, size_sockaddr)) < 0)
er("bind()", x);

if((x = listen(sfd_server, 1)) < 0)
er("listen()", x);

printf(ID "FTP Server started up @ local:%d. Waiting for client(s)...\n\n", PORTSERVER);
//END: initialization


while(1)
{
if((x = sfd_client = accept(sfd_server, (struct sockaddr*) &sin_client, &size_sockaddr)) < 0)
er("accept()", x);
printf(ID "Communication started with %s:%d\n", inet_ntoa(sin_client.sin_addr), ntohs(sin_client.sin_port));
fflush(stdout);

struct client_info* ci = client_info_alloc(sfd_client, connection_id++);
serve_client(ci);
}

close(sfd_server);
printf(ID "Done.\n");
fflush(stdout);

return 0;
}
CAsyncLockingQueue::CAsyncLockingQueue()
{
	mQueue.clear();
	nInt32 res = pthread_mutex_init(&mLockMutex, NULL);
	if(res != 0)
	{
		nstring er("CAsyncLockingQueue::CAsyncLockingQueue() - can not create mutex section code: ");
		er.append(CStringUtils::IntTo16xString(res));
		throw NOVA_EXP(er.c_str(), BAD_OPERATION);
	}
}
Esempio n. 22
0
File: task.hpp Progetto: lquan/CSAI
 forceinline ModEvent
 ManFlexTask::norun(Space& home, int e, int l) {
   if (e <= l) {
     Iter::Ranges::Singleton sr(e-_p.min()+1,l);
     GECODE_ME_CHECK(_s.minus_r(home,sr,false));
     Iter::Ranges::Singleton er(e+1,_p.min()+l);
     return _e.minus_r(home,er,false);
   } else {
     return Int::ME_INT_NONE;
   }
 }
Esempio n. 23
0
void
acl_ethertype::event_handler::handle_populate(const client_db::key_t& key)
{
  /*
   * dump VPP acl ethertypes
   */
  std::shared_ptr<acl_ethertype_cmds::dump_cmd> cmd =
    std::make_shared<acl_ethertype_cmds::dump_cmd>(~0);

  HW::enqueue(cmd);
  HW::write();

  for (auto& record : *cmd) {
    auto& payload = record.get_payload();
    handle_t hdl(payload.sw_if_index);
    std::shared_ptr<interface> itf = interface::find(hdl);
    uint8_t n_input = payload.n_input;
    uint8_t count = payload.count;
    ethertype_rules_t ler;
    if (itf) {
      for (int i = 0; i < count; i++) {
        ethertype_t e = ethertype_t::from_numeric_val(payload.whitelist[i]);
        if (n_input) {
          ethertype_rule_t er(e, direction_t::INPUT);
          ler.insert(er);
          n_input--;
        } else {
          ethertype_rule_t er(e, direction_t::OUTPUT);
          ler.insert(er);
        }
      }
      if (!ler.empty()) {
        acl_ethertype a_e(*itf, ler);
        VOM_LOG(log_level_t::DEBUG) << "ethertype dump: " << a_e.to_string();
        OM::commit(key, a_e);
      }
    } else {
      VOM_LOG(log_level_t::ERROR) << "no interface:" << payload.sw_if_index;
    }
  }
}
shared_ptr<ZLEncodingConverter> MyEncodingConverterProvider::createConverter(const std::string &encoding) {
	EncodingCharReader er(encoding);
	char **encodingMap = er.createTable();
	if (encodingMap != 0) {
		if (er.bytesNumber() == 1) {
                  return shared_ptr<ZLEncodingConverter>(new MyOneByteEncodingConverter(encoding, encodingMap));
		} else if (er.bytesNumber() == 2) {
                  return shared_ptr<ZLEncodingConverter>(new MyTwoBytesEncodingConverter(encodingMap));
		}
	}
	return shared_ptr<ZLEncodingConverter>();
}
Esempio n. 25
0
void TreeViewItem::OnMouseLeftButtonDbclk(suic::MouseEventArg& e)
{
    __super::OnMouseLeftButtonDbclk(e);

    if (GetItems()->GetCount() > 0)
    {
        suic::RoutedEventArg er(this);
        _expand->OnClick(er);
    }

    e.Handled(true);
}
Esempio n. 26
0
 Scalar matrix_form(int n, double *wt, Func<Scalar> *u_ext[], Func<Real> *u, 
                    Func<Real> *v, Geom<Real> *e, ExtData<Scalar> *ext) const {
   cplx ikappa = cplx(0.0, kappa);
   Scalar result1 = 0;
   Scalar result2 = 0;
   for (int i = 0; i < n; i++)
     result1 += wt[i] * gamma(e->elem_marker, e->x[i], e->y[i]) * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i]));
   for (int i = 0; i < n; i++)
     result2 += wt[i] * er(e->elem_marker, e->x[i], e->y[i]) * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i]));
   return 1.0/mu_r * int_curl_e_curl_f<Real, Scalar>(n, wt, u, v) -
          ikappa * sqrt(mu_0 / e_0) * result1 - sqr(kappa) * result2;
 }
Esempio n. 27
0
void ViewManager::sendEvent( ViewEvent ve, View * view )
//------------------------------------------------------
{
    int i;

    for( i = 0; i < _eventReceivers->entries(); i += 1 ) {
        EventReceiver & er( (*_eventReceivers)[ i ] );

        if( er._wantsEvents & ve ) {
            er._receiver->event( ve, view );
        }
    }
}
Esempio n. 28
0
unsigned int Neutral::buildTree( const Eref& e, vector< Id >& tree )
	const 
{
	unsigned int ret = 1;
	Eref er( e.element(), ALLDATA );
	vector< Id > kids = getChildren( er );
	sort( kids.begin(), kids.end() );
	kids.erase( unique( kids.begin(), kids.end() ), kids.end() );
	for ( vector< Id >::iterator i = kids.begin(); i != kids.end(); ++i )
		ret += buildTree( i->eref(), tree );
	tree.push_back( e.element()->id() );
	return ret;
}
Esempio n. 29
0
// the operation of PRT command
void command_prt(struct packet* shp, struct packet* data, int sfd_client, char* lpwd)
{
    if(DEBUG)
        printf("Starting prt...\n");
    int x;
    int dataportnum = atoi(shp->buffer);
    shp->type = INFO;
    shp->comid = PRT;
    strcpy(shp->buffer, dataportnum ? "OK: Port Gotten; processing..." : "ER: Error getting port num.");
 
    printpacket(shp, HP);

    data = htonp(shp);
    if(( x = send(sfd_client, data, size_packet, 0)) != size_packet)
        er("send()", x);

    if(DEBUG)
        printf("OK, waiting for connection\n");

    if(dataportnum)
    {
        struct sockaddr_in skin_server_data;
        int x;
        size_t size_sockaddr = sizeof(struct sockaddr), size_packet = sizeof(struct packet);

        if(( x = sfd_server_data = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
            er("socket()", x);

        memset((char*) & skin_server_data, 0, sizeof(struct sockaddr_in));
        skin_server_data.sin_family = AF_INET;
        skin_server_data.sin_addr.s_addr = inet_addr(IPCLIENT);
        skin_server_data.sin_port = htons(dataportnum);

        if(( x = connect(sfd_server_data, (struct sockaddr*) &skin_server_data, size_sockaddr)) < 0)
            er("connect()", x);
        printf(ID "Data channel build. Communicating with client @ %s:%d...\n\n", IPCLIENT, dataportnum);
    }
    send_EOT(shp, data, sfd_client);    
}
Esempio n. 30
0
// Generate expected return of next n periods
vec ARMA11::predict(int n, vec y)
{
	int m = y.n_elem-1;
	vec x = residual(y);
	vec er(n);

	er[0] = mu-phi*(y[m]-mu)+psi*x[m];
	if (n>1) {
		for (int i=1; i<n; i++) {
			er[i] = mu-phi*er[i-1];
		}
	}	
	return er;
}