static void add_button_clicked(GtkButton *button, XmiMsimGuiLayerDialog *dialog) { //make entries empty and disable OK button GtkWidget *compound_dialog = xmi_msim_gui_compound_dialog_new(GTK_WINDOW(dialog), XMI_MSIM_GUI_COMPOUND_DIALOG_TYPE_ADD); int rv = gtk_dialog_run(GTK_DIALOG(compound_dialog)); if (rv == GTK_RESPONSE_ACCEPT) { //something was changed gchar *compound = xmi_msim_gui_compound_dialog_get_compound(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog)); gdouble compound_weight = xmi_msim_gui_compound_dialog_get_weight(XMI_MSIM_GUI_COMPOUND_DIALOG(compound_dialog)); struct compoundData *cd, *cd2, *cdsum; cd2 = CompoundParser(compound); //get current composition int n_elements, *Z; double *weight; xmi_msim_gui_layer_dialog_get_composition(dialog, &n_elements, &Z, &weight); if (n_elements > 0) { xmi_layer layer = {n_elements, Z, weight, 0.0, 0.0}; //copy xmi_layer to compoundData and add current contents cd = xmi_layer2compoundData(&layer); //calculate sum cdsum = add_compound_data(*cd, 1.0, *cd2, compound_weight/100.0); xmi_msim_gui_layer_dialog_set_composition(dialog, cdsum->nElements, cdsum->Elements, cdsum->massFractions); g_free(Z); g_free(weight); FreeCompoundData(cdsum); FreeCompoundData(cd); } else { //list is empty! xmi_scale_double(cd2->massFractions, cd2->nElements, compound_weight/100.0); if (cd2->nElements == 1) { // if compound double density = ElementDensity(cd2->Elements[0]); gchar *buffer = g_strdup_printf("%f", density); g_signal_handler_block(G_OBJECT(dialog->densityEntry), dialog->density_changed); gtk_entry_set_text(GTK_ENTRY(dialog->densityEntry), buffer); g_signal_handler_unblock(G_OBJECT(dialog->densityEntry), dialog->density_changed); g_free(buffer); } xmi_msim_gui_layer_dialog_set_composition(dialog, cd2->nElements, cd2->Elements, cd2->massFractions); } FreeCompoundData(cd2); } gtk_widget_destroy(compound_dialog); return; }
void dialog_buttons_clicked_cb (GtkDialog *dialog, gint response_id, gpointer data) { struct compoundWidget *cw = (struct compoundWidget *) data; struct compoundData *cd, *cd2, *cdsum; char *textPtr; double weight; double density, thickness; int i; GtkTreeIter iter; char buffer[512]; #if DEBUG == 1 fprintf(stdout,"Entering dialog_buttons_clicked_cb\n"); #endif if (response_id == GTK_RESPONSE_REJECT) { gtk_widget_hide_all(GTK_WIDGET(dialog)); } else if (response_id == GTK_RESPONSE_ACCEPT) { //update if (cw->kind == CW_ADD) { #if DEBUG == 1 fprintf(stdout,"Before mallocing cd2\n"); #endif //adding something cd2 = (struct compoundData *) malloc(sizeof(struct compoundData)); if (CompoundParser(gtk_entry_get_text(GTK_ENTRY(cw->compoundEntry)),cd2 ) != 1) { fprintf(stdout,"compoundParser error in dialog_buttons_clicked_cb\n"); exit(1); } #if DEBUG == 1 fprintf(stdout,"After calling CompoundParser: compound is %s\n",gtk_entry_get_text(GTK_ENTRY(cw->compoundEntry))); #endif weight = strtod(gtk_entry_get_text(GTK_ENTRY(cw->weightEntry)),NULL); #if DEBUG == 1 fprintf(stdout,"After calling CompoundParser: weight is %lf\n",weight); #endif if (*(cw->lw->my_layer) != NULL && (*(cw->lw->my_layer))->n_elements > 0) { //copy xmi_layer to compoundData and add current contents cd = xmi_layer2compoundData(*(cw->lw->my_layer) ); //calculate sum cdsum = add_compound_data(*cd, 1.0, *cd2, weight/100.0); density =(*(cw->lw->my_layer))->density; thickness=(*(cw->lw->my_layer))->thickness; xmi_free_layer(*(cw->lw->my_layer)); free( *(cw->lw->my_layer)); *(cw->lw->my_layer) = compoundData2xmi_layer (cdsum); (*(cw->lw->my_layer))->thickness = thickness; (*(cw->lw->my_layer))->density = density; } else if (*(cw->lw->my_layer) == NULL) { *(cw->lw->my_layer) = compoundData2xmi_layer (cd2); (*(cw->lw->my_layer))->thickness = 0.0; (*(cw->lw->my_layer))->density = 0.0; xmi_scale_double((*(cw->lw->my_layer))->weight,(*(cw->lw->my_layer))->n_elements, weight/100.0); } else if ((*(cw->lw->my_layer))->n_elements == 0) { free( *(cw->lw->my_layer)); *(cw->lw->my_layer) = compoundData2xmi_layer (cd2); xmi_scale_double((*(cw->lw->my_layer))->weight,(*(cw->lw->my_layer))->n_elements, weight/100.0); } else { fprintf(stdout,"error in dialog_buttons_clicked_cb\n"); exit(1); } } else if (cw->kind == CW_EDIT) { weight = strtod(gtk_entry_get_text(GTK_ENTRY(cw->weightEntry)),NULL); (*(cw->lw->my_layer))->weight[cw->index] = weight/100.0; } //update store gtk_list_store_clear(cw->lw->store); for (i = 0 ; i < (*(cw->lw->my_layer))->n_elements ; i++) { gtk_list_store_append(cw->lw->store, &iter); gtk_list_store_set(cw->lw->store, &iter, SYMBOL_COLUMN, AtomicNumberToSymbol((*(cw->lw->my_layer))->Z[i]), WEIGHT_COLUMN, (*(cw->lw->my_layer))->weight[i]*100.0, -1 ); } sprintf(buffer,"%g", xmi_sum_double((*(cw->lw->my_layer))->weight,(*(cw->lw->my_layer))->n_elements )*100.0); gtk_entry_set_text(GTK_ENTRY(cw->lw->sumEntry), buffer); gtk_widget_hide_all(GTK_WIDGET(dialog)); } }
int main() { struct compoundData *cdtest, *cdtest1, *cdtest2, *cdtest3; int i; char *symbol; Crystal_Struct* cryst; Crystal_Atom* atom; double energy = 8; double debye_temp_factor = 1.0; double rel_angle = 1.0; double bragg, q, dw; double f0, fp, fpp; xrlComplex FH, F0; xrlComplex FHbar; struct compoundDataNIST *cdn; char **nistCompounds; struct radioNuclideData *rnd; char **radioNuclides; XRayInit(); /*if something goes wrong, the test will end with EXIT_FAILURE //SetHardExit(1);*/ SetErrorMessages(0); printf("Example of C program using xraylib\n"); printf("Density of pure Al: %f g/cm3\n", ElementDensity(13)); printf("Ca K-alpha Fluorescence Line Energy: %f\n", LineEnergy(20,KA_LINE)); printf("Fe partial photoionization cs of L3 at 6.0 keV: %f\n",CS_Photo_Partial(26,L3_SHELL,6.0)); printf("Zr L1 edge energy: %f\n",EdgeEnergy(40,L1_SHELL)); printf("Pb Lalpha XRF production cs at 20.0 keV (jump approx): %f\n",CS_FluorLine(82,LA_LINE,20.0)); printf("Pb Lalpha XRF production cs at 20.0 keV (Kissel): %f\n",CS_FluorLine_Kissel(82,LA_LINE,20.0)); printf("Bi M1N2 radiative rate: %f\n",RadRate(83,M1N2_LINE)); 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; printf("Ca(HCO3)2 contains %g atoms and %i elements\n",cdtest->nAtomsAll,cdtest->nElements); for (i = 0 ; i < cdtest->nElements ; i++) printf("Element %i: %f %%\n",cdtest->Elements[i],cdtest->massFractions[i]*100.0); FreeCompoundData(cdtest); /*parser test for SiO2 (quartz)*/ if ((cdtest = CompoundParser("SiO2")) == NULL) return 1; printf("SiO2 contains %g atoms and %i elements\n",cdtest->nAtomsAll,cdtest->nElements); for (i = 0 ; i < cdtest->nElements ; i++) printf("Element %i: %f %%\n",cdtest->Elements[i],cdtest->massFractions[i]*100.0); FreeCompoundData(cdtest); printf("Ca(HCO3)2 Rayleigh cs at 10.0 keV: %f\n",CS_Rayl_CP("Ca(HCO3)2",10.0f) ); 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)); 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)); 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)); printf("Compton profile for Fe at pz = 1.1 : %f\n",ComptonProfile(26,1.1f)); printf("M5 Compton profile for Fe at pz = 1.1 : %f\n",ComptonProfile_Partial(26,M5_SHELL,1.1f)); printf("M1->M5 Coster-Kronig transition probability for Au : %f\n",CosKronTransProb(79,FM15_TRANS)); printf("L1->L3 Coster-Kronig transition probability for Fe : %f\n",CosKronTransProb(26,FL13_TRANS)); printf("Au Ma1 XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MA1_LINE,10.0f)); printf("Au Mb XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MB_LINE,10.0f)); printf("Au Mg XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MG_LINE,10.0f)); printf("K atomic level width for Fe: %f\n", AtomicLevelWidth(26,K_SHELL)); printf("Bi L2-M5M5 Auger non-radiative rate: %f\n",AugerRate(86,L2_M5M5_AUGER)); printf("Bi L3 Auger yield: %f\n", AugerYield(86, L3_SHELL)); if ((cdtest1 = CompoundParser("SiO2")) == NULL) return 1; if ((cdtest2 = CompoundParser("Ca(HCO3)2")) == NULL) return 1; cdtest3 = add_compound_data(*cdtest1, 0.4, *cdtest2, 0.6); for (i = 0 ; i < cdtest3->nElements ; i++) printf("Element %i: %f %%\n",cdtest3->Elements[i],cdtest3->massFractions[i]*100.0); FreeCompoundData(cdtest1); FreeCompoundData(cdtest2); FreeCompoundData(cdtest3); symbol = AtomicNumberToSymbol(26); printf("Symbol of element 26 is: %s\n",symbol); xrlFree(symbol); printf("Number of element Fe is: %i\n",SymbolToAtomicNumber("Fe")); printf("Pb Malpha XRF production cs at 20.0 keV with cascade effect: %f\n",CS_FluorLine_Kissel(82,MA1_LINE,20.0)); 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)); 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)); 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)); printf("Al mass energy-absorption cs at 20.0 keV: %f\n", CS_Energy(13, 20.0)); printf("Pb mass energy-absorption cs at 40.0 keV: %f\n", CS_Energy(82, 40.0)); printf("CdTe mass energy-absorption cs at 40.0 keV: %f\n", CS_Energy_CP("CdTe", 40.0)); /* Si Crystal structure */ cryst = Crystal_GetCrystal("Si", NULL); if (cryst == NULL) return 1; printf ("Si unit cell dimensions are %f %f %f\n", cryst->a, cryst->b, cryst->c); printf ("Si unit cell angles are %f %f %f\n", cryst->alpha, cryst->beta, cryst->gamma); printf ("Si unit cell volume is %f\n", cryst->volume); printf ("Si atoms at:\n"); printf (" Z fraction X Y Z\n"); for (i = 0; i < cryst->n_atom; i++) { atom = &cryst->atom[i]; printf (" %3i %f %f %f %f\n", atom->Zatom, atom->fraction, atom->x, atom->y, atom->z); } /* Si diffraction parameters */ printf ("\nSi111 at 8 KeV. Incidence at the Bragg angle:\n"); bragg = Bragg_angle (cryst, energy, 1, 1, 1); printf (" Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI); q = Q_scattering_amplitude (cryst, energy, 1, 1, 1, rel_angle); printf (" Q Scattering amplitude: %f\n", q); Atomic_Factors (14, energy, q, debye_temp_factor, &f0, &fp, &fpp); printf (" Atomic factors (Z = 14) 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); 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); printf (" F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im); /* Diamond diffraction parameters */ cryst = Crystal_GetCrystal("Diamond", NULL); printf ("\nDiamond 111 at 8 KeV. Incidence at the Bragg angle:\n"); bragg = Bragg_angle (cryst, energy, 1, 1, 1); printf (" Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI); q = Q_scattering_amplitude (cryst, energy, 1, 1, 1, rel_angle); printf (" Q Scattering amplitude: %f\n", q); Atomic_Factors (6, energy, q, debye_temp_factor, &f0, &fp, &fpp); 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); 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); printf (" F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im); FHbar = Crystal_F_H_StructureFactor (cryst, energy, -1, -1, -1, debye_temp_factor, rel_angle); dw = 1e10 * 2 * (R_E / cryst->volume) * (KEV2ANGST * KEV2ANGST/ (energy * energy)) * sqrt(c_abs(c_mul(FH, FHbar))) / PI / sin(2*bragg); printf (" Darwin width: %f micro-radians\n", 1e6*dw); /* Alpha Quartz diffraction parameters */ cryst = Crystal_GetCrystal("AlphaQuartz", NULL); printf ("\nAlpha Quartz 020 at 8 KeV. Incidence at the Bragg angle:\n"); bragg = Bragg_angle (cryst, energy, 0, 2, 0); printf (" Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI); q = Q_scattering_amplitude (cryst, energy, 0, 2, 0, rel_angle); printf (" Q Scattering amplitude: %f\n", q); Atomic_Factors (8, energy, q, debye_temp_factor, &f0, &fp, &fpp); 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); 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); printf (" F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im); /* Muscovite diffraction parameters */ cryst = Crystal_GetCrystal("Muscovite", NULL); printf ("\nMuscovite 331 at 8 KeV. Incidence at the Bragg angle:\n"); bragg = Bragg_angle (cryst, energy, 3, 3, 1); printf (" Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI); q = Q_scattering_amplitude (cryst, energy, 3, 3, 1, rel_angle); printf (" Q Scattering amplitude: %f\n", q); Atomic_Factors (19, energy, q, debye_temp_factor, &f0, &fp, &fpp); 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); 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); printf (" F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im); printf ("\n"); /* compoundDataNIST tests */ cdn = GetCompoundDataNISTByName("Uranium Monocarbide"); printf ("Uranium Monocarbide\n"); printf (" Name: %s\n", cdn->name); printf (" Density: %f g/cm3\n", cdn->density); for (i = 0 ; i < cdn->nElements ; i++) { printf(" Element %i: %f %%\n",cdn->Elements[i],cdn->massFractions[i]*100.0); } FreeCompoundDataNIST(cdn); cdn = NULL; cdn = GetCompoundDataNISTByIndex(NIST_COMPOUND_BRAIN_ICRP); printf ("NIST_COMPOUND_BRAIN_ICRP\n"); printf (" Name: %s\n", cdn->name); printf (" Density: %f g/cm3\n", cdn->density); for (i = 0 ; i < cdn->nElements ; i++) { printf(" Element %i: %f %%\n",cdn->Elements[i],cdn->massFractions[i]*100.0); } FreeCompoundDataNIST(cdn); cdn = NULL; nistCompounds = GetCompoundDataNISTList(NULL); printf ("List of available NIST compounds:\n"); for (i = 0 ; nistCompounds[i] != NULL ; i++) { printf (" Compound %i: %s\n", i, nistCompounds[i]); xrlFree(nistCompounds[i]); } xrlFree(nistCompounds); printf ("\n"); /* radioNuclideData tests */ rnd = GetRadioNuclideDataByName("109Cd"); printf ("109Cd\n"); printf (" Name: %s\n", rnd->name); printf (" Z: %i\n", rnd->Z); printf (" A: %i\n", rnd->A); printf (" N: %i\n", rnd->N); printf (" Z_xray: %i\n", rnd->Z_xray); printf (" X-rays:\n"); for (i = 0 ; i < rnd->nXrays ; i++) printf (" %f keV -> %f %%\n", LineEnergy(rnd->Z_xray, rnd->XrayLines[i]), rnd->XrayIntensities[i]*100.0); printf (" Gamma rays:\n"); for (i = 0 ; i < rnd->nGammas ; i++) printf (" %f keV -> %f %%\n", rnd->GammaEnergies[i], rnd->GammaIntensities[i]*100.0); FreeRadioNuclideData(rnd); rnd = GetRadioNuclideDataByIndex(RADIO_NUCLIDE_125I); printf ("RADIO_NUCLIDE_125I\n"); printf (" Name: %s\n", rnd->name); printf (" Z: %i\n", rnd->Z); printf (" A: %i\n", rnd->A); printf (" N: %i\n", rnd->N); printf (" Z_xray: %i\n", rnd->Z_xray); printf (" X-rays:\n"); for (i = 0 ; i < rnd->nXrays ; i++) printf (" %f keV -> %f %%\n", LineEnergy(rnd->Z_xray, rnd->XrayLines[i]), rnd->XrayIntensities[i]*100.0); printf (" Gamma rays:\n"); for (i = 0 ; i < rnd->nGammas ; i++) printf (" %f keV -> %f %%\n", rnd->GammaEnergies[i], rnd->GammaIntensities[i]*100.0); FreeRadioNuclideData(rnd); radioNuclides = GetRadioNuclideDataList(NULL); printf ("List of available radionuclides:\n"); for (i = 0 ; radioNuclides[i] != NULL ; i++) { printf (" Radionuclide %i: %s\n", i, radioNuclides[i]); xrlFree(radioNuclides[i]); } xrlFree(radioNuclides); printf ("\n--------------------------- END OF XRLEXAMPLE1 -------------------------------\n"); return 0; }
int main() { struct compoundData cdtest, cdtest1, cdtest2, *cdtest3; int i; char *symbol; XRayInit(); /*if something goes wrong, the test will end with EXIT_FAILURE //SetHardExit(1);*/ printf("Example of C program using xraylib\n"); printf("Ca K-alpha Fluorescence Line Energy: %f\n", LineEnergy(20,KA_LINE)); printf("Fe partial photoionization cs of L3 at 6.0 keV: %f\n",CS_Photo_Partial(26,L3_SHELL,6.0)); printf("Zr L1 edge energy: %f\n",EdgeEnergy(40,L1_SHELL)); printf("Pb Lalpha XRF production cs at 20.0 keV (jump approx): %f\n",CS_FluorLine(82,LA_LINE,20.0)); printf("Pb Lalpha XRF production cs at 20.0 keV (Kissel): %f\n",CS_FluorLine_Kissel(82,LA_LINE,20.0)); printf("Bi M1N2 radiative rate: %f\n",RadRate(83,M1N2_LINE)); 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; printf("Ca(HCO3)2 contains %i atoms and %i elements\n",cdtest.nAtomsAll,cdtest.nElements); for (i = 0 ; i < cdtest.nElements ; i++) 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; printf("SiO2 contains %i atoms and %i elements\n",cdtest.nAtomsAll,cdtest.nElements); for (i = 0 ; i < cdtest.nElements ; i++) printf("Element %i: %lf %%\n",cdtest.Elements[i],cdtest.massFractions[i]*100.0); FREE_COMPOUND_DATA(cdtest) printf("Ca(HCO3)2 Rayleigh cs at 10.0 keV: %f\n",CS_Rayl_CP("Ca(HCO3)2",10.0f) ); 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)); 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)); 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)); printf("Compton profile for Fe at pz = 1.1 : %f\n",ComptonProfile(26,1.1f)); printf("M5 Compton profile for Fe at pz = 1.1 : %f\n",ComptonProfile_Partial(26,M5_SHELL,1.1f)); printf("M1->M5 Coster-Kronig transition probability for Au : %f\n",CosKronTransProb(79,FM15_TRANS)); printf("L1->L3 Coster-Kronig transition probability for Fe : %f\n",CosKronTransProb(26,FL13_TRANS)); printf("Au Ma1 XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MA1_LINE,10.0f)); printf("Au Mb XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MB_LINE,10.0f)); printf("Au Mg XRF production cs at 10.0 keV (Kissel): %f\n", CS_FluorLine_Kissel(79,MG_LINE,10.0f)); printf("K atomic level width for Fe: %f\n", AtomicLevelWidth(26,K_SHELL)); printf("Bi L2-M5M5 Auger non-radiative rate: %f\n",AugerRate(86,L2_M5M5_AUGER)); if (CompoundParser("SiO2",&cdtest1) == 0) return 1; if (CompoundParser("Ca(HCO3)2",&cdtest2) == 0) return 1; cdtest3 = add_compound_data(cdtest1, 0.4, cdtest2, 0.6); for (i = 0 ; i < cdtest3->nElements ; i++) printf("Element %i: %lf %%\n",cdtest3->Elements[i],cdtest3->massFractions[i]*100.0); FREE_COMPOUND_DATA(*cdtest3) xrlFree(cdtest3); symbol = AtomicNumberToSymbol(26); printf("Symbol of element 26 is: %s\n",symbol); xrlFree(symbol); printf("Number of element Fe is: %i\n",SymbolToAtomicNumber("Fe")); printf("Pb Malpha XRF production cs at 20.0 keV with cascade effect: %f\n",CS_FluorLine_Kissel(82,MA1_LINE,20.0)); 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)); 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)); 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; printf ("Si unit cell dimensions are %f %f %f\n", cryst->a, cryst->b, cryst->c); printf ("Si unit cell angles are %f %f %f\n", cryst->alpha, cryst->beta, cryst->gamma); printf ("Si unit cell volume is %f\n", cryst->volume); printf ("Si atoms at:\n"); printf (" Z fraction X Y Z\n"); Crystal_Atom* atom; for (i = 0; i < cryst->n_atom; i++) { atom = &cryst->atom[i]; printf (" %3i %f %f %f %f\n", atom->Zatom, atom->fraction, atom->x, atom->y, atom->z); } /* Si diffraction parameters */ 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); printf (" Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI); float q = Q_scattering_amplitude (cryst, energy, 1, 1, 1, rel_angle); printf (" Q Scattering amplitude: %f\n", q); float f0, fp, fpp; Atomic_Factors (14, energy, q, debye_temp_factor, &f0, &fp, &fpp); 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); 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); printf (" F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im); /* Diamond diffraction parameters */ cryst = Crystal_GetCrystal("Diamond", NULL); printf ("\nDiamond 111 at 8 KeV. Incidence at the Bragg angle:\n"); bragg = Bragg_angle (cryst, energy, 1, 1, 1); printf (" Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI); q = Q_scattering_amplitude (cryst, energy, 1, 1, 1, rel_angle); printf (" Q Scattering amplitude: %f\n", q); Atomic_Factors (6, energy, q, debye_temp_factor, &f0, &fp, &fpp); 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); 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); 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); printf (" Darwin width: %f micro-radians\n", 1e6*dw); /* Alpha Quartz diffraction parameters */ cryst = Crystal_GetCrystal("AlphaQuartz", NULL); printf ("\nAlpha Quartz 020 at 8 KeV. Incidence at the Bragg angle:\n"); bragg = Bragg_angle (cryst, energy, 0, 2, 0); printf (" Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI); q = Q_scattering_amplitude (cryst, energy, 0, 2, 0, rel_angle); printf (" Q Scattering amplitude: %f\n", q); Atomic_Factors (8, energy, q, debye_temp_factor, &f0, &fp, &fpp); 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); 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); printf (" F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im); /* Muscovite diffraction parameters */ cryst = Crystal_GetCrystal("Muscovite", NULL); printf ("\nMuscovite 331 at 8 KeV. Incidence at the Bragg angle:\n"); bragg = Bragg_angle (cryst, energy, 3, 3, 1); printf (" Bragg angle: Rad: %f Deg: %f\n", bragg, bragg*180/PI); q = Q_scattering_amplitude (cryst, energy, 3, 3, 1, rel_angle); printf (" Q Scattering amplitude: %f\n", q); Atomic_Factors (19, energy, q, debye_temp_factor, &f0, &fp, &fpp); 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); 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); printf (" F0=FH(0,0,0) structure factor: (%f, %f)\n", F0.re, F0.im); printf ("\n--------------------------- END OF XRLEXAMPLE1 -------------------------------\n"); return 0; }