Re: Need help with user-written routine in SOR$

briggs_at_encompasserve.org
Date: 01/04/05


Date: 4 Jan 2005 08:15:15 -0600

In article <EBce7tBhsjo5@eisner.encompasserve.org>, briggs@encompasserve.org writes:
> I take that to mean that
>
> ADRS1 is one record contents by reference
>
> ADRS2 is the other record contents by reference
>
> LENG1 is a 16 bit word containing the length of the one record by reference
>
> LENG2 is a 16 bit word containing the length of the other record by reference
>
> CNTX is an unininterpreted argument. The type and mechanism you choose
> when you pass it in SOR$BEGIN_SORT should match the ones you use when
> you retrieve it in your user equal routine.

Testing appears to confirm this. Minimal Fortran code based on the
above interpretation follows.

I did not try to push the envelope by trying to sort records larger than
32K bytes to test whether the length words were signed nor did I try
to sort records larger than 64K bytes to test whether the length could
occupy 32 bits rather than 16.

The context argument that I chose was longword 0 by value -- the default
for a missing argument. Probably I was over-paranoid there, specifying
it explicitly a couple places rather than consistently omitting it
everywhere.

        options /extend_source
        implicit none

        integer sor$begin_sort
        integer sor$pass_files
        integer sor$sort_merge
        integer sor$end_sort
        integer user_equal
        integer user_compare
        external user_equal
        external user_compare

        integer status

        status = sor$pass_files ( 'input.dat', 'output.dat' )
        if ( .not. status ) then
                type *, 'pass files failed'
                call sys$exit ( %val(status) )
        end if

        status = sor$begin_sort ( ,,,, user_compare, user_equal,,, )
        if ( .not. status ) then
                type *, 'begin sort failed'
                call sys$exit ( %val(status) )
        end if

        status = sor$sort_merge ( %val(0) )
        if ( .not. status ) then
                type *, 'sort merge failed'
                call sys$exit ( %val(status) )
        end if

        status = sor$end_sort ( %val(0) )
        if ( .not. status ) then
                type *, 'end sort failed'
                call sys$exit ( %val(status) )
        end if

        end

        integer function user_compare ( s1, s2, l1, l2, ctx )
        implicit none

        integer *2 l1, l2
        byte s1(l1), s2(l2)
        integer ctx

        integer i

        write ( 6, '(1x, a)' ) 'user compare'
        write ( 6, '(1x, i5, 1x, <l1>a)' ) l1, (char(s1(i)), i = 1, l1 )
        write ( 6, '(1x, i5, 1x, <l2>a)' ) l1, (char(s2(i)), i = 1, l2 )

        user_compare = 0
        return

        end

        integer function user_equal ( s1, s2, l1, l2, ctx )
        implicit none

        integer *2 l1, l2
        byte s1(l1), s2(l2)
        integer ctx

        integer i

        write ( 6, '(1x, a)' ) 'user equal'
        write ( 6, '(1x, i5, 1x, <l1>a)' ) l1, (char(s1(i)), i = 1, l1 )
        write ( 6, '(1x, i5, 1x, <l2>a)' ) l1, (char(s2(i)), i = 1, l2 )

        user_equal = 1
        return

        end

Given input file:

a
ab
abc
abcd
f

This displayed:

$ r test
user compare
    1 f
    4 abcd
user equal
    1 f
    4 abcd
user compare
    4 abcd
    3 abc
user equal
    4 abcd
    3 abc
user compare
    3 abc
    2 ab
user equal
    3 abc
    2 ab
user compare
    2 ab
    1 a
user equal
    2 ab
    1 a

Reasonable results. 4 comparisons and 4 equality tests to sort a 5
record file whose records all turned out to be "equal".

        John Briggs



Relevant Pages

  • Re: Unvollendetes read(STDIN_FILENO)
    ... Wenn ABC eine zusammenhängende Sequenz ist, ... einzelnes readgarantiert alles holt, also ABCD, und nicht ... mit einem generalisierten Terminal-Interface auskommt, ... fuer Unsinn Du Dir ausdenken kannst, um Deinen Unwillen, es richtig zu ...
    (de.comp.os.unix.programming)
  • Re: Unvollendetes read(STDIN_FILENO)
    ... aber der Beginn von ABCD, kann ich das nur beurteilen, wenn ein einzelnes ... wärs nur ABC. ... werden koennen, dass vom Sender die Einhaltung _definierter_ ...
    (de.comp.os.unix.programming)
  • Repost: DrawString and ellipsis problem ... please help
    ... I have a rectangle with a string inside and the user can drag the mouse ... a string "abcd" is progressively displayed as: ... abc... ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: File parsing
    ... Build an array or associatiave array... ... I can NOT read until the next occurance ot "abc"- abc 5 ...
    (comp.lang.awk)