<commit_before>#include <iostream>
#include <fstream>
#include <string>

#include "spectrum.hpp"
#include "input.hpp"
extern "C"
{
	// __declspec(dllexport) 
	void sim(char * input_file, 
	char * output_file, 
	// Total
	double * y_vec,
	// Separate
	double * y_sep,
	// XRF
	int * Z_vec,
	int * row,
	int * lines,
	double * xrf_ev,
	double * xrf_y,
	// Compton
	double * comp_ev,
	double * comp_y,
	// Rayleigh
	double * ray_y,
	// Detector
	double * det_,
	int * n_channels,
	int * win_mat,
	// Illumination
	double * il_,
	// Solid angle
	double * sa,
	int * nout);
}


void sim(char * input_file, 
	char * output_file, 
	// Total
	double * y_vec,
	// Separate
	double * y_sep,
	// XRF
	int * Z_vec,
	int * row,
	int * lines,
	double * xrf_ev,
	double * xrf_y,
	// Compton
	double * comp_ev,
	double * comp_y,
	// Rayleigh
	double * ray_y,
	// Detector
	double * det_,
	int * n_channels,
	int * win_mat,
	// Illumination
	double * il_,
	// Solid angle
	double * sa,
	int * nout)
{
	Sample sp;
	Illumination il;
	solid_angle omega;
	Detector det;
	
	// Read input file
	readfile(input_file, sp, il, omega, det);
	
	// Calculate spectrum
	Spectrum spec(sp, il, omega, det, true, true, true);
	
	// Save results to file
	std::ofstream fout;
	fout.open(output_file);
	spec.out(fout);
	fout.close();
	
	// Return results
	
	// Total
	if (spec.y_vec.size() > *nout)
		std::cerr << "Error: Output for y_vec out of range! ("
		<< *nout << " given, needs "
		<< spec.y_vec.size() << ".)" << std::endl;
	else
		for (auto i : spec.y_vec)
			*(y_vec++) = i;
		// *y_vec = -1;
	*(nout++) = spec.y_vec.size();
	
	// Separate
	if (spec.y_sep.size() > ((*nout)+2)*(*(nout-1)))
		std::cerr << "Error: Output for y_sep out of range! ("
		<< ((*nout)+2)*(*(nout-1)) << " given, needs "
		<< spec.y_sep.size() << ".)" << std::endl;
	else
		for (auto i : spec.y_sep)
			*(y_sep++) = i;
		// *y_sep = -1;
	
	
	// XRF
	if (spec.xrf.Z_vec.size() > *nout)
		std::cerr << "Error: Output for xrf.Z_vec out of range! ("
		<< *nout << " given, needs "
		<< spec.xrf.Z_vec.size() << ".)" << std::endl;
	else
	{
		for (auto i : spec.xrf.Z_vec)
			*(Z_vec++) = i;
		// *Z_vec = -1;
	
		for (auto i : spec.xrf.row)
			*(row++) = i;
		// *row = -1;
	}
	*(nout++) = spec.xrf.Z_vec.size();
	
	if (spec.xrf.lines.size() > *nout)
		std::cerr << "Error: Output for xrf.lines out of range! ("
		<< *nout << " given, needs "
		<< spec.xrf.lines.size() << ".)" << std::endl;
	else
	{
		for (auto i : spec.xrf.lines)
			*(lines++) = i;
		// *lines = -1;
	
		for (auto i : spec.xrf.ev_vec)
			*(xrf_ev++) = i;
		// *xrf_ev = -1;
		
		for (auto i : spec.xrf.y_vec)
			*(xrf_y++) = i;
		// *xrf_y = -1;
	}
	*(nout++) = spec.xrf.lines.size();
	
	// Compton
	if (spec.comp.ev_vec.size() > *nout)
		std::cerr << "Error: Output for comp.ev_vec out of range! ("
		<< *nout << " given, needs "
		<< spec.comp.ev_vec.size() << ".)" << std::endl;
	else
	{
		for (auto i : spec.comp.ev_vec)
			*(comp_ev++) = i;
		// *comp_ev = -1;
		
		for (auto i : spec.comp.y_vec)
			*(comp_y++) = i;
		// *comp_y = -1;
	}
	*(nout++) = spec.comp.ev_vec.size();
	

	// Rayleigh
	*ray_y = spec.ray.y;
	
	// Detector
	*(det_++) = det.channel.ev_offset;
	*(det_++) = det.channel.ev_gain;
	*n_channels = det.channel.n_channels;
	*(det_++) = det.response.noise;
	*(det_++) = det.response.fano;
	*(det_++) = det.response.gamma;
	*(det_++) = det.response.fs;
	*(det_++) = det.response.ft;
	*(det_++) = det.window.thickness;
	*det_ = det.window.density;
	for (int i = 0; i < det.window.material.length(); i++)
		*(win_mat++) = int(det.window.material.at(i));
	*(win_mat) = int('\n');
	
	// Illumination
	*(il_++) = il.ev0;
	*(il_++) = il.psi;
	*(il_) = il.alpha;
	
	// Solid angle
	for (int i = 0; i < 4; i++)
		*(sa++) = omega.angle_range[i];
	*(sa++) = omega.theta_inc;
	*(sa) = omega.beta_inc;
	
}

<commit_msg>Fixed nout in cwrapper.cc.<commit_after>#include <iostream>
#include <fstream>
#include <string>

#include "spectrum.hpp"
#include "input.hpp"
extern "C"
{
	// __declspec(dllexport) 
	void sim(char * input_file, 
	char * output_file, 
	// Total
	double * y_vec,
	// Separate
	double * y_sep,
	// XRF
	int * Z_vec,
	int * row,
	int * lines,
	double * xrf_ev,
	double * xrf_y,
	// Compton
	double * comp_ev,
	double * comp_y,
	// Rayleigh
	double * ray_y,
	// Detector
	double * det_,
	int * n_channels,
	int * win_mat,
	// Illumination
	double * il_,
	// Solid angle
	double * sa,
	int * nout);
}


void sim(char * input_file, 
	char * output_file, 
	// Total
	double * y_vec,
	// Separate
	double * y_sep,
	// XRF
	int * Z_vec,
	int * row,
	int * lines,
	double * xrf_ev,
	double * xrf_y,
	// Compton
	double * comp_ev,
	double * comp_y,
	// Rayleigh
	double * ray_y,
	// Detector
	double * det_,
	int * n_channels,
	int * win_mat,
	// Illumination
	double * il_,
	// Solid angle
	double * sa,
	int * nout)
{
	Sample sp;
	Illumination il;
	solid_angle omega;
	Detector det;
	
	// Read input file
	readfile(input_file, sp, il, omega, det);
	
	// Calculate spectrum
	Spectrum spec(sp, il, omega, det, true, true, true);
	
	// Save results to file
	std::ofstream fout;
	fout.open(output_file);
	spec.out(fout);
	fout.close();

	// Make a copy of nout
	int nout_[4];
	for (int i=0; i<4; i++)
        nout_[i] = nout[i];

	// Return results
	
	// Total
	if (spec.y_vec.size() > nout_[0])
		std::cerr << "Error: Output for y_vec out of range! ("
		<< *nout_ << " given, needs "
		<< spec.y_vec.size() << ".)" << std::endl;
	else
		for (auto i : spec.y_vec)
			*(y_vec++) = i;
		// *y_vec = -1;
	*(nout++) = spec.y_vec.size();
	
	// Separate
	if (spec.y_sep.size() > (nout_[1]+2)*nout_[0])
		std::cerr << "Error: Output for y_sep out of range! ("
		<< (nout_[1]+2)*nout_[0] << " given, needs "
		<< spec.y_sep.size() << ".)" << std::endl;
	else
		for (auto i : spec.y_sep)
			*(y_sep++) = i;
		// *y_sep = -1;
	
	
	// XRF
	if (spec.xrf.Z_vec.size() > nout_[1])
		std::cerr << "Error: Output for xrf.Z_vec out of range! ("
		<< nout_[1] << " given, needs "
		<< spec.xrf.Z_vec.size() << ".)" << std::endl;
	else
	{
		for (auto i : spec.xrf.Z_vec)
			*(Z_vec++) = i;
		// *Z_vec = -1;
	
		for (auto i : spec.xrf.row)
			*(row++) = i;
		// *row = -1;
	}
	*(nout++) = spec.xrf.Z_vec.size();
	
	if (spec.xrf.lines.size() > nout_[2])
		std::cerr << "Error: Output for xrf.lines out of range! ("
		<< nout_[2] << " given, needs "
		<< spec.xrf.lines.size() << ".)" << std::endl;
	else
	{
		for (auto i : spec.xrf.lines)
			*(lines++) = i;
		// *lines = -1;
	
		for (auto i : spec.xrf.ev_vec)
			*(xrf_ev++) = i;
		// *xrf_ev = -1;
		
		for (auto i : spec.xrf.y_vec)
			*(xrf_y++) = i;
		// *xrf_y = -1;
	}
	*(nout++) = spec.xrf.lines.size();
	
	// Compton
	if (spec.comp.ev_vec.size() > nout_[3])
		std::cerr << "Error: Output for comp.ev_vec out of range! ("
		<< nout_[3] << " given, needs "
		<< spec.comp.ev_vec.size() << ".)" << std::endl;
	else
	{
		for (auto i : spec.comp.ev_vec)
			*(comp_ev++) = i;
		// *comp_ev = -1;
		
		for (auto i : spec.comp.y_vec)
			*(comp_y++) = i;
		// *comp_y = -1;
	}
	*(nout++) = spec.comp.ev_vec.size();
	

	// Rayleigh
	*ray_y = spec.ray.y;
	
	// Detector
	*(det_++) = det.channel.ev_offset;
	*(det_++) = det.channel.ev_gain;
	*n_channels = det.channel.n_channels;
	*(det_++) = det.response.noise;
	*(det_++) = det.response.fano;
	*(det_++) = det.response.gamma;
	*(det_++) = det.response.fs;
	*(det_++) = det.response.ft;
	*(det_++) = det.window.thickness;
	*det_ = det.window.density;
	for (int i = 0; i < det.window.material.length(); i++)
		*(win_mat++) = int(det.window.material.at(i));
	*(win_mat) = int('\n');
	
	// Illumination
	*(il_++) = il.ev0;
	*(il_++) = il.psi;
	*(il_) = il.alpha;
	
	// Solid angle
	for (int i = 0; i < 4; i++)
		*(sa++) = omega.angle_range[i];
	*(sa++) = omega.theta_inc;
	*(sa) = omega.beta_inc;
	
}


{'fraction_non_alphanumeric': 0.21504549532231193, 'fraction_numerical': 0.00589516852492631, 'mean_word_length': 2.8049731838127743, 'pattern_counts': {'":': 0, '<': 134, '<?xml version=': 0, '>': 19, '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': '5588233', 'n_tokens_mistral': 3662, 'n_tokens_neox': 3416, 'n_words': 753}