<commit_before>/**
 * reproject.c
 * Authors: <NAME> <<EMAIL>>
 * Date: {07/14/2017}
 */


#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#ifndef M_PI
#    define M_PI 3.14159265358979323846
#endif

int * pointIndexOnLat(double ** plat, double ** plon,  int * oriID, int *pcount, int nBlockY) {

	double *lat = *plat;
	double *lon = *plon;
	int count = *pcount;

	double blockR = M_PI/nBlockY;

	int * index;
	int * pointsInB;
	
	double * newLon;
	double * newLat;

	if(NULL == (index = (int *)malloc(sizeof(int) * (nBlockY + 1))))
	{
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	}

	if(NULL == (pointsInB = (int *)malloc(sizeof(int) * nBlockY)))
	{
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	}

	for(int i = 0; i < nBlockY; i++)
	{
		pointsInB[i] = 0;
	}

	int blockID;
		
	for(int i = 0; i < count; i++) {
	
		blockID = (int)((lat[i] + M_PI/2) / blockR);
		
		if(blockID >= 0 && blockID < nBlockY) {
			pointsInB[blockID] ++;
		}
	}

	index[0] = 0;
	for(int i = 1; i < nBlockY + 1; i++) {
		index[i] = index[i - 1] + pointsInB[i - 1];
	}

	if(NULL == (newLon = (double *)malloc(sizeof(double) * index[nBlockY]))) {
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	} 
	if(NULL == (newLat = (double *)malloc(sizeof(double) * index[nBlockY]))) {
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	}
	
	pointsInB[0] = 0;
	for(int i = 1; i < nBlockY; i++) {
		pointsInB[i] = index[i];
	}
	
	for(int i = 0; i < count; i++) {
		
		blockID = (int)((lat[i] + M_PI/2) / blockR);
		if(blockID >= 0 && blockID < nBlockY) {
			newLon[pointsInB[blockID]] = lon[i];
			newLat[pointsInB[blockID]] = lat[i];
			oriID[pointsInB[blockID]] = i;
			pointsInB[blockID] ++;
	
		}
	}
	


	free(pointsInB);
	free(lon);
	free(lat);

	count = index[nBlockY];
	*pcount = count;
	*plon = newLon;
	*plat = newLat;

//	printf("%0x\n", lat);

	return index;
}

//Finding the nearest neiboring point's ID 
void nearestNeighbor(double ** psouLat, double ** psouLon, int nSou, double * tarLat, double * tarLon, int * tarNNSouID, int nTar, double maxR) {

	//printf("%0x\n", souLat);
	double * souLat = *psouLat;
	double * souLon = *psouLon;

	const double earthRadius = 6367444;
	double radius = maxR / earthRadius;
	int nBlockY = M_PI / radius;

	double blockR = M_PI / nBlockY;
	

	for(int i = 0; i < nSou; i++) {
		souLat[i] = souLat[i] * M_PI / 180;
		souLon[i] = souLon[i] * M_PI / 180;
	}

	for(int i = 0; i < nTar; i++) {
		tarLat[i] = tarLat[i] * M_PI / 180;
		tarLon[i] = tarLon[i] * M_PI / 180;
	}

	int * souID;
	if(NULL == (souID = (int *)malloc(sizeof(double) * nSou))) {
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	}
	int * pnSou;
	pnSou = &nSou;
	int * souIndex = pointIndexOnLat(psouLat, psouLon, souID, pnSou, nBlockY);
	nSou = * pnSou;
	souLat = *psouLat;
	souLon = *psouLon;

	double tLat, tLon;
	double sLat, sLon;
	int blockID;
	int startBlock, endBlock;
<commit_msg>Minor changes<commit_after>/**
 * reproject.c
 * Authors: <NAME> <<EMAIL>>
 * Date: {07/14/2017}
 */


#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#ifndef M_PI
#    define M_PI 3.14159265358979323846
#endif

int * pointIndexOnLat(double ** plat, double ** plon,  int * oriID, int count, int nBlockY) {

	double *lat = *plat;
	double *lon = *plon;

	double blockR = M_PI/nBlockY;

	int * index;
	int * pointsInB;
	
	double * newLon;
	double * newLat;

	if(NULL == (index = (int *)malloc(sizeof(int) * (nBlockY + 1))))
	{
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	}

	if(NULL == (pointsInB = (int *)malloc(sizeof(int) * nBlockY)))
	{
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	}

	for(int i = 0; i < nBlockY; i++)
	{
		pointsInB[i] = 0;
	}

	int blockID;
		
	for(int i = 0; i < count; i++) {
	
		blockID = (int)((lat[i] + M_PI/2) / blockR);
		
		if(blockID >= 0 && blockID < nBlockY) {
			pointsInB[blockID] ++;
		}
	}

	index[0] = 0;
	for(int i = 1; i < nBlockY + 1; i++) {
		index[i] = index[i - 1] + pointsInB[i - 1];
	}

	if(NULL == (newLon = (double *)malloc(sizeof(double) * index[nBlockY]))) {
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	} 
	if(NULL == (newLat = (double *)malloc(sizeof(double) * index[nBlockY]))) {
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	}
	
	pointsInB[0] = 0;
	for(int i = 1; i < nBlockY; i++) {
		pointsInB[i] = index[i];
	}
	
	for(int i = 0; i < count; i++) {
		
		blockID = (int)((lat[i] + M_PI/2) / blockR);
		if(blockID >= 0 && blockID < nBlockY) {
			newLon[pointsInB[blockID]] = lon[i];
			newLat[pointsInB[blockID]] = lat[i];
			oriID[pointsInB[blockID]] = i;
			pointsInB[blockID] ++;
	
		}
	}
	


	free(pointsInB);
	free(lon);
	free(lat);

	count = index[nBlockY];
	*plon = newLon;
	*plat = newLat;

//	printf("%0x\n", lat);

	return index;
}

//Finding the nearest neiboring point's ID 
void nearestNeighbor(double ** psouLat, double ** psouLon, int nSou, double * tarLat, double * tarLon, int * tarNNSouID, int nTar, double maxR) {

	//printf("%0x\n", souLat);
	double * souLat = *psouLat;
	double * souLon = *psouLon;

	const double earthRadius = 6367444;
	double radius = maxR / earthRadius;
	int nBlockY = M_PI / radius;

	double blockR = M_PI / nBlockY;
	

	for(int i = 0; i < nSou; i++) {
		souLat[i] = souLat[i] * M_PI / 180;
		souLon[i] = souLon[i] * M_PI / 180;
	}

	for(int i = 0; i < nTar; i++) {
		tarLat[i] = tarLat[i] * M_PI / 180;
		tarLon[i] = tarLon[i] * M_PI / 180;
	}

	int * souID;
	if(NULL == (souID = (int *)malloc(sizeof(double) * nSou))) {
		printf("ERROR: Out of memory at line %d in file %s\n", __LINE__, __FILE__);
		exit(1);
	}
	int * souIndex = pointIndexOnLat(psouLat, psouLon, souID, nSou, nBlockY);
	souLat = *psouLat;
	souLon = *psouLon;

	double tLat, tLon;
	double sLat, sLon;
	int blockID;
	int startBlock, endBlock;

{'fraction_non_alphanumeric': 0.1827018121911038, 'fraction_numerical': 0.02471169686985173, 'mean_word_length': 3.444363103953148, 'pattern_counts': {'":': 0, '<': 33, '<?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': '1823986', 'n_tokens_mistral': 2895, 'n_tokens_neox': 2652, 'n_words': 646}