[fpc-pascal] sorting and merging array of records
waldo kitty
wkitty42 at windstream.net
Tue Jan 10 05:14:09 CET 2012
i have a li'l project i've been wanting to do for a really long time... as i'm
trying to do more and more with FPC, i've experimented a bit and found that i
should be able to handle this project much easier without the old DOS
limitations on memory usage and without having to use special stuff like
extended and expanded memory...
so, the basics are that i'm also an amateur satellite observer... i keep up with
the satellites via what's known as TLE (two line element) files... the ones i
use are actually three lines where the first line is the satellite's common
english name and the other two lines are the actual TLE element lines... there
are certain enforced limits on these lines... as such, i have defined a record
type
sat_name = string[25];
line_data = string[69];
two_line = array [1..2] of line_data;
three_line_data = record
satname : sat_name;
satdata : two_line;
end;
const
max_sats = 65536;
var
sat_data : array [1..max_sats] of three_line_data;
abuf : two_line;
new_data : three_line_data;
right now i'm loading the array via a simple readln into the array elements...
Procedure Input_Satellite(index : word);
begin
if not EOF(fsat) then
begin
Readln(fsat,sat_data[index].satname);
Readln(fsat,sat_data[index].satdata[1]);
Readln(fsat,sat_data[index].satdata[2]);
end; {if}
end; {Procedure Input_Satellite}
this is fine for the initial loading but i'm needing to read additional TLE
files and insert those records into the above array... my problem is that i need
the array sorted on a sectional value from sat_data[index].satdata[1]
sat_catnr := Copy(abuf[1],3,5);
and
new_catnr := Copy(abuf[1],3,5);
which are loaded and compared between sat_data[index].sat_data and new_data.sat_data
in the case of collisions (same catnr), i need to choose between the greater of
a pair of values from the stored record (sat_data) and the new record (new_data)
read from a file...
Function Real_Value(buffer : string;
start,length : integer) : double;
var
result : integer;
answer : double;
begin
buffer := Copy(buffer,start,length);
Convert_Blanks(buffer);
if buffer = '' then
buffer := '0';
Val(buffer,answer,result);
if result = 0 then
Real_Value := answer
else
Real_Value := 0.0;
end; {Function Real_Value}
via...
sat_epoch := Real_Value(abuf[1],19,14);
and
new_epoch := Real_Value(abuf[1],19,14);
which are loaded and compared between sat_data[index].satdata and
new_data.satdata...
my problem is that i cannot find any similar examples where an array of records
is built, sorted and duplicates are eliminated based on specific factors of the
two records being compared...
uncle has been failing me for the last several hours and i'm loosing sight of
what i'm trying to get done... i've seen references to using a tstringlinst as
well as something apparently non-existent called a tarray... in all of the stuff
i've seen on tstringlinst, there's nothing that i find that is close to what i'm
(thinking i'm) looking for... and here's where i keep getting diverted away from
the final goal due to trying to follow everything else :/
More information about the fpc-pascal
mailing list