1 /*////////////////////////////////////////////////////////////////////////////// 2 // 10 // 11 // 12 // Example to demonstrate how to use libnucnet routines to create a 13 // Libnucnet__Nuc structure of nuclear species, add species to the 14 // structure, write the data to an xml file, and clear the structure 15 // and free the allocated memory. 16 // 17 // 18 // 19 // See the README.txt file in this directory for copyright and license 20 // information. 21 // 22 // 23 //////////////////////////////////////////////////////////////////////////////*/ 24 25 #include 26 27 int main( int argc, char **argv ) { 28 29 Libnucnet__Nuc *p_my_nuclei; 30 Libnucnet__Species *p_species; 31 FILE *p_input_file; 32 size_t i, i_partf_count; 33 unsigned int i_z, i_a; 34 int i_state; 35 double d_mass_excess; 36 float f_spin; 37 char s_state[2]; 38 double d_t9, d_log10_partf; 39 gsl_vector *p_t9, *p_log10_partf; 40 41 /*============================================================================ 42 // Check input. 43 //==========================================================================*/ 44 45 if ( argc != 3 ) { 46 fprintf( 47 stderr, "\nUsage: %s input_file output_file \n", argv[0] 48 ); 49 fprintf( 50 stderr, "\n input_file: name of input text file\n" 51 ); 52 fprintf( 53 stderr, "\n output_file: name of output xml file\n\n" 54 ); 55 return EXIT_FAILURE; 56 } 57 58 /*============================================================================ 59 // Create the collection. 60 //==========================================================================*/ 61 62 p_my_nuclei = Libnucnet__Nuc__new( ); 63 64 /*============================================================================ 65 // Open input file. 66 //==========================================================================*/ 67 68 if( ( p_input_file = fopen( argv[1], "r" ) ) == NULL ) { 69 fprintf( stderr, "Could not open file.\n" ); 70 return EXIT_FAILURE; 71 } 72 73 /*============================================================================ 74 // Read in input. 75 //==========================================================================*/ 76 77 while( !feof( p_input_file ) ) { 78 79 fscanf( 80 p_input_file, 81 "%d%d%lf%f\n", 82 &i_z, 83 &i_a, 84 &d_mass_excess, 85 &f_spin 86 ); 87 88 fscanf( p_input_file, "%s%d\n", s_state, &i_state ); 89 90 fscanf( p_input_file, "%d\n", &i_partf_count ); 91 92 p_t9 = gsl_vector_alloc( i_partf_count ); 93 p_log10_partf = gsl_vector_alloc( i_partf_count ); 94 95 for( i = 0; i < i_partf_count; i++ ) { 96 97 fscanf( 98 p_input_file, 99 "%lf%lf\n", 100 &d_t9, 101 &d_log10_partf 102 ); 103 104 gsl_vector_set( p_t9, i, d_t9 ); 105 gsl_vector_set( p_log10_partf, i, d_log10_partf ); 106 107 } 108 109 p_species = 110 Libnucnet__Species__new( 111 i_z, 112 i_a, 113 "example", 114 i_state, 115 s_state, 116 d_mass_excess, 117 f_spin, 118 p_t9, 119 p_log10_partf 120 ); 121 122 Libnucnet__Nuc__addSpecies( p_my_nuclei, p_species ); 123 124 gsl_vector_free( p_t9 ); 125 gsl_vector_free( p_log10_partf ); 126 127 } 128 129 /*============================================================================ 130 // Close input file. 131 //==========================================================================*/ 132 133 fclose( p_input_file ); 134 135 /*============================================================================ 136 // Write out nuclear data to xml file. 137 //==========================================================================*/ 138 139 Libnucnet__Nuc__writeToXmlFile( p_my_nuclei, argv[2] ); 140 141 /*============================================================================ 142 // Clean up 143 //==========================================================================*/ 144 145 Libnucnet__Nuc__free( p_my_nuclei ); 146 147 /*============================================================================ 148 // Done! 149 //==========================================================================*/ 150 151 return EXIT_SUCCESS; 152 153 } 154