(j3.2006) Select Rank

Bill Long longb
Mon Feb 16 00:16:24 EST 2015


On Feb 14, 2015, at 10:59 AM, Whitlock, Stan <stan.whitlock at intel.com> wrote:

> I'm not advocating a new feature at this late date but I don't see Bill's suggestion as getting me very far.  In:
> 
>  select case (rank(A))
> 
>  case (1)
>  ...
>  case (2)
>  ...
> 
>  end select
> 
> in case (1) I can't say:
> 
> 	A (4) = 1		! assuming A has a 4th element
> 
> But we could probably define SELECT RANK so you could say:
> 
>  select rand (A)
> 
>  case (1)
> 	A (4) = 1
>  case (2)
> 	A (2,3) = 1
>  end select rank
> 
> /Stan
> 

It was not clear if Van was suggesting something simple, or he wanted to allow variable length subscript lists on the variable name.  The later (like the example from Stan) is a pretty radical departure from basic Fortran syntax rules, and I fear it would be a full employment feature for /Interp for years to come.  Rather than completely removing the limitations on where an assumed-rank object could appear in a program (assuming we want this feature in F2020 at all), there is a simpler option:  Allow an assumed-rank name as a selector in an associate construct.  Since the associate names do not appear in declaration statements there is a less disruption to the standard. 

select rank (A)  

case (1)
   associate (B => A)  ! Current rules already say B assumes the rank of A
        B(4) = 1
   end associate
case (2)
   associate (B=>A)  ! Or maybe (B(:,:) => A) to be more explicit about the rank of B
       B(2,3) = 1
   end associate
?
! case default not allowed for select rank, or allowed, but no reference to A allowed.

end select


OR, borrowing from the syntax of SELECT TYPE, an alternative that is a bit more confusing and more work to implement, but still simpler than the original:

select rank (B => A)
 
case(1)
   B(4) = 1
case(2)
   B(2,3) = 1

end select

In either case, the usage of the assumed-rank object is still very limited, avoiding unintended side effects.


Cheers,
Bill


Bill Long                                                                       longb at cray.com
Fortran Technical Suport  &                                  voice:  651-605-9024
Bioinformatics Software Development                     fax:  651-605-9142
Cray Inc./ Cray Plaza, Suite 210/ 380 Jackson St./ St. Paul, MN 55101





More information about the J3 mailing list