1

For convenience I would like to be able to reference elements of a static look up table implemented as a 1d array like this

Item = [1,7,2,5,3](I)

Where I is an integer index to the static array in the square brackets. I know I can declare a named array and use that, but I’m wondering if there’s an appropriate syntax for the above intent.

Ian Bush
  • 6,996
  • 1
  • 21
  • 27
user1383092
  • 507
  • 1
  • 7
  • 17
  • 1
    *Fuggeddaaboutit*, there's no Fortran syntax close to that. The approach you know you can use is the approach to use, not forgetting that the static array can be declared to be a `parameter`. It's not clear to me why you would want to use the 'array literal' in multiple locations when you could declare it once and use it many times - it would be a *magic array*. – High Performance Mark Feb 18 '20 at 10:08
  • Thanks. I’ll stop looking. Yes the static array parameter is what I will do. This (honestly!) is only to be used in one place so I’d rather have the literal values where they are used than in another part of the code. – user1383092 Feb 18 '20 at 10:12
  • The linked question is about array function results, but it's really much the same concept for array expressions. As High Performance Mark says, there's no syntax even close, so you'll need do something like the wrapping mentioned in the other answers. – francescalus Feb 18 '20 at 10:12
  • *I’d rather have the literal values where they are used* You may be able to take advantage of the screamingly modern `block` construct to declare the array near to its only use if that appeals. Or possibly `associate`. – High Performance Mark Feb 18 '20 at 10:19
  • Thanks High Performance Mark. Nice idea - unfortunately my compiler is not quite screamingly modern enough. I appreciate the suggestions. – user1383092 Feb 18 '20 at 10:33

0 Answers0