i am trying to write a C program to do the following: i have a file which has x, y coordinates given as two columns. now the program has to take the first x,y pair i.e. from the first line and check a database of roughly 10,000 data files which again have x, y coordinates as first and second column respectively to see whether within a tolerance of 1.0 there are matches or not. i made a bash script earlier but it was too slow, so i'm attempting to write a C program.
here is the bash script:
#!/bin/bash
#---------Error values-----------#
error_x=1.0
error_y=1.0
s=1
#--------------------------------#
user_file="refstars.list"
user_file1="JD_N.list"
list=`echo *.ref`
user_num_line=`wc -l $user_file | awk '{print $1}'`
count=1
for (( user_line=1; user_line<=$user_num_line; user_line++ ))
do
user_x=`awk 'NR=='$user_line' {print $1}' $user_file`
user_y=`awk 'NR=='$user_line' {print $2}' $user_file`
x_low=`echo "$user_x - $error_x" | bc -l`
x_high=`echo "$user_x + $error_x" | bc -l`
y_low=`echo "$user_y - $error_y" | bc -l`
y_high=`echo "$user_y + $error_y" | bc -l`
for file in $list
do
z1=`awk '{if ($2 >= '$x_low' && $2 <= '$x_high' && $3 >= '$y_low' && $3 <= '$y_high') print $2}' $file`
z2=`awk '{if ($2 >= '$x_low' && $2 <= '$x_high' && $3 >= '$y_low' && $3 <= '$y_high') print $3}' $file`
z3=`awk '{if ($2 >= '$x_low' && $2 <= '$x_high' && $3 >= '$y_low' && $3 <= '$y_high') print $4}' $file`
z4=`awk '{if ($2 >= '$x_low' && $2 <= '$x_high' && $3 >= '$y_low' && $3 <= '$y_high') print $5}' $file`
echo "$file $z1 $z2 $z2 $z3 $z4 " >> $count.list
done
count=`echo "$count + $s" | bc -l`
done
exit 0
and here is the C program i'm attempting to write.
#include<stdio.h>
#include<math.h>
#include<string.h>
#include <stdlib.h>
int main()
{
FILE *file;
float col1[11000];
float col2[11000];
float curr_arr;
/* make sure it is large enough to hold all the data! */
int i, j;
float error_x, error_y;
int count, s;
file = fopen("/home/visi05/reference/refstars.list", "r");
if (file == NULL) {
//printf("Error: can't open file.\n");
return 1;
} else {
//printf("File opened successfully.\n");
i = 0;
while (!feof(file)) {
/* loop through and store the numbers into the array */
fscanf(file, "%f\t%f", &col1[i], &col2[i]);
i++;
}
}
printf("Number of coordinates read: %d\n\n", i);
for
printf ("%d", col1[500]);
fclose(file);
return 0;
}
please help