### Configure Meson Build Options Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Displays the available configuration options for the Meson build system for xraylib. ```bash meson configure ``` -------------------------------- ### Install xraylib using pip Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Installs the xraylib Python package using pip, the standard Python package installer. This command fetches and installs the latest available wheels. ```bash pip install xraylib ``` -------------------------------- ### Get xraylib info on macOS using Homebrew Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Retrieves detailed information about the xraylib package installed via Homebrew on macOS. This command shows supported bindings and other relevant details. ```bash brew info tschoonj/tap/xraylib ``` -------------------------------- ### Execute Ruby xraylib Example Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Command to execute the Ruby Monte Carlo simulation example. ```bash ruby mc.rb ``` -------------------------------- ### Compile xraylib with Meson Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Builds xraylib using the Meson build system. This method supports building the core C library and Fortran/Python bindings. Requires Meson (>= 0.60.0) and Python 3. ```bash meson setup builddir --buildtype=release --prefix= ninja -C builddir ninja -C builddir test ninja -C builddir install ``` -------------------------------- ### Compile Fortran xraylib Example Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Command to compile the Fortran fundamental parameter method example using gfortran, linking against the xraylib Fortran bindings. ```bash gfortran -o fpm `pkg-config --cflags libxrlf03` fpm.f90 `pkg-config --libs libxrlf03` ``` -------------------------------- ### Download and Unpack xraylib Source Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Commands to download and extract the xraylib source code tarball. It's recommended to use official releases rather than GitHub-generated source archives. ```bash unxz xraylib-version.tar.xz tar xvf xraylib-version.tar cd xraylib-version ``` -------------------------------- ### Configure xraylib with GNU Autotools Options Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Shows help for configuring the xraylib build with GNU Autotools, including options for enabling/disabling specific language bindings and integration. ```bash ./configure --help ``` -------------------------------- ### Install xraylib on macOS using Homebrew Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Installs the xraylib library on macOS using the Homebrew package manager. This command adds the xraylib tap and installs the package. ```bash brew install tschoonj/tap/xraylib ``` -------------------------------- ### Compile xraylib with GNU Autotools Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Builds xraylib using the traditional GNU Autotools build system. This method supports a wider range of language bindings compared to Meson. Requires Autoconf, Automake, and Libtool. ```bash autoreconf -fi ./configure make make check make install ``` -------------------------------- ### Xraylib Example in C Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Demonstrates the basic usage of the Xraylib library in C. This example typically involves initializing the library, setting up material compositions, and performing calculations like atomic scattering factors or mass attenuation coefficients. ```C #include #include int main() { // Example: Calculate mass attenuation coefficient for a material // Replace with actual Xraylib function calls printf("Xraylib C Example\n"); return 0; } ``` -------------------------------- ### Xraylib Example in C# Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Shows how to use the Xraylib library in C# applications. This example would typically involve calling the C# bindings for Xraylib. ```C# using System; using xraylib; public class XraylibCSharpExample { public static void Main(string[] args) { // Example: Get critical angle for total reflection // Replace with actual Xraylib function calls Console.WriteLine("Xraylib C# Example"); } } ``` -------------------------------- ### C++ xraylib Bindings Example with Exception Handling Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Illustrates the usage of xraylib's C++ bindings, including how to include the header and handle potential errors using C++ exceptions. The example calls `AtomicLevelWidth` and uses a try-catch block to manage expected exceptions. ```C++ #include "xraylib++.h" #include #include int main(int argc, char **argv) { double width; width = xrlpp::AtomicLevelWidth(26, K_SHELL); assert(fabs(width - 1.19E-3) < 1E-6); width = xrlpp::AtomicLevelWidth(92, N7_SHELL); assert(fabs(width - 0.31E-3) < 1E-8); try { width = xrlpp::AtomicLevelWidth(185, K_SHELL); abort(); } catch (std::invalid_argument &e) { // do nothing, exception is expected } return 0; } ``` -------------------------------- ### Xraylib Example in Pascal Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Shows how to use the Xraylib library from a Pascal program. This example would typically involve calling C-compatible Xraylib functions through Pascal's foreign function interface. ```Pascal program XraylibPascalExample; {$mode objfpc} uses xraylib; begin // Example: Get atomic weight of an element // Replace with actual Xraylib function calls Writeln('Xraylib Pascal Example'); end. ``` -------------------------------- ### Xraylib Example in Lua Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Demonstrates the usage of the Xraylib library with Lua scripting. This example would show how to call Xraylib functions from a Lua environment. ```Lua -- Example: Get mass density of a compound -- Replace with actual Xraylib function calls print("Xraylib Lua Example") ``` -------------------------------- ### Xraylib Example in Ruby Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Illustrates how to integrate Xraylib functionality into Ruby programs. This example would focus on calling Xraylib methods from Ruby scripts. ```Ruby # Example: Calculate photoelectric absorption cross section # Replace with actual Xraylib function calls puts "Xraylib Ruby Example" ``` -------------------------------- ### Xraylib Example in C++ Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Illustrates the integration of Xraylib into C++ applications. This example would showcase calling Xraylib functions using C++ syntax and data structures. ```C++ #include #include int main() { // Example: Calculate fluorescence yield // Replace with actual Xraylib function calls std::cout << "Xraylib C++ Example" << std::endl; return 0; } ``` -------------------------------- ### Install xraylib using Anaconda Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Installs the xraylib package from the conda-forge channel using the Anaconda package manager. This is the recommended method for scientific Python distributions. ```bash conda install -c conda-forge xraylib ``` -------------------------------- ### Enable Specific Language Integrations with Autotools Source: https://github.com/tschoonj/xraylib/wiki/Installation-instructions Advanced options for the GNU Autotools configure script to force integration of language bindings into default interpreter locations. ```bash ./configure --enable-perl-integration ./configure --enable-python-integration ./configure --enable-ruby-integration ./configure --enable-php-integration ``` -------------------------------- ### Xraylib Example in PHP Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Provides an example of using the Xraylib library within PHP web applications or scripts. This would involve calling PHP extensions or wrappers for Xraylib. ```PHP ``` -------------------------------- ### Xraylib Example in Java Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Provides an example of using the Xraylib library within a Java program. This would involve calling the Java wrapper for Xraylib functions. ```Java public class XraylibJavaExample { public static void main(String[] args) { // Example: Get element symbol // Replace with actual Xraylib function calls System.out.println("Xraylib Java Example"); } } ``` -------------------------------- ### Xraylib Example in Fortran 2003 Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Provides an example of integrating Xraylib functionality into a Fortran 2003 program. This would involve calling Fortran-compatible Xraylib routines for scientific computations. ```Fortran program xraylib_fortran_example implicit none ! Example: Calculate Compton scattering cross section ! Replace with actual Xraylib function calls print *, "Xraylib Fortran Example" end program xraylib_fortran_example ``` -------------------------------- ### PHP: Configuration in php.ini Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Provides examples of how to configure the php.ini file to enable the xraylib extension and set the include path. ```INI extension=/xraylib.so include_path= ``` -------------------------------- ### Xraylib Example in IDL Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Shows how to utilize the Xraylib library from within the Interactive Data Language (IDL). This example would focus on calling Xraylib functions for data analysis and visualization. ```IDL ; Example: Get element properties ; Replace with actual Xraylib function calls print, "Xraylib IDL Example" ``` -------------------------------- ### Xraylib Example in Python Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Demonstrates the use of the Xraylib library in Python. This example typically involves importing the library and calling functions for various material science calculations. ```Python import xraylib # Example: Get atomic number of an element # Replace with actual Xraylib function calls print("Xraylib Python Example") ``` -------------------------------- ### Xraylib Example in Perl Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Illustrates how to use the Xraylib library within a Perl script. This example would typically show how to import the necessary modules and call Xraylib functions for material analysis. ```Perl use strict; use warnings; use xraylib; # Example: Calculate density of a material # Replace with actual Xraylib function calls print "Xraylib Perl Example\n"; ``` -------------------------------- ### Xraylib Example with Python-Numpy Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Demonstrates using Xraylib in conjunction with the NumPy library in Python for efficient numerical operations. This example would leverage NumPy arrays for handling large datasets or performing vectorized calculations. ```Python import xraylib import numpy as np # Example: Calculate mass attenuation coefficients for a range of energies using NumPy # Replace with actual Xraylib and NumPy function calls energies = np.logspace(1, 5, 100) # Example energies in eV print("Xraylib Python-NumPy Example") ``` -------------------------------- ### Disable Windows Installer Source: https://github.com/tschoonj/xraylib/blob/master/meson_options.txt Disables the building of a Windows installer. Set 'value' to 'disabled' to prevent its creation. ```meson option('windows-installer', type: 'feature', value: 'disabled', description: 'Build Windows installer') ``` -------------------------------- ### Simulate Photon Transmission with Monte Carlo (Ruby) Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Demonstrates using the Monte Carlo method in Ruby to determine the fraction of photons that penetrate a sample of a given thickness. It utilizes xraylib for calculating the total mass attenuation coefficient. ```Ruby require 'xraylib' compound = "Uranium Monocarbide" cdn = Xraylib.GetCompoundDataNISTByName(compound) density = cdn['density'] #g/cm3 thickness = 0.01 #cm energy = 50.0 #keV mu_rho = Xraylib.CS_Total_CP(compound, energy)*density transmitted = 0 total = 100000 total.times {|i| x = -Math.log(rand())/mu_rho transmitted += 1 if x > thickness } printf("transmitted: %i\n", transmitted) printf("MC fraction: %f\n", Float(transmitted)/total) printf("True fraction: %f\n", Math.exp(-mu_rho*thickness)) ``` -------------------------------- ### Calculate XRF Intensity with Fundamental Parameter Method (Fortran) Source: https://github.com/tschoonj/xraylib/wiki/Code-examples Demonstrates calculating the expected first-order net-line intensity of an XRF line for a given sample and X-ray beam using Fortran 2003. It utilizes xraylib functions for compound parsing, total cross-sections, and line energies. Compilation requires the Fortran bindings for xraylib. ```Fortran PROGRAM fpm USE :: xraylib USE, INTRINSIC :: ISO_C_BINDING USE, INTRINSIC :: ISO_FORTRAN_ENV IMPLICIT NONE REAL (C_DOUBLE) :: flux = 1E9 !photons/s REAL (C_DOUBLE) :: G = 1E-5 REAL (C_DOUBLE) :: density = 3.19 !g/cm3 REAL (C_DOUBLE) :: thickness = 0.1 !cm REAL (C_DOUBLE) :: xrf_intensity, chi REAL (C_DOUBLE) :: mu_0, mu_1, w_Ca, A_corr, Q REAL (C_DOUBLE) :: alpha = 45.0, beta = 45.0 !degrees REAL (C_DOUBLE) :: beam_energy = 20.0 !keV TYPE (xrl_error), POINTER :: error => NULL () TYPE (compoundData), POINTER :: cd CHARACTER (len=50) :: apatite = 'Ca5(PO4)3(OH)0.33F0.33Cl0.33' REAL (C_DOUBLE), PARAMETER :: deg2rad = 3.14159265359/180.0 cd => CompoundParser(apatite, error) IF (ASSOCIATED(error)) THEN ! If the compound is invalid, an error message will be printed WRITE (error_unit, '(A,A)') 'Error message: ', TRIM(error%message) STOP ENDIF w_Ca = cd%massFractions(6) ! fortran array indexing starts at 1!!!! mu_0 = CS_Total_CP(apatite, beam_energy) mu_1 = CS_Total_CP(apatite, LineEnergy(20, KL3_LINE)) chi = mu_0/SIN(deg2rad*alpha) + mu_1/SIN(deg2rad*beta) A_corr = (1.0-EXP(-chi*density*thickness))/(chi*density*thickness) Q = CS_FluorLine_Kissel(20, KL3_LINE, beam_energy) xrf_intensity = flux*G*Q*w_Ca*density*thickness*A_corr DEALLOCATE(cd) WRITE (*, '(A, ES12.4)') 'xrf_intensity: ', xrf_intensity END PROGRAM fpm ``` -------------------------------- ### Initialize NETLink for xraylib (Mathematica) Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API This Mathematica code initializes the NETLink package, which is necessary for interacting with Windows DLLs like xraylib. It includes steps to uninstall and reinstall NETLink, potentially forcing a 32-bit environment. ```Mathematica Needs["NETLink`"]; UninstallNET[]; InstallNET["Force32Bit"->True]; dllLocation="C:\\SomeFolder\\PathToDLL\\libxrl-7.dll"; ``` -------------------------------- ### .NET (C#): Add Reference and Instantiate Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Explains how to add the XrayLib.NET.dll reference in Visual Studio and instantiate the XrayLib class using a singleton pattern. ```C# using Science; XrayLib xl = XrayLib.Instance; ``` -------------------------------- ### Compile Fortran Bindings with pkg-config Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Demonstrates how to compile Fortran programs linked with the xraylib Fortran bindings using pkg-config to manage compiler and linker flags. This ensures the necessary library components are correctly included. ```bash gfortran `pkg-config --cflags libxrlf03` program.f90 `pkg-config --libs libxrlf03` ``` -------------------------------- ### Call xraylib Functions in Mathematica Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API These Mathematica commands demonstrate how to call the previously defined xraylib functions with sample arguments. ```Mathematica CSPhoto[33, 15.00]; CSFluorLineKissel[33, 0, 15.00]; FluorYield[33, 0]; ``` -------------------------------- ### IDL: Load Constants Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Demonstrates how to load xraylib constants into IDL scripts by adding a specific line to the script or startup file. ```IDL @xraylib ``` -------------------------------- ### Compiling C++ Bindings with pkg-config Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Provides the command-line instruction to compile C++ programs that use xraylib bindings. It utilizes `pkg-config` to automatically fetch the necessary compiler and linker flags for the libxrl library. ```bash g++ `pkg-config --cflags libxrl` program.cpp `pkg-config --libs libxrl` ``` -------------------------------- ### Link xraylib framework in macOS Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Demonstrates how to link the xraylib framework in macOS applications from the command line using clang. ```Bash clang -framework xraylib -o test test.c ``` ```Objective-C #import ``` -------------------------------- ### Get Electron Configuration Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Returns the number of electrons in a specified shell for a given element. ```c double ElectronConfig(int Z, int shell, xrl_error **error); ``` -------------------------------- ### Get Atomic Level Width Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Retrieves the atomic level width for a specific element and electron shell. The width is returned in keV. ```c double AtomicLevelWidth(int Z, int shell, xrl_error **error); ``` -------------------------------- ### Java: Import and Basic Usage Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Demonstrates how to import the xraylib Java library and handle potential runtime exceptions when calling functions with invalid arguments. ```Java import com.github.tschoonj.xraylib.Xraylib; try { double weight = Xraylib.AtomicWeight(185); } catch (IllegalArgumentException e) { // an error occurred! System.out.println(e.getMessage()); } ``` -------------------------------- ### Get Auger Yield Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Returns the Auger yield for a given element Z and shell. The shell is specified using xraylib macros. ```c double AugerYield(int Z, int shell, xrl_error **error); ``` -------------------------------- ### Link xraylib DLL in Visual Studio Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Steps to configure Visual Studio projects to link against the xraylib DLL. This includes setting additional library directories and specifying the library in additional dependencies. ```C libxrl-11.lib ``` -------------------------------- ### Compile C code with pkg-config Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API This snippet demonstrates how to compile C code using pkg-config to link against the xraylib library. It ensures that the preprocessor can find the necessary headers and the linker can find the library. ```Bash gcc `pkg-config --cflags libxrl` program.c `pkg-config --libs libxrl` ``` ```C #include ``` -------------------------------- ### Get Fluorescence Yield Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Returns the fluorescence yield for a given element Z and shell. The shell is specified using xraylib macros. ```c double FluorYield(int Z, int shell, xrl_error **error); ``` -------------------------------- ### Include xraylib headers in C/C++ for Visual Studio Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Instructions for including xraylib headers in C/C++ projects within Visual Studio on Windows. This involves configuring the project's additional include directories. ```C #include ``` -------------------------------- ### Get Jump Factors Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Returns the jump factor for a given element and shell. Requires the element's atomic number (Z) and a shell-type macro. ```C double JumpFactor(int Z, int shell, xrl_error **error); ``` -------------------------------- ### Get X-ray Fluorescence Line Energy Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Retrieves the energy of a specified X-ray fluorescence line for a given element Z. The energy is returned in keV. ```c double LineEnergy(int Z, int line, xrl_error **error); ``` -------------------------------- ### Enable Fortran Bindings Source: https://github.com/tschoonj/xraylib/blob/master/meson_options.txt Configures the build to include Fortran 2003 bindings. The 'value' can be set to 'auto' or 'enabled' to build the bindings. ```meson option('fortran-bindings', type: 'feature', value: 'auto', description: 'Build Fortran 2003 bindings') ``` -------------------------------- ### Get Radiative Rates Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Returns the radiative rate for a given element and fluorescence line. Requires the element's atomic number (Z) and a line-type macro. ```C double RadRate(int Z, int line, xrl_error **error); ``` -------------------------------- ### Get Compound Data by Name (NIST) Source: https://github.com/tschoonj/xraylib/wiki/Appendix-xraylib-macros Retrieves composition data for a NIST-defined compound using its name. This function is part of the Xraylib library and accepts string names for compounds. ```python from xraylib import xraylib # Example: Get data for Acetone compound_name = "Acetone" compound_data = xraylib.GetCompoundDataNISTByName(compound_name) print(compound_data) ``` -------------------------------- ### PHP: Include and Exception Handling Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Illustrates how to include the xraylib PHP module and manage errors using PHP's exception handling. ```PHP include("xraylib.php"); try { $weight = AtomicWeight(-5); } catch (Exception &e) { echo "The exception message is: " . $e->getMessage(); } ``` -------------------------------- ### Get List of Radionuclide Names Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Retrieves a list of available radionuclide names from the xraylib database. The function returns a NULL-terminated array of strings and can optionally provide the total count of radionuclides. ```c char **GetRadioNuclideDataList(int *nRadioNuclides, xrl_error **error); ``` -------------------------------- ### Get Element Density in C Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Retrieves the density of an element at room temperature given its atomic number Z. The function returns the density in g/cm^3. It includes an error handling parameter. ```c double ElementDensity(int Z, xrl_error **error); ``` -------------------------------- ### Get Atomic Weight in C Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Retrieves the atomic weight of an element given its atomic number Z. The function returns the atomic weight in g/mol. It includes an error handling parameter. ```c double AtomicWeight(int Z, xrl_error **error); ``` -------------------------------- ### Get Compound Data by Index (NIST) Source: https://github.com/tschoonj/xraylib/wiki/Appendix-xraylib-macros Retrieves composition data for a NIST-defined compound using its index. This function is part of the Xraylib library and requires the compound's macro identifier. ```python from xraylib import xraylib # Example: Get data for A-150 Tissue-Equivalent Plastic compound_index = xraylib.NIST_COMPOUND_A_150_TISSUE_EQUIVALENT_PLASTIC compound_data = xraylib.GetCompoundDataNISTByIndex(compound_index) print(compound_data) ``` -------------------------------- ### Get Absorption Edge Energies Source: https://github.com/tschoonj/xraylib/wiki/The-xraylib-API-list-of-all-functions Retrieves the absorption edge energy for a specified element and shell. The energy is returned in keV. Requires the element's atomic number (Z) and a shell-type macro. ```C double EdgeEnergy(int Z, int shell, xrl_error **error); ``` -------------------------------- ### Query xraylib Functions (Matlab) Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API This Matlab command lists all available functions within the loaded xraylib library, providing detailed information about each function. ```Matlab libfunctions('libxrl', '-full') ``` -------------------------------- ### Ruby: Require and Exception Handling Source: https://github.com/tschoonj/xraylib/wiki/Using-the-xraylib-API Shows how to include the xraylib Ruby module and handle errors using Ruby's exception mechanism. ```Ruby require 'xraylib' begin weight = Xraylib.AtomicWeight(-5) rescue Exception => e print "Exception caught: " + e end ``` -------------------------------- ### Get RadioNuclide Data by Index Source: https://github.com/tschoonj/xraylib/wiki/Appendix-xraylib-macros Retrieves X-ray and gamma intensity profiles for a given radionuclide using its index. This function is part of the xraylib library and relies on predefined macros for radionuclide identification. ```python from xraylib import GetRadioNuclideDataByIndex # Example usage: # data = GetRadioNuclideDataByIndex(RADIO_NUCLIDE_55FE) # print(data) ```