Skip to content

Commit

Permalink
xraylib version 2.14.0
Browse files Browse the repository at this point in the history
Added .NET bindings, contributed by Matthew Wormington
Updated TODO
Updated nsis input file
  • Loading branch information
tschoonj committed Nov 1, 2010
1 parent aba3c22 commit 69d04a1
Show file tree
Hide file tree
Showing 23 changed files with 3,153 additions and 11 deletions.
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Write bindings for Matlab and Octave
Add database for structure effects
Improve support on Windows platforms
Resonant Raman effect
M-shell Coster-Kronig factors
...
12 changes: 9 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ DISABLE_BINDINGS=no
CROSS_COMPILING=
LDFLAGS_LIBXRL=

#cross_compiling variable is not reliable on modern bash shells... look at the compiler instead
#cross_compiling variable is not reliable on modern bash shells due to wine integration... look at the compiler instead
#check instead of $build and $host differ


Expand All @@ -87,7 +87,7 @@ if test "x$host" != "x$build" ; then
AC_CHECK_PROGS([WINE],[wine],["nowine"])
;;
*)
AC_MSG_ERROR([Detected platform that's not supported for cross-compilation])
AC_MSG_ERROR([A platform was detected that is not supported for cross-compilation])
;;
esac

Expand All @@ -98,7 +98,13 @@ if test "x$host" != "x$build" ; then
LDFLAGS+="-no-undefined"
LDFLAGS_LIBXRL=-Wl,--output-def,libxrl-$LIB_CURRENT_MINUS_AGE.def
else
LDFLAGS_LIBXRL=""
case "$host" in
*mingw*)
#build dll
LDFLAGS+="-no-undefined"
LDFLAGS_LIBXRL=-Wl,--output-def,libxrl-$LIB_CURRENT_MINUS_AGE.def
;;
esac
fi


Expand Down
2 changes: 1 addition & 1 deletion example/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ endif

TESTS = $(check_PROGRAMS) $(check_SCRIPTS)

EXTRA_DIST = xrlexample4.pro xrlexample2.pl xrlexample5.py xrlexample7.java
EXTRA_DIST = xrlexample4.pro xrlexample2.pl xrlexample5.py xrlexample7.java xrlexample8.cs


#test the idl bindings using this script
Expand Down
91 changes: 91 additions & 0 deletions example/xrlexample8.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Diagnostics;
using Science;

namespace Test
{
class Program
{
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();

XrayLib xl = XrayLib.Instance;
// If something goes wrong, the test will end with EXIT_FAILURE
xl.SetHardExit(1);

Console.Title = String.Format("XrayLib.NET v{0}.{1}",
XrayLib.VERSION_MAJOR, XrayLib.VERSION_MINOR);
Console.WriteLine("Example C# program using XrayLib.NET\n");
Console.WriteLine("Ca K-alpha Fluorescence Line Energy: {0}",
xl.LineEnergy(20, XrayLib.KA_LINE));
Console.WriteLine("Fe partial photoionization cs of L3 at 6.0 keV: {0}",
xl.CS_Photo_Partial(26, XrayLib.L3_SHELL, 6.0));
Console.WriteLine("Zr L1 edge energy: {0}",
xl.EdgeEnergy(40, XrayLib.L1_SHELL));
Console.WriteLine("Pb Lalpha XRF production cs at 20.0 keV (jump approx): {0}",
xl.CS_FluorLine(82, XrayLib.LA_LINE, 20.0));
Console.WriteLine("Pb Lalpha XRF production cs at 20.0 keV (Kissel): {0}",
xl.CS_FluorLine_Kissel(82, XrayLib.LA_LINE, 20.0));
Console.WriteLine("Bi M1N2 radiative rate: {0}",
xl.RadRate(83, XrayLib.M1N2_LINE));
Console.WriteLine("U M3O3 Fluorescence Line Energy: {0}",
xl.LineEnergy(92, XrayLib.M3O3_LINE));

Console.WriteLine("Pb information: {0}",
xl.GetElementData(82).ToString());

// Parser test for Ca(HCO3)2 (calcium bicarbonate)
CompoundData cd = new CompoundData("Ca(HCO3)2");
Console.WriteLine("Ca(HCO3)2 contains:");
Console.Write(cd.ToString());

// Parser test for SiO2 (quartz)
cd.Parse("SiO2");
Console.WriteLine("SiO2 contains:");
Console.Write(cd.ToString());

Console.WriteLine("Ca(HCO3)2 Rayleigh cs at 10.0 keV: {0}",
xl.CS_Rayl_CP("Ca(HCO3)2", 10.0));
Console.WriteLine("CS2 Refractive Index at 10.0 keV : {0} - {1} i",
xl.Refractive_Index_Re("CS2", 10.0, 1.261), xl.Refractive_Index_Im("CS2", 10.0, 1.261));
Console.WriteLine("C16H14O3 Refractive Index at 1 keV : {0} - {1} i",
xl.Refractive_Index_Re("C16H14O3", 1.0, 1.2), xl.Refractive_Index_Im("C16H14O3", 1.0, 1.2));
Console.WriteLine("SiO2 Refractive Index at 5 keV : {0} - {1} i",
xl.Refractive_Index_Re("SiO2", 5.0, 2.65), xl.Refractive_Index_Im("SiO2", 5.0, 2.65));

Console.WriteLine("Compton profile for Fe at pz = 1.1 : {0}",
xl.ComptonProfile(26, 1.1f));
Console.WriteLine("M5 Compton profile for Fe at pz = 1.1 : {0}",
xl.ComptonProfile_Partial(26, XrayLib.M5_SHELL, 1.1f));

sw.Stop();
Console.WriteLine("Time: {0} ms", sw.ElapsedMilliseconds);

Console.ReadLine();
}
}
}

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

2 changes: 1 addition & 1 deletion include/xraylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern "C" {


#define XRAYLIB_MAJOR 2
#define XRAYLIB_MINOR 13
#define XRAYLIB_MINOR 14


//#define ZMAX 120
Expand Down
40 changes: 38 additions & 2 deletions nsis/README
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ Now to produce the installer itself we used the NullSoft Installer System. After

----

The Python bindings
===================
Python bindings
===============

These were compiled using the mingw32 compiler for windows using a modified version of the xrlsetup.py file found in the python folder.
The command we used:

python xrlsetup.py build_ext --inplace --compiler=mingw32

The produced _xraylib.pyd file is of course dependent on the python version it was compiled against...
The package includes bindings for Python version 2.6, 2.7 and 3.1.


----


IDL bindings
============
Expand All @@ -46,5 +49,38 @@ make_dll,'xraylib_idl','libxrlidl','IDL_Load',INPUT_DIR='.',EXTRA_CFLAGS='-I"C:\
Depending on the versions of IDL, xraylib and Visual Studio that are installed, these commands may need to be altered.


----


.NET bindings
=============

The .NET Framework can be installed on computers running Microsoft Windows operating systems. It supports multiple programming languages, including C#, VB.NET, C++/CLI, Pascal, Fortran and includes a large class library for that solves many common programming problems. Microsoft offers free versions of its Express Edition compilers from http://www.microsoft.com/express/

These were compiled using Visual Studio 2008 Standard and was built against .NET Framework Version 2. The binding consists of a single, mixed-mode assembly XrayLib.NET.dll written in C++/CLI. The assembly provides the interop between a managed XrayLib class and the native functions and types exposed by libxrl-3.dll. This combines the language interoperability of .NET with the performance of the native underlying functions.

A pre-built Release version of the assembly and an example program can be found in the bin folder together with a HTML Help v1 file.

To use XrayLib.NET.dll in Visual Studio:

1) Right-click on your project in the Solution Explorer

2) Click the References... menu item

3) Click the Add New Reference... button in the dialog box

4) Click the Browse tab of the Add Reference dialog box

5) Navigate to the xraylib Lib folder and select the XrayLib.NET.dll file

6) Click the OK buttons to add the assembly reference and close the dialog boxes

7) Assuming you are using C#, add the following line to the top of your source code file

using Science;

8) To create a instance of the XrayLib class that provides access to the XrayLib functionality, use the make the following call

XrayLib xl = XrayLib.Instance;

The class uses the static property Instance to implement a singleton pattern so that only a single instance of the XrayLib class is created and can be used throughout your program.
40 changes: 40 additions & 0 deletions nsis/dotNet/AssemblyInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "stdafx.h"

using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;

//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly:AssemblyTitleAttribute("XrayLibNET")];
[assembly:AssemblyDescriptionAttribute("")];
[assembly:AssemblyConfigurationAttribute("")];
[assembly:AssemblyCompanyAttribute("")];
[assembly:AssemblyProductAttribute("XrayLibNET")];
[assembly:AssemblyCopyrightAttribute("Copyright (c) 2010")];
[assembly:AssemblyTrademarkAttribute("")];
[assembly:AssemblyCultureAttribute("")];

//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly:AssemblyVersionAttribute("1.0.*")];

[assembly:ComVisible(false)];

[assembly:CLSCompliantAttribute(true)];

[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
Loading

0 comments on commit 69d04a1

Please sign in to comment.