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, and remove them.
libnucnet routines demonstrated in example1.c are:
- Line 71: Libnucnet__Nuc__new()
- Line 88: Libnucnet__Species__new()
- Line 100: Libnucnet__Nuc__addSpecies()
- Line 143: Libnucnet__Species__copy()
- Line 150: Libnucnet__Nuc__updateSpecies()
- Line 168: Libnucnet__Nuc__removeSpecies()
- Line 170: Libnucnet__Nuc__getSpeciesByName()
- Line 181: Libnucnet__Nuc__free()
- Line 243: Libnucnet__Nuc__iterateSpecies()
- Line 256: Libnucnet__Nuc__getNumberOfSpecies()
- Line 281: Libnucnet__Species__getIndex()
- Line 282: Libnucnet__Species__getZ()
- Line 283: Libnucnet__Species__getA()
- Line 284: Libnucnet__Species__getName()
- Line 285: Libnucnet__Species__getMassExcess()
- Line 286: Libnucnet__Species__getSpin()
- Line 287: 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 61: Libnucnet__Nuc__new()
- Line 109: Libnucnet__Species__new()
- Line 121: Libnucnet__Nuc__addSpecies()
- Line 138: Libnucnet__Nuc__writeToXmlFile()
- Line 144: 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 44: 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.3/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 53: Libnucnet__Nuc__new_from_xml()
- Line 68: Libnucnet__Nuc__free()
- Line 101: Libnucnet__Nuc__iterateSpecies()
- Line 112: Libnucnet__Nuc__getNumberOfSpecies()
- Line 138: Libnucnet__Species__getIndex()
- Line 139: Libnucnet__Species__getZ()
- Line 140: Libnucnet__Species__getA()
- Line 141: Libnucnet__Species__getName()
- Line 142: Libnucnet__Species__getMassExcess()
- Line 143: Libnucnet__Species__getSpin()
- Line 144: 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.3/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 56: Libnucnet__Nuc__new_from_xml()
- Line 65: Libnucnet__Nuc__setSpeciesCompareFunction()
- Line 70: Libnucnet__Nuc__sortSpecies()
- Line 82: Libnucnet__Nuc__free()
- Line 115: Libnucnet__Nuc__iterateSpecies()
- Line 126: Libnucnet__Nuc__getNumberOfSpecies()
- Line 152: Libnucnet__Species__getIndex()
- Line 153: Libnucnet__Species__getZ()
- Line 154: Libnucnet__Species__getA()
- Line 155: Libnucnet__Species__getName()
- Line 156: Libnucnet__Species__getMassExcess()
- Line 157: Libnucnet__Species__getSpin()
- Line 158: 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 52: Libnucnet__Nuc__new_from_xml()
- Line 54: Libnucnet__Nuc__extractSubset()
- Line 60: Libnucnet__Nuc__free()
- Line 66: Libnucnet__Nuc__writeToXmlFile()
To run example6, type the following on the command line:
./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 58: Libnucnet__Nuc__new_from_xml()
- Line 74: Libnucnet__Nuc__updateFromXml()
- Line 80: Libnucnet__Nuc__sortSpecies()
- Line 93: Libnucnet__Nuc__free()
- Line 126: Libnucnet__Nuc__iterateSpecies()
- Line 139: Libnucnet__Nuc__getNumberOfSpecies()
- Line 160: Libnucnet__Species__getIndex()
- Line 161: Libnucnet__Species__getZ()
- Line 162: Libnucnet__Species__getA()
- Line 163: Libnucnet__Species__getName()
- Line 164: Libnucnet__Species__getMassExcess()
- Line 165: Libnucnet__Species__getSpin()
- Line 166: 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.3/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 50: Libnucnet__Nuc__new_from_xml()
- Line 53: Libnucnet__Nuc__new()
- Line 55: Libnucnet__Nuc__updateFromXml()
- Line 63: Libnucnet__Nuc__getSpeciesByName()
- Line 68: Libnucnet__Nuc__free()
- Line 80: Libnucnet__Species__getZ()
- Line 85: Libnucnet__Species__getA()
- Line 90: Libnucnet__Species__getMassExcess()
- Line 95: Libnucnet__Species__getSpin()
- Line 97: Libnucnet__Species__getSource()
- Line 105: Libnucnet__Species__getPartitionFunctionT9()
- Line 106: 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 58: Libnucnet__Nuc__new_from_xml()
- Line 68: Libnucnet__Nuc__getSpeciesByZA()
- Line 85: Libnucnet__Species__getName()
- Line 86: Libnucnet__Species__getIndex()
- Line 88: 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 51: Libnucnet__Nuc__new_from_xml()
- Line 59: Libnucnet__Nuc__getSpeciesByName()
- Line 79: Libnucnet__Species__computePartitionFunction()
- Line 88: 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 59: Libnucnet__Nuc__new_from_xml()
- Line 69: Libnucnet__Nuc__getSpeciesByZA()
- Line 84: Libnucnet__Nuc__free()
- Line 92: Libnucnet__Species__getName()
- Line 100: 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