For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2005 > number of columns









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 number of columns
slyi.ath.cx

2005-07-28, 5:02 pm

Given an input text file of space separated number data (of same type
to make it simple), can you think of an elegant way to extract number
of columns in a given row? (using pure Fortran, of course)
- each EOL starts a new row
- every column is separated by at least one space -- can be more

slyi.

Duane Bozarth

2005-07-28, 5:02 pm

"slyi.ath.cx" wrote:
>
> Given an input text file of space separated number data (of same type
> to make it simple), can you think of an elegant way to extract number
> of columns in a given row? (using pure Fortran, of course)
> - each EOL starts a new row
> - every column is separated by at least one space -- can be more


Nothing real "elegant" comes to mind -- the straightforward algorithm is
to read the line, reduce multiple blanks to one, and then count embedded
blanks.
Dick Russell

2005-07-28, 5:02 pm

You might also play with EOR=label in the READ statement. You could
initialize a vector longer than the maximum number of items to be read
with a value that wouldn't be in the data, do the READ of that vector
with "*" as format spec, then count number of values assigned different
values by the READ. Two DO loops and a READ. I haven't actually used
EOR= before, so I can't say if what I am proposing would work. Let us
know if you do try it.

David Frank

2005-07-28, 5:02 pm


"slyi.ath.cx" <leventyilmaz@gmail.com> wrote in message
news:1122562099.851207.133200@o13g2000cwo.googlegroups.com...
> Given an input text file of space separated number data (of same type
> to make it simple), can you think of an elegant way to extract number
> of columns in a given row? (using pure Fortran, of course)
> - each EOL starts a new row
> - every column is separated by at least one space -- can be more
>
> slyi.
>


Elegant will have to await a compiler that supports the current standard,
but below aint too bad..

program test
integer :: values(40)
character(80) :: line

open (1,file='test.txt')
write (1,'(a)') '11 222 0 333 44444'
write (1,'(a)') '55 666 777, 888888 999'
rewind (1)
do
read (1,'(a)',end=101) line
n = 0 ! # values in line
do i = 1,79
if (line(i:i) /= ' '.and.line(i+1:i+1) == ' ') n = n+1
end do
read (line,*) values(1:n)
write (*,'(99(i0,1x))') values(1:n)
end do
101 stop
end program

! Outputs:
! 11 222 0 333 44444
! 55 666 777 888888 999


Dick Russell

2005-07-28, 5:02 pm

You might also play with EOR=label in the READ statement. You could
initialize a vector longer than the maximum number of items to be read
with a value that wouldn't be in the data, do the READ of that vector
with "*" as format spec, then count number of values assigned different
values by the READ. Two DO loops and a READ. I haven't actually used
EOR= before, so I can't say if what I am proposing would work. Let us
know if you do try it.

Dick Russell

2005-07-28, 5:02 pm

I should have tried it before speaking so quickly. The Lahey LF95 5.6
compiler complains of invalid combination of specifiers in the READ.
The manual says if EOR= is present, then ADVANCE='NO' must be present,
but ADVANCE can be used only with an explicit format expression. I
guess EOR= was intended for other things.

Duane Bozarth

2005-07-28, 5:02 pm

"slyi.ath.cx" wrote:
>
> Given an input text file of space separated number data (of same type
> to make it simple), can you think of an elegant way to extract number
> of columns in a given row? (using pure Fortran, of course)
> - each EOL starts a new row
> - every column is separated by at least one space -- can be more


Actually, if your definition of "pure Fortran" includes nonstandard
compiler extensions and your compiler of choice includes the "Q" edit
descriptor that returns the remaining number of characters in an input
line, that might provide a way to write a fairly neat function to count
the columns...

The thought would be to write a loop reading variables in and return the
remaining characters in the input line. As long as non-zero, there's
still at least one more column. When done the number of succssful reads
is the number of columns...
Rich Townsend

2005-07-28, 5:02 pm

Duane Bozarth wrote:
> "slyi.ath.cx" wrote:
>
>
>
> Nothing real "elegant" comes to mind -- the straightforward algorithm is
> to read the line, reduce multiple blanks to one, and then count embedded
> blanks.


Something like this would be quite easy to code up using the
ISO_VARYING_STRING part of the Fortran standard (and even easier once we
have the dynamic-length strings of F2003). Example code:

---CUT HERE--
program count_cols

use ISO_VARYING_STRING

implicit none

type(VARYING_STRING) :: line
integer :: len_line
integer :: len_prev
integer :: n_columns
integer :: i_blank

! Read a line of data

call GET(line)

! Reduce multiple blanks to single blank

len_prev = 0

reduce_loop : do

len_line = LEN(line)

if(len_line == len_prev) exit

line = REPLACE(line, ' ', ' ', EVERY=.TRUE.)

len_prev = len_line

end do reduce_loop

! Strip leading and trailing blanks

line = TRIM(ADJUSTL(line))

! Count the number of columns, by counting blanks

if(line /= '') then

n_columns = 1

count_loop : do

i_blank = INDEX(line, ' ')

if(i_blank == 0) exit count_loop

line = EXTRACT(line, START=i_blank+1)

n_columns = n_columns + 1

end do count_loop

else

n_columns = 0

endif

print *, 'Columns:', n_columns

end program count_cols
---CUT HERE---

Source code for the ISO_VARYING_STRING module can be downloaded from my
website here:

http://www.star.ucl.ac.uk/~rhdt/download/#iso

cheers,

Rich
Colin Watters

2005-07-29, 5:05 pm

Yes not too bad, but fails on edge effects.
If a line starts with a blank, or ends with a non-blank ...
could be fixed by reading into the middle of line, i.e.:

line = ' '
read (1,'(a)',end=101) line(2:79)

--
Qolin

Email: my qname at domain
Domain: qomputing dot demon dot co dot uk

"David Frank" <dave_frank@hotmail.com> wrote in message
news:3N8Ge.18487$aY6.12383@newsread1.news.atl.earthlink.net...
>
> "slyi.ath.cx" <leventyilmaz@gmail.com> wrote in message
> news:1122562099.851207.133200@o13g2000cwo.googlegroups.com...
>
> Elegant will have to await a compiler that supports the current standard,
> but below aint too bad..
>
> program test
> integer :: values(40)
> character(80) :: line
>
> open (1,file='test.txt')
> write (1,'(a)') '11 222 0 333 44444'
> write (1,'(a)') '55 666 777, 888888 999'
> rewind (1)
> do
> read (1,'(a)',end=101) line
> n = 0 ! # values in line
> do i = 1,79
> if (line(i:i) /= ' '.and.line(i+1:i+1) == ' ') n = n+1
> end do
> read (line,*) values(1:n)
> write (*,'(99(i0,1x))') values(1:n)
> end do
> 101 stop
> end program
>
> ! Outputs:
> ! 11 222 0 333 44444
> ! 55 666 777 888888 999
>
>



David Frank

2005-07-30, 4:01 am


"Colin Watters" <qolin.see_signature@nowhere.co.uk> wrote in message
news:dce6tj$dm3$1$8300dec7@news.demon.co.uk...
> Yes not too bad, but fails on edge effects.
> If a line starts with a blank, or ends with a non-blank ...
> could be fixed by reading into the middle of line, i.e.:
>
> line = ' '
> read (1,'(a)',end=101) line(2:79)
>
> --
> Qolin
>


Your "fix" hasnt fixed anything
1. There is NO problem with lines starting with a blank, as shown with
revised text file generation below.
2. If line length (80) allotted encounters a line that has a char in column
80 then my program fails to detect a "last value"
OTOH, your "fix" above has read in even fewer chars (79) and has ALSO
failed with that line.

Solution:
We both assume its possible to declare line > than file's max record length,
if 80 is too short then substitute 800.

And, your line = ' ' does nothing.
if line allotted is long enuf, than we are guaranteed a trailing blank
detection of last value by
read (1,'(a)') line
since Fortran reads are blanking line's trailing chars beyond shorter length
file records being input.

As always the programmer has to know what the program is dealing with
data-wise, in F2003 this particular problem
goes away by declaring line has varying length.
character(:),allocatable :: line

! ---------------------
program test
integer :: values(40)
character(80) :: line
open (1,file='test.txt')
write (1,'(a)') ' 11 222 0 333 44444' ! gen. leading blanks
write (1,'(a)') ' 55 666 777, 888888 999'
rewind (1)
do
read (1,'(a)',end=101) line
n = 0 ! # values in line
do i = 1,79
if (line(i:i) /= ' '.and.line(i+1:i+1) == ' ') n = n+1
end do
read (line,*) values(1:n)
write (*,'(99(i0,1x))') values(1:n)
end do
101 stop
end program

Outputs:
11 222 0 333 44444
55 666 777 888888 999




David Frank

2005-07-30, 9:01 am

Colin,
Here is my solution #2,
IMO, no-one else has proposed (let alone shown code for) anything that will
work..

! --------------------
program test
integer,parameter :: maxneg = #80000000
integer :: v(40)
character(80) :: s

open (1,file='test.txt')
write (1,'(a)') '11 222 0 333 44444'
write (1,'(a)') ' 55 666 777, 888888 999'
rewind (1)

do
read (1,'(a)',end=101) s
s = s(1:len_trim(s)) // ' ' // char(0) ! null terminates list read (CVF
only?)
v = maxneg
read (s,*,err=1) v
1 do n = 1,40
if (v(n) == maxneg) exit
end do
write (*,'(40(i0,1x))') v(1:n-1)
end do
101 stop
end program


Rich Townsend

2005-07-30, 5:01 pm

David Frank wrote:
> Colin,
> Here is my solution #2,
> IMO, no-one else has proposed (let alone shown code for) anything that will
> work..


My post from two days shows code that works and doesn't suffer from the
edge effects that your #1 solution did. I assume you have simply missed it.

cheers,

Rich
David Frank

2005-07-31, 9:00 am


"Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
news:dcgl77$dj4$1@scrotar.nss.udel.edu...
> David Frank wrote:
>
> My post from two days shows code that works and doesn't suffer from the
> edge effects that your #1 solution did. I assume you have simply missed
> it.
>
> cheers,
>
> Rich


I have already replied saying there are no edge effects, only a decision
selecting file's max record length.

IMO, your large varying module solution is living on borrowed time and I
cant get interested in coding something
thats obsolete when next round of compilers are released and when there are
adequate work-arounds with F95
and CVF.

Btw,
I have added a 3rd solution that reads the file char_by_char plus congealed
solutions 1,2 into subroutines called by a numdec.f90 test program thus
documenting my recent efforts to this problem with real test numbers.
Note the char_by_char solution has no fixed limits to numbers,chars per
record.
Like I said, Fortran almost always provides multiple techniques to achieve a
solution.

see:
http://home.earthlink.net/~dave_gemini/numdec.f90


slyi.ath.cx

2005-08-02, 9:10 am

The solutions here were very useful.
Thank you all!!

- slyi

robin

2005-08-11, 10:01 pm


David Frank wrote in message ...
>A "Sly one" asks in comp.lang.fortran topic "number of columns""
>" Given an input text file of space separated number data (of same type
>" to make it simple), can you think of an elegant way to extract number
>" of columns in a given row? (using pure Fortran, of course)
>"- each EOL starts a new row
>" - every column is separated by at least one space -- can be more
>" slyi.
>
>After several replies with no working results posted (including from poster
>below),
>yours truly has provided not one, but 3 solutions with results.
>Of course you pli'ers would have difficulty in translating any of my
>solutions and will respond,



It's trivial in PL/I.

get edit (s)) (l);
n = 1 + TALLY(TRIM(S), ' ') - TALLY(TRIM(S), ' ');


robin

2005-08-11, 10:01 pm


David Frank wrote in message ...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:i3wKe.78730$oJ.69943@news-server.bigpond.net.au...
>
>I have added a Tally string function to my string_functions module
>(strings.f90 file)
>and immediately found a case where it produces a wrong count of items in
>list.
>Try my offending string with your tally.
>
>include 'strings.f90' !
>http://home.earthlink.net/~dave_gemini/strings.f90
>! ---------------------
>program check_tally
>use string_functions
>
>! count columns
>write (*,*) 1 + tally('123',' ') - tally('123',' ') ! = 1
>write (*,*) 1 + tally(' 123 ',' ') - tally(' 123 ',' ') ! = 3 shud =
>1
>write (*,*) 1 + tally('1 2 3 ',' ') - tally('1 2 3',' ') ! = 3
>end program


If you look closely at the PL/I assignment statement,
you will see your mistake.


David Frank

2005-08-11, 10:01 pm


"robin" <robin_v@bigpond.com> wrote in message
news:KYQKe.81327$oJ.16615@news-server.bigpond.net.au...
>
>
> If you look closely at the PL/I assignment statement,
> you will see your mistake.


do you agree pl/i tally shud return a count = 2 for following?
tally('xxx', 'xx')



David Frank

2005-08-12, 9:01 am


"robin" <robin_v@bigpond.com> wrote in message
news:KYQKe.81327$oJ.16615@news-server.bigpond.net.au...
>
> David Frank wrote in message ...
>
> If you look closely at the PL/I assignment statement,
> you will see your mistake.
>
>


But you wont ACTUALLY create a test program IDENTICAL in function to below,
why not?
If you say my TALLY is wrong, then
as a Fortran book author, you MUST know how to make it give same output ==
PL/I tally..

! ---------------------
program check_tally ! count of items in strings
character(40) :: lines(3) = ['123', ' 123', '1 2 3']

do n = 1,3
n1 = tally(trim(lines(n)),' ')
n2 = tally(trim(lines(n)),' ')
write (*,*) n1, n2, 1+n1-n2
end do

! 0 0 1 correct
! 2 1 2 wrong
! 3 1 3 correct

stop
contains
! --------------------
INTEGER FUNCTION Tally (line,s)
CHARACTER(*) :: line, s
INTEGER :: i

Tally = 0
DO i = 1,LEN(line)-LEN(s)+1
IF (line(i:i+LEN(s)-1) == s) Tally = Tally+1
END DO
END FUNCTION Tally

end program


robin

2005-08-12, 10:32 pm

From: David Frank <dave_frank@hotmail.com>
Date: Friday, 12 August 2005 4:57


| "robin" <robin_v@bigpond.com> wrote in message
news:KYQKe.81327$oJ.16615@news-server.bigpond.net.au...

|> David Frank wrote in message ...

|>>"robin" <robin_v@bigpond.com> wrote in message
|>>news:i3wKe.78730$oJ.69943@news-server.bigpond.net.au...
|>>>
|>>> David Frank wrote in message
|>>> <23uKe.3570$RZ2.1613@newsread3.news.atl.earthlink.net>...
|>>>>
|>>>>"robin" <robin_v@bigpond.com> wrote in message
|>>>>news:FthKe.78174$oJ.41379@news-server.bigpond.net.au...
|>>>>>
|>>>>> It's trivial in PL/I.
|>>>>>
|>>>>> n = 1 + TALLY(TRIM(S), ' ') - TALLY(TRIM(S), ' ');
|>>>
|>>>>I bet I am not alone is thinking that
|>>>>n = 1 + xx - xx = 1 which is not a count of columns
|>>>
|>>> If you look carefully t the code you will see that it is not
|>>> 1 + xx - xx.
|>>> One string constant has one blank ; the other has two blanks.
|>>
|>>I have added a Tally string function to my string_functions module
|>>(strings.f90 file)
|>>and immediately found a case where it produces a wrong count of items in
|>>list.
|>>Try my offending string with your tally.
|>>
|>>include 'strings.f90' !
|>>http://home.earthlink.net/~dave_gemini/strings.f90
|>>! ---------------------
|>>program check_tally
|>>use string_functions
|>>
|>>! count columns
|>>write (*,*) 1 + tally('123',' ') - tally('123',' ') ! = 1
|>>write (*,*) 1 + tally(' 123 ',' ') - tally(' 123 ',' ') ! = 3 shud =1
|>>write (*,*) 1 + tally('1 2 3 ',' ') - tally('1 2 3',' ') ! = 3
|>>end program

|> If you look closely at the PL/I assignment statement,
|> you will see your mistake.

|But you wont ACTUALLY create a test program IDENTICAL in function to below,
|why not?

Why would I write code to implement your wrong solution?
when I have written one that provides the correct solution?

I already told you what is wrong with your code.
Since then, all you have done is to put in another mistake in your code.

|If you say my TALLY is wrong, then
|as a Fortran book author, you MUST know how to make it give same output ==
|PL/I tally..

|! ---------------------
|program check_tally ! count of items in strings
|character(40) :: lines(3) = ['123', ' 123', '1 2 3']

|do n = 1,3
| n1 = tally(trim(lines(n)),' ')
| n2 = tally(trim(lines(n)),' ')
| write (*,*) n1, n2, 1+n1-n2
|end do
|
|! 0 0 1 correct
|! 2 1 2 wrong
|! 3 1 3 correct

|stop
|contains
|! --------------------
|INTEGER FUNCTION Tally (line,s)
|CHARACTER(*) :: line, s
|INTEGER :: i

|Tally = 0
|DO i = 1,LEN(line)-LEN(s)+1
| IF (line(i:i+LEN(s)-1) == s) Tally = Tally+1
|END DO
|END FUNCTION Tally

|end program


gerard46

2005-08-13, 4:00 am

| robin wrote:
|> David Frank wrote:
|| robin wrote:
||> David Frank wrote in message ...
||>>robin wrote:
|||>>> David Frank:
||>>>>robin wrote:
||>>>>> It's trivial in PL/I.
||>>>>>
||>>>>> n = 1 + TALLY(TRIM(S), ' ') - TALLY(TRIM(S), ' ');

||>>>>I bet I am not alone is thinking that
||>>>>n = 1 + xx - xx = 1 which is not a count of columns

||>>> If you look carefully t the code you will see that it is not
||>>> 1 + xx - xx.
||>>> One string constant has one blank ; the other has two blanks.

||>>I have added a Tally string function to my string_functions module
||>>(strings.f90 file)
||>>and immediately found a case where it produces a wrong count of items in
||>>list.
||>>Try my offending string with your tally.

||>>include 'strings.f90' !
||>>http://home.earthlink.net/~dave_gemini/strings.f90
||>>! ---------------------
||>>program check_tally
||>>use string_functions
||>>
||>>! count columns
||>>write (*,*) 1 + tally('123',' ') - tally('123',' ') ! = 1
||>>write (*,*) 1 + tally(' 123 ',' ') - tally(' 123 ',' ') ! = 3 shud =1
||>>write (*,*) 1 + tally('1 2 3 ',' ') - tally('1 2 3',' ') ! = 3
||>>end program

||> If you look closely at the PL/I assignment statement,
||> you will see your mistake.
|
||But you wont ACTUALLY create a test program IDENTICAL in function to below,
||why not?

| Why would I write code to implement your wrong solution?
| when I have written one that provides the correct solution?
|
| I already told you what is wrong with your code.
| Since then, all you have done is to put in another mistake in your code.
|
||If you say my TALLY is wrong, then
||as a Fortran book author, you MUST know how to make it give same output ==
||PL/I tally..
|
||! ---------------------
||program check_tally ! count of items in strings
||character(40) :: lines(3) = ['123', ' 123', '1 2 3']
|
||do n = 1,3
|| n1 = tally(trim(lines(n)),' ')
|| n2 = tally(trim(lines(n)),' ')
|| write (*,*) n1, n2, 1+n1-n2
||end do
||
||! 0 0 1 correct
||! 2 1 2 wrong
||! 3 1 3 correct
|
||stop
||contains
||! --------------------
||INTEGER FUNCTION Tally (line,s)
||CHARACTER(*) :: line, s
||INTEGER :: i
|
||Tally = 0
||DO i = 1,LEN(line)-LEN(s)+1
|| IF (line(i:i+LEN(s)-1) == s) Tally = Tally+1
||END DO
||END FUNCTION Tally
|
||end program

Frank, Frank,Frank. You are confusting the PL/1 TRIM
function with the Fortran TRIM function. PL/1's TRIM
function removes both leading and trailing blanks, and
Fortran's TRIM function only removes the trailing blanks.

Does anyone else in this newsgroup think this Fortran
cra... er, discussion is totally bogus ? With this
level of Fortran coding, I'm beginning to think that
Frank's experienced Fortran programming leaves a LOT to
be desired. ___________________________________Gerar
d S.








David Frank

2005-08-13, 9:01 am

"gerard46" <gerard46@rtt.net> wrote in message
news:yaydnUNegccV6GDfRVn-1A@onvoy.com...

> Frank, Frank,Frank. You are confusting the PL/1 TRIM
> function with the Fortran TRIM function. PL/1's TRIM
> function removes both leading and trailing blanks, and
> Fortran's TRIM function only removes the trailing blanks.
>
> Does anyone else in this newsgroup think this Fortran
> cra... er, discussion is totally bogus ? With this
> level of Fortran coding, I'm beginning to think that
> Frank's experienced Fortran programming leaves a LOT to
> be desired. ___________________________________Gerar
d S.
>


Why did IBM adopt such arcane WRONG TRIM syntax,
99.44% of the time users want to just truncate a string.

Below is my equivalent Fortran1 liner to count number of columns

! ---------------------
include "strings.f90" ! http://home.earthlink.net/~dave_gemini/strings.f90
program demo_tally ! 1 statement count of items in string
use string_functions

character(40) :: s = '1 2 3 4 5'

write (*,*) '#cols= ', 1 + tally(trim(adjustl(s)),' ') -
tally(trim(adjustl(s)),' ')
end program


robin

2005-08-13, 5:01 pm


David Frank wrote in message ...
>
>"Tim Challenger" <tim.challenger@aon.at> wrote in message
>news:1123834414. cd944ada7721aa06519379328dd16a20@teranew
s...
>
>Yes, I am right and ALL you pli'ers are wrong, tally cant be used since
>BY INSPECTION
> " 123" scanned with 1 blank returns 2, scanned with 2 blanks
>returns 1
> thus the result 1+2-1 = 2 is WRONG there is 1 item in the list.



That's because your program is wrong, and you haven't
fixed it yet.


gerard46

2005-08-13, 5:01 pm

| David Frank wrote:
|> gerard46 wrote:
|> Frank, Frank,Frank. You are confusting the PL/1 TRIM
|> function with the Fortran TRIM function. PL/1's TRIM
|> function removes both leading and trailing blanks, and
|> Fortran's TRIM function only removes the trailing blanks.
|>
|> Does anyone else in this newsgroup think this Fortran
|> cra... er, discussion is totally bogus ? With this
|> level of Fortran coding, I'm beginning to think that
|> Frank's experienced Fortran programming leaves a LOT to
|> be desired. ___________________________________Gerar
d S.

| Why did IBM adopt such arcane WRONG TRIM syntax,
| 99.44% of the time users want to just truncate a string.

Frank, Frank, Frank. It's a poor workman who blames his
tools.

Know thy tools that you are working with.

I don't feel that TRIM should only work on the right
side of a string. When I ask the butcher to trim a
piece of meat (of fat), I don't expect him to only
do the right side. TRIM is supposed to, er... trim
blanks. PL/1's TRIM (to me) is more intuitive. But
in any case, one should know what a function does
when using that function. .... And don't eat the
yellow snow. _________________________________Gerard S.




David Frank

2005-08-13, 5:01 pm


"gerard46" <gerard46@rtt.net> wrote in message
news:-rSdnU3A5tKwhGPfRVn-3g@onvoy.com...
>| David Frank wrote:
> |> gerard46 wrote:
> |> Frank, Frank,Frank. You are confusting the PL/1 TRIM
> |> function with the Fortran TRIM function. PL/1's TRIM
> |> function removes both leading and trailing blanks, and
> |> Fortran's TRIM function only removes the trailing blanks.
> |>
> |> Does anyone else in this newsgroup think this Fortran
> |> cra... er, discussion is totally bogus ? With this
> |> level of Fortran coding, I'm beginning to think that
> |> Frank's experienced Fortran programming leaves a LOT to
> |> be desired. ___________________________________Gerar
d S.
>
> | Why did IBM adopt such arcane WRONG TRIM syntax,
> | 99.44% of the time users want to just truncate a string.
>
> Frank, Frank, Frank. It's a poor workman who blames his
> tools.
>
> Know thy tools that you are working with.
>
> I don't feel that TRIM should only work on the right
> side of a string. When I ask the butcher to trim a
> piece of meat (of fat), I don't expect him to only
> do the right side. TRIM is supposed to, er... trim
> blanks. PL/1's TRIM (to me) is more intuitive. But
> in any case, one should know what a function does
> when using that function. .... And don't eat the
> yellow snow. _________________________________Gerard S.
>



I dont blame available Fortran syntax, I blame myself for not knowing all of
its uses...
e.g. below is a Fortran 1-line solution that uses the count function, can
this be 1-line translated to PL/I using its count function?

! ------------
program tally
character(20) :: s = ' 1 2 333' ! allocated len must be > len_trim(s)

write (*,*) count([(s(i:i) /= ' '.and.s(i+1:i+1) == ' ',i=1,len_trim(s))])
! outputs: 3
end program


Rich Townsend

2005-08-13, 5:01 pm

David Frank wrote:
> "gerard46" <gerard46@rtt.net> wrote in message
> news:-rSdnU3A5tKwhGPfRVn-3g@onvoy.com...
>
>
>
>
> I dont blame available Fortran syntax, I blame myself for not knowing all of
> its uses...
> e.g. below is a Fortran 1-line solution that uses the count function, can
> this be 1-line translated to PL/I using its count function?
>
> ! ------------
> program tally
> character(20) :: s = ' 1 2 333' ! allocated len must be > len_trim(s)
>
> write (*,*) count([(s(i:i) /= ' '.and.s(i+1:i+1) == ' ',i=1,len_trim(s))])
> ! outputs: 3
> end program
>
>


In the last iteration of the implied do loop, s(i+1:i+1) is an
out-of-range substring. I believe this is a bug.

cheers,

Rich
Rich Townsend

2005-08-13, 5:01 pm

Rich Townsend wrote:
> David Frank wrote:
>
>
> In the last iteration of the implied do loop, s(i+1:i+1) is an
> out-of-range substring. I believe this is a bug.


Scratch that, I missed the comment on the declaration of s

cheers,

Rich
James Van Buskirk

2005-08-13, 5:01 pm

"Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
news:ddla1h$gp8$1@scrotar.nss.udel.edu...

> Scratch that, I missed the comment on the declaration of s


Then it's a bug in the function predicate. C'mon, you guys can
fix this up easy enough...

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


David Frank

2005-08-13, 5:01 pm


"James Van Buskirk" <not_valid@comcast.net> wrote in message
news:XumdnZEQg8S8oWPfRVn-gg@comcast.com...
> "Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
> news:ddla1h$gp8$1@scrotar.nss.udel.edu...
>
>
> Then it's a bug in the function predicate. C'mon, you guys can
> fix this up easy enough...
>


You got me, detecting column start instead of column end doesnt work if
column 1 is not blank



James J. Weinkam

2005-08-13, 5:01 pm

David Frank wrote:

.....

>
> Why did IBM adopt such arcane WRONG TRIM syntax,
> 99.44% of the time users want to just truncate a string.
>


As usual you display your ignorance. As you have been told repeatedly, you
should study the manual and learn PL/I before you try to criticize it. There
are quite a few things about PL/I that can be legitimately criticized, but you
have to do it from a base of knowledge rather than ignorance if you want to be
taken seriously.

In the case of trim, you are complaining about what you believe to be the
semantics of trim, not the syntax, and you are doing so without knowing the full
capabilities of PL/I's TRIM function.

For example TRIM(s,', ',', ') trims both commas and spaces from both the
beginning and end of s, while TRIM(s,'') trims blanks from the end and nothing
from the beginning. I'll leave the rest to your private research in the manual.
robin

2005-08-13, 10:00 pm


David Frank wrote in message ...
>"gerard46" <gerard46@rtt.net> wrote in message
>news:yaydnUNegccV6GDfRVn-1A@onvoy.com...
>
>
>Why did IBM adopt such arcane WRONG TRIM syntax,
>99.44% of the time users want to just truncate a string.



That's exactly what the PL/I TRIM function does -
namely truncate a string.
You have the choice of truncating the end, truncating the
beginning, or both.

>Below is my equivalent Fortran1 liner to count number of columns



The PL/I TALLY function is builtin. Yours is hand coded,
so your solution is not a one-liner, but ten-liner.


robin

2005-08-14, 9:00 am

From: David Frank <dave_frank@hotmail.com>
Date: Saturday, 13 August 2005 9:29

|"gerard46" <gerard46@rtt.net> wrote in message
news:-rSdnU3A5tKwhGPfRVn-3g@onvoy.com...
|>| David Frank wrote:
|> |> gerard46 wrote:
|> |> Frank, Frank,Frank. You are confusting the PL/1 TRIM
|> |> function with the Fortran TRIM function. PL/1's TRIM
|> |> function removes both leading and trailing blanks, and
|> |> Fortran's TRIM function only removes the trailing blanks.
|> |>
|> |> Does anyone else in this newsgroup think this Fortran
|> |> cra... er, discussion is totally bogus ? With this
|> |> level of Fortran coding, I'm beginning to think that
|> |> Frank's experienced Fortran programming leaves a LOT to
|> |> be desired. ___________________________________Gerar
d S.

|> | Why did IBM adopt such arcane WRONG TRIM syntax,
|> | 99.44% of the time users want to just truncate a string.

The syntax of TRIM in PL/I is - in its simplest form - exactly the
same as that of Fortran.
The TRIM function in Fortran is actually a truncate function,
so it perhaps should have been more appropriately named TRUNCATE.
The TRIM function in PL/I is appropriately named because
it may remove from both ends.

|> Frank, Frank, Frank. It's a poor workman who blames his
|> tools.
|>
|> Know thy tools that you are working with.
|>
|> I don't feel that TRIM should only work on the right
|> side of a string. When I ask the butcher to trim a
|> piece of meat (of fat), I don't expect him to only
|> do the right side. TRIM is supposed to, er... trim
|> blanks. PL/1's TRIM (to me) is more intuitive. But
|> in any case, one should know what a function does
|> when using that function. .... And don't eat the
|> yellow snow. _________________________________Gerard S.

|I dont blame available Fortran syntax, I blame myself for not knowing all of
|its uses...
|e.g. below is a Fortran 1-line solution that uses the count function, can
|this be 1-line translated to PL/I using its count function?

I already have.
Recall n = 1 - TALLY(TRIM(s), ' ') - TALLY(TRIM(s), ' '); ?
The corresponding PL/I function is called TALLY.

|! ------------
|program tally
|character(20) :: s = ' 1 2 333' ! allocated len must be > len_trim(s)
|write (*,*) count([(s(i:i) /= ' '.and.s(i+1:i+1) == ' ',i=1,len_trim(s))]) !
outputs: 3
|end program

This program is data-conscious in that is requires at least one trailing blank
in the string.
[For "data conscious" read "has a bug".]



David Frank

2005-08-14, 9:00 am


"robin" <robin_v@bigpond.com> wrote in message
news:0IwLe.83123$oJ.43342@news-server.bigpond.net.au...
>
> David Frank wrote in message ...
>
>
> That's exactly what the PL/I TRIM function does -
> namely truncate a string.
> You have the choice of truncating the end, truncating the
> beginning, or both.
>


Thats fine, what I would object to is a Fortran default TRIM doing both but
fortunately it doesnt
and TRIM(ADJUSTL(line)) can be used for the RARE BOTH TRIM.

I also asked whether my Fortran one-liner below, replacing my translation of
your TALLY 1 liner

ncols = COUNT([(line(i:i) /= ' '.and.line(i+1:i+1) == '
',i=1,LEN_TRIM(line))])

could be translated thus simplifying your current inefficient PL/I one-liner
below.

ncols = 1 + TALLY(TRIM(line),' ') - TALLY(TRIM(line),' ')

Sooo, whats your answer?.


David Frank

2005-08-14, 9:00 am


"robin" <robin_v@bigpond.com> wrote in message
news:HTDLe.84648$oJ.63138@news-server.bigpond.net.au...
> The syntax of TRIM in PL/I is - in its simplest form - exactly the
> same as that of Fortran.
> The TRIM function in Fortran is actually a truncate function,
> so it perhaps should have been more appropriately named TRUNCATE.
> The TRIM function in PL/I is appropriately named because
> it may remove from both ends.
>


>
> I already have.
> Recall n = 1 - TALLY(TRIM(s), ' ') - TALLY(TRIM(s), ' '); ?


How did you tell TRIM in your statement to trim the beginning of s?
Unless it does your statement doesnt work as I have demonstrated.


David Frank

2005-08-14, 9:00 am


"robin" <robin_v@bigpond.com> wrote in message
news:0IwLe.83123$oJ.43342@news-server.bigpond.net.au...
>


>
> The PL/I TALLY function is builtin. Yours is hand coded,
> so your solution is not a one-liner, but ten-liner.
>


Ha ha, then why dont your count the statements in IBM's TALLY function?
But even so you have miscounted, my Tally function has 1 executable
statement.
Lets see you hand-code a replacement for your built-in TALLY using your
COUNT function.

INTEGER FUNCTION Tally (line,s)
CHARACTER(*) :: line, s
INTEGER :: i
Tally = COUNT( [ (line(i:i+LEN(s)-1) == s, i = 1,LEN(line)-LEN(s)+1) ] )
END FUNCTION Tally



David Frank

2005-08-14, 9:00 am


"James Van Buskirk" <not_valid@comcast.net> wrote in message
news:XumdnZEQg8S8oWPfRVn-gg@comcast.com...
> "Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
> news:ddla1h$gp8$1@scrotar.nss.udel.edu...
>
>
> Then it's a bug in the function predicate. C'mon, you guys can
> fix this up easy enough...
>


Apparently we cant, whats your fix (not that I agree there has to be one)

Declaring a large len string where there is nil probability an assignment
gets truncated
e.g.
character(200) :: s = ' 1 22 333' ! many trailing blanks as a result

ncols = count( [ (s(i:i) /= ' '.and.s(i+1:i+1) == ' ', i=1,len_trim(s)) ] )

is a safe solution, if you disagree then use 20000 or whatever.




Rich Townsend

2005-08-14, 9:00 am

David Frank wrote:
> "James Van Buskirk" <not_valid@comcast.net> wrote in message
> news:XumdnZEQg8S8oWPfRVn-gg@comcast.com...
>
>
>
> Apparently we cant, whats your fix (not that I agree there has to be one)
>
> Declaring a large len string where there is nil probability an assignment
> gets truncated
> e.g.
> character(200) :: s = ' 1 22 333' ! many trailing blanks as a result
>
> ncols = count( [ (s(i:i) /= ' '.and.s(i+1:i+1) == ' ', i=1,len_trim(s)) ] )
>
> is a safe solution, if you disagree then use 20000 or whatever.
>


Or use my original F95 code to count the number of columns -- the one
based around ISO_VARYING_STRING, which has worked perfectly from the
start, unlike the consistently-defective code posted by others.

cheers,

Rich
David Frank

2005-08-14, 9:00 am


"Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
news:ddnblm$59r$1@scrotar.nss.udel.edu...
> David Frank wrote:
>
> Or use my original F95 code to count the number of columns -- the one
> based around ISO_VARYING_STRING, which has worked perfectly from the
> start, unlike the consistently-defective code posted by others.
>
> cheers,
>
> Rich


Your solution is so laffable I am posting it for our PL/I readers as an
example that bad coding can be done in ANY language..

- ---- Rich Townsend's recommended solution to count columns --------
program count_cols

use ISO_VARYING_STRING

implicit none

type(VARYING_STRING) :: line
integer :: len_line
integer :: len_prev
integer :: n_columns
integer :: i_blank

! Read a line of data

call GET(line)

! Reduce multiple blanks to single blank

len_prev = 0

reduce_loop : do

len_line = LEN(line)

if(len_line == len_prev) exit

line = REPLACE(line, ' ', ' ', EVERY=.TRUE.)

len_prev = len_line

end do reduce_loop

! Strip leading and trailing blanks

line = TRIM(ADJUSTL(line))

! Count the number of columns, by counting blanks

if(line /= '') then

n_columns = 1

count_loop : do

i_blank = INDEX(line, ' ')

if(i_blank == 0) exit count_loop

line = EXTRACT(line, START=i_blank+1)

n_columns = n_columns + 1

end do count_loop

else

n_columns = 0

endif

print *, 'Columns:', n_columns

end program count_cols


Rich Townsend

2005-08-14, 5:01 pm

David Frank wrote:
> "Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
> news:ddnblm$59r$1@scrotar.nss.udel.edu...
>
>
>
> Your solution is so laffable I am posting it for our PL/I readers as an
> example that bad coding can be done in ANY language..


My code was an implementation of an approach that a previous poster had
suggested. I nowhere claimed it is the *best* approach to doing things,
merely that it produced verifiably-correct results in all cases.

That's more than can be said for the broken code you post above.

cheers,

Rich
Gary L. Scott

2005-08-14, 5:01 pm

In-Reply-To: <g9FLe.5321$RZ2.4802@newsread3.news.atl.earthlink.net>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@supernews.com
Lines: 54
Xref: number1.nntp.dca.giganews.com comp.lang.fortran:135782

David Frank wrote:
> "robin" <robin_v@bigpond.com> wrote in message
> news:0IwLe.83123$oJ.43342@news-server.bigpond.net.au...
>
>
>
>
> Ha ha, then why dont your count the statements in IBM's TALLY function?
> But even so you have miscounted, my Tally function has 1 executable
> statement.
> Lets see you hand-code a replacement for your built-in TALLY using your
> COUNT function.
>
> INTEGER FUNCTION Tally (line,s)
> CHARACTER(*) :: line, s
> INTEGER :: i
> Tally = COUNT( [ (line(i:i+LEN(s)-1) == s, i = 1,LEN(line)-LEN(s)+1) ] )
> END FUNCTION Tally
>
>
>


I'm curious as to why the interest in challenges targeted at PL1. It is
such a marginal language, hardly used at all outside the mainframe
environment and rapidly decreasing there in favor of C. I used to use
PL1 a little on the mainframe and it had features that I liked, but in
the end, even there, I came to use VS Fortran almost exclusively because
I wanted the code to be more portable (easy availability of compilers
in other environments). More interesting to me would be C or Ada
challenges. Not necessarily because I believe that Fortran is superior,
but because I like to learn about the other languages (although if I
really wanted to learn, I'd find an alternate means).

--

Gary Scott
mailto:garyscott@ev1.net

Fortran Library: http://www.fortranlib.com

Support the Original G95 Project: http://www.g95.org
-OR-
Support the GNU GFortran Project: http://gcc.gnu.org/fortran/index.html

Why are there two? God only knows.


If you want to do the impossible, don't hire an expert because he knows
it can't be done.

-- Henry Ford
Rich Townsend

2005-08-14, 5:01 pm

Gary L. Scott wrote:
> David Frank wrote:
>
>
> I'm curious as to why the interest in challenges targeted at PL1. It is
> such a marginal language, hardly used at all outside the mainframe
> environment and rapidly decreasing there in favor of C. I used to use
> PL1 a little on the mainframe and it had features that I liked, but in
> the end, even there, I came to use VS Fortran almost exclusively because
> I wanted the code to be more portable (easy availability of compilers
> in other environments). More interesting to me would be C or Ada
> challenges. Not necessarily because I believe that Fortran is superior,
> but because I like to learn about the other languages (although if I
> really wanted to learn, I'd find an alternate means).
>


In Perl:

---
#!/usr/bin/perl

$line = ' 1 22 333';

$n_columns = split ' ', $line;

print "$n_columns\n";
---

This is using a "special" feature of the split function. To quote from
the manpage:

As a special case, specifying a PATTERN of space (' ') will
split on white space just as "split" with no arguments does.

Assigning the result from split (an array) to a scalar counts the number
of elements in that result -- i.e., the number of columns.

cheers,

Rich
David Frank

2005-08-14, 5:01 pm

I posted a 1-liner using Fortran's count function and asked if you could
translate it using
PL/I's count function. You havent said whether its possible or not, why
not?

Btw, if you are successful it will be twice as fast as the current 2 Tally
operations.



robin

2005-08-15, 4:01 am


David Frank wrote in message ...
>I posted a 1-liner using Fortran's count function and asked if you could
>translate it using
>PL/I's count function.


Let's get this rignt.
You want us to write code to duplicate yuour buggy Fortran statement?

> You havent said whether its possible or not, why not?



Of course it's possible to write something duplicating your buggy code.

But I have posted a correct piece of code for this.


robin

2005-08-15, 4:01 am


David Frank wrote in message
<7mELe.7691$ns.1663@newsread1.news.atl.earthlink.net>...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:HTDLe.84648$oJ.63138@news-server.bigpond.net.au...
[color=darkred]
>
>How did you tell TRIM in your statement to trim the beginning of s?
>Unless it does your statement doesnt work as I have demonstrated.



James Wienkam has already explained this to you.


robin

2005-08-15, 4:01 am


Gary L. Scott wrote:


> I'm curious as to why the interest in challenges targeted at PL1. It is
> such a marginal language, hardly used at all outside the mainframe
> environment


PL/I has been available on PCs and small computers since the
1970s (as well, as of course, on the mainframe).
IBM PL/I has been available on the IBM PC and compatibles
for quite some time both as a stand-alone product and as
a development tool for IBM mainframes with which it
is fully compatible.
Other suppliers than IBM provide PL/I on the PC and on
various manufacturers' computers.
[color=darkred]
> and rapidly decreasing there in favor of C. I used to use



James Van Buskirk

2005-08-15, 4:01 am

"David Frank" <dave_frank@hotmail.com> wrote in message
news:EfGLe.7703$ns.3370@newsread1.news.atl.earthlink.net...

> Apparently we cant, whats your fix (not that I agree there has to be one)


You know, my first recursive solution to the blank compression
problem left a trailing blank if present. Why don't you just
run your ac-implied-do up to LEN(s)-1 and then think about
what it means if the last character of s is blank or not?

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


David Frank

2005-08-15, 9:01 am


"James Van Buskirk" <not_valid@comcast.net> wrote in message
news:zYqdnQpYYdKxvZ3eRVn-rA@comcast.com...
> "David Frank" <dave_frank@hotmail.com> wrote in message
> news:EfGLe.7703$ns.3370@newsread1.news.atl.earthlink.net...
>
>
> You know, my first recursive solution to the blank compression
> problem left a trailing blank if present. Why don't you just
> run your ac-implied-do up to LEN(s)-1 and then think about
> what it means if the last character of s is blank or not?
>


But what happens if a line being processed from file is truncated due to
declaration being to short?
Left out column(s) dont get counted, so only F95 solution is to extend the
declared length. Whatever
length you then decide will be be 100% ok, 100,200,etc add 1 more
101,201,etc+1 and you have equal
capability WITHOUT having to make the 1-liner count UNREADABLE.


David Frank

2005-08-15, 9:01 am


"robin" <robin_v@bigpond.com> wrote in message
news:3JTLe.85455$oJ.59326@news-server.bigpond.net.au...
>
> David Frank wrote in message
> <7mELe.7691$ns.1663@newsread1.news.atl.earthlink.net>...
>
>
>
> James Wienkam has already explained this to you.
>
>


But has he explained it to you? Your statement above is buggy..


David Frank

2005-08-15, 9:01 am


"robin" <robin_v@bigpond.com> wrote in message
news:6CTLe.85449$oJ.58668@news-server.bigpond.net.au...
>
> David Frank wrote in message ...
>
>
>
> No need to bother, as it's a generic built-in function.
>


Which you must call twice to get #cols, whereas COUNT only scans the line
once and ought to be twice as fast.

But keep ignoring my question, PLI readers are used to your refusing to
admit any PL/I shortcomings all thu my informing them about the superiority
of Fortran vs PL/I in http://home.earthlink.net/~dave_gemini/pli_cant.faq
which sheds light on your PL/I FAQ claim that PL/I is more powerful.



>



David Frank

2005-08-15, 9:01 am


"James Van Buskirk" <not_valid@comcast.net> wrote in message
news:zYqdnQpYYdKxvZ3eRVn-rA@comcast.com...
>
> You know, my first recursive solution to the blank compression
> problem left a trailing blank if present. Why don't you just
> run your ac-implied-do up to LEN(s)-1 and then think about
> what it means if the last character of s is blank or not?
>


Running a "recursive solution" to leave a trailing blank is nasty,
but I had a 2nd look, I came up with below, and its not too messy as a
1-liner..

! --------------
include "strings.f90" ! http://home.earthlink.net/~dave_gemini/strings.f90

program demo ! Count_Items in string_functions module
use string_functions

character(10) :: s = ' 1 2 333' ! len_trim = 10

write (*,*) Count_Items(s) ! outputs 3
write (*,*) Count_Items(' 1 2 333 ') ! outputs 3

! demo 1-liner count items
ncols = count([(s(i:i)/=' '.and.s(i+1:i+1)=='
'.or.i==len_trim(s)-1.and.s(i+1:i+1)/=' ',i=1,len_trim(s)-1)])
end program


Tom Linden

2005-08-15, 9:01 am

On Mon, 15 Aug 2005 04:02:29 GMT, robin <robin_v@bigpond.com> wrote:

>
> Gary L. Scott wrote:
>
>
>
> PL/I has been available on PCs and small computers since the
> 1970s (as well, as of course, on the mainframe).
> IBM PL/I has been available on the IBM PC and compatibles
> for quite some time both as a stand-alone product and as
> a development tool for IBM mainframes with which it
> is fully compatible.
> Other suppliers than IBM provide PL/I on the PC and on
> various manufacturers' computers.
>
>
>


Still in used a fair amount on VMS.

David Frank

2005-08-15, 9:01 am


"David Frank" <dave_frank@hotmail.com> wrote in message
news:tjZLe.8041$ns.3631@newsread1.news.atl.earthlink.net...
>

No he didnt and both of you have obfuscated the issue.
[color=darkred]
>

"James J. Weinkam" <jjw@cs.sfu.ca> wrote in message
news:3MsLe.175941$9A2.159578@edtnps89...
> David Frank wrote:
>
>
> For example TRIM(s,', ',', ') trims both commas and spaces from both the
> beginning and end of s,


very unintuitive and hard to remember what the args and their syntax.

It appeared to me that plain trim was same as Fortran since Robin said
"TRIM in its simplest form is same as Fortran"

Since I must surmise (despite what you two say) that plain TRIM is NOT the
same as Fortran but does a left trim as a default, (HORRORS!)
then I withdraw my statement that your slow 2 tally computation is buggy...




David Frank

2005-08-15, 9:01 am


"robin" <robin_v@bigpond.com> wrote in message
news:7HTLe.85453$oJ.71690@news-server.bigpond.net.au...
>
> David Frank wrote in message ...
>
> Let's get this rignt.
> You want us to write code to duplicate yuour buggy Fortran statement?
>
>
>
> Of course it's possible to write something duplicating your buggy code.
>
> But I have posted a correct piece of code for this.
>


Prove my 1-liner is buggy,
http://home.earthlink.net/~dave_gemini/strings.f90


Rephrasing and again putting the question in your face..
Can PL/I count be used to scan a line and count items in a 1-liner?

How about yes/no without all the "squirming" to phrase a response that
doesnt admit you cant
but (in your mind only) allows you to later say "I have already responded"


robin

2005-08-15, 5:02 pm


David Frank wrote in message ...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:7HTLe.85453$oJ.71690@news-server.bigpond.net.au...

[color=darkred]
>Rephrasing and again putting the question in your face..
>Can PL/I count be used to scan a line and count items in a 1-liner?



You know that it can.
In several postings Iincluding the first) it has been provided thus:

n = 1 + TALLY(TRIM(S), ' ') - TALLY(TRIM(S), ' ');


robin

2005-08-15, 5:02 pm


David Frank wrote in message ...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:3JTLe.85455$oJ.59326@news-server.bigpond.net.au...
[color=darkred]
>But has he explained it to you? Your statement above is buggy..



No it isn't.
If you think otherwise, explain why.


robin

2005-08-15, 5:02 pm


David Frank wrote in message ...
>
>"David Frank" <dave_frank@hotmail.com> wrote in message
>news:tjZLe.8041$ns.3631@newsread1.news.atl.earthlink.net...
>
>No he didnt and both of you have obfuscated the issue.
>
>"James J. Weinkam" <jjw@cs.sfu.ca> wrote in message
>news:3MsLe.175941$9A2.159578@edtnps89...
[color=darkred]
>
>very unintuitive and hard to remember what the args and their syntax.
>
>It appeared to me that plain trim was same as Fortran since Robin said
>"TRIM in its simplest form is same as Fortran"


I said that _syntactically_ it is the same in its simplest form.

The semantics is different, as James Weinkam explained to you.


Paul Van Delst

2005-08-15, 5:02 pm

robin wrote:
> David Frank wrote in message ...
>
>
>
>
>
>
>
> You know that it can.
> In several postings Iincluding the first) it has been provided thus:
>
> n = 1 + TALLY(TRIM(S), ' ') - TALLY(TRIM(S), ' ');


Over the years, it's been quite well-established (by posters to c.l.f and c.l.pl1) that these
"Fortran vs PL/I" exercises (which is what they typically end up being turned into) are generally
bogus and cooked up with a moving target such that PL/I can never win, no matter how well suited to
a particular task it may be. For the current "test" both DF's Fortran code and knowledge of PL/I has
pretty much been shown to be lacking by people more knowledgable in either/both, so why bother
continuing the discussion? Let's use the electrons for something useful.

cheers,

paulv

--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
David Frank

2005-08-15, 5:02 pm


"robin" <robin_v@bigpond.com> wrote in message
news:B63Me.86140$oJ.51211@news-server.bigpond.net.au...
>
> David Frank wrote in message ...
>
>
> You know that it can.


I know no such thing, you have yet to post ANY code using PL/I COUNT
function..

> In several postings Iincluding the first) it has been provided thus:
>
> n = 1 + TALLY(TRIM(S), ' ') - TALLY(TRIM(S), ' ');
>


Well yes, I also have also shown my TALLY 1-line function solution, but your
broken record above is unresponsive.
I have moved on to using Fortran's COUNT function for this challenge. You
are stuck with your TALLY solution.

I repeat, can you use PL/I COUNT FUNCTION to scan the line just ONCE and
derive the #items it contains
in a "1 line solution" the same as I have shown in my previous reply,
yes/no?




David Frank

2005-08-15, 5:02 pm


"robin" <robin_v@bigpond.com> wrote in message
news:za3Me.86141$oJ.41889@news-server.bigpond.net.au...
>
> David Frank wrote in message ...
>
>
>
> No it isn't.
> If you think otherwise, explain why.
>


I said hours ago your tally statement is right, but you cant resist
responding to a message in which I am wrong,
even if its been withdrawn, can you?

otoh, you say my 1-liner using Fortran count is buggy, but dont respond
when I show a totally unnecessary correction
(just to make you happy) that doesnt have what you call a bug, why is
that?

Do you withdraw your statement my count function is buggy?

re: "Of course it's possible to write something duplicating your buggy code"

OK now we are getting somewhere,
when will we see your PL/I COUNT function solution, I have coaxed a reply
saying you can do it, lets see it!!!






David Frank

2005-08-15, 5:02 pm


"Paul Van Delst" <paul.vandelst@noaa.gov> wrote in message
news:ddqi13$vju$1@news.nems.noaa.gov...
> so why bother continuing the discussion? Let's use the electrons for
> something useful.
>
> cheers,
>
> paulv


What else do PLI'ers have to read in comp.lang.pl1 ?
In the month of July there was I believe 1 topic opened
with 1 reply (not counting the 2 dozen viagra-like topics).
So far in August, we have a dozen respondees with dozens of replies in
this topic.

AND it was Robin who cross-posted, not me..
I dont originate cross-postings..


David Frank

2005-08-15, 5:02 pm

My previous works, but below shortens it...

Count_Items = COUNT([(s(i:i)/=' '.AND.s(i+1:i+1)==' '.OR.i==LEN_TRIM(s)-1,
i=1,LEN_TRIM(s)-1)])

I have dropped the last clause from my previous solution as its always true
when i = len_trim(s)-1
its kinda obscure how the 2 compound clauses interact to produce the right
count.

ncols = count([(s(i:i)/=' '.and.s(i+1:i+1)=='
'.or.i==len_trim(s)-1.and.s(i+1:i+1)/=' ',i=1,len_trim(s)-1)])


gerard46

2005-08-15, 5:02 pm

| David Frank wrote:
| My previous works, but below shortens it...
|
| Count_Items = COUNT([(s(i:i)/=' '.AND.s(i+1:i+1)==' '.OR.i==LEN_TRIM(s)-1,
| i=1,LEN_TRIM(s)-1)])
|
| I have dropped the last clause from my previous solution as its always true
| when i = len_trim(s)-1
| its kinda obscure how the 2 compound clauses interact to produce the right
| count.
|
| ncols = count([(s(i:i)/=' '.and.s(i+1:i+1)=='
| '.or.i==len_trim(s)-1.and.s(i+1:i+1)/=' ',i=1,len_trim(s)-1)])

If this is the best that Fortran can do just to count the number
of columns, I don't want any part of it. Waaaaaay to obsure and the code
is too obtuse for my taste. _______________________________________G
erard S.




William M. Klein

2005-08-15, 5:02 pm

"David Frank" <dave_frank@hotmail.com> wrote in message
news:a21Me.6814$Je.1592@newsread2.news.atl.earthlink.net...
<snip>
> Rephrasing and again putting the question in your face..
> Can PL/I count be used to scan a line and count items in a 1-liner?
>


I was hoping that you (DF) would go away again, but as it appears you aren't ...

One more time:

A) provide ANY reason that it is important that the same number of lines are
used in two different programming languages to perform the same task.

B) Give any BUSINESS (or other application reason) WHY a "logical programming
specification" should REQUIRE a specific construct (e.g. "COUNT") to be used if
another (or combination of others) are available natively in the other language.

C) If you claim that a Fortran COUNT solution is "more efficient" than a PL/I
TALLY solution, please provide the run-time results (performance results) of the
two programs compiled and run in the same environment. If not, then don't make
assumptions on what is and is not "efficient" coding - much less with all
compilers (for a specific language) in all environements (hardware and operating
systems).

***

If your ONE AND ONLY reason for asking for "x-number of lines" of code (in PL/I)
use the "ABC" construct, is that the current PL/I FAQ makes a statement about
Fortran 95 (not Fortran in general), then provide an alternative FAQ and post a
reference to it, but do NOT clutter up the PL/I (or Fortran) newsgroups with
"challenges" to do things that are ridiculous and have no bearing on how
"programming specs" are given to real programmers.


--
Bill Klein
wmklein <at> ix.netcom.com


David Frank

2005-08-16, 4:01 am


"gerard46" <gerard46@rtt.net> wrote in message
news:xLudnSEMebqwap3eRVn-iA@onvoy.com...
>| David Frank wrote:
> | My previous works, but below shortens it...
> |
> | Count_Items = COUNT([(s(i:i)/=' '.AND.s(i+1:i+1)=='
> '.OR.i==LEN_TRIM(s)-1,
> | i=1,LEN_TRIM(s)-1)])
> |
> | '.or.i==len_trim(s)-1.and.s(i+1:i+1)/=' ',i=1,len_trim(s)-1)])
>
> If this is the best that Fortran can do just to count the number
> of columns, I don't want any part of it. Waaaaaay to obsure and the code
> is too obtuse for my taste. _______________________________________G
erard
> S.
>
>


Thanks for the comments, there are responsible for my simpler version below.

Count_Items = COUNT( [.TRUE., s(i:i) /= ' ' .AND. s(i+1,i+1) == ' ', i
=1,LEN_TRIM(s)-1) ] )

As to whats going on, its not that difficult to understand.
I have setup an array of TRUE FALSE entries setting the first entry to TRUE
and the remainder TRUE FALSE
entries set by evaluating consecutive chars as to their not blank and blank
status stopping at 1 char before the last
char in the string.
This array of TRUE FALSE is then input into the COUNT function which returns
a count of the TRUE entries.

Its difficult to imagine any further simplification in Fortran that runs any
faster in a 1-liner.


David Frank

2005-08-16, 4:01 am


"David Frank" <dave_frank@hotmail.com> wrote in message
news:dHgMe.7332$Je.347@newsread2.news.atl.earthlink.net...
>
>
> Thanks for the comments, there are responsible for my simpler version
> below.
>
> Count_Items = COUNT( [.TRUE., s(i:i) /= ' ' .AND. s(i+1,i+1) == ' ', i
> =1,LEN_TRIM(s)-1) ] )
>


Whoops, I didnt test above for a blank string, which will have a count = 1
I'm back to the previous version, oh well the exercise may have let some in
on what is happening.


James Van Buskirk

2005-08-16, 4:01 am

"David Frank" <dave_frank@hotmail.com> wrote in message
news:WLgMe.7341$Je.2540@newsread2.news.atl.earthlink.net...

> Whoops, I didnt test above for a blank string, which will have a count =

1
> I'm back to the previous version, oh well the exercise may have let some

in
> on what is happening.


Run the ac-implied-do out to LEN(s)-1, replace .TRUE. with a
test of s(LEN(s):LEN(s)), insert that missing parenthesis, and
test your solution a bit.

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


David Frank

2005-08-16, 4:01 am


"David Frank" <dave_frank@hotmail.com> wrote in message
news:WLgMe.7341$Je.2540@newsread2.news.atl.earthlink.net...
>
> "David Frank" <dave_frank@hotmail.com> wrote in message
> news:dHgMe.7332$Je.347@newsread2.news.atl.earthlink.net...
>
> Whoops, I didnt test above for a blank string, which will have a count =
> 1
> I'm back to the previous version, oh well the exercise may have let some
> in on what is happening.


Premature withdrawal just to handle a blank string,
above is worth rescuing as it will be faster than the previous more complex
logical evaluation.
Sooo, whats NOW the final version (I hope) of this 1-liner?




Tim Challenger

2005-08-16, 4:01 am

On Fri, 12 Aug 2005 11:57:30 GMT, David Frank wrote:

> ...
> But you wont ACTUALLY create a test program IDENTICAL in function to below,
> why not?
> If you say my TALLY is wrong, then
> as a Fortran book author, you MUST know how to make it give same output ==
> PL/I tally..
> ...


Now you want *us* to do *your* work for you?
--
Tim C.
Tim Challenger

2005-08-16, 4:01 am

On Sat, 13 Aug 2005 13:44:13 GMT, David Frank wrote:

> "gerard46" <gerard46@rtt.net> wrote in message
> news:yaydnUNegccV6GDfRVn-1A@onvoy.com...
>

Can remove from both.
[color=darkred]

I'm not touching that.

[color=darkred]
>
> Why did IBM adopt such arcane WRONG TRIM syntax,
> 99.44% of the time users want to just truncate a string.



Because the PLI TRIM bf can do both.

--
Tim C.
David Frank

2005-08-16, 4:01 am


"James Van Buskirk" <not_valid@comcast.net> wrote in message
news:r4qdnc8Yau3LAZzeRVn-vA@comcast.com...
> "David Frank" <dave_frank@hotmail.com> wrote in message
> news:WLgMe.7341$Je.2540@newsread2.news.atl.earthlink.net...
>
> 1
> in
>
> Run the ac-implied-do out to LEN(s)-1, replace .TRUE. with a
> test of s(LEN(s):LEN(s)), insert that missing parenthesis, and
> test your solution a bit.
>
> --
> write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
> 6.0134700243160014d-154/),(/'x'/)); end
>
>


I have already replaced the .TRUE. with LEN_TRIM(s) > 0 and yes I
definitely need to test more..

Do you agree this is likely FASTEST 1-liner?

http://home.earthlink.net/~dave_gemini/strings.f90



Herman D. Knoble

2005-08-16, 5:06 pm

On Mon, 15 Aug 2005 21:26:54 GMT, "William M. Klein" <wmklein@nospam.netcom.com> wrote:

-|"David Frank" <dave_frank@hotmail.com> wrote in message
-|news:a21Me.6814$Je.1592@newsread2.news.atl.earthlink.net...
-|<snip>
-|> Rephrasing and again putting the question in your face..
-|> Can PL/I count be used to scan a line and count items in a 1-liner?
-|>
-|
-|I was hoping that you (DF) would go away again, but as it appears you aren't ...
-|
I for one hope that David Frank never "goes away". The codes, especially his,
posted in connection with his questions and challenges are not only instructive,
but is what this Fortran forum is all about. Code improves with critique -
of the code - not the authors.

Thanks.
Skip Knoble




Rich Townsend

2005-08-16, 5:06 pm

Herman D. Knoble wrote:
> On Mon, 15 Aug 2005 21:26:54 GMT, "William M. Klein" <wmklein@nospam.netcom.com> wrote:
>
> -|"David Frank" <dave_frank@hotmail.com> wrote in message
> -|news:a21Me.6814$Je.1592@newsread2.news.atl.earthlink.net...
> -|<snip>
> -|> Rephrasing and again putting the question in your face..
> -|> Can PL/I count be used to scan a line and count items in a 1-liner?
> -|>
> -|
> -|I was hoping that you (DF) would go away again, but as it appears you aren't ...
> -|
> I for one hope that David Frank never "goes away". The codes, especially his,
> posted in connection with his questions and challenges are not only
> instructive,

^^^^^^^^^^


You mis-spelled 'bug ridden, non-standard and poorly benchmarked'

> but is what this Fortran forum is all about. Code improves with critique -
> of the code - not the authors.


But DF roundly ignores most criticisms of his code (mainly, that it
doesn't work), and makes bizzare claims about the code of others (that
they are incorrect because they do not use IEOR and no other intrinsic,
etc). That, and his crue against PL/I smacks of true internet kookery.

cheers,

Rich
robin

2005-08-16, 5:06 pm


David Frank wrote in message ...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:6CTLe.85449$oJ.58668@news-server.bigpond.net.au...
>
>Which you must call twice to get #cols, whereas COUNT only scans the line
>once and ought to be twice as fast.



In your program, COUNT doesn't scan the line at all.
Your code scans the line, examining 3 characters at every step,
and creates a logical array that COUNT scans.


robin

2005-08-16, 5:06 pm


David Frank wrote in message ...
>
>
>Running a "recursive solution" to leave a trailing blank is nasty,
>but I had a 2nd look, I came up with below, and its not too messy as a
>1-liner..
>
>! --------------
>include "strings.f90" !
>program demo ! Count_Items in string_functions module
>use string_functions
>
>character(10) :: s = ' 1 2 333' ! len_trim = 10
>
>write (*,*) Count_Items(s) ! outputs 3
>write (*,*) Count_Items(' 1 2 333 ') ! outputs 3
>
>! demo 1-liner count items
>ncols = count([(s(i:i)/=' '.and.s(i+1:i+1)=='
>'.or.i==len_trim(s)-1.and.s(i+1:i+1)/=' ',i=1,len_trim(s)-1)])
>end program



1. What happens when S is 'D' ?
2. What happens when S is 'D' ? (and S has a declared length of 1).


robin

2005-08-16, 5:06 pm


David Frank wrote in message ...
>My previous works,


did it?

>but below shortens it...
>
>Count_Items = COUNT([(s(i:i)/=' '.AND.s(i+1:i+1)==' '.OR.i==LEN_TRIM(s)-1,
>i=1,LEN_TRIM(s)-1)])



Try s = 'G'


Rich Townsend

2005-08-16, 5:06 pm

robin wrote:
> David Frank wrote in message ...
>
>
>
>
> 1. What happens when S is 'D' ?
> 2. What happens when S is 'D' ? (and S has a declared length of 1).
>
>


Well, it would appear that the implied do loop in the ncols assignement
has zero length. Thus, the resulting logical array has zero length.
Thus, the COUNT() intrinsic returns zero. Thus, DF's example code is
broken. Again.

cheers,

Rich
Rich Townsend

2005-08-16, 5:06 pm

David Frank wrote:
> "James Van Buskirk" <not_valid@comcast.net> wrote in message
> news:zYqdnQpYYdKxvZ3eRVn-rA@comcast.com...
>
>
>
> But what happens if a line being processed from file is truncated due to
> declaration being to short?


This doesn't happen if you use the GET() intrinsic in the standard
ISO_VARYING_STRING module.

> Left out column(s) dont get counted, so only F95 solution is to extend the
> declared length. Whatever


No, the only F95 solution is to use ISO_VARYING_STRING or some similar,
home-grown capability.

cheers,

Rich
David Frank

2005-08-16, 5:06 pm


"robin" <robin_v@bigpond.com> wrote in message
news:G0oMe.592$FA3.353@news-server.bigpond.net.au...
>
> David Frank wrote in message ...
>
> did it?
>
>
>
> Try s = 'G'
>
>


My final? 1-liner can be seen at
http://home.earthlink.net/~dave_gemini/strings.f90

It was posted in response to James at 4:11 am thats almost 7+ hours prior
to your reply.

It has no problem with s = 'G' you have another test?

Where is your PROMISED PL/I count solution?




David Frank

2005-08-16, 5:06 pm


"robin" <robin_v@bigpond.com> wrote in message
news:FWnMe.589$FA3.354@news-server.bigpond.net.au...
>
> David Frank wrote in message ...
>
>
> 1. What happens when S is 'D' ?
> 2. What happens when S is 'D' ? (and S has a declared length of 1).
>
>


below was tested
write(*,*) Count_Items('D') ! outputs 1


Rich Townsend

2005-08-16, 5:06 pm

David Frank wrote:
> "robin" <robin_v@bigpond.com> wrote in message
> news:G0oMe.592$FA3.353@news-server.bigpond.net.au...
>
>
>
> My final? 1-liner can be seen at
> http://home.earthlink.net/~dave_gemini/strings.f90
>
> It was posted in response to James at 4:11 am thats almost 7+ hours prior
> to your reply.
>


Congratulations! At last, a working solution -- 19 days after I posted
my own working solution, on July 28th. Well done, David!

cheers,

Rich
David Frank

2005-08-16, 5:06 pm


"Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
news:ddta6i$b1$1@scrotar.nss.udel.edu...

>
> Congratulations! At last, a working solution -- 19 days after I posted my
> own working solution, on July 28th. Well done, David!
>


You mean your laffable solution that has about 20 statements running in a
loop that must take forever
to decide what the number of columns are?


Rich Townsend

2005-08-16, 5:06 pm

David Frank wrote:
> "Rich Townsend" <rhdt@barVOIDtol.udel.edu> wrote in message
> news:ddta6i$b1$1@scrotar.nss.udel.edu...
>
>
>
>
> You mean your laffable solution that has about 20 statements running in a
> loop that must take forever
> to decide what the number of columns are?
>
>


It may run slower; but the fact that it was working correctly from the
start made it infinitely more efficient than the broken code you've been
posting for ws. Thank god people like you don't have jobs in
mission-critical applications.

cheers,

Rich
beliavsky@aol.com

2005-08-16, 5:06 pm

Rich Townsend wrote:

<snip>

> It may run slower; but the fact that it was working correctly from the
> start made it infinitely more efficient than the broken code you've been
> posting for ws. Thank god people like you don't have jobs in
> mission-critical applications.


I don't want to take a position for or against David Frank here, but it
appears from http://www.unics.uni-hannover.de/rrzn/gehrke/c2f.html that
he is a

"retired RCA Missile Test Project radar programmer (28 yrs)..
at Cape Canaveral/Patrick AFB Florida"

Anything with "missile" in it, done by the Air Force, sounds
"mission-critical" to me :). If this information about Mr. Frank is
incorrect, I apologize to him in advance.

Rich Townsend

2005-08-16, 5:06 pm

beliavsky@aol.com wrote:
> Rich Townsend wrote:
>
> <snip>
>
>
>
> I don't want to take a position for or against David Frank here, but it
> appears from http://www.unics.uni-hannover.de/rrzn/gehrke/c2f.html that
> he is a
>
> "retired RCA Missile Test Project radar programmer (28 yrs)..
> at Cape Canaveral/Patrick AFB Florida"
>
> Anything with "missile" in it, done by the Air Force, sounds
> "mission-critical" to me :). If this information about Mr. Frank is
> incorrect, I apologize to him in advance.
>


Well, it's nice to know that David was once performing a valuable job.
But unfortunately this bears no relation to his current competency. Just
look how GT went off the deep end after he left Ontario Hydro's research
division.

cheers,

Rich
robin

2005-08-17, 4:07 am

Version 7 now?

David Frank wrote 16/8/2005 @ 0:35 in message ...

|Thanks for the comments, there are responsible for my simpler version below.

|Count_Items = COUNT( [.TRUE., s(i:i) /= ' ' .AND. s(i+1,i+1) == ' ', i
=1,LEN_TRIM(s)-1) ] )

|As to whats going on, its not that difficult to understand.
|I have setup an array of TRUE FALSE entries setting the first entry to TRUE
|and the remainder TRUE FALSE
|entries set by evaluating consecutive chars as to their not blank and blank
|status stopping at 1 char before the last
|char in the string.
|This array of TRUE FALSE is then input into the COUNT function which returns
|a count of the TRUE entries.
|
|Its difficult to imagine any further simplification in Fortran that runs any
faster in a 1-liner.

|David Frank wrote 16/8/2005 @ 0:40 in message ...

|>"David Frank" <dave_frank@hotmail.com> wrote in message
|>news:dHgMe.7332$Je.347@newsread2.news.atl.earthlink.net...
|>>
|>> Thanks for the comments, there are responsible for my simpler version
|>> below.

|>> Count_Items = COUNT( [.TRUE., s(i:i) /= ' ' .AND. s(i+1,i+1) == ' ', i
|>> =1,LEN_TRIM(s)-1) ] )
|>
|>Whoops, I didnt test above for a blank string, which will have a count = 1
|>I'm back to the previous version, oh well the exercise may have let some in
|>on what is happening.

Did the previous version work ?


robin

2005-08-17, 4:07 am


David Frank wrote in message
<5FpMe.7637$Je.2609@newsread2.news.atl.earthlink.net>...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:FWnMe.589$FA3.354@news-server.bigpond.net.au...
>
>below was tested
>write(*,*) Count_Items('D') ! outputs 1



Where below?


David Frank

2005-08-17, 4:07 am


"robin" <robin_v@bigpond.com> wrote in message
news:k0yMe.2215$FA3.1154@news-server.bigpond.net.au...

> Did the previous version work ?
>


I will respond ,
WHEN you post your PROMISED version of a 1-liner Count_Items using PL/I's
COUNT function
OR
ADMIT PL/I count function cant be used in a 1-liner solution as I have done.


David Frank

2005-08-17, 4:07 am


"robin" <robin_v@bigpond.com> wrote in message
news:c4yMe.2217$FA3.1380@news-server.bigpond.net.au...
>
>
> Where below?
>


I will respond ,
WHEN you post your PROMISED version of a 1-liner Count_Items using PL/I's
COUNT function
OR
ADMIT PL/I count function cant be used in a 1-liner solution as I have done.



gerard46

2005-08-17, 5:04 pm

| David Frank wrote: |
|> robin wrote:
|> Did the previous version work ?

| I will respond ,
| WHEN you post your PROMISED version of a 1-liner Count_Items using PL/I's
| COUNT function
| OR
| ADMIT PL/I count function cant be used in a 1-liner solution as I have done.

Nobody promised a version using COUNT. That was your idea. Why anybody
would use such a tool when a BIF such as TALLY does the job so much easier.
Stepping through the character strings "converting" each character to a
boolean value so that COUNT can er, count 'em seems to be a bit, er,
over-the-top, and way more complicated than necessary. I think Robin's
solution is the shortest, easiest to understand, and certainly the
fastest to code.

Frank, if you insist on not responding to a simple request
["Did the previous version (of yours) work?"],
it really sounds like you are avoiding the question. If somebody asked
that question of my code, I would respond immediately (and with
clarification if necessary), and I wouldn't hide behide a strawman
argument (or strawman challenge) ---- I'll answer that as soon as you
jump over THIS rope THIS high ... ---- sounds like schoolground antics
and posturing.

You wanted a 1-liner (WHY, I don't know...) to count the number of
columns in a string. When Robin did post a succinct piece of code,
you switched to challenge her to write equivalent code using a BIF
that (as it seemed to me) not suited to the task at hand, namely
the COUNT function. Proof positive that you can force a square
peg into a round hole if you are clever enough. I think the use
of the TALLY function is the best solution to your trival challenge,
in that her solution is short, easy to understand (compared to your
so-called 1-liner), and much quicker to code (as witnessed by the
many failed (incorrect/buggy) attempts using COUNT. ____________Gerard S.




William M. Klein

2005-08-17, 5:04 pm

Notice that DF still hasn't answered my questions (similar to your comments):

****

One more time:

A) provide ANY reason that it is important that the same number of lines are
used in two different programming languages to perform the same task.

B) Give any BUSINESS (or other application reason) WHY a "logical programming
specification" should REQUIRE a specific construct (e.g. "COUNT") to be used if
another (or combination of others) are available natively in the other language.

C) If you claim that a Fortran COUNT solution is "more efficient" than a PL/I
TALLY solution, please provide the run-time results (performance results) of the
two programs compiled and run in the same environment. If not, then don't make
assumptions on what is and is not "efficient" coding - much less with all
compilers (for a specific language) in all environments (hardware and operating
systems).

***

If your ONE AND ONLY reason for asking for "x-number of lines" of code (in PL/I)
use the "ABC" construct, is that the current PL/I FAQ makes a statement about
Fortran 95 (not Fortran in general), then provide an alternative FAQ and post a
reference to it, but do NOT clutter up the PL/I (or Fortran) newsgroups with
"challenges" to do things that are ridiculous and have no bearing on how
"programming specs" are given to real programmers.


--
Bill Klein
wmklein <at> ix.netcom.com
"gerard46" <gerard46@rtt.net> wrote in message
news:RqydnZNvB7_e-p7eRVn-3A@onvoy.com...
>| David Frank wrote: |
> |> robin wrote:
> |> Did the previous version work ?
>
> | I will respond ,
> | WHEN you post your PROMISED version of a 1-liner Count_Items using PL/I's
> | COUNT function
> | OR
> | ADMIT PL/I count function cant be used in a 1-liner solution as I have done.
>
> Nobody promised a version using COUNT. That was your idea. Why anybody
> would use such a tool when a BIF such as TALLY does the job so much easier.
> Stepping through the character strings "converting" each character to a
> boolean value so that COUNT can er, count 'em seems to be a bit, er,
> over-the-top, and way more complicated than necessary. I think Robin's
> solution is the shortest, easiest to understand, and certainly the
> fastest to code.
>
> Frank, if you insist on not responding to a simple request
> ["Did the previous version (of yours) work?"],
> it really sounds like you are avoiding the question. If somebody asked
> that question of my code, I would respond immediately (and with
> clarification if necessary), and I wouldn't hide behide a strawman
> argument (or strawman challenge) ---- I'll answer that as soon as you
> jump over THIS rope THIS high ... ---- sounds like schoolground antics
> and posturing.
>
> You wanted a 1-liner (WHY, I don't know...) to count the number of
> columns in a string. When Robin did post a succinct piece of code,
> you switched to challenge her to write equivalent code using a BIF
> that (as it seemed to me) not suited to the task at hand, namely
> the COUNT function. Proof positive that you can force a square
> peg into a round hole if you are clever enough. I think the use
> of the TALLY function is the best solution to your trival challenge,
> in that her solution is short, easy to understand (compared to your
> so-called 1-liner), and much quicker to code (as witnessed by the
> many failed (incorrect/buggy) attempts using COUNT. ____________Gerard S.
>
>
>
>



robin

2005-08-17, 10:01 pm


David Frank wrote in message ...
>
>"robin" <robin_v@bigpond.com> wrote in message
>news:c4yMe.2217$FA3.1380@news-server.bigpond.net.au...
>
>I will respond ,
>WHEN you post your PROMISED version of a 1-liner Count_Items using PL/I's
>COUNT function
>OR
>ADMIT PL/I count function cant be used in a 1-liner solution as I have done.


As I have said several times before :-

PL/I's count function is called TALLY, and
the PL/I equivalent has been posted several
times already, and you have read it.


robin

2005-08-17, 10:01 pm


David Frank wrote in message ...