Skip to content

Commit 516e9f2

Browse files
committed
Hacked header code to get it working on all files, regardless of header version
1 parent 77ce4ff commit 516e9f2

20 files changed

Lines changed: 182 additions & 692 deletions

File tree

‎cmake/unit_testing.cmake‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ enable_testing()
1212

1313
add_subdirectory( src/ACEtk/Table/Data/Parse/test )
1414
add_subdirectory( src/ACEtk/Table/Data/test )
15-
add_subdirectory( src/ACEtk/Table/Header/String/test )
1615
add_subdirectory( src/ACEtk/Table/Header/test )
1716
add_subdirectory( src/ACEtk/Table/test )
1817
add_subdirectory( src/ACEtk/ContinuousEnergyTable/test )

‎python/src/ContinuousEnergyTable.python.cpp‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,21 +177,6 @@ void wrapContinuousEnergyTable( python::module& module, python::module& ) {
177177
"principal_cross_section_block",
178178
&Table::principalCrossSectionBlock,
179179
"The principal cross section block"
180-
)
181-
//! @todo solve the header version print issue to add this to the table definitions instead
182-
.def(
183-
184-
"to_file",
185-
[] ( const Table& self, const std::string& filename ) {
186-
187-
std::ofstream out( filename );
188-
self.print< 1, 0, 0 >( out );
189-
out.close();
190-
},
191-
"Write the ACE table to a file\n\n"
192-
"Arguments:\n"
193-
" self the table\n"
194-
" filename the file name and path"
195180
);
196181

197182
// add standard block definitions

‎python/src/Table.python.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void wrapTable( python::module& module, python::module& ) {
7373
[] ( const Component& self, const std::string& filename ) {
7474

7575
std::ofstream out( filename );
76-
self.print< 1,0,0 >( out );
76+
self.print( out );
7777
out.close();
7878
},
7979
"Write the ACE table to a file\n\n"
@@ -102,7 +102,7 @@ void wrapTable( python::module& module, python::module& ) {
102102
[] ( const Component& self ) {
103103

104104
std::ostringstream out;
105-
self.print< 1,0,0 >( out );
105+
self.print( out );
106106
return out.str();
107107
},
108108
"Return the string representation of the ACE table"

‎python/src/definitions.hpp‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ void addStandardTableDefinitions( PythonClass& table ) {
4848
"table\n\n"
4949
"Arguments:\n"
5050
" filename the file name and path"
51+
)
52+
.def(
53+
54+
"to_file",
55+
[] ( const Table& self, const std::string& filename ) {
56+
57+
std::ofstream out( filename );
58+
self.print( out );
59+
out.close();
60+
},
61+
"Write the ACE table to a file\n\n"
62+
"Arguments:\n"
63+
" self the table\n"
64+
" filename the file name and path"
5165
);
5266
}
5367

‎src/ACEtk/ContinuousEnergyTable/test/resources/92235.710nc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
2.0.1 92235.710nc ENDFB-VII.1
2-
233.024800 2.5301E-08 2012-12-19 3
3-
The next two lines are the first two lines of 'old-style' ACE.
2+
233.024800 2.5301E-08 2012-12-19 2
43
92235.80c 233.024800 2.5301E-08 12/19/12
54
U235 ENDF71x (jlconlin) Ref. see jlconlin (ref 09/10/2012 10:00:53) mat9228
65
0 0. 0 0. 0 0. 0 0.

‎src/ACEtk/Table.hpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define NJOY_ACETK_TABLE
33

44
// system includes
5+
#include <cctype>
56
#include <istream>
67
#include <regex>
78
#include <string>

‎src/ACEtk/Table/Header.hpp‎

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,94 @@
1+
/**
2+
* @class
3+
* @brief The header information in an ACE file
4+
*
5+
* There are multiple version of the header.
6+
*
7+
* The 1.0.0 (or legacy header) contains the following information:
8+
* - line 1: ZAID, AW (atomic mass ratio), TZ (temperature in MeV), date
9+
* - line 2: description (70 characters), material identifier (10 characters)
10+
*
11+
* The 2.0.0 and 2.0.1 header contains the following information:
12+
* - line 1: VERS (header version), SZAID, SRC (evaluation source)
13+
* - line 2: AW (atomic mass ratio), TZ (temperature in MeV), date, N (comments)
14+
* - line 3 to N+2: comment lines (this is often 2 lines for the 1.0.0
15+
* header but that is not guaranteed)
16+
*
17+
* Some ACE files with 2.0.x headers also seem to have some formatting issues
18+
* where the data is shifted by a column.
19+
*/
120
class Header {
2-
public:
3-
#include "ACEtk/Table/Header/String.hpp"
421

5-
/* convenience typedefs */
6-
using Comment = String<70>;
7-
using SZAID = String<24, true>;
8-
922
/* fields */
10-
year_month_day processDate;
11-
Quantity< Mega<ElectronVolts> > processTemperature;
12-
double atomicWeightRatio;
13-
SZAID szaid;
14-
std::vector< Comment > comments;
15-
16-
protected:
17-
using MAT = String<10, true>;
18-
using Source = String<24>;
19-
20-
template< int... values >
21-
using Version = std::integer_sequence< int, values... > ;
22-
23-
std::optional< MAT > mat;
24-
std::optional< Source > source;
23+
std::string zaid_;
24+
double temp_;
25+
double awr_;
26+
std::string date_;
27+
std::vector< std::string > comments_;
28+
29+
/* auxiliary functions */
30+
static std::string strip( const std::string& string ) {
31+
32+
std::string result = string;
33+
auto notspace = [] ( char c ) { return !std::isspace( c ); };
34+
35+
auto front = std::find_if( result.begin(), result.end(), notspace );
36+
result.erase( result.begin(), front );
37+
auto back = std::find_if( result.rbegin(), result.rend(), notspace );
38+
result.erase( back.base(), result.end() );
39+
return result;
40+
}
41+
42+
static std::string left( const std::string& string, std::size_t length ) {
43+
44+
std::string result = string;
45+
result.resize( length, ' ' );
46+
return result;
47+
}
48+
49+
static std::string right( const std::string& string, std::size_t length ) {
50+
51+
std::string result = string;
52+
const auto pivot = result.size();
53+
left( result, length );
54+
std::rotate( result.begin(),
55+
std::next( result.begin(), pivot ),
56+
result.end() );
57+
return result;
58+
}
2559

2660
public:
27-
Header( year_month_day processDate,
28-
Quantity< Mega<ElectronVolts> > processTemperature,
29-
double atomicWeightRatio,
30-
SZAID&& szaid,
31-
std::vector< Comment >&& comments ) :
32-
processDate( processDate ),
33-
processTemperature( processTemperature ),
34-
atomicWeightRatio( atomicWeightRatio ),
35-
szaid( std::move(szaid) ),
36-
comments( std::move(comments) ){}
37-
38-
/* static methods */
39-
#include "ACEtk/Table/Header/src/parse.hpp"
61+
62+
Header( const Header& ) = default;
63+
Header( Header&& ) = default;
64+
65+
Header( const std::string& zaid, double awr, double temperature,
66+
const std::string& date, const std::string& title,
67+
const std::string& material ) :
68+
zaid_( strip( zaid ) ), awr_( awr ), temp_( temperature ),
69+
date_( strip( date ) ),
70+
comments_( { left( title, 70 ) + right( material, 10 ) } ) {}
71+
72+
/**
73+
* @brief Constructor (from a buffer)
74+
*
75+
* @tparam Iterator a buffer iterator
76+
*
77+
* @param[in] state the buffer state
78+
*/
79+
template< typename Iterator >
80+
Header( State< Iterator >& state )
81+
try : Header( parse( state ) ) {}
82+
catch( std::exception& e ) {
83+
84+
Log::info("Error while constructing ACE Table Header");
85+
throw e;
86+
}
87+
88+
/* static methods */
4089
#include "ACEtk/Table/Header/src/print.hpp"
90+
91+
private:
92+
93+
#include "ACEtk/Table/Header/src/parse.hpp"
4194
};

‎src/ACEtk/Table/Header/String.hpp‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎src/ACEtk/Table/Header/String/test/CMakeLists.txt‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎src/ACEtk/Table/Header/String/test/String.test.cpp‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)