void compound_changed(GtkWidget * widget, gpointer data) { char *textPtr,*textPtr2,*endPtr,*lastPtr; struct compoundWidget *cw = (struct compoundWidget *) data; struct compoundData cd; double weight; int cp_rv; textPtr = (char *) gtk_entry_get_text(GTK_ENTRY(cw->compoundEntry)); textPtr2 = (char *) gtk_entry_get_text(GTK_ENTRY(cw->weightEntry)); weight = strtod(textPtr2, &endPtr); cp_rv = CompoundParser(textPtr, &cd); #if DEBUG == 1 fprintf(stdout,"weight: %lf\n",weight); #endif lastPtr = textPtr2 + strlen(textPtr2); #if DEBUG == 1 fprintf(stdout,"lastPtr: %p\n",lastPtr); fprintf(stdout,"endPtr: %p\n",endPtr); #endif if (widget == cw->compoundEntry) { if (cp_rv == 1) { gtk_widget_modify_base(widget,GTK_STATE_NORMAL,&white); FREE_COMPOUND_DATA(cd); } else { //bad value gtk_widget_modify_base(widget,GTK_STATE_NORMAL,&red); gtk_widget_set_sensitive(cw->okButton,FALSE); } if (cp_rv == 1 && lastPtr == endPtr && weight > 0.0) { gtk_widget_set_sensitive(cw->okButton,TRUE); } } else if (widget == cw->weightEntry) { if (lastPtr == endPtr && weight > 0.0) { gtk_widget_modify_base(widget,GTK_STATE_NORMAL,&white); } else { //bad value gtk_widget_modify_base(widget,GTK_STATE_NORMAL,&red); gtk_widget_set_sensitive(cw->okButton,FALSE); } if (cp_rv == 1 && lastPtr == endPtr && weight > 0.0) { gtk_widget_set_sensitive(cw->okButton,TRUE); FREE_COMPOUND_DATA(cd); } } }
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; }