j3-fortran / fortran_proposals

Proposals for the Fortran Standard Committee
178 stars 15 forks source link

Allow for Variable expressions in Select Case #250

Open Soulagenda opened 2 years ago

Soulagenda commented 2 years ago

Because I tried to do this and it didn't work, so I am making a request for it to work. I think it would be nice if it worked. It went something like this


Integer :: iVar Integer, Allocatable :: VA, VB, VC, VD(:), VE, VF, VG, VH, VI, VJ !They all will have a unique value Real, Allocatable :: VarArray(:)

DoConcurrent (iVar:1, NVar) Select Case (iVar) Case (VA, VB, VD, VE) ...instruction1 Case (VG, VH) .....instruction2 Case Default End Select End do


I am about to make myself dizzy attempting to create logic with if statements along with checking allocations and whatever else I'll have to do to make it work. It would be nice for variables to be allowed in the Case() and those that are not allocated can be automatically ignored. I would use it for unique integers but in case some have equal value, select case will just choose the first case that has a match. For example, if iVar=VB=VG then the code will execute instructions for VB. Though this may result in some unintended consequences in code behavior for developers who may not be initially careful in ensuring uniqueness of variable values or properly tracking allocations. Such potential mishaps can be highlighted with warnings.