From: Giorgio Pastore on
glen herrmannsfeldt wrote:
> Giorgio Pastore <pastgio(a)units.it> wrote:
>
> (snip)
>
>> For example the
>> description of control mechanism of a do loop looks reasonable at a
>> first glimpse but actually it is not very neat: it may generate
>> misconceptios.
>
> Could you be more specific on that one?

From S.J. Chapman "Fortran 95/2003 For Scientists and Engineers (3rd
edition), p.137:

"The counting loop construct functions as follows:
1. Each of the three DO loop parameters istart, iend and incr may be a
costant, a variable or an expression. If they are variables or
expressions, then their values are calculated before the start of the
loop, and the resulting values are used to control the loop.
2. At the beginning of the execution of the DO loop, the program assigns
the value istart to control variable index. If index*incr <= iend*incr,
the program executes the statements within the body of the loop.
....
4 step 2 is repeated over and over as long as index*incr <= iend*incr.
When this cndition is not longer true, execution skips to the first
statement following the end of the DO loop.

The number of iterations to be performed by the DO loop may be
calculated by the following equation iter = (iend-istart+incr)/incr.
...."

Strictly speaking there is nothing wrong. But let's compare with the
description of the DO loop control which is in the 2003 standard:

"
1- The initial parameter m1, m2 and m3 are evaluated (here I have
summarized)
2- The DO variable becomes defined with the value of the initial
parameter m1.
3- The iteration count is established and is the value of the expression
(m2 − m1 + m3)/m3, unless that value is negative, in which case the
iteration count is 0.
...."

Let us see how the same information is provided by Metcalf, Reid, Cohen
(Fortran 95/2003 explained, p.60):

"The number of iterations of a do construct is given by the formula
max((expr2-expr1+expr3)/expr3,0)..." (very terse!)

You can see that neither the standard nor MRC mention the mechanism of
checking the condition index*incr <= iend*incr.
Although in the past I tought Chapman's description quite useful for
pedagogical reasons, I have realized that in practice, novices may skip
the key information that "their values are calculated before the start
of the loop, and the resulting values are used to control the loop" and
may believe that the repetition count may be changed dynamically just
because Chapman's description put the emphasis on checking the condition
every time. The result may be some wasting of time to understand why a
do loop like the following repeats always only three times

i=1
j=3
do ic=i,j
if(ic==2)j=2*j
end do

(I have left only the bare bones of the relevant situation).

Of course, reading carefully, one could say that Chapman provides the
right information too. Still it is a fact that that part of the
description may be easily forgotten. Using the description provived by
the Standard or by MRC much less possibility of misunderstanding would
have been left.


Giorgio
From: Arjen Markus on
On 12 aug, 08:02, Vincenzo Mercuri <c...(a)lang.c> wrote:
> Paul van Delst wrote:
> > With the caveat that C-interop is not covered at all in the Chapman book. Someone please correct me if I'm wrong, but I
> > just went through my copy again to doublecheck and could not find it covered.
>
> Actually I'll need to deepen this topic.
> Is it fully covered in the other 2 books?
> If not, could you suggest any other resource?
>
> --
> Vincenzo Mercuri

I am not aware of good references on the subject, but this group has
ample experience with it (myself included). So, unless I am mistaken
about the available references, a good option is to pose questions
on the combination of Fortran and C in this forum.

Regards,

Arjen
From: Vincenzo Mercuri on
Arjen Markus wrote:

> I am not aware of good references on the subject, but this group has
> ample experience with it (myself included). So, unless I am mistaken
> about the available references, a good option is to pose questions
> on the combination of Fortran and C in this forum.

Thank you then, I'll be glad to post any question
on this subject.


--
Vincenzo Mercuri
From: Vincenzo Mercuri on
rudra wrote:

> If you are still looking for ans, I may suggest you one thing. I have
> all of them with me, and as i have realized, you better take a bottom-
> top approach in your list.
> Begin with Chapman's as it is most ilaborate, with lots of example and
> tips(though you may not be willing to abide by them to the point)


Thanks. Actually I am thinking about beginning with Chapman's,
As a first reading it would be helpful for me since it is a college
textbook as far as I understand. Also Guide to Fortran 2003 Programming
by Walter Brainerd seems to be a suitable choice. And then of course
I'll be prepared enough to use Metcalf's and Maine's as references.


> you may also look for "Computing for scientists: principles of
> programming with Fortran 90 and C++" by by R. J. Barlow and A. R.
> Barnett. Its not detailed....but good one. very precise description
> about pointers.


That title sounds really interesting. I think it would be
good when I'll need to compare Fortran and C++ 'OO' paradigm
in a scientific programming context. Thank you.

--
Vincenzo Mercuri
From: Vincenzo Mercuri on
Giorgio Pastore wrote:

[...]
> Of course, reading carefully, one could say that Chapman provides the
> right information too. Still it is a fact that that part of the
> description may be easily forgotten. Using the description provived by
> the Standard or by MRC much less possibility of misunderstanding would
> have been left.


I'll take it into account. Thanks again.


--
Vincenzo Mercuri