<commit_before>/*
 * interpreter_interface.cpp
 *
 * Wrapper to allow routines to be called from fortran and/or provide a result
 * without requiring the caller to include interpreter.h or deal with namespaces
 * or classes.
 *
 *  Created on: Aug 10, 2013
 *      Author: basbas
 */

#include "config.h"
#include "sip_interface.h"
#include "interpreter.h"
#include "index_table.h"
#include "block.h"
#include <stdexcept>

#ifdef HAVE_MPI
#include "sip_mpi_attr.h"
#include "sip_server.h"
#endif // HAVE_MPI

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Gets a currently active scalar value
 * @param name
 * @return
 */
double scalar_value(const char * name) {
	return sip::Interpreter::global_interpreter->scalar_value(std::string(name));
}

/**
 * Sets the value of a currently active scalar
 * @param name
 * @param value
 */
void set_scalar_value(const char * name, double value) {
	sip::Interpreter::global_interpreter->set_scalar_value(std::string(name),
			value);
}

/**
 * query existance of double constant from initialization data
 * @param cname [in]  Name of the constant
 * @return 0 for exists
 */
int query_scalar_constant(const char*cname) {
    try {
	sip::Interpreter::global_interpreter->sip_tables().setup_reader().predefined_scalar(
			std::string(cname));
	return 1;
    } catch(const std::out_of_range& oor) {
	return 0;
    }
}

/**
 * Get a double constant from initialization data
 * @param cname [in]  Name of the constant
 * @return Value of the constant
 */
double scalar_constant(const char*cname) {
	return sip::Interpreter::global_interpreter->sip_tables().setup_reader().predefined_scalar(
			std::string(cname));
}

/**
 * query integer constant from initialization data
 * @param cname [in]  Name of the constant
 * @return 0 for exists
 */
int query_int_constant(const char*cname) {
    try {
	sip::Interpreter::global_interpreter->sip_tables().setup_reader().predefined_int(
			std::string(cname));
	return 1;
    } catch(const std::out_of_range& oor) {
	return 0;
    }
}

/**<commit_msg>updated comments to reflect correct return value<commit_after>/*
 * interpreter_interface.cpp
 *
 * Wrapper to allow routines to be called from fortran and/or provide a result
 * without requiring the caller to include interpreter.h or deal with namespaces
 * or classes.
 *
 *  Created on: Aug 10, 2013
 *      Author: basbas
 */

#include "config.h"
#include "sip_interface.h"
#include "interpreter.h"
#include "index_table.h"
#include "block.h"
#include <stdexcept>

#ifdef HAVE_MPI
#include "sip_mpi_attr.h"
#include "sip_server.h"
#endif // HAVE_MPI

#ifdef __cplusplus
extern "C" {
#endif

/**
 * Gets a currently active scalar value
 * @param name
 * @return
 */
double scalar_value(const char * name) {
	return sip::Interpreter::global_interpreter->scalar_value(std::string(name));
}

/**
 * Sets the value of a currently active scalar
 * @param name
 * @param value
 */
void set_scalar_value(const char * name, double value) {
	sip::Interpreter::global_interpreter->set_scalar_value(std::string(name),
			value);
}

/**
 * query existance of double constant from initialization data
 * @param cname [in]  Name of the constant
 * @return 1 for exists
 */
int query_scalar_constant(const char*cname) {
    try {
	sip::Interpreter::global_interpreter->sip_tables().setup_reader().predefined_scalar(
			std::string(cname));
	return 1;
    } catch(const std::out_of_range& oor) {
	return 0;
    }
}

/**
 * Get a double constant from initialization data
 * @param cname [in]  Name of the constant
 * @return Value of the constant
 */
double scalar_constant(const char*cname) {
	return sip::Interpreter::global_interpreter->sip_tables().setup_reader().predefined_scalar(
			std::string(cname));
}

/**
 * query integer constant from initialization data
 * @param cname [in]  Name of the constant
 * @return 1 for exists
 */
int query_int_constant(const char*cname) {
    try {
	sip::Interpreter::global_interpreter->sip_tables().setup_reader().predefined_int(
			std::string(cname));
	return 1;
    } catch(const std::out_of_range& oor) {
	return 0;
    }
}

/**
{'fraction_non_alphanumeric': 0.12356532356532357, 'fraction_numerical': 0.005860805860805861, 'mean_word_length': 4.527665317139001, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7216955', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1350, 'n_words': 370}