Next: , Previous: , Up: Options   [Contents][Index]


4.2.42 ‘-n)’: Reverse array indices [FORTRAN] (FTANGLE)

This somewhat experimental flag permits FORTRAN programmers to use C-style array indices. Conversions such as the following are made (during the output phase of FTANGLE):

a(k)(i) => a(i,k)
a(k)(i,j) => a(i,j,k)
a(k)(j)(i) => a(i,j,k)

[No spaces may intervene between ‘)’ and ‘(’; effectively, ‘)(’ is treated as one token for the purposes of ‘-n)’.] This feature permits convenient definitions of macros that deal with multi-dimensional vectors.

Unfortunately, FTANGLE doesn’t fully understand the syntax of the source code—and never will, unless it is fully integrated with a compiler. It will therefore be confused by situations like the following FORTRAN example:

dimension x(0:4)(1:2) // OK
character*90 ch(4) // OK
write(6,*) ((x(i)(j),i=1,2), j=3,4) // Will reverse incorrectly.
c = ch(4)(3:4) // Shouldn’t reverse, but will.

One solution, due to Charles Karney, is to insert a space to prevent ‘)(’ from being recognized as a single token. However, since ordinary white space is eaten on input, one must resort to something like the following (‘$UNQUOTE’ is a built-in FWEB function; see $UNQUOTE):

@m SP $UNQUOTE(' ')
@a
dimension x(0:4)(1:2)
character*90 ch(4)
write(6,*) SP ((x(i)(j),i=1,2), j=3,4)
c = ch(4)SP(3:4)

This option is controlled by the three style-file parameters ‘paren.len’, ‘paren.num’, and ‘paren.nest’. (See Style.) ‘paren.len’ is the default number of bytes to be allocated for each index; if an index is longer than this number, the current length is increased by this number and storage is automatically reallocated. ‘paren.num’ is the maximum number of allowed indices; for example, when processing ‘a(i)(j)(k)’, ‘paren.num’ is 3. ‘paren.nest’ is the maximum parenthesis nesting level. In the example ‘x(a(i)(j)(k))’, ‘paren.nest’ is 2. If either of the last two parameters is exceeded, a message will be issued asking you to increase the appropriate value.


Next: , Previous: , Up: Options   [Contents][Index]