For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2005 > "Set" in FTN90









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 "Set" in FTN90
Ftn 90

2005-12-05, 7:04 pm

Is there an easy way to check to see if a number is in a group in FTN90? I
want to do something like this:

if N in[234,123,876,367,296,109,333,976] then
call found_one
else
call not_there
end if

Thanks!

Chris Hulbert

2005-12-05, 7:04 pm


Ftn 90 wrote:
> Is there an easy way to check to see if a number is in a group in FTN90? I
> want to do something like this:
>
> if N in[234,123,876,367,296,109,333,976] then
> call found_one
> else
> call not_there
> end if
>
> Thanks!


SELECT CASE (N)
CASE (234,123,876,367,296,109,333,976)
CALL found_one
CASE DEFAULT
CALL not_there
END SELECT

Rich Townsend

2005-12-05, 7:04 pm

Ftn 90 wrote:
> Is there an easy way to check to see if a number is in a group in FTN90? I
> want to do something like this:
>
> if N in[234,123,876,367,296,109,333,976] then
> call found_one
> else
> call not_there
> end if
>
> Thanks!
>


if(ANY(N == (/234,123,876,367,296,109,333,976/))) then
call found_one
else
call not_there
endif

cheers,

Rich
Ftn 90

2005-12-06, 7:57 am

ftn90@fortran.com said...
>
> Is there an easy way to check to see if a number is in a group in FTN90?

I
>want to do something like this:
>
>if N in[234,123,876,367,296,109,333,976] then
> call found_one
>else
> call not_there
>end if
>
>Thanks!
>


Thanks, guys! Either the SELECCT CASE or the IF (with the ANY) will work fine.
I used to write a ton of FTN-66 (yes, an old guy!) and then spent 10-12 years
writting Pascal code. Back into FTN now and am playing catch up with the new
features of FTN-90. I knew there had to be a simple way.

- Paul in Nova Scotia, Canada

Herman D. Knoble

2005-12-06, 7:57 am

CASE implies the use of a constant vector; whereas Rich's solution
with ANY intrinsic will work with any integer vector. That is for
example:

integer:: N
integer, dimension(8):: set

Set = (/234,123,876,367,296,109,333,976/)
N=109

! Use of ANY intrinsic.
if(ANY(N == Set)) then
print *, "1 Found; N Is In Set."
else
print *, "1 Not Found; N Not In Set."
endif
end

The next part of your question might be:
What is the subscript (or location) of the vector, Set,
whose element matches N?

Skip

On 5 Dec 2005 11:32:14 -0800, "Chris Hulbert" <cchgroupmail@gmail.com> wrote:

-|
-|Ftn 90 wrote:
-|> Is there an easy way to check to see if a number is in a group in FTN90? I
-|> want to do something like this:
-|>
-|> if N in[234,123,876,367,296,109,333,976] then
-|> call found_one
-|> else
-|> call not_there
-|> end if
-|>
-|> Thanks!
-|
-|SELECT CASE (N)
-|CASE (234,123,876,367,296,109,333,976)
-| CALL found_one
-|CASE DEFAULT
-| CALL not_there
-|END SELECT

Sponsored Links







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

Copyright 2008 codecomments.com