Warning: This is no longer the latest available version of this module. Please see the releases page for the most recent version. The Webnucleo group strongly recommends the use of the latest version of any of its online modules.
This tutorial demonstrates how to use example codes in the libnucnet distribution src/examples directory. The sample input files used in the tutorial are included in the distribution release and may be located in the data_pub directory.
Example 1: Create a collection of nuclei, add species from a text file, and remove them.
libnucnet routines demonstrated in example1.c are:
- Line 84: Libnucnet__Nuc__new()
- Line 101: Libnucnet__Species__new()
- Line 113: Libnucnet__Nuc__addSpecies()
- Line 156: Libnucnet__Species__copy()
- Line 163: Libnucnet__Nuc__updateSpecies()
- Line 181: Libnucnet__Nuc__removeSpecies()
- Line 183: Libnucnet__Nuc__getSpeciesByName()
- Line 194: Libnucnet__Nuc__free()
- Line 256: Libnucnet__Nuc__iterateSpecies()
- Line 269: Libnucnet__Nuc__getNumberOfSpecies()
- Line 294: Libnucnet__Species__getIndex()
- Line 295: Libnucnet__Species__getZ()
- Line 296: Libnucnet__Species__getA()
- Line 297: Libnucnet__Species__getName()
- Line 298: Libnucnet__Species__getMassExcess()
- Line 299: Libnucnet__Species__getSpin()
- Line 300: Libnucnet__Species__getSource()
To run example1, type the following on the command line:
./example1 > ex1_output.txt
The result is ex1_output.txt
Example 2: Create a collection of nuclei, add species, and write data to an xml file.
libnucnet routines demonstrated in example2.c are:
- Line 73: Libnucnet__Nuc__new()
- Line 121: Libnucnet__Species__new()
- Line 133: Libnucnet__Nuc__addSpecies()
- Line 150: Libnucnet__Nuc__writeToXmlFile()
- Line 156: Libnucnet__Nuc__free()
To run example2, type the following on the command line:
./example2 ../../data_pub/example_nuc.txt ex2_output.xml
The result is ex2_output.xml
Example 3: Validate a Libnucnet__Nuc input xml file against Webnucleo's schema.
libnucnet routines demonstrated in example3.c are:
- Line 56: Libnucnet__Nuc__is_valid_input_xml()
To run example3, type the following on the command line:
./example3 ../../data_pub/example_nuc.xml
The result is
Valid input Libnucnet__Nuc xml file!
To see what happens when the input xml is invalid (the following input file has a negative mass number for the neutron), type:
./example3 ../../data_pub/example_nuc_wrong.xml
The result is
../../data_pub/example_nuc_wrong.xml:58: element a: Schemas validity error : Element 'a': '-1' is not a valid value of the atomic type '{http://www.webnucleo.org/home/modules/libnucnet/0.5/xsd_pub/libnucnet__nuc__types/}a_type'.
Example 4: Create a collection of nuclei from an input xml file and output the data about each species.
libnucnet routines demonstrated in example4.c are:
- Line 65: Libnucnet__Nuc__new_from_xml()
- Line 80: Libnucnet__Nuc__free()
- Line 113: Libnucnet__Nuc__iterateSpecies()
- Line 124: Libnucnet__Nuc__getNumberOfSpecies()
- Line 150: Libnucnet__Species__getIndex()
- Line 151: Libnucnet__Species__getZ()
- Line 152: Libnucnet__Species__getA()
- Line 153: Libnucnet__Species__getName()
- Line 154: Libnucnet__Species__getMassExcess()
- Line 155: Libnucnet__Species__getSpin()
- Line 156: Libnucnet__Species__getSource()
To run example4, type the following on the command line:
./example4 ../../data_pub/example_nuc.xml > ex4_output.txt
The result is ex4_output.txt
You can also select out certain species with an xpath expression. For example, to select only isotopes of elements between and including neon and calcium, type:
./example4 ../../data_pub/example_nuc.xml "[ z >= 10 and z <= 20 ]" > ex4_xpath_output.txt
The result is ex4_xpath_output.txt
Finally note you can also read data over the web. For example, to select data from the original example xml file residing on Webnucleo's server, type:
./example4 http://www.webnucleo.org/home/modules/libnucnet/0.5/data_pub/example_nuc.xml > ex4_web_output.txt
The result is ex4_web_output.txt
Example 5: Sort the species in a collection of nuclei according to a user-supplied function.
libnucnet routines demonstrated in example5.c are:
- Line 72: Libnucnet__Nuc__new_from_xml()
- Line 81: Libnucnet__Nuc__setSpeciesCompareFunction()
- Line 86: Libnucnet__Nuc__sortSpecies()
- Line 98: Libnucnet__Nuc__free()
- Line 131: Libnucnet__Nuc__iterateSpecies()
- Line 142: Libnucnet__Nuc__getNumberOfSpecies()
- Line 168: Libnucnet__Species__getIndex()
- Line 169: Libnucnet__Species__getZ()
- Line 170: Libnucnet__Species__getA()
- Line 171: Libnucnet__Species__getName()
- Line 172: Libnucnet__Species__getMassExcess()
- Line 173: Libnucnet__Species__getSpin()
- Line 174: Libnucnet__Species__getSource()
To run example5, type the following on the command line:
./example5 ../../data_pub/example_nuc.xml > ex5_output.txt
The result is ex5_output.txt
Example 6: Create a collection of nuclei from an input xml file and output a subset chosen by an xpath expression to a new file.
libnucnet routines demonstrated in example6.c are:
- Line 64: Libnucnet__Nuc__new_from_xml()
- Line 66: Libnucnet__Nuc__extractSubset()
- Line 72: Libnucnet__Nuc__free()
- Line 78: Libnucnet__Nuc__writeToXmlFile()
To output data about nuclei in the input file with atomic number less than or equal to 10, type:
./example6 ../../data_pub/example_nuc.xml "[z <= 10]" ex6_output.xml
The result is ex6_output.xml
Example 7: Create a collection of nuclei from data read over the web, output the data, modify the nuclear data with data from a local file, and output the updated data.
libnucnet routines demonstrated in example7.c are:
- Line 70: Libnucnet__Nuc__new_from_xml()
- Line 86: Libnucnet__Nuc__updateFromXml()
- Line 92: Libnucnet__Nuc__sortSpecies()
- Line 105: Libnucnet__Nuc__free()
- Line 138: Libnucnet__Nuc__iterateSpecies()
- Line 151: Libnucnet__Nuc__getNumberOfSpecies()
- Line 176: Libnucnet__Species__getIndex()
- Line 177: Libnucnet__Species__getZ()
- Line 178: Libnucnet__Species__getA()
- Line 179: Libnucnet__Species__getName()
- Line 180: Libnucnet__Species__getMassExcess()
- Line 181: Libnucnet__Species__getSpin()
- Line 182: Libnucnet__Species__getSource()
To modify data for Z < 5 from the original Webnucleo.org nuclear data file with data from a local file (the changes are modified data for beryllium-7 and the addition of carbon 12), type at the command line:
./example7 http://www.webnucleo.org/home/modules/libnucnet/0.5/data_pub/example_nuc.xml ../../data_pub/example_nuc_new.xml "[ z < 5 ]" > ex7_output.txt
The result is ex7_output.txt
Example 8: Create a collection of nuclei from an input xml file and print out data about a particular species selected by its name.
libnucnet routines demonstrated in example8.c are:
- Line 62: Libnucnet__Nuc__new_from_xml()
- Line 65: Libnucnet__Nuc__new()
- Line 67: Libnucnet__Nuc__updateFromXml()
- Line 75: Libnucnet__Nuc__getSpeciesByName()
- Line 80: Libnucnet__Nuc__free()
- Line 92: Libnucnet__Species__getZ()
- Line 97: Libnucnet__Species__getA()
- Line 102: Libnucnet__Species__getMassExcess()
- Line 107: Libnucnet__Species__getSpin()
- Line 109: Libnucnet__Species__getSource()
- Line 117: Libnucnet__Species__getPartitionFunctionT9()
- Line 118: Libnucnet__Species__getPartitionFunctionLog10()
To run example8, type the following on the command line:
./example8 ../../data_pub/example_nuc.xml si28 > ex8_output.txt
The result is ex8_output.txt
Example 9: Create a collection of nuclei from an input xml file and output data about a particular species selected by its charge, mass, and state.
libnucnet routines demonstrated in example9.c are:
- Line 72: Libnucnet__Nuc__new_from_xml()
- Line 80: Libnucnet__Nuc__getSpeciesByZA()
- Line 104: Libnucnet__Species__getName()
- Line 105: Libnucnet__Species__getIndex()
- Line 107: Libnucnet__Nuc__free()
To run example9, type the following on the command line:
./example9 ../../data_pub/example_nuc.xml 13 27 > ex9_output.txt
The result is ex9_output.txt
When there are multiple states present for the isotope, select them by their state index (for example, g or m):
./example9 ../../data_pub/example_nuc.xml 13 26 m > ex9_state_output.txt
The result is ex9_state_output.txt
Example 10: Create a collection of nuclei from an input xml file and print out the nuclear partition function for a particular species selected by its name.
libnucnet routines demonstrated in example10.c are:
- Line 63: Libnucnet__Nuc__new_from_xml()
- Line 71: Libnucnet__Nuc__getSpeciesByName()
- Line 91: Libnucnet__Species__computePartitionFunction()
- Line 100: Libnucnet__Nuc__free()
To run example10, type the following on the command line:
./example10 ../../data_pub/example_nuc.xml ca42 > ex10_output.txt
The result is ex10_output.txt
Example 11: Create a collection of nuclei from an input xml file and print out the nuclear partition function for a particular species selected by its charge, mass, and state.
libnucnet routines demonstrated in example11.c are:
- Line 71: Libnucnet__Nuc__new_from_xml()
- Line 79: Libnucnet__Nuc__getSpeciesByZA()
- Line 101: Libnucnet__Nuc__free()
- Line 109: Libnucnet__Species__getName()
- Line 117: Libnucnet__Species__computePartitionFunction()
To run example11, type the following on the command line:
./example11 ../../data_pub/example_nuc.xml 13 27 > ex11_output.txt
The result is ex11_output.txt
When there are multiple states present for the isotope, select them by their state index (for example, g or m):
./example11 ../../data_pub/example_nuc.xml 13 26 m > ex11_state_output.txt
The result is ex11_state_output.txt