xraylib 4.3.0
repository·master·Indexed 41 days ago
https://github.com/tschoonj/xraylibA specialized library for modeling and calculating the interactions between X-rays and various forms of matter. It provides tools for X-ray physics and material science, featuring native C implementations and .NET bindings via XrayLib.NET.dll.
What's inside xraylib
- xraylib is a library designed for simulating and calculating the interactions of X-rays with matter. It provides tools for researchers and developers working with X-ray physics and material science.
Understanding XRayInit and data preloading
masterThe library uses a preloading procedure to handle data initialization:
- Modern usage: The routine
XRayInitinxrayfiles.cis used to read in the data generated by thesrc/pr_data.cprogram. - Legacy compatibility: For older programs that call
XRayInitdirectly (before the preloading procedure was implemented), the library includes a dummyXRayInitlocated insrc/xrayfiles_inline.cto prevent linking errors.
- Modern usage: The routine
How xraylib data is loaded and updated
masterThe data files located in the
data/directory are not parsed at runtime. Instead, they are processed during the build phase to create a C source file (src/xrayglob_inline.c) containing variable array definitions. This source file is then compiled directly into thexrayliblibrary.Important: If you modify any files in the
data/directory, you must rebuild the entirexrayliblibrary for the changes to take effect in your application.Use XrayLib.NET.dll in Visual Studio
masterTo integrate the XrayLib .NET bindings into a Visual Studio project, you must add the
XrayLib.NET.dllassembly as a reference. This assembly is a mixed-mode C++/CLI component that provides interop between managed .NET classes and the nativelibxrl-7.dllfunctions.Steps to add the reference:
- Right-click your project in the Solution Explorer.
- Select References....
- Click Add New Reference....
- Select the Browse tab.
- Navigate to the
xraylib Libfolder and selectXrayLib.NET.dll. - Click OK to complete the reference addition.
Install xraylib
masterxraylib can be installed using several methods depending on your operating system:
- Linux/Unix/macOS: Compile from source using GNU Autotools or meson. Detailed compilation instructions are located in the
INSTALLfile within the repository. - Windows: A pre-built installer is available which includes the 64-bit DLL and the necessary xraylib headers.
- Linux/Unix/macOS: Compile from source using GNU Autotools or meson. Detailed compilation instructions are located in the
Initialize XrayLib in C# using the Singleton pattern
masterThe .NET bindings use a singleton pattern to manage the
XrayLibclass. Instead of manual instantiation, you access the functionality through the staticInstanceproperty. This ensures only one instance of the class exists throughout your program's lifecycle.To use it in C#, include the
Sciencenamespace and access the instance as shown below.using Science; // Access the singleton instance XrayLib xl = XrayLib.Instance;