Hey guys, I am having a small problem with my code, see below.
/***************************************************************
* RADAR_SYSTEM *
* VERSION: 1.1 *
* AUTHOR: 205123 *
* DATE: 23/03/04 * *
/**************************************************************/
#include <stdio.h>
#include "radar_gen.h"
#include <math.h>
int max_aircraft=2;
int main()
{
int i,j;
float aircraft_distance,aircraft_range,aircraft_x_pos,aircraft_y_pos,aircraft_altitude,e;
struct radar_data aircraft[30];
struct ship_data ship;
for(j=1; j<10; j++)
{
wait_for_next_scan(1.00);
for(i=1; i<=1; i++)
{
get_radar_data(&aircraft);
get_ship_data(&ship);
e=aircraft.elevation*(3.14/180);
aircraft_range=aircraft.range * 25/1000;
aircraft_distance=aircraft_range * cos(e);
aircraft_x_pos=ship.x_pos + aircraft_distance;
aircraft_y_pos=ship.y_pos - aircraft_distance * cos((ship.heading) + (aircraft.bearing));
aircraft_altitude= (sin(e) * aircraft_range)*1000;
//printf("-----------------------------------------------------------------");
//printf("\nShip Data:\n-----------------------------------------------------------------");
//printf("\nThe ship's heading is:\t\t|\t%lf km\t\t|\n",ship.heading);
//printf("\nThe ship's x pos is:\t\t|\t%lf km\t\t|\n",ship.x_pos);
//printf("\nThe ship's y pos is:\t\t|\t%lf km\t\t|\n\n",ship.y_pos);
//printf("-----------------------------------------------------------------");
printf("\nAircraft Data:\n\n");
printf("IFF Code\t|Altitude\t|X Position\t|Y Position |\n------------------------------------------------------------|\n");
printf("%d\t\t|%f\t|%f\t|%f |\n\n\n",aircraft.IFF_code,aircraft_altitude,aircraft_x_pos,aircraft_y_pos);
printf("%d\t\t|%f\t|%f\t|%f |\n\n\n",aircraft.IFF_code,aircraft_altitude,aircraft_x_pos,aircraft_y_pos);
//printf("\nThe aircraft's bearing is:\t|\t%lf degrees\t|\n",aircraft.bearing);
//printf("\nThe aircrafts range is:\t\t|\t%d range gates\t|\n",aircraft.range);
//printf("\nThe aircrafts elevation is:\t|\t%lf degrees\t|\n",aircraft.elevation);
//printf("\nThe aircrafts distance:\t\t|\t%f km\t\t|\n",aircraft_distance);
//printf("\nThe aircrafts IFF code is:\t|\t%d\t\t\t|\n",aircraft.IFF_code);
//printf("\nThe aircrafts x pos is:\t\t|\t%f km\t\t|\n",aircraft_x_pos);
//printf("\nThe aircrafts y pos is:\t\t|\t%f km\t\t|\n",aircraft_y_pos);
//printf("\nThe Aircrafts altitude is:\t|\t%f meters\t|\n",aircraft_altitude);
}
}
}
What the code does is reads from a file that provides radar data on aircrafs. Doing a few calculation, I can figure out the x, y positions of the planes and the altitude of them. Now because there can be more than one plane, (defined in Max_aircraft) you can get any number of up to 20 aircraft in one scan. What I am trying to do is display all the aircraft details in one table per scan. What I have got ay the moment is every scan, each aircraft details is displayed in a seprate table statrement. I am also trying to get it so the y cooridents are sorted in accending order, I now you have to use a bubble sort in the array, but am a little unsure how it is written in the code. If anyone has got any idea, I would be thankful.
Cheers