1 /*//////////////////////////////////////////////////////////////////////////////
2 //
10 //
11 // See the README.txt file in this directory for copyright and license
12 // information.
13 //
14 //
15 //
16 // Example to demonstrate how to use libnucnet routines to create
17 // a new Libnucnet structure from an input xml file, print out data
18 // about the input zones, and clear the
19 // structure and free the allocated memory.
20 //
21 //
22 //
23 //////////////////////////////////////////////////////////////////////////////*/
24
25 #include
26
27 int print_zone_abundances( Libnucnet__Zone *, int * );
28
29 int
30 print_species_abundance(
31 Libnucnet__Species *, Libnucnet__Zone *p_zone
32 );
33
34 /*##############################################################################
35 // main().
36 //############################################################################*/
37
38 int main( int argc, char * argv[] ) {
39
40 Libnucnet *p_my_nucnet;
41 int i_count = 0;
42
43 /*============================================================================
44 // Check input.
45 //==========================================================================*/
46
47 if ( argc!= 2 ) {
48 fprintf(
49 stderr, "\nUsage: %s filename\n\n", argv[0]
50 );
51 fprintf(
52 stderr, " filename = input nuclear network xml filename\n\n"
53 );
54
55 return EXIT_FAILURE;
56 }
57
58 /*============================================================================
59 // Read input file.
60 //==========================================================================*/
61
62 p_my_nucnet = Libnucnet__new_from_xml( argv[1], NULL, NULL );
63
64 /*============================================================================
65 // Print number of zones.
66 //==========================================================================*/
67
68 printf( "\nNumber of zones = %d\n\n",
69 Libnucnet__getNumberOfZones( p_my_nucnet )
70 );
71
72 /*============================================================================
73 // Print zone abundances.
74 //==========================================================================*/
75
76 Libnucnet__iterateZones(
77 p_my_nucnet,
78 (Libnucnet__Zone__iterateFunction) print_zone_abundances,
79 &i_count
80 );
81
82 /*============================================================================
83 // Clean up and exit.
84 //==========================================================================*/
85
86 Libnucnet__free( p_my_nucnet );
87 return EXIT_SUCCESS;
88
89 }
90
91 /*##############################################################################
92 // print_zone_abundances().
93 //############################################################################*/
94
95 int
96 print_zone_abundances( Libnucnet__Zone *p_zone, int *p_count )
97 {
98
99 printf(
100 "Zone %d (Label 1 = %s Label 2 = %s Label 3 = %s)\n\n",
101 (*p_count)++,
102 Libnucnet__Zone__getLabel( p_zone, 1 ),
103 Libnucnet__Zone__getLabel( p_zone, 2 ),
104 Libnucnet__Zone__getLabel( p_zone, 3 )
105 );
106
107 printf( "Species\tAbundance\n" );
108 printf( "=======\t=========\n" );
109
110 Libnucnet__Nuc__iterateSpecies(
111 Libnucnet__Net__getNuc(
112 Libnucnet__Zone__getNet( p_zone )
113 ),
114 (Libnucnet__Species__iterateFunction) print_species_abundance,
115 p_zone
116 );
117
118 printf( "\n\n" );
119
120 return 1;
121
122 }
123
124 /*##############################################################################
125 // print_species_abundance().
126 //############################################################################*/
127
128 int
129 print_species_abundance
130 (
131 Libnucnet__Species *p_species,
132 Libnucnet__Zone *p_zone
133 )
134 {
135
136 double d_abund;
137
138 d_abund =
139 Libnucnet__Zone__getSpeciesAbundance( p_zone, p_species );
140
141 if( d_abund > 0 )
142 printf(
143 "%s\t%f\n",
144 Libnucnet__Species__getName( p_species ),
145 d_abund
146 );
147
148 return 1;
149
150 }
151