For Programmers: Free Programming Magazines  


Home > Archive > Fortran > September 2005 > Re: Reduce Blanks challenge









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Reduce Blanks challenge
glen herrmannsfeldt

2005-08-22, 3:57 am

David Frank wrote:
(snip)

> My current solution that meets these revised specs, uses 3 statements:
>
> pad = char(0) ! allow pack to use null chars to pad its output
> a = Copy(line) ! copy line to char array
> outline = line(1:1) // Copy( PACK(a(2:), a(2:)/=' '.or.a(1:)/=' ',pad) )


There was, somewhere in this discussion the question about how
many passes through the array different solutions make.

Would someone like to tell me how many passes through the
array this one makes?

The array operators are nice, and PL/I has them, too, but sometimes
they can result in much more work being done than without array
operators.

-- glen

David Frank

2005-08-22, 7:57 am


"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:57CdnaTewo2W95TeRVn-gg@comcast.com...
> David Frank wrote:
> (snip)
>
>
> There was, somewhere in this discussion the question about how
> many passes through the array different solutions make.
>
> Would someone like to tell me how many passes through the
> array this one makes?
>


you sure you are not talking about Count_Items(line) challenge to make 1
pass thru line?

> The array operators are nice, and PL/I has them, too,


Can it array-slice as used above a(2:) ?


> they can result in much more work being done than without array
> operators.
>


I wouldnt say CVF does much more..

OK, Glen since I have found you to be one of the more rational folks
posting in comp.lang.pl1

I put it to you to arbitrate Giles and myself position.
He thinks his flag setting results:

1. in a faster solution than my 3 statements above, it doesnt, both run in
0.81 +-0.01 sec
2. he thinks his flag setting is more legible, but I violently disagree,
what do you think?

Sooo, have a look at below


include "strings.f90"
! --------------------
program test
use string_functions
character(40) :: line = ' the quick brown fox'
character(40) :: newline
real :: t1,t2

do
call cpu_time(t1)
do n = 1,1000000
newline = reduce_blanks(line) ! see: string_functions
end do
call cpu_time(t2)
write (*,91) 'frank ',t2-t1,' |',ctrim(newline),'|'

call cpu_time(t1)
do n = 1,1000000
newline = reduce_blanks_flag(line)
end do
call cpu_time(t2)
write (*,91) 'giles ',t2-t1,' |',ctrim(newline),'|'

read (*,*) ! <cr> repeat 2 tests above
end do
stop
91 format (a,f0.2,3a)
contains
! --------------------
function reduce_blanks_flag (line) result (outline)
character(*) :: line
character(LEN(line)) :: outline
character :: a(len(line)), pad(len(line))
logical :: flag(len(line))

pad = char(0) ; a = Copy(line)
flag = a == ' '
flag(2:) = .not.(flag(:len(line)-1) .and. flag(2:)) ! H O R R I F I C
flag(1) = .true.
outline = copy( pack(a, flag, pad) )

end function reduce_blanks_flag
end program


robin

2005-08-22, 9:57 pm


glen herrmannsfeldt wrote in message <57CdnaTewo2W95TeRVn-gg@comcast.com>...
>David Frank wrote:
>(snip)
>
>
>There was, somewhere in this discussion the question about how
>many passes through the array different solutions make.
>
>Would someone like to tell me how many passes through the
>array this one makes?


Absolutely NONE, because this code has an array bounds error
(incompatible arrays).


David Frank

2005-08-23, 7:57 am


"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
news:57CdnaTewo2W95TeRVn-gg@comcast.com...
> David Frank wrote:
> (snip)
>
> The array operators are nice, and PL/I has them, too, but sometimes
> they can result in much more work being done than without array
> operators.
>
> -- glen
>


And the reason you wont respond to my pointing out PL/I doesnt support array
sub-scripting IS ?
e.g. a(2:)

Folks, this is typical PLI'er clamming-up anytime I expose another Fortran
superiority fact that contradicts:
"PL/I has more power than Fortran-90" -- R. VOWELS PL/I -FAQ






robin

2005-08-23, 9:57 pm


David Frank wrote in message
<7OEOe.627$_84.612@newsread1.news.atl.earthlink.net>...
>
>"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
>news:57CdnaTewo2W95TeRVn-gg@comcast.com...
>
>And the reason you wont respond to my pointing out PL/I doesnt support array
>sub-scripting IS ?
>e.g. a(2:)
>
>Folks, this is typical PLI'er clamming-up anytime I expose another Fortran
>superiority fact that contradicts:
>"PL/I has more power than Fortran-90" -- R. VOWELS PL/I -FAQ



Some time back, I demonstrated to you in this forum that
you can do this style - a(2:) - in PL/I.


David Frank

2005-08-23, 9:57 pm


"robin" <robin_v@bigpond.com> wrote in message
news:S3POe.8483$FA3.4889@news-server.bigpond.net.au...
>
> David Frank wrote in message
> <7OEOe.627$_84.612@newsread1.news.atl.earthlink.net>...
>
>
> Some time back, I demonstrated to you in this forum that
> you can do this style - a(2:) - in PL/I.
>
>


Instead of saying you can do it and blathering on and on, just show us a
translation of below, how hard is that?

integer :: dog(10), cat(3)

dog(5:7) = cat

Show a array declaration and then array sub-scripting


robin

2005-08-24, 7:56 am


David Frank wrote in message ...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:S3POe.8483$FA3.4889@news-server.bigpond.net.au...
[color=darkred]
>Instead of saying you can do it and blathering on and on, just show us a
>translation of below, how hard is that?
>
>integer :: dog(10), cat(3)
>
>dog(5:7) = cat
>
>Show a array declaration and then array sub-scripting



I did this for you some time back, and see no need to repeat it.


robin

2005-09-15, 9:57 pm

David Frank wrote in message <7OEOe.627$_84.612@newsread1.news.atl.earthlink.net>...
>
>"glen herrmannsfeldt" <gah@ugcs.caltech.edu> wrote in message
>news:57CdnaTewo2W95TeRVn-gg@comcast.com...
>
>And the reason you wont respond to my pointing out PL/I doesnt support array
>sub-scripting IS ?
>e.g. a(2:)


I have demonstrated for you in this forum PL/I codes using this notation.

>Folks, this is typical PLI'er clamming-up anytime I expose another Fortran
>superiority fact that contradicts:
>"PL/I has more power than Fortran-90" -- R. VOWELS PL/I -FAQ


On the contrary, because PL/I can do this, and much more including
accepting Fortran source statements
intermixed with PL/I source (also demonstrated in this forum)
demonstrates the superiority of PL/I.




Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com