[fpc-pascal] sorting and merging array of records

waldo kitty wkitty42 at windstream.net
Tue Jan 10 22:02:17 CET 2012


On 1/10/2012 14:41, Sven Barth wrote:
> On 10.01.2012 20:12, waldo kitty wrote:
>> i don't know what this is pointing to because it is evidently not in my
>> sources but in a unit i'm loading... the actual compiler message is
>>
>> (750,50) Error: Operator is not overloaded
>> satsort.pas(434) Fatal: There were 1 errors compiling module, stopping
>> satsort.pas(0) Fatal: Compilation aborted
>>
>
> Oh damn it, I forgot about that.
>
> Is it possible for you to update to version 2.6? The problem is the following:
> the list I mentioned to you uses a equality operator ("=") of two values of the
> type you specialize with. Thus you need an overloaded operator in case of
> records. But you can't use a global overloaded operator (which you could do in
> FPC 2.4.5), as the specialization will only see those types, functions and
> operators that were visible when the generic (the TFPGList) was declared. So
> you'll need to use advanced records for that (which are only available from
> 2.6.0 on).

hummm... i may not need this specialization, then... i'm not comparing the 
entire record but portions of the fields in the records... i've made a few 
changes that should make this easier for me to do... let me show an example of 
an input record...

ISS (Zarya)
1 25544U 98067A   11355.91136867  .00021672  00000-0  28116-3 0  6701
2 25544  51.6441 296.4760 0024445 190.7247 276.2995 15.58432251750217


this breaks out like this...

line    columns  example          description
   0     1-24     ISS (Zarya)      common name

   1     1        1                element line number
   1     3-7      25545            catalog number
   1     8        U                elset classification
   1     10-17    98067A           international designator
   1     19-32    11355.91136867   epoch (UTC)
   1     34-43     .00021672       1st deriv of mean motion
   1     45-52     00000-0         2nd deriv of mean motion
   1     54-61     28116-3         B* drag term
   1     63       0                element set type
   1     65-68     670             element number
   1     69       1                checksum

   2     1        2                element line number
   2     3-7      25545            catalog number
   2     9-16      51.6441         orbit inclination
   2     18-25    296.4760         rt ascension acend node
   2     27-33    0024445          eccentricity
   2     35-42    190.7247         arg of perigee (degrees)
   2     44-51    276.2995         mean anomaly (degrees)
   2     53-63    15.58432251      mean motion (revs/day)
   2     64-68    75021            rev number at epoch
   2     69       3                checksum


so i now have the following to define the record... since i only need the 
catalog number to check for duplicates and the epoch to determine which one to 
keep, i've added those two fields to the record and pull them during the reading 
of the data (see Input_Satellite_List procedure below)...

type
   cat_nbr    = string[5];
   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;
                       catnbr  : cat_nbr;
                       epoch   : double;
                     end;


var
   aList      : TSatDataList;


[...]


Function IsSameReal(num1,num2 : double) : integer;

begin
   if (num1 < num2) then IsSameReal := -1
   else
     if (num1 = num2) then IsSameReal := 0
     else
       if (num1 > num2) then IsSameReal := 1;
end;

Function IsSameStr(str1,str2 : cat_nbr) : boolean;

begin
   IsSameStr := str1 = str2;
end;

Procedure Input_Satellite_List(var aInputFile: TextFile);

var
   data : three_line_data;
   dupe : boolean;
   i,x  : integer;

begin
   if not EOF(aInputFile) then
     begin
       Readln(aInputFile,data.satname);
       Readln(aInputFile,data.satdata[1]);
       Readln(aInputFile,data.satdata[2]);
       data.catnbr := Copy(data.satdata[1],3,5);
       data.epoch  := Real_Value(data.satdata[1],19,14);
       dupe := False;
       for i := 0 to aList.Count -1 do
         if IsSameStr(aList[i].catnbr,data.catnbr) then  // make the dupe check
           begin                        // if catnbrs are the same
             dupe := True;              // first mark dupe true
             x := IsSameReal(aList[i].epoch,data.epoch); // compare epochs
             case x of
              -1: begin                 // aList < data, replace with data
                    aList[i] := data;
                  end;
              0 : begin                 // aList = data, ignore data
                  end;
              1 : begin                 // aList > data, ignore data
                  end;
             end; {case}
           end; {if IsSameStr}
       if not dupe then
         aList.Add(data);               // not a dupe so add it
     end; {if not EOF}
end; {Procedure Input Satellite List}


with this not working like this i just need to shove them into a list or 
collection or something to hold them for more processing and then writing the 
list out to a plain 7bit ascii text file...

i'm not sure where the equality operator you speak of above comes from or why i 
need it in play :/

something else i need to make sure of is that this will compile on my OS/2 FPC 
2.4.2 since that is the environment it will be under when it goes production... 
unless, of course, there's a shiney new 0s2260full.zip file for me to play with ;)

this tool i'm working on is to replace an old DOS one with those old memory 
limits... that old tool takes 20+ minutes to process all the TLEs and then can 
only put 2797 of them in the output file when there are actually several hundred 
more that should be in there, too...

should i maybe continue to use an array like i was at first? is an array on the 
stack or heap? i tried doing something before with setlength to enlarge the 
array when a new record needed to be added but the sizes weren't right for some 
reason and it just kept ganking on me so i am coming at this from some other 
direction ;) is there something better, easier, faster to use?

[TRIM]
>
> Now you should be able to successfully specialize the TFPGList.
>
> If you can't update to 2.6.0:
> 1. I'd like to know why :)

as i wrote in another message, my windows' boxen update from SVN and every time 
i've tried to update FPC and make whatever, it breaks and i'm scared to break 
what i currently have working... i always have to blow the directory away, then 
svn it all back down, and then do the make thing... the ugly part is that i also 
have lazarus built with and using this svn'd version of FPC so i definitely do 
not want to be breaking that, either...

a second reason is i don't do the svn thing on the OS/2 box and so have to rely 
on an install package for that OS... the last time i did this, i unzipped 
os2242full.zip to /fpc and went from there... i recall having to manually 
configure a lot of stuff, though... include paths and the like... i still don't 
have the help working properly in any environment which greatly hampers things :/

> 2. You can then use the TList which is based on pointers (and requires a bit
> manual housekeeping, but I can help you here as well if you want)

TList? hummm... better? smaller? faster? easier to use? small memory footprint? 
i'm game to try things as long as it works in the end ;)

>> i don't know if this is because i wrote an IsSameStr function because i
>> could not find an IsSame one... i actually have two... one checks if two
>> string vars have the same string and the other checks if two double vars
>> have the same double... IsSameStr is boolean for true or false but
>> IsSameReal returns an integer of -1 (var1 < var2), 0 (var1 = var2) or 1
>> (var1 > var2)...
>
> The IsSame was merely a placeholder for a function that compares your two
> satellites records (and that you already seem to have created ;) )

that's what i thought :) i'm sure you saw them above?





More information about the fpc-pascal mailing list