Beispiel #1
0
static float Jump_from_L2(int Z,float E)
{
  float Factor=1.0,JumpL1,JumpL2,JumpK;
  float TaoL1=0.0,TaoL2=0.0;
	if( E > EdgeEnergy(Z,K_SHELL) ) {
	  JumpK = JumpFactor(Z,K_SHELL) ;
	  if( JumpK <= 0. )
		return 0. ;
	  Factor /= JumpK ;
	}
	JumpL1 = JumpFactor(Z,L1_SHELL) ;
	JumpL2 = JumpFactor(Z,L2_SHELL) ;
	if(E>EdgeEnergy (Z,L1_SHELL)) {
	  if( JumpL1 <= 0.|| JumpL2 <= 0. )
		return 0. ;
	  TaoL1 = (JumpL1-1) / JumpL1 ;
	  TaoL2 = (JumpL2-1) / (JumpL2*JumpL1) ;
	}
	else if( E > EdgeEnergy(Z,L2_SHELL) ) {
	  if( JumpL2 <= 0. )
		return 0. ;
	  TaoL1 = 0. ;
	  TaoL2 = (JumpL2-1)/(JumpL2) ;
	}
	else
	  Factor = 0;
	Factor *= (TaoL2 + TaoL1*CosKronTransProb(Z,F12_TRANS)) * FluorYield(Z,L2_SHELL) ;

	return Factor;

}
Beispiel #2
0
static double Jump_from_L2(int Z, double E, xrl_error **error)
{
  double Factor = 1.0, JumpL1, JumpL2, JumpK;
  double TaoL1 = 0.0, TaoL2 = 0.0;
  double edgeK = EdgeEnergy(Z, K_SHELL, NULL);
  double edgeL1 = EdgeEnergy(Z, L1_SHELL, NULL);
  double edgeL2 = EdgeEnergy(Z, L2_SHELL, NULL);
  double ck_L12, yield;

  if (E > edgeK && edgeK > 0.0) {
    JumpK = JumpFactor(Z, K_SHELL, NULL);
    if (JumpK == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    Factor /= JumpK ;
  }

  JumpL1 = JumpFactor(Z, L1_SHELL, NULL);
  JumpL2 = JumpFactor(Z, L2_SHELL, NULL);

  if (E > edgeL1 && edgeL1 > 0.0) {
    if (JumpL1 == 0.0 || JumpL2 == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    TaoL1 = (JumpL1 - 1) / JumpL1 ;
    TaoL2 = (JumpL2 - 1) / (JumpL2 * JumpL1) ;
  }
  else if (E > edgeL2 && edgeL2 > 0.0) {
    if (JumpL2 == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    TaoL1 = 0.0;
    TaoL2 = (JumpL2 - 1) / JumpL2;
  }
  else {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, TOO_LOW_EXCITATION_ENERGY);
    return 0.0;
  }

  ck_L12 = CosKronTransProb(Z, F12_TRANS, NULL);
  if (TaoL1 > 0 && ck_L12 == 0.0) {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_CK);
    return 0.0;
  }

  yield = FluorYield(Z, L2_SHELL, NULL);
  if (yield == 0.0) {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_FLUOR_YIELD);
    return 0.0;
  }

  Factor *= (TaoL2 + TaoL1 * ck_L12) * yield;

  return Factor;
}
Beispiel #3
0
static float Jump_from_L3(int Z,float E )
{
  float Factor=1.0,JumpL1,JumpL2,JumpL3,JumpK;
  float TaoL1=0.0,TaoL2=0.0,TaoL3=0.0;

	if( E > EdgeEnergy(Z,K_SHELL) ) {
	  JumpK = JumpFactor(Z,K_SHELL) ;
	  if( JumpK <= 0. )
	return 0.;
	  Factor /= JumpK ;
	}
	JumpL1 = JumpFactor(Z,L1_SHELL) ;
	JumpL2 = JumpFactor(Z,L2_SHELL) ;
	JumpL3 = JumpFactor(Z,L3_SHELL) ;
	if( E > EdgeEnergy(Z,L1_SHELL) ) {
	  if( JumpL1 <= 0.|| JumpL2 <= 0. || JumpL3 <= 0. )
	return 0. ;
	  TaoL1 = (JumpL1-1) / JumpL1 ;
	  TaoL2 = (JumpL2-1) / (JumpL2*JumpL1) ;
	  TaoL3 = (JumpL3-1) / (JumpL3*JumpL2*JumpL1) ;
	}
	else if( E > EdgeEnergy(Z,L2_SHELL) ) {
	  if( JumpL2 <= 0. || JumpL3 <= 0. )
	return 0. ;
	  TaoL1 = 0. ;
	  TaoL2 = (JumpL2-1) / (JumpL2) ;
	  TaoL3 = (JumpL3-1) / (JumpL3*JumpL2) ;
	}
	else if( E > EdgeEnergy(Z,L3_SHELL) ) {
	  TaoL1 = 0. ;
	  TaoL2 = 0. ;
	  if( JumpL3 <= 0. )
	return 0. ;
	  TaoL3 = (JumpL3-1) / JumpL3 ;
	}
	else
	  Factor = 0;
	Factor *= (TaoL3 + TaoL2 * CosKronTransProb(Z,F23_TRANS) +
		TaoL1 * (CosKronTransProb(Z,F13_TRANS) + CosKronTransProb(Z,FP13_TRANS)
		+ CosKronTransProb(Z,F12_TRANS) * CosKronTransProb(Z,F23_TRANS))) ;
	Factor *= (FluorYield(Z,L3_SHELL) ) ;
	return Factor;

}
Beispiel #4
0
static float Jump_from_L1(int Z,float E)
{
  float Factor=1.0,JumpL1,JumpK;
	if( E > EdgeEnergy(Z,K_SHELL) ) {
	  JumpK = JumpFactor(Z,K_SHELL) ;
	  if( JumpK <= 0. )
		return 0. ;
	  Factor /= JumpK ;
	}
	if (E > EdgeEnergy(Z, L1_SHELL)) {
	  JumpL1 = JumpFactor(Z, L1_SHELL);
	  if (JumpL1 <= 0.0) return 0.0;
	  Factor *= ((JumpL1-1)/JumpL1) * FluorYield(Z, L1_SHELL);
	}
	else
	  return 0.;
  return Factor;

}
Beispiel #5
0
static double Jump_from_L1(int Z, double E, xrl_error **error)
{
  double Factor = 1.0, JumpL1, JumpK;
  double edgeK = EdgeEnergy(Z, K_SHELL, NULL);
  double edgeL1 = EdgeEnergy(Z, L1_SHELL, NULL);
  double yield;

  if (E > edgeK && edgeK > 0.0) {
    JumpK = JumpFactor(Z, K_SHELL, NULL);
    if (JumpK == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    Factor /= JumpK ;
  }
 
  if (E > edgeL1 && edgeL1 > 0.0) {
    JumpL1 = JumpFactor(Z, L1_SHELL, NULL);
    if (JumpL1 == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    yield = FluorYield(Z, L1_SHELL, NULL);
    if (yield == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_FLUOR_YIELD);
      return 0.0;
    }
    Factor *= ((JumpL1 - 1) / JumpL1) * yield;
  }
  else {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, TOO_LOW_EXCITATION_ENERGY);
    return 0.0;
  }

  return Factor;
}
Beispiel #6
0
float LineEnergy(int Z, int line)
{
  float line_energy;
  float lE[50],rr[50];
  float tmp=0.0,tmp1=0.0,tmp2=0.0;
  int i;
  int temp_line;
  
  if (Z<1 || Z>ZMAX) {
    ErrorExit("Z out of range in function LineEnergy");
    return 0;
  }
  
  if (line>=KA_LINE && line<LA_LINE) {
    if (line == KA_LINE) {
	for (i = KL1; i <= KL3 ; i++) {
	 lE[i] = LineEnergy_arr[Z][i];
	 rr[i] = RadRate_arr[Z][i];
	 tmp1+=rr[i];
	 tmp+=lE[i]*rr[i];

	 if (lE[i]<0.0 || rr[i]<0.0) {
	  ErrorExit("Line not available in function LineEnergy");
	  return 0;
	 }
	}
    }
    else if (line == KB_LINE) {
    	for (i = KM1; i < KP5; i++) {
	 lE[i] = LineEnergy_arr[Z][i];
	 rr[i] = RadRate_arr[Z][i];
	 tmp1+=rr[i];
	 tmp+=lE[i]*rr[i];
	 if (lE[i]<0.0 || rr[i]<0.0) {
	  ErrorExit("Line not available in function LineEnergy");
	  return 0;
	 }
	}
    }
   if (tmp1>0)   return tmp/tmp1;  else return 0.0;
  }
  
  if (line == LA_LINE) {
	temp_line = L3M5_LINE;
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L3_SHELL)+0.1);
	tmp2=tmp1;
	tmp=LineEnergy(Z,temp_line)*tmp1;
	temp_line = L3M4_LINE;
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L3_SHELL)+0.1);
	tmp2+=tmp1;
	tmp+=LineEnergy(Z,temp_line)*tmp1 ;
  	if (tmp2>0)   return tmp/tmp2;  else return 0.0;
  }
  else if (line == LB_LINE) {
	temp_line = L2M4_LINE;     /* b1 */
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L2_SHELL)+0.1);
	tmp2=tmp1;
	tmp=LineEnergy(Z,temp_line)*tmp1;

	temp_line = L3N5_LINE;     /* b2 */
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L3_SHELL)+0.1);
	tmp2+=tmp1;
	tmp+=LineEnergy(Z,temp_line)*tmp1 ;

	temp_line = L1M3_LINE;     /* b3 */
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L1_SHELL)+0.1);
	tmp2+=tmp1;
	tmp+=LineEnergy(Z,temp_line)*tmp1 ;

	temp_line = L1M2_LINE;     /* b4 */
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L1_SHELL)+0.1);
	tmp2+=tmp1;
	tmp+=LineEnergy(Z,temp_line)*tmp1 ;

	temp_line = L3O3_LINE;     /* b5 */
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L3_SHELL)+0.1);
	tmp2+=tmp1;
	tmp+=LineEnergy(Z,temp_line)*tmp1 ;

	temp_line = L3O4_LINE;     /* b5 */
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L3_SHELL)+0.1);
	tmp2+=tmp1;
	tmp+=LineEnergy(Z,temp_line)*tmp1 ;

	temp_line = L3N1_LINE;     /* b6 */
	tmp1=CS_FluorLine(Z, temp_line,EdgeEnergy(Z,L3_SHELL)+0.1);
	tmp2+=tmp1;
	tmp+=LineEnergy(Z,temp_line)*tmp1 ;
  	if (tmp2>0)   return tmp/tmp2;  else return 0.0;
  }
  /*
   * special cases for composed lines
   */
  else if (line == L1N67_LINE) {
 	return (LineEnergy(Z, L1N6_LINE)+LineEnergy(Z,L1N7_LINE))/2.0; 
  }
  else if (line == L1O45_LINE) {
 	return (LineEnergy(Z, L1O4_LINE)+LineEnergy(Z,L1O5_LINE))/2.0; 
  }
  else if (line == L1P23_LINE) {
 	return (LineEnergy(Z, L1P2_LINE)+LineEnergy(Z,L1P3_LINE))/2.0; 
  }
  else if (line == L2P23_LINE) {
 	return (LineEnergy(Z, L2P2_LINE)+LineEnergy(Z,L2P3_LINE))/2.0; 
  }
  else if (line == L3O45_LINE) {
 	return (LineEnergy(Z, L3O4_LINE)+LineEnergy(Z,L3O5_LINE))/2.0; 
  }
  else if (line == L3P23_LINE) {
 	return (LineEnergy(Z, L3P2_LINE)+LineEnergy(Z,L3P3_LINE))/2.0; 
  }
  else if (line == L3P45_LINE) {
 	return (LineEnergy(Z, L3P4_LINE)+LineEnergy(Z,L3P5_LINE))/2.0; 
  }
  
  line = -line - 1;
  if (line<0 || line>=LINENUM) {
    ErrorExit("Line not available in function LineEnergy");
    return 0;
  }
  
  line_energy = LineEnergy_arr[Z][line];
  if (line_energy < 0.) {
    ErrorExit("Line not available in function LineEnergy");
    return 0;
  }
  return line_energy;
}
Beispiel #7
0
double CS_FluorLine(int Z, int line, double E, xrl_error **error)
{
  double JumpK;
  double cs_line, Factor = 1.0;

  if (Z < 1 || Z > ZMAX) {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, Z_OUT_OF_RANGE);
    return 0.0;
  }

  if (E <= 0.0) {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, NEGATIVE_ENERGY);
    return 0.0;
  }

  if (line >= KN5_LINE && line <= KB_LINE) {
    double edgeK = EdgeEnergy(Z, K_SHELL, error);
    double cs, rr;
    if (E > edgeK && edgeK > 0.0) {
      double yield;
      JumpK = JumpFactor(Z, K_SHELL, error);
      if (JumpK == 0.0) {
	return 0.0;
      }
      yield = FluorYield(Z, K_SHELL, error);
      if (yield == 0.0) {
	return 0.0;
      }
      Factor = ((JumpK - 1)/JumpK) * yield;
    }
    else if (edgeK == 0.0) {
      return 0.0;
    }
    else {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, TOO_LOW_EXCITATION_ENERGY);
      return 0.0;
    }

    cs = CS_Photo(Z, E, error);
    if (cs == 0.0) {
      return 0.0;
    }

    rr = RadRate(Z, line, error);
    if (rr == 0.0) {
      return 0.0;
    }

    cs_line = cs * Factor * rr;
  }
  else if ((line <= L1L2_LINE && line >= L3Q1_LINE) || line == LA_LINE) {
    double cs, rr;
    cs = CS_Photo(Z, E, error);
    if (cs == 0.0) {
      return 0.0;
    }

    rr = RadRate(Z, line, error);
    if (rr == 0.0) {
      return 0.0;
    }

    if (line >= L1P5_LINE && line <= L1L2_LINE) {
      Factor = Jump_from_L1(Z, E, error);
    }
    else if (line >= L2Q1_LINE && line <= L2L3_LINE)  {
      Factor = Jump_from_L2(Z, E, error);
    }
    /*
     * it's safe to use LA_LINE since it's only composed of 2 L3-lines
     */
    else if ((line >= L3Q1_LINE && line <= L3M1_LINE) || line == LA_LINE) {
      Factor = Jump_from_L3(Z, E, error);
    }
    if (Factor == 0.0) {
      return 0.0;
    }
    cs_line = cs * Factor * rr;
  }
  else if (line == LB_LINE) {
    /*
     * b1->b17
     */
    double cs;
    cs_line = Jump_from_L2(Z, E, NULL) * (RadRate(Z, L2M4_LINE, NULL) + RadRate(Z, L2M3_LINE, NULL)) +
      Jump_from_L3(Z, E, NULL) * (RadRate(Z, L3N5_LINE, NULL) + RadRate(Z, L3O4_LINE, NULL) + RadRate(Z, L3O5_LINE, NULL) + RadRate(Z, L3O45_LINE, NULL) + RadRate(Z, L3N1_LINE, NULL) + RadRate(Z, L3O1_LINE, NULL) + RadRate(Z, L3N6_LINE, NULL) + RadRate(Z, L3N7_LINE, NULL) + RadRate(Z, L3N4_LINE, NULL)) +
      Jump_from_L1(Z, E, NULL) * (RadRate(Z, L1M3_LINE, NULL) + RadRate(Z, L1M2_LINE, NULL) + RadRate(Z, L1M5_LINE, NULL) + RadRate(Z, L1M4_LINE, NULL));

    if (cs_line == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, TOO_LOW_EXCITATION_ENERGY);
      return 0.0;
    }
    cs = CS_Photo(Z, E, error);
    if (cs == 0.0) {
      return 0.0;
    }
    cs_line *= cs;
  }
  else {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, INVALID_LINE);
    return 0.0;
  }
  
  
  return cs_line;
}            
Beispiel #8
0
static double Jump_from_L3(int Z, double E, xrl_error **error)
{
  double Factor=1.0, JumpL1, JumpL2, JumpL3, JumpK;
  double TaoL1=0.0, TaoL2=0.0, TaoL3=0.0;
  double edgeK = EdgeEnergy(Z, K_SHELL, NULL);
  double edgeL1 = EdgeEnergy(Z, L1_SHELL, NULL);
  double edgeL2 = EdgeEnergy(Z, L2_SHELL, NULL);
  double edgeL3 = EdgeEnergy(Z, L3_SHELL, NULL);
  double ck_L23, ck_L13, ck_LP13, ck_L12;
  double yield;

  if (E > edgeK && edgeK > 0.0) {
    JumpK = JumpFactor(Z, K_SHELL, NULL);
    if (JumpK == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    Factor /= JumpK ;
  }
  JumpL1 = JumpFactor(Z, L1_SHELL, NULL);
  JumpL2 = JumpFactor(Z, L2_SHELL, NULL);
  JumpL3 = JumpFactor(Z, L3_SHELL, NULL);
  if (E > edgeL1 && edgeL1 > 0.0) {
    if (JumpL1 == 0.0 || JumpL2 == 0.0 || JumpL3 == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    TaoL1 = (JumpL1 - 1) / JumpL1 ;
    TaoL2 = (JumpL2 - 1) / (JumpL2 * JumpL1) ;
    TaoL3 = (JumpL3 - 1) / (JumpL3 * JumpL2 * JumpL1) ;
  }
  else if (E > edgeL2 && edgeL2 > 0.0) {
    if (JumpL2 == 0.0 || JumpL3 == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    TaoL1 = 0.0;
    TaoL2 = (JumpL2 - 1) / (JumpL2) ;
    TaoL3 = (JumpL3 - 1) / (JumpL3 * JumpL2) ;
  }
  else if (E > edgeL3 && edgeL3 > 0.0) {
    TaoL1 = 0.0;
    TaoL2 = 0.0;
    if (JumpL3 == 0.0) {
      xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_JUMP_FACTOR);
      return 0.0;
    }
    TaoL3 = (JumpL3 - 1) / JumpL3 ;
  }
  else {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, TOO_LOW_EXCITATION_ENERGY);
    return 0.0;
  }

  ck_L23 = CosKronTransProb(Z, F23_TRANS, NULL);
  ck_L13 = CosKronTransProb(Z, F13_TRANS, NULL);
  ck_LP13 = CosKronTransProb(Z, FP13_TRANS, NULL);
  ck_L12 = CosKronTransProb(Z, F12_TRANS, NULL);

  if (TaoL2 > 0.0 && ck_L23 == 0.0) {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_CK);
    return 0.0;
  }

  if (TaoL1 > 0.0 && (ck_L13 + ck_LP13 == 0.0 || ck_L12 == 0.0 || ck_L23 == 0.0)) {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_CK);
    return 0.0;
  }

  Factor *= TaoL3 + TaoL2 * ck_L23 + TaoL1 * (ck_L13 + ck_LP13 + ck_L12 * ck_L23);

  yield = FluorYield(Z, L3_SHELL, NULL);
  if (yield == 0.0) {
    xrl_set_error_literal(error, XRL_ERROR_INVALID_ARGUMENT, UNAVAILABLE_FLUOR_YIELD);
    return 0.0;
  }

  Factor *= yield;
  return Factor;
}
Beispiel #9
0
int main()
{
  struct compoundData cdtest;
  int i;
  XRayInit();
  //if something goes wrong, the test will end with EXIT_FAILURE
  //SetHardExit(1);

  std::printf("Example of C++ program using xraylib\n");
  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 (CompoundParser("Ca(HCO3)2",&cdtest) == 0)
	return 1;
  std::printf("Ca(HCO3)2 contains %i atoms and %i elements\n",cdtest.nAtomsAll,cdtest.nElements);
  for (i = 0 ; i < cdtest.nElements ; i++)
    std::printf("Element %i: %lf %%\n",cdtest.Elements[i],cdtest.massFractions[i]*100.0);

  FREE_COMPOUND_DATA(cdtest)

  //parser test for SiO2 (quartz)
  if (CompoundParser("SiO2",&cdtest) == 0)
	return 1;

  std::printf("SiO2 contains %i atoms and %i elements\n",cdtest.nAtomsAll,cdtest.nElements);
  for (i = 0 ; i < cdtest.nElements ; i++)
    std::printf("Element %i: %lf %%\n",cdtest.Elements[i],cdtest.massFractions[i]*100.0);

  FREE_COMPOUND_DATA(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("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));

  /* 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");

  float energy = 8;
  float debye_temp_factor = 1.0;
  float rel_angle = 1.0;

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

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

  float 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);

  Complex 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);

  Complex FHbar = Crystal_F_H_StructureFactor (cryst, energy, -1, -1, -1, debye_temp_factor, rel_angle);
  float dw = 1e10 * 2 * (R_E / cryst->volume) * (KEV2ANGST * KEV2ANGST/ (energy * energy)) * 
                                                  sqrt(c_abs(c_mul(FH, FHbar))) / PI / 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);


  std::printf ("\n--------------------------- END OF XRLEXAMPLE6 -------------------------------\n");
  return 0;
}
Beispiel #10
0
float CS_FluorLine(int Z, int line, float E)
{
  float JumpK;
  float cs_line, Factor = 1.;

  if (Z<1 || Z>ZMAX) {
    ErrorExit("Z out of range in function CS_FluorLine");
    return 0;
  }

  if (E <= 0.) {
    ErrorExit("Energy <=0 in function CS_FluorLine");
    return 0;
  }

  if (line>=KN5_LINE && line<=KB_LINE) {
    if (E > EdgeEnergy(Z, K_SHELL)) {
      JumpK = JumpFactor(Z, K_SHELL);
      if (JumpK <= 0.)
	return 0.;
      Factor = ((JumpK-1)/JumpK) * FluorYield(Z, K_SHELL);
    }
    else
      return 0.;                               
    cs_line = CS_Photo(Z, E) * Factor * RadRate(Z, line) ;
  }

  else if (line>=L1P5_LINE && line<=L1L2_LINE) {
	Factor=Jump_from_L1(Z,E);
	cs_line = CS_Photo(Z, E) * Factor * RadRate(Z, line) ;
  }
  
  else if (line>=L2Q1_LINE && line<=L2L3_LINE)  {
	Factor=Jump_from_L2(Z,E);
	cs_line = CS_Photo(Z, E) * Factor * RadRate(Z, line) ;
  }
  /*
   * it's safe to use LA_LINE since it's only composed of 2 L3-lines
   */
  else if ((line>=L3Q1_LINE && line<=L3M1_LINE) || line==LA_LINE) {
	Factor=Jump_from_L3(Z,E);
	cs_line = CS_Photo(Z, E) * Factor * RadRate(Z, line) ;
  }
  else if (line==LB_LINE) {
   	/*
	 * b1->b17
	 */
   	cs_line=Jump_from_L2(Z,E)*(RadRate(Z,L2M4_LINE)+RadRate(Z,L2M3_LINE))+
		   Jump_from_L3(Z,E)*(RadRate(Z,L3N5_LINE)+RadRate(Z,L3O4_LINE)+RadRate(Z,L3O5_LINE)+RadRate(Z,L3O45_LINE)+RadRate(Z,L3N1_LINE)+RadRate(Z,L3O1_LINE)+RadRate(Z,L3N6_LINE)+RadRate(Z,L3N7_LINE)+RadRate(Z,L3N4_LINE)) +
		   Jump_from_L1(Z,E)*(RadRate(Z,L1M3_LINE)+RadRate(Z,L1M2_LINE)+RadRate(Z,L1M5_LINE)+RadRate(Z,L1M4_LINE));
   	cs_line*=CS_Photo(Z, E);
  }

  else {
    ErrorExit("Line not allowed in function CS_FluorLine");
    return 0;
  }
  
  
  return (cs_line);
}            
Beispiel #11
0
int getAtomicXRayCS_Kissel (int shellID)
{
  int   i, Z;
  float energy_keV;
  
  Z = SymbolToAtomicNumber ( targetFormula );
  edgeEnergy = 0.0;
  fluorYield = 1.0;
  jumpFactor = 1.0;
  levelWidth = 0.0;
  electronConfig  = Z;

  if (verbose > 3) { 
    fprintf(stdout, "getAtomicXRayCS: Z = %d\n", Z);
    fprintf(stdout, "getAtomicXRayCS_Kissel: shellID = %d\n", shellID);
    if (verbose>2) { fprintf(stdout, "Index  PhotonEnergy   TotalCS      PhotoCS     coherentCS   incohrentCS \n"); }
  }

  if (shellID <= 30 && shellID >= 0) {
    edgeEnergy = 1000.0 * EdgeEnergy(Z, shellID);
    fluorYield = FluorYield(Z, shellID);
    jumpFactor = JumpFactor(Z, shellID);
    electronConfig  = ElectronConfig(Z, shellID);
    levelWidth = AtomicLevelWidth(Z, shellID);
    for ( i = 0; i < npts; i++ ) {
      energy_keV  = 0.001 * energy[i];
      if ( energy[i] > edgeEnergy ) {
        photo[i]  = CS_Photo_Partial (Z, shellID, energy_keV);
      } else {
        photo[i]  = 0.0;
      }
      total[i]    = 0.0;
      rayleigh[i] = 0.0;
      compton[i]  = 0.0;
      if (verbose>2) { fprintf(stdout, "%4d %12.1f %12.4g %12.4g %12.4g %12.4g \n", i, energy[i], total[i], photo[i], rayleigh[i], compton[i]); }
    }
  } else if (shellID > 99) {
    for ( i = 0; i < npts; i++ ) {
      energy_keV  = 0.001 * energy[i];
      total[i]    = CS_Total_Kissel ( Z, energy_keV );
      photo[i]    = CS_Photo_Total  ( Z, energy_keV );
      rayleigh[i] = CS_Rayl  ( Z, energy_keV );
      compton[i]  = CS_Compt ( Z, energy_keV );
      if (verbose>2) { fprintf(stdout, "%4d %12.1f %12.4g %12.4g %12.4g %12.4g \n", i, energy[i], total[i], photo[i], rayleigh[i], compton[i]); }
    }
  } else {
    for ( i = 0; i < npts; i++ ) {
      energy_keV  = 0.001 * energy[i];
      photo[i]    = CS_Photo ( Z, energy_keV );
      total[i]    = CS_Total ( Z, energy_keV );
      rayleigh[i] = CS_Rayl  ( Z, energy_keV );
      compton[i]  = CS_Compt ( Z, energy_keV );
      if (verbose>2) { fprintf(stdout, "%4d %12.1f %12.4g %12.4g %12.4g %12.4g \n", i, energy[i], total[i], photo[i], rayleigh[i], compton[i]); }
    }
  }

  if (verbose > 1) { 
    fprintf(stdout, "edgeEnergy = %f, fluorYield = %f,  jumpFactor = %f,", edgeEnergy, fluorYield, jumpFactor);
    fprintf(stdout, " electronConfig = %f, levelWidth = %f \n", electronConfig, levelWidth);
  }
  return 0;
}
Beispiel #12
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;
}