ordering integer array
  Home FAQ Contact Sign in
comp.lang.fortran only
 
Advanced search
POPULAR GROUPS

more...

comp.lang.fortran Profile…
 Up
ordering integer array         


Author: Ron Ford
Date: Aug 15, 2008 16:08

I have a program whose output is an array of integers.

implicit none

integer, parameter:: sides = 6
integer, parameter:: trials = 100

integer, dimension(sides)::A
integer, dimension(trials)::C
integer:: b, clock, seed, ii, i, counter, tab, penultimate
real:: harvest

! seed random num generator
CALL SYSTEM_CLOCK(COUNT=clock)
seed = clock + 37
CALL RANDOM_SEED(PUT = seed)

! prime the pump
call random_number(harvest)
b = 3 + nint(10*harvest)
do i=1,b
call random_number(harvest)
print *, i, harvest
end do
Show full article (2.82Kb)
48 Comments
Re: ordering integer array         


Author: dpb
Date: Aug 15, 2008 16:46

Ron Ford wrote:
> I have a program whose output is an array of integers.
>
> implicit none
...
> integer, dimension(trials)::C
...
> What is a slick way to order C?

Need a sort routine...(DOH! :) ).

Depending on the compiler you're using, it may or may not have an
extended intrinsic or compatibility sort module.

CVF has SORTQQ or QSORT; can't speak for others altho the lineage would
suggest Intel would. There are a myriad of sort routines available on
the 'net from Netlib and similar sources. One can also write a
braindead version relatively easily which would be adequate for
small-sized arrays...

--
no comments
Re: ordering integer array         


Author: e p chandler
Date: Aug 15, 2008 17:51

On Aug 15, 7:08 pm, Ron Ford wrote:
> I have a program whose output is an array of integers.
>
> implicit none
>
> integer, parameter:: sides = 6
> integer, parameter:: trials = 100
>
> integer, dimension(sides)::A
> integer, dimension(trials)::C
> integer:: b, clock, seed, ii, i, counter, tab, penultimate
> real:: harvest
>
> ! seed random num generator
> CALL SYSTEM_CLOCK(COUNT=clock)
> seed = clock + 37
> CALL RANDOM_SEED(PUT = seed)
>
> ! prime the pump
> call random_number(harvest) ...
Show full article (4.02Kb)
no comments
Re: ordering integer array         


Author: Ron Ford
Date: Aug 15, 2008 19:28

On Fri, 15 Aug 2008 18:46:58 -0500, dpb posted:
> Ron Ford wrote:
>> I have a program whose output is an array of integers.
>>
>> implicit none
> ...
>> integer, dimension(trials)::C
> ...
>> What is a slick way to order C?
>
> Need a sort routine...(DOH! :) ).
Show full article (1.05Kb)
no comments
Re: ordering integer array         


Author: dpb
Date: Aug 15, 2008 19:53

Ron Ford wrote:
...
> I was hoping for an intrinsic. minloc and maxloc won't help?
Hopes dashed, sorry... :)

One could cobble a solution up w/ minloc() and/or maxloc(), sure, but it
would be pretty ugly
-- repetitive calling minloc() on the array w/o the
preceding location included either by indexing and/or moving elements or
via MASK optional argument would yield a solution eventually, but it
would be pretty inefficient sort algorithm.

--
no comments
Re: ordering integer array         


Author: Ron Ford
Date: Aug 15, 2008 20:11

On Fri, 15 Aug 2008 21:53:30 -0500, dpb posted:
> Ron Ford wrote:
> ...
>> I was hoping for an intrinsic. minloc and maxloc won't help?
> Hopes dashed, sorry... :)
>
> One could cobble a solution up w/ minloc() and/or maxloc(), sure, but it
> would be pretty ugly -- repetitive calling minloc() on the array w/o the
> preceding location included either by indexing and/or moving elements or
> via MASK optional argument would yield a solution eventually, but it
> would be pretty inefficient sort algorithm.

Alright, well I'll do the keystrokes to implement MR&C's selection sort.
Since millions of particles have hit my retinas in the last hours, I can
promise a solition based on typing. It'll take me some time to find the
page again.

Fish, chips and 997 points of light,
--
What men value in this world is not rights but privileges. 7
H. L. Mencken
no comments
Re: ordering integer array         


Author: Ron Ford
Date: Aug 15, 2008 20:51

On Fri, 15 Aug 2008 17:51:58 -0700 (PDT), e p chandler posted:
> On Aug 15, 7:08 pm, Ron Ford wrote:
>> I have a program whose output is an array of integers.
>>
>> implicit none
>>
>> integer, parameter:: sides = 6
>> integer, parameter:: trials...
Show full article (4.60Kb)
no comments
Re: ordering integer array         


Author: Ron Ford
Date: Aug 17, 2008 11:49

On Fri, 15 Aug 2008 17:51:58 -0700 (PDT), e p chandler posted:
> On Aug 15, 7:08 pm, Ron Ford wrote:
>> I have a program whose output is an array of integers.
>>
>> implicit none
>>
>> integer, parameter:: sides = 6
>> integer, parameter:: trials...
Show full article (6.56Kb)
no comments
Re: ordering integer array         


Author: Ron Ford
Date: Aug 17, 2008 21:05

On Fri, 15 Aug 2008 17:51:58 -0700 (PDT), e p chandler posted:
> On Aug 15, 7:08 pm, Ron Ford wrote:
>> What is a slick way to order C?
>
> If you have a good upper bound on the values in C and it is small,
> then you can just throw each value into a bin as you generate it!

50 bins would suffice well for this sort. I use maxput to deal with the
outliers:

implicit none

integer, parameter:: sides = 6
integer, parameter:: trials = 100
integer, parameter:: bins = 100
integer, parameter:: percentile = 95

integer, dimension(sides)::A
integer, dimension(trials)::C
integer, dimension(bins)::D
integer:: b, clock, seed, ii, i, counter, &
tab, maxput, penultimate, goal
real:: harvest, tot
Show full article (2.77Kb)
no comments
Re: ordering integer array         


Author: e p chandler
Date: Aug 18, 2008 13:35

On Aug 18, 12:05 am, Ron Ford wrote:
> On Fri, 15 Aug 2008 17:51:58 -0700 (PDT), e p chandler posted:
>
>> On Aug 15, 7:08 pm, Ron Ford wrote:
>>> What is a slick way to order C?
>
>> If you have a good upper bound on the values in C and it is small,
>> then you can just throw each value into a bin as you generate it!
>
> 50 bins would suffice well for this sort.  I use maxput to deal with the
> outliers:
>
> implicit none
>
> integer, parameter:: sides = 6
> integer, parameter:: trials = 100
> integer, parameter:: bins = 100
> integer, parameter:: percentile = 95
>
> integer, dimension(sides)::A ...
Show full article (3.68Kb)
no comments
1 2 3 4 5