Exemplo n.º 1
0
char *
vcc_regexp(struct vcc *tl)
{
	char buf[BUFSIZ], *p;
	vre_t *t;
	const char *error;
	int erroroffset;

	Expect(tl, CSTR);
	if (tl->err)
		return (NULL);
	memset(&t, 0, sizeof t);
	t = VRE_compile(tl->t->dec, 0, &error, &erroroffset);
	if (t == NULL) {
		VSB_printf(tl->sb,
		    "Regexp compilation error:\n\n%s\n\n", error);
		vcc_ErrWhere(tl, tl->t);
		return (NULL);
	}
	VRE_free(&t);
	sprintf(buf, "VGC_re_%u", tl->unique++);
	p = TlAlloc(tl, strlen(buf) + 1);
	strcpy(p, buf);

	Fh(tl, 0, "static void *%s;\n", buf);
	Fi(tl, 0, "\tVRT_re_init(&%s, ",buf);
	EncToken(tl->fi, tl->t);
	Fi(tl, 0, ");\n");
	Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf);
	return (p);
}
Exemplo n.º 2
0
void bench_filo()
{
    All_Memo_counter MC_INIT;
    stow_memory_counter(MC_INIT);
    INT nb = 200;

    {
         ElFilo<III> Fi(4);
		 INT i;

         for ( i= 0; i<nb; i++)
             Fi.pushlast(III(i));

         for ( i= 0; i<nb; i++)
             Fi[i].i() *= 2;

         for ( i= 0; i<nb; i++)
             BENCH_ASSERT(Fi[i].i() == 2*i);

         for ( i= 2*(nb-1) ; i>= 2; i-= 2)
             BENCH_ASSERT(Fi.poplast().i() == i);

         BENCH_ASSERT(Fi.nb() == 1);
    }
    verif_memory_state(MC_INIT);
}
Exemplo n.º 3
0
void Rubik::turnCubeRight() { //White to blue
	Fi(false);
	B(false);
	this->shift(this->middle, 3, 1, 4, 2);
	this->shift(this->edges, 6, 19, 9, 20);
	this->shift(this->edges, 7, 21, 8, 18);

	std::map<std::string, std::string> tempMap(movesDictionary);
	//Dictionary
	movesDictionary[_R] = tempMap[_D];
	movesDictionary[_Ri] = tempMap[_Di];
	movesDictionary[_R2] = tempMap[_D2];
	movesDictionary[_L] = tempMap[_U];
	movesDictionary[_Li] = tempMap[_Ui];
	movesDictionary[_L2] = tempMap[_U2];
	movesDictionary[_U] = tempMap[_R];
	movesDictionary[_Ui] = tempMap[_Ri];
	movesDictionary[_U2] = tempMap[_R2];
	/*movesDictionary[_B] = movesDictionary[_B];
	movesDictionary[_Bi] = movesDictionary[_Bi];
	movesDictionary[_B2] = movesDictionary[_B2];
	movesDictionary[_F] = movesDictionary[_F];
	movesDictionary[_Fi] = movesDictionary[_Fi];
	movesDictionary[_F2] = movesDictionary[_F2];*/
	movesDictionary[_D] = tempMap[_L];
	movesDictionary[_Di] = tempMap[_Li];
	movesDictionary[_D2] = tempMap[_L2];

}
void
vcc_ParseLeastBusyDirector(struct tokenlist *tl, const struct token *t_policy,
    const struct token *t_dir)
{
	struct token *t_field, *t_be;
	int nbh, nelem;
	struct fld_spec *fs;
	const char *first;

	fs = vcc_FldSpec(tl, "!backend", NULL);

	Fc(tl, 0, "\nstatic const struct vrt_dir_least_busy_entry "
	    "vdrre_%.*s[] = {\n", PF(t_dir));

	for (nelem = 0; tl->t->tok != '}'; nelem++) {	/* List of members */
		first = "";
		t_be = tl->t;
		vcc_ResetFldSpec(fs);
		nbh = -1;

		ExpectErr(tl, '{');
		vcc_NextToken(tl);
		Fc(tl, 0, "\t{");

		while (tl->t->tok != '}') {	/* Member fields */
			vcc_IsField(tl, &t_field, fs);
			ERRCHK(tl);
			if (vcc_IdIs(t_field, "backend")) {
				vcc_ParseBackendHost(tl, &nbh,
				    t_dir, t_policy, nelem);
				Fc(tl, 0, "%s .host = &bh_%d", first, nbh);
				ERRCHK(tl);
			} else {
				ErrInternal(tl);
			}
			first = ", ";
		}
		vcc_FieldsOk(tl, fs);
		if (tl->err) {
			vsb_printf(tl->sb,
			    "\nIn member host specification starting at:\n");
			vcc_ErrWhere(tl, t_be);
			return;
		}
		Fc(tl, 0, " },\n");
		vcc_NextToken(tl);
	}
	Fc(tl, 0, "};\n");
	Fc(tl, 0,
	    "\nstatic const struct vrt_dir_least_busy vdrr_%.*s = {\n",
	    PF(t_dir));
	Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir));
	Fc(tl, 0, "\t.nmember = %d,\n", nelem);
	Fc(tl, 0, "\t.members = vdrre_%.*s,\n", PF(t_dir));
	Fc(tl, 0, "};\n");
	Fi(tl, 0, "\tVRT_init_dir_least_busy("
	    "cli, &VGC_backend_%.*s , &vdrr_%.*s);\n", PF(t_dir), PF(t_dir));
	Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend_%.*s);\n", PF(t_dir));
}
Exemplo n.º 5
0
void Atomic_Factors (int Z, float energy, float q, float debye_factor, 
                                  float* f0, float* f_prime, float* f_prime2) {

  *f0       = FF_Rayl(Z, q) * debye_factor; 
  *f_prime  = Fi(Z, energy) * debye_factor;
  *f_prime2 = -Fii(Z, energy) * debye_factor;

}
Exemplo n.º 6
0
void Atomic_Factors (int Z, double energy, double q, double debye_factor, 
                                  double* f0, double* f_prime, double* f_prime2) {

  *f0       = FF_Rayl(Z, q) * debye_factor; 
  *f_prime  = Fi(Z, energy) * debye_factor;
  *f_prime2 = -Fii(Z, energy) * debye_factor;

}
Exemplo n.º 7
0
void Elements::recount(int time)
{
	vector<double> Temp(numofnods);
	double kxx=MATERIAL_COND;
	double kyy=MATERIAL_COND;
	double h=MATERIAL_EXCH;
	Matrix<double> K(numofnods);
	for(int i=0;i<numofnods;i++)
		K[i][i]=0;
	Row<double> F(numofnods);
	Row<double> Fi(3);
	Matrix<double> Ki(3);
	for(unsigned int i=0;i<Set.size();i++)
	{
		double A=Set[i].square();
		Ki=kxx/4/A*Set[i].B()+kyy/4/A*Set[i].C();
		Fi=Set[i].Q(time);
		for(int s=0;s<3;s++)
		{
			F[Data[i].index(s)]+=Fi[s];
			for(int p=0;p<3;p++)
				K[Data[i].index(s)][Data[i].index(p)]+=Ki[s][p];
		}
	}
	for(unsigned int i=0;i<Conditions.size();i++)
	{
		Ki=Conditions[i].L()*h;
		Fi=Conditions[i].R();
		if(Conditions[i].type()) Fi*=h;
		for(int s=0;s<2;s++)
		{
			F[Conditions[i].index(s)]+=Fi[s];
			for(int p=0;p<2;p++)
				K[Conditions[i].index(s)][Conditions[i].index(p)]+=Ki[s][p];
		}
	}
	int diag=(min(NUMOFCOLS,NUMOFROWS)+1)*2+1;
	DiagonalSystem<double> Solution(K,F,diag);
	Solution.Gauss();
	Temp=Solution.solutuion().ToVector();
	if(time==0)
	{
		ofstream file;
		file.open("matrixoutput.txt");
		file<<K<<"Free vector:\n"<<F;
		file<<"Solution:\n";
		file<<Solution.solutuion();
		file.close();
		/*DWORD thID;
		DSystem TempSystem(K,F);
		CreateThread(NULL, NULL, FileWriter, &TempSystem, NULL, &thID);*/
	}
	for(unsigned int i=0;i<Set.size();i++)
	{
		Set[i].settemp(Temp[Data[i].i()],Temp[Data[i].k()],Temp[Data[i].j()]);
		Set[i].recounttemp();
	}
}
Exemplo n.º 8
0
void Cube::RotateCounterClockwise()
{
    Fi();
    SaveState();
    subCubes[0][0][1] = ROTATE_CCLK(oldSubCubes[0][2][1]);
    subCubes[1][0][1] = ROTATE_CCLK(oldSubCubes[0][1][1]);
    subCubes[2][0][1] = ROTATE_CCLK(oldSubCubes[0][0][1]);
    subCubes[0][1][1] = ROTATE_CCLK(oldSubCubes[1][2][1]);
    subCubes[1][1][1] = ROTATE_CCLK(oldSubCubes[1][1][1]);
    subCubes[2][1][1] = ROTATE_CCLK(oldSubCubes[1][0][1]);
    subCubes[0][2][1] = ROTATE_CCLK(oldSubCubes[2][2][1]);
    subCubes[1][2][1] = ROTATE_CCLK(oldSubCubes[2][1][1]);
    subCubes[2][2][1] = ROTATE_CCLK(oldSubCubes[2][0][1]);
    B();
}
Exemplo n.º 9
0
/**********************************************************
  getRefraction ()
  
  This function retrieve the x-ray index of refraction and
  Atomic scattering factors f1 and f2
***********************************************************/
int getRefraction (int mode)
{
  int     i, Z=0;
  float   energy_keV;
  complex cosThetaIn, sinThetaIn, cosThetaOut, n, sAmpReflect, pAmpReflect;
  
  if (verbose > 3) { fprintf(stdout, "getRefraction: targetFormula = %s\n", targetFormula); }
  if (verbose > 2) { 
    if ( mode==1 ) { 
      fprintf(stdout, "\n Index  PhotonEnergy    delta        beta"); 
    } else if ( mode==6 ) { 
      fprintf(stdout, "\n Index  PhotonEnergy    delta        beta      Refelectivity"); 
    } else { fprintf(stdout, "\n Index  PhotonEnergy       f1          f2"); 
    }
    fprintf(stdout, "\n            (eV)       ");
  }

  cosThetaIn = cos(thetaIn  * degToRad);
  sinThetaIn = sin(thetaIn  * degToRad);
  if (mode > 9 )   { Z = SymbolToAtomicNumber ( targetFormula ); }
  for ( i = 0; i < npts; i++ ) {
    energy_keV  = 0.001 * energy[i];
    if ( mode < 10 ) {  /* Compound target */
      RefracIndexRe[i] = Refractive_Index_Re ( targetFormula, energy_keV, targetDensity );
      RefracIndexIm[i] = Refractive_Index_Im ( targetFormula, energy_keV, targetDensity );
      delta[i]         = 1.0 - RefracIndexRe[i];
      beta[i]          = RefracIndexIm[i];
      if (verbose>2) { fprintf(stdout, "\n %4d %12.1f %12.4g %12.4g", i, energy[i], delta[i], beta[i]); }
      if ( mode==6 ) {  /* Mirror reflectivity */
        n = RefracIndexRe[i] + RefracIndexIm[i] * _Complex_I;
        cosThetaOut     = csqrt(n * n - sinThetaIn * sinThetaIn) / n;
        sAmpReflect     = ( cosThetaIn - n * cosThetaOut ) / (cosThetaIn + n * cosThetaOut );
        pAmpReflect     = ( cosThetaOut - n * cosThetaIn ) / (cosThetaOut + n * cosThetaIn );
        reflectivity[i] = 0.5 * (1.0 + polarization) * cabs(pAmpReflect * pAmpReflect) + 0.5 * (1.0 - polarization) * cabs(sAmpReflect * sAmpReflect);
        // fprintf(stdout, "\n n = %f,%f, determ = %f, %f", n, determ); 
        // fprintf(stdout, "\n sAmpReflect = %f, %f, pAmpReflect = %f, %f, reflectivity = %f", sAmpReflect, pAmpReflect, reflectivity[i]); 
        if (verbose>2) { fprintf(stdout, "%12.4g", reflectivity[i]); }
      }
    } else { /* Atomic scattering factor */
      ScattFactor1[i] = Z + Fi( Z, energy_keV );
      ScattFactor2[i] = - Fii(Z, energy_keV );
      if (verbose>2) { fprintf(stdout, "\n %4d %12.1f %12.4g %12.4g", i, energy[i], ScattFactor1[i], ScattFactor2[i]); }
    }
  }

  fprintf(stdout, "\n");
  return 0;
}
Exemplo n.º 10
0
bool TestCompiler::makeClean( const QString &workPath )
{
    QDir D;
    if (!D.exists(workPath)) {
        testOutput_.append( "Directory '" + workPath + "' doesn't exist" );
        return false;
    }

    D.setCurrent(workPath);
    QFileInfo Fi( workPath + "/Makefile");
    if (Fi.exists())
        // Run make clean
        return runCommand( makeCmd_ + " clean" );

    return true;
}
Exemplo n.º 11
0
double AnalyticIntegral(
	SpkModel                    &model           ,
	const std::valarray<int>    &N               , 
	const std::valarray<double> &y               ,
	const std::valarray<double> &alpha           ,
	const std::valarray<double> &L               ,
	const std::valarray<double> &U               ,
	size_t                       individual      )
{
	double Pi   = 4. * atan(1.);

	// set the fixed effects
	model.setPopPar(alpha);

	// set the individual
	model.selectIndividual(individual);

	// index in y where measurements for this individual starts
	size_t start = 0;
	size_t i;
	for(i = 0; i < individual; i++)
	{	assert( N[i] >= 0 );
		start += N[i];
	}

	// number of measurements for this individual
	assert( N[individual] >= 0 );
	size_t Ni = N[individual];

	// data for this individual
	std::valarray<double> yi = y[ std::slice( start, Ni, 1 ) ];

	// set the random effects = 0
	std::valarray<double> b(1);
	b[0] = 0.;
	model.setIndPar(b);

	std::valarray<double> Fi(Ni);
	model.dataMean(Fi);

	// model for the variance of random effects
	std::valarray<double> D(1);
	model.indParVariance(D);

	// model for variance of the measurements given random effects
	std::valarray<double> Ri( Ni * Ni );
	model.dataVariance(Ri);

	// determine bHat
	double residual = 0;
	size_t j;
	for(j = 0; j < Ni; j++)
	{	assert( Ri[j * Ni + j] == Ri[0] );
		residual += (yi[j] - Fi[j]);
	}
	std::valarray<double> bHat(1);
	bHat[0] = residual * D[0] / (Ni * D[0] + Ri[0]);

	// now evaluate the Map Bayesian objective at its optimal value
	model.setIndPar(bHat);
	model.dataMean(Fi);
	double sum = bHat[0] * bHat[0] / D[0] + log( 2. * Pi * D[0] );
	for(j = 0; j < Ni; j++)
	{	sum += (yi[j] - Fi[j]) * (yi[j] - Fi[j]) / Ri[0];
		sum += log( 2. * Pi * Ri[0] );
	}
	double GHat = .5 * sum;

	// square root of Hessian of the Map Bayesian objective
	double rootHessian = sqrt( 1. / D[0] + Ni / Ri[0]);

	// determine the values of beta that correspond to the limits
	double Gamma_L = (L[0] - bHat[0]) * rootHessian;
	double Gamma_U = (U[0] - bHat[0]) * rootHessian;

	// compute the upper tails corresponding to the standard normal
	double Q_L    = gsl_sf_erf_Q(Gamma_L);
	double Q_U    = gsl_sf_erf_Q(Gamma_U);

	// analytic value of the integral
	double factor   = exp(-GHat) * sqrt(2. * Pi) / rootHessian;
	return  factor * (Q_L - Q_U);
}
Exemplo n.º 12
0
void
vcc_ParseImport(struct vcc *tl)
{
	void *hdl;
	char fn[1024];
	char buf[256];
	struct token *mod, *t1;
	const char *modname;
	const char *proto;
	const char *abi;
	const char **spec;
	struct symbol *sym;
	const struct symbol *osym;
	const char *p;
	// int *modlen;

	t1 = tl->t;
	SkipToken(tl, ID);		/* "import" */

	ExpectErr(tl, ID);
	mod = tl->t;
	vcc_NextToken(tl);

	osym = VCC_FindSymbol(tl, mod, SYM_NONE);
	if (osym != NULL && osym->kind != SYM_VMOD) {
		VSB_printf(tl->sb, "Module %.*s conflics with other symbol.\n",
		    PF(mod));
		vcc_ErrWhere2(tl, t1, tl->t);
		return;
	}
	if (osym != NULL) {
		VSB_printf(tl->sb, "Module %.*s already imported.\n",
		    PF(mod));
		vcc_ErrWhere2(tl, t1, tl->t);
		VSB_printf(tl->sb, "Previous import was here:\n");
		vcc_ErrWhere2(tl, osym->def_b, osym->def_e);
		return;
	}

	bprintf(fn, "%.*s", PF(mod));
	sym = VCC_AddSymbolStr(tl, fn, SYM_VMOD);
	ERRCHK(tl);
	AN(sym);
	sym->def_b = t1;
	sym->def_e = tl->t;

	if (tl->t->tok == ID) {
		if (!tl->unsafe_path) {
			VSB_printf(tl->sb,
			    "'import ... from path...'"
			    " not allowed.\nAt:");
			vcc_ErrToken(tl, tl->t);
			vcc_ErrWhere(tl, tl->t);
			return;
		}
		if (!vcc_IdIs(tl->t, "from")) {
			VSB_printf(tl->sb, "Expected 'from path...'\n");
			vcc_ErrWhere(tl, tl->t);
			return;
		}
		vcc_NextToken(tl);
		ExpectErr(tl, CSTR);
		bprintf(fn, "%s", tl->t->dec);
		vcc_NextToken(tl);
	} else {
		bprintf(fn, "%s/libvmod_%.*s.so", tl->vmod_dir, PF(mod));
	}

	Fh(tl, 0, "static void *VGC_vmod_%.*s;\n", PF(mod));

	Fi(tl, 0, "\tif (VRT_Vmod_Init(&VGC_vmod_%.*s,\n", PF(mod));
	Fi(tl, 0, "\t    &Vmod_%.*s_Func,\n", PF(mod));
	Fi(tl, 0, "\t    sizeof(Vmod_%.*s_Func),\n", PF(mod));
	Fi(tl, 0, "\t    \"%.*s\",\n", PF(mod));
	Fi(tl, 0, "\t    ");
	EncString(tl->fi, fn, NULL, 0);
	Fi(tl, 0, ",\n\t    ");
	Fi(tl, 0, "cli))\n");
	Fi(tl, 0, "\t\treturn(1);\n");

	SkipToken(tl, ';');

	hdl = dlopen(fn, RTLD_NOW | RTLD_LOCAL);
	if (hdl == NULL) {
		VSB_printf(tl->sb, "Could not load module %.*s\n\t%s\n\t%s\n",
		    PF(mod), fn, dlerror());
		vcc_ErrWhere(tl, mod);
		return;
	}

	bprintf(buf, "Vmod_%.*s_Name", PF(mod));
	modname = dlsym(hdl, buf);
	if (modname == NULL) {
		VSB_printf(tl->sb, "Could not load module %.*s\n\t%s\n\t%s\n",
		    PF(mod), fn, "Symbol Vmod_Name not found");
		vcc_ErrWhere(tl, mod);
		return;
	}
	if (!vcc_IdIs(mod, modname)) {
		VSB_printf(tl->sb, "Could not load module %.*s\n\t%s\n",
		    PF(mod), fn);
		VSB_printf(tl->sb, "\tModule has wrong name: <%s>\n", modname);
		vcc_ErrWhere(tl, mod);
		return;
	}

	bprintf(buf, "Vmod_%.*s_ABI", PF(mod));
	abi = dlsym(hdl, buf);
	if (abi == NULL || strcmp(abi, VMOD_ABI_Version) != 0) {
		VSB_printf(tl->sb, "Could not load module %.*s\n\t%s\n",
		    PF(mod), fn);
		VSB_printf(tl->sb, "\tABI mismatch, expected <%s>, got <%s>\n",
			   VMOD_ABI_Version, abi);
		vcc_ErrWhere(tl, mod);
		return;
	}

	bprintf(buf, "Vmod_%.*s_Proto", PF(mod));
	proto = dlsym(hdl, buf);
	if (proto == NULL) {
		VSB_printf(tl->sb, "Could not load module %.*s\n\t%s\n\t%s\n",
		    PF(mod), fn, "Symbol Vmod_Proto not found");
		vcc_ErrWhere(tl, mod);
		return;
	}
	bprintf(buf, "Vmod_%.*s_Spec", PF(mod));
	spec = dlsym(hdl, buf);
	if (spec == NULL) {
		VSB_printf(tl->sb, "Could not load module %.*s\n\t%s\n\t%s\n",
		    PF(mod), fn, "Symbol Vmod_Spec not found");
		vcc_ErrWhere(tl, mod);
		return;
	}
	Fh(tl, 0, "static struct vmod_priv vmod_priv_%.*s;\n", PF(mod));
	for (; *spec != NULL; spec++) {
		p = *spec;
		if (!strcmp(p, "OBJ")) {
			p += strlen(p) + 1;
			sym = VCC_AddSymbolStr(tl, p, SYM_OBJECT);
			XXXAN(sym);
			sym->args = p;
		} else if (!strcmp(p, "INIT")) {
			p += strlen(p) + 1;
			Fi(tl, 0, "\t%s(&vmod_priv_%.*s, &VCL_conf);\n",
			    p, PF(mod));
		} else {
			sym = VCC_AddSymbolStr(tl, p, SYM_FUNC);
			ERRCHK(tl);
			AN(sym);
			sym->eval = vcc_Eval_SymFunc;
			p += strlen(p) + 1;
			sym->cfunc = p;
			p += strlen(p) + 1;
			sym->args = p;

			/* Functions which return VOID are procedures */
			if (!memcmp(p, "VOID\0", 5))
				sym->kind = SYM_PROC;
		}
	}
	Fh(tl, 0, "\n%s\n", proto);

	/* XXX: zero the function pointer structure ?*/
	Ff(tl, 0, "\tvmod_priv_fini(&vmod_priv_%.*s);\n", PF(mod));
	Ff(tl, 0, "\tVRT_Vmod_Fini(&VGC_vmod_%.*s);\n", PF(mod));
}
Foam::tmp<Foam::surfaceScalarField> Foam::wallLubricationModel::Ff() const
{
    return fvc::interpolate(pair_.dispersed())*fvc::flux(Fi());
}
Foam::tmp<Foam::volVectorField> Foam::wallLubricationModel::F() const
{
    return pair_.dispersed()*Fi();
}
Exemplo n.º 15
0
int main()
{
  struct compoundData *cdtest;
  int i;
  XRayInit();
  SetErrorMessages(0);
  //if something goes wrong, the test will end with EXIT_FAILURE
  //SetHardExit(1);

  std::printf("Example of C++ program using xraylib\n");
  std::printf("Density of pure Al: %f g/cm3\n", ElementDensity(13));
  std::printf("Ca K-alpha Fluorescence Line Energy: %f\n",
	 LineEnergy(20,KA_LINE));
  std::printf("Fe partial photoionization cs of L3 at 6.0 keV: %f\n",CS_Photo_Partial(26,L3_SHELL,6.0));
  std::printf("Zr L1 edge energy: %f\n",EdgeEnergy(40,L1_SHELL));
  std::printf("Pb Lalpha XRF production cs at 20.0 keV (jump approx): %f\n",CS_FluorLine(82,LA_LINE,20.0));
  std::printf("Pb Lalpha XRF production cs at 20.0 keV (Kissel): %f\n",CS_FluorLine_Kissel(82,LA_LINE,20.0));
  std::printf("Bi M1N2 radiative rate: %f\n",RadRate(83,M1N2_LINE));
  std::printf("U M3O3 Fluorescence Line Energy: %f\n",LineEnergy(92,M3O3_LINE));
  //parser test for Ca(HCO3)2 (calcium bicarbonate)
  if ((cdtest = CompoundParser("Ca(HCO3)2")) == NULL)
	return 1;
  std::printf("Ca(HCO3)2 contains %g atoms, %i elements and has a molar mass of %g g/mol\n", cdtest->nAtomsAll, cdtest->nElements, cdtest->molarMass);
  for (i = 0 ; i < cdtest->nElements ; i++)
    std::printf("Element %i: %f %% and %g atoms\n", cdtest->Elements[i], cdtest->massFractions[i]*100.0, cdtest->nAtoms[i]);

  FreeCompoundData(cdtest);

  //parser test for SiO2 (quartz)
  if ((cdtest = CompoundParser("SiO2")) == NULL)
	return 1;
  std::printf("SiO2 contains %g atoms, %i elements and has a molar mass of %g g/mol\n", cdtest->nAtomsAll, cdtest->nElements, cdtest->molarMass);
  for (i = 0 ; i < cdtest->nElements ; i++)
    std::printf("Element %i: %f %% and %g atoms\n", cdtest->Elements[i], cdtest->massFractions[i]*100.0, cdtest->nAtoms[i]);


  FreeCompoundData(cdtest);

  std::printf("Ca(HCO3)2 Rayleigh cs at 10.0 keV: %f\n",CS_Rayl_CP("Ca(HCO3)2",10.0f) );

  std::printf("CS2 Refractive Index at 10.0 keV : %f - %f i\n",Refractive_Index_Re("CS2",10.0f,1.261f),Refractive_Index_Im("CS2",10.0f,1.261f));
  std::printf("C16H14O3 Refractive Index at 1 keV : %f - %f i\n",Refractive_Index_Re("C16H14O3",1.0f,1.2f),Refractive_Index_Im("C16H14O3",1.0f,1.2f));
  std::printf("SiO2 Refractive Index at 5 keV : %f - %f i\n",Refractive_Index_Re("SiO2",5.0f,2.65f),Refractive_Index_Im("SiO2",5.0f,2.65f));
  std::printf("Compton profile for Fe at pz = 1.1 : %f\n",ComptonProfile(26,1.1f));
  std::printf("M5 Compton profile for Fe at pz = 1.1 : %f\n",ComptonProfile_Partial(26,M5_SHELL,1.1f));
  std::printf("K atomic level width for Fe: %f\n", AtomicLevelWidth(26,K_SHELL));
  std::printf("M1->M5 Coster-Kronig transition probability for Au : %f\n",CosKronTransProb(79,FM15_TRANS));
  std::printf("L1->L3 Coster-Kronig transition probability for Fe : %f\n",CosKronTransProb(26,FL13_TRANS));
  std::printf("Au Ma1 XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MA1_LINE,10.0f));
  std::printf("Au Mb XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MB_LINE,10.0f));
  std::printf("Au Mg XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MG_LINE,10.0f));

  std::printf("Bi L2-M5M5 Auger non-radiative rate: %f\n",AugerRate(86,L2_M5M5_AUGER));
  std::printf("Bi L3 Auger yield: %f\n", AugerYield(86, L3_SHELL));

  std::printf("Sr anomalous scattering factor Fi at 10.0 keV: %f\n", Fi(38, 10.0));
  std::printf("Sr anomalous scattering factor Fii at 10.0 keV: %f\n", Fii(38, 10.0));
 
  char *symbol = AtomicNumberToSymbol(26);
  std::printf("Symbol of element 26 is: %s\n",symbol);
  xrlFree(symbol);

  std::printf("Number of element Fe is: %i\n",SymbolToAtomicNumber("Fe"));

  std::printf("Pb Malpha XRF production cs at 20.0 keV with cascade effect: %f\n",CS_FluorLine_Kissel(82,MA1_LINE,20.0));
  std::printf("Pb Malpha XRF production cs at 20.0 keV with radiative cascade effect: %f\n",CS_FluorLine_Kissel_Radiative_Cascade(82,MA1_LINE,20.0));
  std::printf("Pb Malpha XRF production cs at 20.0 keV with non-radiative cascade effect: %f\n",CS_FluorLine_Kissel_Nonradiative_Cascade(82,MA1_LINE,20.0));
  std::printf("Pb Malpha XRF production cs at 20.0 keV without cascade effect: %f\n",CS_FluorLine_Kissel_no_Cascade(82,MA1_LINE,20.0));

  std::printf("Al mass energy-absorption cs at 20.0 keV: %f\n", CS_Energy(13, 20.0));
  std::printf("Pb mass energy-absorption cs at 40.0 keV: %f\n", CS_Energy(82, 40.0));
  std::printf("CdTe mass energy-absorption cs at 40.0 keV: %f\n", CS_Energy_CP("CdTe", 40.0));

  /* Si Crystal structure */

  Crystal_Struct* cryst = Crystal_GetCrystal("Si", NULL);
  if (cryst == NULL) return 1;
  std::printf ("Si unit cell dimensions are %f %f %f\n", cryst->a, cryst->b, cryst->c);
  std::printf ("Si unit cell angles are %f %f %f\n", cryst->alpha, cryst->beta, cryst->gamma);
  std::printf ("Si unit cell volume is %f\n", cryst->volume);
  std::printf ("Si atoms at:\n");
  std::printf ("   Z  fraction    X        Y        Z\n");
  Crystal_Atom* atom;
  for (i = 0; i < cryst->n_atom; i++) {
    atom = &cryst->atom[i];
    std::printf ("  %3i %f %f %f %f\n", atom->Zatom, atom->fraction, atom->x, atom->y, atom->z);
  }

  /* Si diffraction parameters */

  std::printf ("\nSi111 at 8 KeV. Incidence at the Bragg angle:\n");

  double energy = 8;
  double debye_temp_factor = 1.0;
  double rel_angle = 1.0;

  double bragg = Bragg_angle (cryst, energy, 1, 1, 1);
  std::printf ("  Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI);

  double q = Q_scattering_amplitude (cryst, energy, 1, 1, 1, rel_angle);
  std::printf ("  Q Scattering amplitude: %f\n", q);

  double f0, fp, fpp;
  Atomic_Factors (14, energy, q, debye_temp_factor, &f0, &fp, &fpp);
  std::printf ("  Atomic factors (Z = 14) f0, fp, fpp: %f, %f, i*%f\n", f0, fp, fpp);

  xrlComplex FH, F0;
  FH = Crystal_F_H_StructureFactor (cryst, energy, 1, 1, 1, debye_temp_factor, rel_angle);
  std::printf ("  FH(1,1,1) structure factor: (%f, %f)\n", FH.re, FH.im);

  F0 = Crystal_F_H_StructureFactor (cryst, energy, 0, 0, 0, debye_temp_factor, rel_angle);
  std::printf ("  F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im);



  /* Diamond diffraction parameters */

  cryst = Crystal_GetCrystal("Diamond", NULL);

  std::printf ("\nDiamond 111 at 8 KeV. Incidence at the Bragg angle:\n");

  bragg = Bragg_angle (cryst, energy, 1, 1, 1);
  std::printf ("  Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI);

  q = Q_scattering_amplitude (cryst, energy, 1, 1, 1, rel_angle);
  std::printf ("  Q Scattering amplitude: %f\n", q);

  Atomic_Factors (6, energy, q, debye_temp_factor, &f0, &fp, &fpp);
  std::printf ("  Atomic factors (Z = 6) f0, fp, fpp: %f, %f, i*%f\n", f0, fp, fpp);

  FH = Crystal_F_H_StructureFactor (cryst, energy, 1, 1, 1, debye_temp_factor, rel_angle);
  std::printf ("  FH(1,1,1) structure factor: (%f, %f)\n", FH.re, FH.im);

  F0 = Crystal_F_H_StructureFactor (cryst, energy, 0, 0, 0, debye_temp_factor, rel_angle);
  std::printf ("  F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im);

  xrlComplex FHbar = Crystal_F_H_StructureFactor (cryst, energy, -1, -1, -1, debye_temp_factor, rel_angle);
  double dw = 1e10 * 2 * (R_E / cryst->volume) * (KEV2ANGST * KEV2ANGST/ (energy * energy)) *
                                                  std::sqrt(c_abs(c_mul(FH, FHbar))) / PI / std::sin(2*bragg);
  std::printf ("  Darwin width: %f micro-radians\n", 1e6*dw);

  /* Alpha Quartz diffraction parameters */

  cryst = Crystal_GetCrystal("AlphaQuartz", NULL);

  std::printf ("\nAlpha Quartz 020 at 8 KeV. Incidence at the Bragg angle:\n");

  bragg = Bragg_angle (cryst, energy, 0, 2, 0);
  std::printf ("  Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI);

  q = Q_scattering_amplitude (cryst, energy, 0, 2, 0, rel_angle);
  std::printf ("  Q Scattering amplitude: %f\n", q);

  Atomic_Factors (8, energy, q, debye_temp_factor, &f0, &fp, &fpp);
  std::printf ("  Atomic factors (Z = 8) f0, fp, fpp: %f, %f, i*%f\n", f0, fp, fpp);

  FH = Crystal_F_H_StructureFactor (cryst, energy, 0, 2, 0, debye_temp_factor, rel_angle);
  std::printf ("  FH(0,2,0) structure factor: (%f, %f)\n", FH.re, FH.im);

  F0 = Crystal_F_H_StructureFactor (cryst, energy, 0, 0, 0, debye_temp_factor, rel_angle);
  std::printf ("  F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im);

  /* Muscovite diffraction parameters */

  cryst = Crystal_GetCrystal("Muscovite", NULL);

  std::printf ("\nMuscovite 331 at 8 KeV. Incidence at the Bragg angle:\n");

  bragg = Bragg_angle (cryst, energy, 3, 3, 1);
  std::printf ("  Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI);

  q = Q_scattering_amplitude (cryst, energy, 3, 3, 1, rel_angle);
  std::printf ("  Q Scattering amplitude: %f\n", q);

  Atomic_Factors (19, energy, q, debye_temp_factor, &f0, &fp, &fpp);
  std::printf ("  Atomic factors (Z = 19) f0, fp, fpp: %f, %f, i*%f\n", f0, fp, fpp);

  FH = Crystal_F_H_StructureFactor (cryst, energy, 3, 3, 1, debye_temp_factor, rel_angle);
  std::printf ("  FH(3,3,1) structure factor: (%f, %f)\n", FH.re, FH.im);

  F0 = Crystal_F_H_StructureFactor (cryst, energy, 0, 0, 0, debye_temp_factor, rel_angle);
  std::printf ("  F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im);

  char **crystals;
  crystals = Crystal_GetCrystalsList(NULL, NULL);
  std::printf ("List of available crystals:\n");
  for (i = 0 ; crystals[i] != NULL ; i++) {
  	std::printf ("  Crystal %i: %s\n", i, crystals[i]);
	xrlFree(crystals[i]);
  }
  xrlFree(crystals);
  std::printf ("\n");

  /* compoundDataNIST tests */
  struct compoundDataNIST *cdn;
  cdn = GetCompoundDataNISTByName("Uranium Monocarbide");
  std::printf ("Uranium Monocarbide\n");
  std::printf ("  Name: %s\n", cdn->name);
  std::printf ("  Density: %lf g/cm3\n", cdn->density);
  for (i = 0 ; i < cdn->nElements ; i++) {
    	std::printf("  Element %i: %lf %%\n",cdn->Elements[i],cdn->massFractions[i]*100.0);
  }

  FreeCompoundDataNIST(cdn);
  cdn = NULL;

  cdn = GetCompoundDataNISTByIndex(NIST_COMPOUND_BRAIN_ICRP);
  std::printf ("NIST_COMPOUND_BRAIN_ICRP\n");
  std::printf ("  Name: %s\n", cdn->name);
  std::printf ("  Density: %lf g/cm3\n", cdn->density);
  for (i = 0 ; i < cdn->nElements ; i++) {
    	std::printf("  Element %i: %lf %%\n",cdn->Elements[i],cdn->massFractions[i]*100.0);
  }

  FreeCompoundDataNIST(cdn);
  cdn = NULL;

  char **nistCompounds = GetCompoundDataNISTList(NULL);
  std::printf ("List of available NIST compounds:\n");
  for (i = 0 ; nistCompounds[i] != NULL ; i++) {
  	std::printf ("  Compound %i: %s\n", i, nistCompounds[i]);
	xrlFree(nistCompounds[i]);
  }
  xrlFree(nistCompounds);

  std::printf ("\n");

  /* radioNuclideData tests */
  struct radioNuclideData *rnd;
  rnd = GetRadioNuclideDataByName("109Cd");
  std::printf ("109Cd\n");
  std::printf ("  Name: %s\n", rnd->name);
  std::printf ("  Z: %i\n", rnd->Z);
  std::printf ("  A: %i\n", rnd->A);
  std::printf ("  N: %i\n", rnd->N);
  std::printf ("  Z_xray: %i\n", rnd->Z_xray);
  std::printf ("  X-rays:\n");
  for (i = 0 ; i < rnd->nXrays ; i++)
  	std::printf ("  %f keV -> %f\n", LineEnergy(rnd->Z_xray, rnd->XrayLines[i]), rnd->XrayIntensities[i]);
  std::printf ("  Gamma rays:\n");
  for (i = 0 ; i < rnd->nGammas ; i++)
  	std::printf ("  %f keV -> %f\n", rnd->GammaEnergies[i], rnd->GammaIntensities[i]);

  FreeRadioNuclideData(rnd);

  rnd = GetRadioNuclideDataByIndex(RADIO_NUCLIDE_125I);
  std::printf ("RADIO_NUCLIDE_125I\n");
  std::printf ("  Name: %s\n", rnd->name);
  std::printf ("  Z: %i\n", rnd->Z);
  std::printf ("  A: %i\n", rnd->A);
  std::printf ("  N: %i\n", rnd->N);
  std::printf ("  Z_xray: %i\n", rnd->Z_xray);
  std::printf ("  X-rays:\n");
  for (i = 0 ; i < rnd->nXrays ; i++)
  	std::printf ("  %f keV -> %f\n", LineEnergy(rnd->Z_xray, rnd->XrayLines[i]), rnd->XrayIntensities[i]);
  std::printf ("  Gamma rays:\n");
  for (i = 0 ; i < rnd->nGammas ; i++)
  	std::printf ("  %f keV -> %f\n", rnd->GammaEnergies[i], rnd->GammaIntensities[i]);

  FreeRadioNuclideData(rnd);

  char **radioNuclides;
  radioNuclides = GetRadioNuclideDataList(NULL);
  std::printf ("List of available radionuclides:\n");
  for (i = 0 ; radioNuclides[i] != NULL ; i++) {
  	std::printf ("  Radionuclide %i: %s\n", i, radioNuclides[i]);
	xrlFree(radioNuclides[i]);
  }
  xrlFree(radioNuclides);

  std::printf ("\n--------------------------- END OF XRLEXAMPLE6 -------------------------------\n");
  return 0;
}
Exemplo n.º 16
0
static void
vcc_ParseHostDef(struct vcc *tl, int serial, const char *vgcname)
{
	struct token *t_field;
	struct token *t_host = NULL;
	struct token *t_port = NULL;
	struct token *t_hosthdr = NULL;
	unsigned saint = UINT_MAX;
	struct fld_spec *fs;
	struct vsb *vsb;
	unsigned u;
	double t;

	Fh(tl, 1, "\n#define VGC_backend_%s %d\n", vgcname, tl->ndirector);

	fs = vcc_FldSpec(tl,
	    "!host",
	    "?port",
	    "?host_header",
	    "?connect_timeout",
	    "?first_byte_timeout",
	    "?between_bytes_timeout",
	    "?probe",
	    "?max_connections",
	    "?saintmode_threshold",
	    NULL);

	SkipToken(tl, '{');

	vsb = VSB_new_auto();
	AN(vsb);
	tl->fb = vsb;

	Fb(tl, 0, "\nstatic const struct vrt_backend vgc_dir_priv_%s = {\n",
	    vgcname);

	Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(tl->t_dir));
	if (serial >= 0)
		Fb(tl, 0, "[%d]", serial);
	Fb(tl, 0, "\",\n");

	/* Check for old syntax */
	if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) {
		VSB_printf(tl->sb,
		    "NB: Backend Syntax has changed:\n"
		    "Remove \"set\" and \"backend\" in front"
		    " of backend fields.\n" );
		vcc_ErrToken(tl, tl->t);
		VSB_printf(tl->sb, " at ");
		vcc_ErrWhere(tl, tl->t);
		return;
	}

	while (tl->t->tok != '}') {

		vcc_IsField(tl, &t_field, fs);
		ERRCHK(tl);
		if (vcc_IdIs(t_field, "host")) {
			ExpectErr(tl, CSTR);
			assert(tl->t->dec != NULL);
			t_host = tl->t;
			vcc_NextToken(tl);
			SkipToken(tl, ';');
		} else if (vcc_IdIs(t_field, "port")) {
			ExpectErr(tl, CSTR);
			assert(tl->t->dec != NULL);
			t_port = tl->t;
			vcc_NextToken(tl);
			SkipToken(tl, ';');
		} else if (vcc_IdIs(t_field, "host_header")) {
			ExpectErr(tl, CSTR);
			assert(tl->t->dec != NULL);
			t_hosthdr = tl->t;
			vcc_NextToken(tl);
			SkipToken(tl, ';');
		} else if (vcc_IdIs(t_field, "connect_timeout")) {
			Fb(tl, 0, "\t.connect_timeout = ");
			vcc_Duration(tl, &t);
			ERRCHK(tl);
			Fb(tl, 0, "%g,\n", t);
			SkipToken(tl, ';');
		} else if (vcc_IdIs(t_field, "first_byte_timeout")) {
			Fb(tl, 0, "\t.first_byte_timeout = ");
			vcc_Duration(tl, &t);
			ERRCHK(tl);
			Fb(tl, 0, "%g,\n", t);
			SkipToken(tl, ';');
		} else if (vcc_IdIs(t_field, "between_bytes_timeout")) {
			Fb(tl, 0, "\t.between_bytes_timeout = ");
			vcc_Duration(tl, &t);
			ERRCHK(tl);
			Fb(tl, 0, "%g,\n", t);
			SkipToken(tl, ';');
		} else if (vcc_IdIs(t_field, "max_connections")) {
			u = vcc_UintVal(tl);
			ERRCHK(tl);
			SkipToken(tl, ';');
			Fb(tl, 0, "\t.max_connections = %u,\n", u);
		} else if (vcc_IdIs(t_field, "saintmode_threshold")) {
			u = vcc_UintVal(tl);
			/* UINT_MAX == magic number to mark as unset, so
			 * not allowed here.
			 */
			if (u == UINT_MAX) {
				VSB_printf(tl->sb,
				    "Value outside allowed range: ");
				vcc_ErrToken(tl, tl->t);
				VSB_printf(tl->sb, " at\n");
				vcc_ErrWhere(tl, tl->t);
			}
			ERRCHK(tl);
			saint = u;
			SkipToken(tl, ';');
		} else if (vcc_IdIs(t_field, "probe") && tl->t->tok == '{') {
			Fb(tl, 0, "\t.probe = &vgc_probe__%d,\n", tl->nprobe);
			vcc_ParseProbeSpec(tl);
			ERRCHK(tl);
		} else if (vcc_IdIs(t_field, "probe") && tl->t->tok == ID) {
			Fb(tl, 0, "\t.probe = &vgc_probe_%.*s,\n", PF(tl->t));
			vcc_AddRef(tl, tl->t, SYM_PROBE);
			vcc_NextToken(tl);
			SkipToken(tl, ';');
		} else if (vcc_IdIs(t_field, "probe")) {
			VSB_printf(tl->sb,
			    "Expected '{' or name of probe.");
			vcc_ErrToken(tl, tl->t);
			VSB_printf(tl->sb, " at\n");
			vcc_ErrWhere(tl, tl->t);
			return;
		} else {
			ErrInternal(tl);
			return;
		}

	}

	vcc_FieldsOk(tl, fs);
	ERRCHK(tl);

	/* Check that the hostname makes sense */
	assert(t_host != NULL);
	if (t_port != NULL)
		Emit_Sockaddr(tl, t_host, t_port->dec);
	else
		Emit_Sockaddr(tl, t_host, "80");
	ERRCHK(tl);

	ExpectErr(tl, '}');

	/* We have parsed it all, emit the ident string */

	/* Emit the hosthdr field, fall back to .host if not specified */
	Fb(tl, 0, "\t.hosthdr = ");
	if (t_hosthdr != NULL)
		EncToken(tl->fb, t_hosthdr);
	else
		EncToken(tl->fb, t_host);
	Fb(tl, 0, ",\n");

	Fb(tl, 0, "\t.saintmode_threshold = %d,\n",saint);

	/* Close the struct */
	Fb(tl, 0, "};\n");

	vcc_NextToken(tl);

	tl->fb = NULL;
	AZ(VSB_finish(vsb));
	Fh(tl, 0, "%s", VSB_data(vsb));
	VSB_delete(vsb);

	Fi(tl, 0, "\tVRT_init_dir(cli, VCL_conf.director, \"simple\",\n"
	    "\t    VGC_backend_%s, &vgc_dir_priv_%s);\n", vgcname, vgcname);
	Ff(tl, 0, "\tVRT_fini_dir(cli, VGCDIR(%s));\n", vgcname);
	tl->ndirector++;
}
Exemplo n.º 17
0
void Cube::DoMethod(CubeRotateMethod method)
{
    switch (method)
    {
    case ROTATE_NONE:
    case ROTATE_NONEi:
        break;
    case ROTATE_FRONT:
        F();
        break;
    case ROTATE_BACK:
        B();
        break;
    case ROTATE_LEFT:
        L();
        break;
    case ROTATE_RIGHT:
        R();
        break;
    case ROTATE_UP:
        U();
        break;
    case ROTATE_DOWN:
        D();
        break;
    case ROTATE_FRONTi:
        Fi();
        break;
    case ROTATE_BACKi:
        Bi();
        break;
    case ROTATE_LEFTi:
        Li();
        break;
    case ROTATE_RIGHTi:
        Ri();
        break;
    case ROTATE_UPi:
        Ui();
        break;
    case ROTATE_DOWNi:
        Di();
        break;
    case ROTATE_WHOLEX:
        RotateUp();
        break;
    case ROTATE_WHOLEY:
        RotateLeft();
        break;
    case ROTATE_WHOLEZ:
        RotateClockwise();
        break;
    case ROTATE_WHOLEXi:
        RotateDown();
        break;
    case ROTATE_WHOLEYi:
        RotateRight();
        break;
    case ROTATE_WHOLEZi:
        RotateCounterClockwise();
        break;
    default:
        break;
    }
}