<commit_before>// Copyright 2014 <NAME> <<EMAIL>>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>
using std::cerr;
using std::endl;
#include <fstream>
using std::ifstream;
#include <exception>
using std::exception;
#include <string>
using std::string;
using std::getline;
#include <limits>
using std::numeric_limits;
#include <cctype>
using std::isdigit;
#include <CImg.h>
using cimg_library::CImg;

#include <ArgumentList.hpp>
using isa::utils::ArgumentList;
#include <ColorMap.hpp>
using AstroData::Color;
using AstroData::getColorMap;
#include <utils.hpp>
using isa::utils::castToType;
#include <Exceptions.hpp>
using isa::Exceptions::EmptyCommandLine;


int main(int argc, char * argv[]) {
		unsigned int nrDMs = 0;
		unsigned int nrPeriods = 0;
		float minSNR = numeric_limits< float >::max();
		float maxSNR = numeric_limits< float >::min();
		float snrSpaceDim = 0.0f;
		float * snrSpace = 0;
		string outFilename;
		ifstream searchFile;

		try {
				ArgumentList args(argc, argv);

				searchFile.open(args.getSwitchArgument< string >("-input"));
				outFilename = args.getSwitchArgument< string >("-output");
				nrDMs = args.getSwitchArgument< unsigned int >("-dms");
				nrPeriods = args.getSwitchArgument< unsigned int >("-periods");
		} catch ( EmptyCommandLine err ) {
				cerr << argv[0] << " -input ... -output ... -dms ... -periods ..." << endl;
				return 1;
		} catch ( exception &err ) {
				cerr << err.what() << endl;
				return 1;
		}

		snrSpace = new float [nrDMs * nrPeriods];
		while ( ! searchFile.eof() ) {
				string temp;
				unsigned int splitPoint = 0;
				unsigned int DM = 0;
				unsigned int period = 0;
				float snr = 0.0f;

				getline(searchFile, temp);
				if ( ! isdigit(temp[0]) ) {
						continue;
				}
				splitPoint = temp.find(" ");
				period = castToType< string, unsigned int >(temp.substr(0, splitPoint));
				temp = temp.substr(splitPoint + 1);
				splitPoint = temp.find(" ");
				temp = temp.substr(splitPoint + 1);
				DM = castToType< string, unsigned int >(temp.substr(0, splitPoint));
				temp = temp.substr(splitPoint + 1);
				splitPoint = temp.find(" ");
				temp = temp.substr(splitPoint + 1);
				snr = castToType< string, float >(temp);

				if ( snr > maxSNR ) {
						maxSNR = snr;
				}
				if ( snr < minSNR ) {
						minSNR = snr;
				}

				snrSpace[(period * nrDMs) + DM] = snr;
		}
		searchFile.close();
		snrSpaceDim = maxSNR - minSNR;

		CImg< unsigned char > searchImage(nrDMs, nrPeriods, 1, 3);
		Color *colorMap = getColorMap();
		for ( unsigned int period = 0; period < nrPeriods; period++ ) {
				for ( unsigned int DM = 0; DM < nrDMs; DM++ ) {
						float snr = snrSpace[(period * nrDMs) + DM];
						searchImage(DM, period, 0, 0) = (colorMap[static_cast< unsigned int >(((snr - minSNR) * 256.0f) / snrSpaceDim)]).getR();
						searchImage(DM, period, 0, 1) = (colorMap[static_cast< unsigned int >(((snr - minSNR) * 256.0f) / snrSpaceDim)]).getG();
						searchImage(DM, period, 0, 2) = (colorMap[static_cast< unsigned int >(((snr - minSNR) * 256.0f) / snrSpaceDim)]).getB();
				}
		}
		searchImage.save(outFilename.c_str());

		return 0;
}<commit_msg>Catching exceptions by reference and freeing memory before returning.<commit_after>// Copyright 2014 <NAME> <<EMAIL>>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <iostream>
using std::cerr;
using std::endl;
#include <fstream>
using std::ifstream;
#include <exception>
using std::exception;
#include <string>
using std::string;
using std::getline;
#include <limits>
using std::numeric_limits;
#include <cctype>
using std::isdigit;
#include <CImg.h>
using cimg_library::CImg;

#include <ArgumentList.hpp>
using isa::utils::ArgumentList;
#include <ColorMap.hpp>
using AstroData::Color;
using AstroData::getColorMap;
#include <utils.hpp>
using isa::utils::castToType;
#include <Exceptions.hpp>
using isa::Exceptions::EmptyCommandLine;


int main(int argc, char * argv[]) {
		unsigned int nrDMs = 0;
		unsigned int nrPeriods = 0;
		float minSNR = numeric_limits< float >::max();
		float maxSNR = numeric_limits< float >::min();
		float snrSpaceDim = 0.0f;
		float * snrSpace = 0;
		string outFilename;
		ifstream searchFile;

		try {
				ArgumentList args(argc, argv);

				searchFile.open(args.getSwitchArgument< string >("-input"));
				outFilename = args.getSwitchArgument< string >("-output");
				nrDMs = args.getSwitchArgument< unsigned int >("-dms");
				nrPeriods = args.getSwitchArgument< unsigned int >("-periods");
		} catch ( EmptyCommandLine &err ) {
				cerr << argv[0] << " -input ... -output ... -dms ... -periods ..." << endl;
				return 1;
		} catch ( exception &err ) {
				cerr << err.what() << endl;
				return 1;
		}

		snrSpace = new float [nrDMs * nrPeriods];
		while ( ! searchFile.eof() ) {
				string temp;
				unsigned int splitPoint = 0;
				unsigned int DM = 0;
				unsigned int period = 0;
				float snr = 0.0f;

				getline(searchFile, temp);
				if ( ! isdigit(temp[0]) ) {
						continue;
				}
				splitPoint = temp.find(" ");
				period = castToType< string, unsigned int >(temp.substr(0, splitPoint));
				temp = temp.substr(splitPoint + 1);
				splitPoint = temp.find(" ");
				temp = temp.substr(splitPoint + 1);
				DM = castToType< string, unsigned int >(temp.substr(0, splitPoint));
				temp = temp.substr(splitPoint + 1);
				splitPoint = temp.find(" ");
				temp = temp.substr(splitPoint + 1);
				snr = castToType< string, float >(temp);

				if ( snr > maxSNR ) {
						maxSNR = snr;
				}
				if ( snr < minSNR ) {
						minSNR = snr;
				}

				snrSpace[(period * nrDMs) + DM] = snr;
		}
		searchFile.close();
		snrSpaceDim = maxSNR - minSNR;

		CImg< unsigned char > searchImage(nrDMs, nrPeriods, 1, 3);
		Color *colorMap = getColorMap();
		for ( unsigned int period = 0; period < nrPeriods; period++ ) {
				for ( unsigned int DM = 0; DM < nrDMs; DM++ ) {
						float snr = snrSpace[(period * nrDMs) + DM];
						searchImage(DM, period, 0, 0) = (colorMap[static_cast< unsigned int >(((snr - minSNR) * 256.0f) / snrSpaceDim)]).getR();
						searchImage(DM, period, 0, 1) = (colorMap[static_cast< unsigned int >(((snr - minSNR) * 256.0f) / snrSpaceDim)]).getG();
						searchImage(DM, period, 0, 2) = (colorMap[static_cast< unsigned int >(((snr - minSNR) * 256.0f) / snrSpaceDim)]).getB();
				}
		}
		searchImage.save(outFilename.c_str());

		delete [] snrSpace;
		return 0;
}
{'fraction_non_alphanumeric': 0.1469833985693076, 'fraction_numerical': 0.013767040086381428, 'mean_word_length': 3.4881889763779528, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1314336', 'n_tokens_mistral': 2882, 'n_tokens_neox': 2456, 'n_words': 726}