From: Eli Osherovich on
On Jun 26, 1:25 pm, Allamarein <matteo.diplom...(a)gmail.com> wrote:
> I'm getting experience with modules.
....

Let's put aside Fortran issues.
Consider the following two lines in your example.

N = SIZE(X)
ALLOCATE(X(1:N))

First, you check the size of X and then you try to allocate it.
Common sense says that if X is not allocated its size is either
undefined or zero (*). Hence, this sequence of operations make little
or no sense.

(*) Yes, one can imagine a situation that X provides correct
information about its size, but actual memory for data storage is not
allocated.
From: Allamarein on
On 26 Giu, 15:42, dpb <n...(a)non.net> wrote:
> dpb wrote:
> > Allamarein wrote:
> > ...
>
> >> I found something about 'assumed-shape' array, but I don't understand
> >> very well.
>
> > I'd suggest reading the language reference manual w/ the compiler or
> > programmers' guide or buy/check out one of the Fortran reference books
> > available.  You'll need it anyway for more than just this...
>
> ...
>
> BTW, I see from another posting you're using the IVF compiler -- by
> comparison to the product of the current Intel team that I have, I'm
> quite sure the documentation that came w/ the compiler is quite thorough
> in having both document types outlined above -- the Guide that is more
> general on Fortran language features as well as the specific language
> syntax manual.  Use them.
>
> As it seems you're new to Fortran, I can't emphasize enough the
> usefulness of a a good reference book (or two).  There are a multitude
> of threads in clf, some within the last couple of weeks even on
> recommendations/discussion of strengths of various titles currently
> available.
>
> --

First of all thank you for your patience.
I'm sorry, I was careless.
Your suggested modification allows my code to work properly.

Yes, I'm new to Fortran (I am proficiency in Matlab, but it is
mandatory I learn this language).
I see IVF's documentation more complex than Matlab one, anyway I seem
to use this compiler quite smartly (I am able to compile a code with
modules and I/O and to debug that). If I have to use more complex
utilities, maybe I'll fend for me. Anyway I'll approach the problem
when it will show.

In this moment I would plug my gaps in Fortran language.
I was looking for tutorials and manuals on Internet, but I am not very
pleased about my resources.
For example:
here I found some intrinsic functions:
http://gcc.gnu.org/onlinedocs/gfortran/Intrinsic-Procedures.html#Intrinsic-Procedures

These are basic tutorials:
http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html
http://wwwasdoc.web.cern.ch/wwwasdoc/f90.html

and following links seem to resemble a manual:
http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/fortran.html
http://www.tcm.phy.cam.ac.uk/~mjr/f1nn.pdf
http://www.liv.ac.uk/HPC/HTMLF90Course/HTMLF90CourseSlides.html

I am sure that I good papery reference book is irreplaceable.
Would you suggest me some titles?
Anyway do you know some useful links?
Tutorials step-by-step would be welcome.

Thank you again.
From: Ron Shepard on
In article <i04te1$or6$1(a)news.eternal-september.org>,
dpb <none(a)non.net> wrote:

> Allamarein wrote:
> > I'm getting experience with modules.
> > Therefore I try to compile a trivial statistical module for
> > educational purpose.
> > SUM function should sum the elements of an input array.
> > I would to not specify array size, but my function should detect that.
> > I tried the following code:
> >
> > MODULE STATISTICS
> >
> > CONTAINS
> >
> > REAL FUNCTION SUM(X)
> > IMPLICIT NONE
> > INTEGER :: N
> > REAL :: RES=0.0

The above is another mistake in this code. This is an
initialization which is done once (e.g. at the beginning of the
program, or during compile time), not an assignment that is
performed each time the function is invoked.

As written, this code will sum up the elements of all the array
arguments that it is ever given throughout a program run. There
might be reasons you would want to do this, but probably not for
this function, right?

> REAL, INTENT(IN) :: X(:)
> >
> > N = SIZE(X)

RES = 0.0

This is what you probably want here, a regular assignment statement
that is executed just before the do loop every time the function is
invoked.

> > DO I = 1,N
> > RES = RES+X(I)
> > END DO
> >
> > SUM = RES
> > END FUNCTION SUM
> >
> > END MODULE STATISTICS
> >
> > Anyway I get some errors. I suppose my problems are in the allocatable
> > variables.
>
> Indeed.
>
> You don't want an allocatable array here, you want an assumed-shape
> array where the number of dimensions is specified by the number of
> colons in the dimension expression and the size is that of the passed
> argument. It requires an explicit interface (which you get w/ the
> module automagically)...
>
> --
From: dpb on
Allamarein wrote:
....

> First of all thank you for your patience.
> I'm sorry, I was careless.
> Your suggested modification allows my code to work properly.

Yes, it would seem that slowing down a little and perusing carefully
would be a starting point... :)

Now, the next step in your exploration will be to figure out how to deal
w/ other shapes of arrays than 1D... :)

....

> In this moment I would plug my gaps in Fortran language.
> I was looking for tutorials and manuals on Internet, but I am not very
> pleased about my resources.
....

> I am sure that I good papery reference book is irreplaceable.
> Would you suggest me some titles?
> Anyway do you know some useful links?
....

As noted in earlier response there have been other threads (multiple
times already in clf you can search for on references). I recall at
least one specifically asking the question within the last week or so.

I really don't have any idea about online resources, no...

--
From: dpb on
Ron Shepard wrote:
> In article <i04te1$or6$1(a)news.eternal-september.org>,
> dpb <none(a)non.net> wrote:
>
>> Allamarein wrote:
....

>>> MODULE STATISTICS
>>>
>>> CONTAINS
>>>
>>> REAL FUNCTION SUM(X)
>>> IMPLICIT NONE
>>> INTEGER :: N
>>> REAL :: RES=0.0
>
> The above is another mistake in this code. This is an
> initialization which is done once (e.g. at the beginning of the
> program, or during compile time), not an assignment that is
> performed each time the function is invoked.
>
> As written, this code will sum up the elements of all the array
> arguments that it is ever given throughout a program run. There
> might be reasons you would want to do this, but probably not for
> this function, right?
>
>> REAL, INTENT(IN) :: X(:)
>>> N = SIZE(X)
>
> RES = 0.0
>
> This is what you probably want here, a regular assignment statement
> that is executed just before the do loop every time the function is
> invoked.
....

Yes; I saw that later and intended to comment on it...glad somebody did
since I forgot about it.

--