Next: 5.2.3 Normal code indentation Up: 5.2 Indentation and spaces Previous: 5.2.1 General layout and   Contents   Index

## 5.2.2 Alignment of assignments and equations

Indentation and alignment of stencil operations are important, as in

! -- Save original values into local copies --
rho=model%rho
ei =model%ei
v1 =model%v1
or
eip_ll=ei(i1-2,i2,i3) + P(i1-2,i2,i3)/rho(i1-2,i2,i3)
eip_l =ei(i1-1,i2,i3) + P(i1-1,i2,i3)/rho(i1-1,i2,i3)
eip_r =ei(i1  ,i2,i3) + P(i1  ,i2,i3)/rho(i1  ,i2,i3)
eip_rr=ei(i1+1,i2,i3) + P(i1+1,i2,i3)/rho(i1+1,i2,i3)
or
! -- Fill buffer zones of temperature array --
T(m1-1     , m2  :n2  , m3  :n3  )=T(m1       , m2  :n2  , m3  :n3  )
T(     n1+1, m2  :n2  , m3  :n3  )=T(     n1  , m2  :n2  , m3  :n3  )
T(m1-1:n1+1, m2-1     , m3  :n3  )=T(m1-1:n1+1, m2       , m3  :n3  )
T(m1-1:n1+1,      n2+1, m3  :n3  )=T(m1-1:n1+1,      n2  , m3  :n3  )
T(m1-1:n1+1, m2-1:n2+1, m3-1     )=T(m1-1:n1+1, m2-1:n2+1, m3       )
T(m1-1:n1+1, m2-1:n2+1,      n3+1)=T(m1-1:n1+1, m2-1:n2+1,      n3  )
In this case, blanks around the ``='' sign might be appropriate. Other examples are
lambda_til_mi(i1,i2,i3)=(1.0-mask_up_mi) * (v1(i1-1,i2,i3)-cs(i1-1,i2,i3)) + &
mask_up_mi  * (v1(i1  ,i2,i3)-cs(i1  ,i2,i3))
or
! -- Delete all global boxes --
if (rhd_box_Exist(modelVis)) call rhd_box_Delete(modelVis)
if (rhd_box_Exist(modelB  )) call rhd_box_Delete(modelB  )
if (rhd_box_Exist(modelA  )) call rhd_box_Delete(modelA  )
Properly aligned assignments facilitate the understanding and debugging enormously.

In more complex assignments, corresponding brackets should be carefully positioned. However, different styles and conventions can be used, as e.g.,

model%v1(i1,i2,i3)=model%v1(i1,i2,i3) - &
( dtimeoverrhodx1 * (flux_rhov11(i1+1, i2  , i3  ) - &
flux_rhov11(i1  , i2  , i3  )) + &
dtimeoverrhodx3 * (flux_rhov13(i1  , i2  , i3+1) - &
flux_rhov13(i1  , i2  , i3  ))    )
or
model%v1(i1,i2,i3)=model%v1(i1,i2,i3) - &
( dtimeoverrhodx1 * (flux_rhov11(i1+1, i2  , i3  ) - &
flux_rhov11(i1  , i2  , i3  )) + &
dtimeoverrhodx3 * (flux_rhov13(i1  , i2  , i3+1) - &
flux_rhov13(i1  , i2  , i3  )) &
)
or
model%v1(i1,i2,i3)=model%v1(i1,i2,i3) - &
( dtimeoverrhodx1 * (flux_rhov11(i1+1, i2  , i3  ) - &
flux_rhov11(i1  , i2  , i3  ) &
)                                 + &
dtimeoverrhodx3 * (flux_rhov13(i1  , i2  , i3+1) - &
flux_rhov13(i1  , i2  , i3  ) &
) &
)
Sometimes, the ``fluffy'' (third) form can greatly increase the readability. Sometimes (probably in the example above), it might just be overdoing it.

Next: 5.2.3 Normal code indentation Up: 5.2 Indentation and spaces Previous: 5.2.1 General layout and   Contents   Index