Accidental Whole Array Assignments

| SimCon Home | fpt Reference Manual Home |

When Do Accidental Whole Array Assignments Occur?

In Fortran 90 and later an entire array may be assigned across an equals sign from another array or array expression in a single statement, for example:

A = B

where A and B are two arrays of the same shape. The array which is assigned may be written without subscripts. This is most unlikely to cause a problem.

However, an entire array may be assigned the value of a scalar expression or variable. All elements of the array assigned are set to the value of the scalar. This is the situation where accidents sometimes occur.

Detecting Potential Problems

The fpt command to detect unsubscripted whole array assignments from scalars is:

CHECK WHOLE ARRAY ASSIGNMENTS FROM SCALAR VARIABLES

Errors in these cases are not common, but we have encountered a sufficient number for the issue to be of concern. The code shown below was part of the design simulation of a medium lift helicopter. This section of the code transferred the engine powers E_PWR(3) from the engine module to the rotor module, variable R_PWR(3). The aircraft has 3 engines.

! DO I = 1,3 R_PWR = E_PWR(I) !---------------^-------------------------------------------------------------- !!! FPT - 3409 Un-subscripted whole array assignment from variable scalar !------------------------------------------------------------------------------ ENDDO

The author didn't need to use a DO loop, but not all aerodynamics engineers are good programmers. The subscript on R_PWR was omitted by accident. The result was that all elements of R_PWR received the power of the port engine, these values were immediately overwritten by the power from the middle engine, and then by the power from the starboard engine.

At first, we didn't think that this was very serious. The three engines are identical, and the pilots usually pulled the power-available levers ganged together. The problem was that the helicopter does its lifing in hover. In hover, the downdraft from the rotors interferes with the air intake to the middle engine, which loses about 12% of its power. Overwriting the middle engine power with that of the starboard engine causes the power available to be overestimated by about 4%. Still not very serious? But the empty aircraft weighs 10 tons and should lift 5 tons. The lift will be reduced by 4% of 15 tons = 0.6 tons. The payload is therefore reduced from 5 tons to 4.4 tons. This matters!

Copyright ©1995 to 2024 Software Validation Ltd. All rights reserved.