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

if it is binary value stored then you can read first 8 bytes in float variable and second 8 bytes in float variable i just dont see where you open different files or i dont understand

stored then you can read first 8 bytes in float varia

ohk, then i have to compare the given value from my ref file with the current file in the loop. More clearly,
in my ref file first column is x coordinates, say x1...xn. I take the first value x1 then check all the first columns of the database whether there is a value x such that (x1-1< x < x1+1) and record these x values in a file 1.list. Thus repeat for all the x2,x3... so on. Can you give me a hint how to go about this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.