Self study guide: Fortran 95 - University of Cambridge
Self study guide: Fortran 95 - University of Cambridge
Self study guide: Fortran 95 - University of Cambridge
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
If the last character <strong>of</strong> a line is an ampersand ‘&’, then it is as if the next line was<br />
joined onto the current one (with the ‘&’ removed). Use this to lay out long<br />
expressions as clearly as possible.<br />
• Another technique is to split long expressions using intermediate calculations. A<br />
simple example would be replacing something like:<br />
res = sqrt(a + b*x + c*x*x + d*x*x*x) + &<br />
log(e * f / (2.345*h + b*x))<br />
with<br />
t1 = a + b*x + c*x*x + d*x*x*x<br />
t2 = E * F / (2.345*h + b*x)<br />
res = sqrt(t1) + log(t2)<br />
• Think about the choice <strong>of</strong> variable names. You can make the variable names very<br />
clear with names such as energy or momentum. This can be very helpful, but<br />
also cumbersome in long expressions. A useful rule <strong>of</strong> thumb is that if there is an<br />
accepted symbol for a physical quantity consider using that (e.g. E and p); use<br />
longer more descriptive names if one does not exist.<br />
We will return to the topic <strong>of</strong> programming style later when we consider how the<br />
program can be broken up into smaller units. This will be the main job in the next<br />
section <strong>of</strong> the course.<br />
23