thread_found_image=1;// thread has just found an image
im_index=0;
im_position=chi_barycenter(&Tsup);
//printf("%d %d %d %f %f a %f %f b %f %f c %f %f \n",x_id*grid_dim+y_id,x_id,y_id,im_position.x,im_position.y,Tsupsource.a.x,Tsupsource.a.y,Tsupsource.b.x,Tsupsource.b.y,Tsupsource.c.x,Tsupsource.c.y);
im_dist[im_index]=chi_dist(im_position,images[index+im_index].center);// get the distance to the real image
for(inti=1;i<nimages_strongLensing[source_id];i++){// get the distance to each real image and keep the index of the closest real image
thread_found_image=1;// thread has just found an image
im_index=0;
im_position=chi_barycenter(&Tinf);// get the barycenter of the triangle
//printf("%d %d %d %f %f a %f %f b %f %f c %f %f \n",x_id*grid_dim+y_id,x_id,y_id,im_position.x,im_position.y,Tsupsource.a.x,Tsupsource.a.y,Tsupsource.b.x,Tsupsource.b.y,Tsupsource.c.x,Tsupsource.c.y);
im_dist[im_index]=chi_dist(im_position,images[index+im_index].center);// get the distance to the real image
for(inti=1;i<nimages_strongLensing[source_id];i++){// get the distance to each real image and keep the index of the closest real image
printf("WARNING: You are using SIE potentials. An image to close to one of the potential centers has been classified as numerical error and removed \n");
}
}
if(skip_image==0){
//checking whether a closest image has already been found
// Loop over all images in the set that are not yet allocated to a theoretical image
// and allocate the closest one
for(inti=0;i<nimages_strongLensing[source_id]&&nimagesfound[image_id][i]==0;i++)// we search for an observed image not already linked (nimagesfound=0)
{
if(im_dist[i]<im_dist[second_closest_id])
{
second_closest_id=i;
im_index=i;// im_index value changes only if we found a not linked yet image
tim[image_id][im_index]=temp;// if we found an observed and not already linked image, we allocate the theoretical image temp
}
}
nimagesfound[image_id][im_index]++;// increasing the total number of images found (If we find more than 1 theoretical image linked to 1 real image, these theoretical
// images are included in this number)
}
}
thread_found_image=0;// for next iteration
}
}
}
}
//////////////////////////////////////computing the local chi square//////////////////////////////////////
printf("WARNING: You are using SIE potentials. An image to close to one of the potential centers has been classified as numerical error and removed \n");
}
}
if(skip_image==0){
//checking whether a closest image has already been found
// Loop over all images in the set that are not yet allocated to a theoretical image
// and allocate the closest one
for(inti=0;i<nimages_strongLensing[source_id]&&nimagesfound[image_id][i]==0;i++)// we search for an observed image not already linked (nimagesfound=0)
{
if(im_dist[i]<im_dist[second_closest_id])
{
second_closest_id=i;
im_index=i;// im_index value changes only if we found a not linked yet image
tim[image_id][im_index]=temp;// if we found an observed and not already linked image, we allocate the theoretical image temp
}
}
nimagesfound[image_id][im_index]++;// increasing the total number of images found (If we find more than 1 theoretical image linked to 1 real image, these theoretical
// images are included in this number)
}
}
thread_found_image=0;// for next iteration
}
}
}
}
//////////////////////////////////////computing the local chi square//////////////////////////////////////