Skip to content

Commit

Permalink
Add "C" bindings for SpecFile, Measurement, and EnergyCalibration.
Browse files Browse the repository at this point in the history
Bindings arent complete, but they are hopefully the most-useful stuff to start out with.
  • Loading branch information
wcjohns committed Aug 26, 2024
1 parent a4bba4a commit e198925
Show file tree
Hide file tree
Showing 5 changed files with 2,623 additions and 11 deletions.
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ option( SpecUtils_BUILD_REGRESSION_TEST "Creates executable to perform interacti
option( SpecUtils_BUILD_EXAMPLE "Builds example SpecUtil applications" OFF )
option( SpecUtils_PYTHON_BINDINGS "Creates python bindings to the c++ code" OFF )
option( SpecUtils_JAVA_SWIG "Creates swig/java bindings to the c++ code" OFF )
option( SpecUtils_C_BINDINGS "Creates C bindings to the c++ code" OFF )
option( SpecUtils_INJA_TEMPLATES "Creates inja template interface" OFF )
option( SpecUtils_USE_SIMD "Use SIMD operations; i386/x64 only right now, and very alpha, and extremely minimally used" OFF )
option( SpecUtils_ENABLE_EQUALITY_CHECKS "Enables the equal_enough(...) functions for comparing two spectrum files." OFF ) #code size is only reason to default to off, I think
Expand Down Expand Up @@ -90,10 +91,6 @@ if( MSVC AND (SpecUtils_PYTHON_BINDINGS OR SpecUtils_BUILD_UNIT_TESTS) )
endif( MSVC AND (SpecUtils_PYTHON_BINDINGS OR SpecUtils_BUILD_UNIT_TESTS) )


if( SpecUtils_PYTHON_BINDINGS )
list( APPEND boost_libs_required python )
endif( SpecUtils_PYTHON_BINDINGS )

if( SpecUtils_BUILD_EXAMPLE )
add_subdirectory( examples )
endif( SpecUtils_BUILD_EXAMPLE )
Expand Down Expand Up @@ -262,6 +259,11 @@ if( SpecUtils_JAVA_SWIG )
list( APPEND sources bindings/swig/SpecUtils.i )
endif( SpecUtils_JAVA_SWIG )

if( SpecUtils_C_BINDINGS )
list( APPEND headers bindings/c/SpecUtils_c.h )
list( APPEND sources bindings/c/SpecUtils_c.cpp )
endif( SpecUtils_C_BINDINGS )

add_library( SpecUtils ${SpecUtils_LIB_TYPE} ${sources} ${headers} ${OTHER_SUPPORT_FILES} )
set_target_properties( SpecUtils PROPERTIES PREFIX "lib" OUTPUT_NAME "SpecUtils" )

Expand Down Expand Up @@ -326,14 +328,22 @@ endif( SpecUtils_USE_FAST_FLOAT )
# We only need boost libraries if we are using boost to parse floats, if we are performing developer
# checks, or we are creating Python bindings
if( SpecUtils_USE_BOOST_SPIRIT OR PERFORM_DEVELOPER_CHECKS OR SpecUtils_PYTHON_BINDINGS )

if( DEFINED boost_SOURCE_DIR )
# We used CMake Fetch to get boost (e.g., in InterSpec)
target_link_libraries( SpecUtils PUBLIC Boost::system Boost::spirit Boost::fusion Boost::algorithm Boost::functional Boost::crc )

else( DEFINED boost_SOURCE_DIR )

if( SpecUtils_PYTHON_BINDINGS )
list( APPEND boost_libs_required python )
endif( SpecUtils_PYTHON_BINDINGS )

find_package( Boost REQUIRED COMPONENTS system ${boost_libs_required} )
if( NOT Boost_FOUND )
message(FATAL_ERROR "Couldnt Find Boost")
endif( NOT Boost_FOUND )

target_link_libraries( SpecUtils PUBLIC Boost::system )
endif( DEFINED boost_SOURCE_DIR )
endif( SpecUtils_USE_BOOST_SPIRIT OR PERFORM_DEVELOPER_CHECKS OR SpecUtils_PYTHON_BINDINGS )
Expand Down Expand Up @@ -389,7 +399,6 @@ endif( SpecUtils_ENABLE_URI_SPECTRA )


if( SpecUtils_PYTHON_BINDINGS )
#target_link_libraries( SpecUtils PUBLIC Boost::python ${PYTHON_LIBRARIES} )
target_link_libraries( SpecUtils PUBLIC Boost::python ${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES} )
endif( SpecUtils_PYTHON_BINDINGS )

Expand Down
2 changes: 1 addition & 1 deletion SpecUtils/EnergyCalibration.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ namespace SpecUtils
const size_t nchannel,
const std::vector<std::pair<float,float>> &deviation_pairs );

/** Gives the energy cooresponding to the passed in _channel_number_.
/** Gives the energy corresponding to the passed in _channel_number_.
@param channel_number The channel number you would like the energy for.
This value may be non-integer (ex, if you want the energy of a peak
Expand Down
10 changes: 5 additions & 5 deletions SpecUtils/SpecFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -1282,14 +1282,14 @@ class SpecFile
const SpecFile &operator=( const SpecFile &rhs );

//load_file(...): returns true when file is successfully loaded, false
// otherwise. Callling this function with parser_type==Auto is
// otherwise. Calling this function with parser_type==Auto is
// the easiest way to load a spectrum file when you dont know the type of
// file. The file_ending_hint is only used in the case of Auto
// and uses the file ending to effect the order of parsers tried, example
// values for this mught be: "n24", "pcf", "chn", etc. The entire filename
// can be passed in since only the letters after the last period are used
// Note: on Windows the filename must be UTF-8, and not whatever the current
// codepoint is.
// code-point is.
bool load_file( const std::string &filename,
ParserType parser_type,
std::string file_ending_hint
Expand All @@ -1304,7 +1304,7 @@ class SpecFile
#Measurement::parse_warnings.
An example condition when a message might be made is if it is know the
neutron real time can sometimes not coorespond to the gamma real time.
neutron real time can sometimes not correspond to the gamma real time.
*/
const std::vector<std::string> &parse_warnings() const;

Expand Down Expand Up @@ -1777,7 +1777,7 @@ class SpecFile
bool load_from_micro_raider_from_data( const char *data );

//load_from_binary_exploranium(...): returns success status; calls reset()
// upon falure, and puts istr to original location
// upon failure, and puts istr to original location
bool load_from_binary_exploranium( std::istream &istr );

//load_from_pcf(...): Set info from GADRAS PCF files. Returns success
Expand Down Expand Up @@ -2011,7 +2011,7 @@ class SpecFile
// the same file while this function is being called.
// If no exception is thrown the specified file will exist and contain the
// relevant information/format.
// If an exception is thrown, there are no garuntees as to if the file will
// If an exception is thrown, there are no guarantees as to if the file will
// exist, or what its contents will be.
void write_to_file( const std::string filename,
const SaveSpectrumAsType format ) const;
Expand Down
Loading

0 comments on commit e198925

Please sign in to comment.