experchange > fortran

Michael_937 (10-20-18, 04:07 AM)
Hello,

What are the best intuitive books to learn Fortran 90/95?

I used Fortran 77 ten years ago.

I program regularly in languages such as C/C++.

Thanks,
Mike
JRR (10-20-18, 02:10 PM)
On 20.10.18 04:07, Michael_937 wrote:
> Hello,
> What are the best intuitive books to learn Fortran 90/95?
> I used Fortran 77 ten years ago.
> I program regularly in languages such as C/C++.
> Thanks,
> Mike

I use Metcalf/Reid/Cohen, Modern Fortran Explained, there was just a new
edition including the Fortran 2018 features (which are however not yet
implemented by all almost all compilers).
JRR (10-20-18, 02:12 PM)
On 20.10.18 04:07, Michael_937 wrote:
> Hello,
> What are the best intuitive books to learn Fortran 90/95?
> I used Fortran 77 ten years ago.
> I program regularly in languages such as C/C++.
> Thanks,
> Mike

Metcalf/Reid/Cohen: Modern Fortran Explained, where there was just a new
version including the Fortran 2018 status which is however not yet
included in almost all compilers):
Ian D Chivers (10-20-18, 02:57 PM)
Our Fortran Resource file has details
of Fortran books.



We are working on a new version at the moment, which has
an expanded section on free compilers, which include

Flang
g95
gfortran
Oracle Developer Studio 6
PGI Community Edition

Hope this helps

Ian

On 20/10/2018 03:07, Michael_937 wrote:
[..]
Eugene Epshteyn (10-21-18, 03:57 AM)
On Friday, October 19, 2018 at 10:07:05 PM UTC-4, Micha...@gmail.com wrote:
> Hello,
> What are the best intuitive books to learn Fortran 90/95?
> I used Fortran 77 ten years ago.
> I program regularly in languages such as C/C++.
> Thanks,
> Mike


As an introduction to modern Fortran for an experienced programmer, this is an excellent book:



I highly recommend it.

--Eugene
Michael Siehl (10-22-18, 12:22 PM)
Am Samstag, 20. Oktober 2018 04:07:05 UTC+2 schrieb Micha...@gmail.com:
> Hello,
> What are the best intuitive books to learn Fortran 90/95?
> I used Fortran 77 ten years ago.
> I program regularly in languages such as C/C++.
> Thanks,
> Mike


For Fortran 95, there are countless excellent online tutorials and books aswell, and even Wikipedia and Wikibooks, for example:





If you need a quick start with the core features of Fortran 90, I would still recommend chapter 3 of 'The High Performance Fortran Handbook' by Koelbel, et al.

Your C++ background should be helpful. For example, programming with the free store (heap) is still best explained in the C++ literature. (In Fortran 90 you'll use the ALLOCATE statement instead of 'new'). The book 'Fortran 95/2003 for Scientists and Engineeres' by Stephen J. Chapman explains this in it's chapter 15.4 (without calling it the free store).

Fortran 90/95 pointers are very powerful for implementing deep and shallow copying with nested data structures. (But this should only be used through some well tested template codes, since it is very error prone else; For thedifferent purposes we are working with several pointers to the same data object.)

Yet, and since we have coarrays since Fortran 2008, one main question is ifwe should not even completely replace such nested data structures by distributed data structures instead. I am currently working on such (in a way, trying to replace pointers by coarrays).
Dominik Gronkiewicz (10-22-18, 01:36 PM)
W dniu sobota, 20 października 2018 04:07:05 UTC+2 użytkownik Micha...@gmail.com napisał:
> Hello,
> What are the best intuitive books to learn Fortran 90/95?
> I used Fortran 77 ten years ago.
> I program regularly in languages such as C/C++.
> Thanks,
> Mike


Can't recommend a particular book, but I can recommend jumping right into Fortran 2008. :)
Wolfgang Kilian (10-22-18, 02:18 PM)
On 2018-10-22 13:36, Dominik Gronkiewicz wrote:
> W dniu sobota, 20 października 2018 04:07:05 UTC+2 użytkownik Micha...@gmail.com napisał:
> Can't recommend a particular book, but I can recommend jumping right into Fortran 2008. :)


Seconded. If you're familiar with designing C++ projects, you can
translate those structures easily into modern Fortran. To be able to do
this, you have to skip plain F95 and adopt F03/F08, which is a superset
of F95. (Main caveat for C++ programmers: in Fortran, use allocatable
objects instead of pointers to objects, whenever dynamic memory is
involved. That's the F95 part which you can find in the books.)

-- Wolfgang
Michael Siehl (10-22-18, 08:41 PM)
Core Fortran 95 is a programming language of it's own and I would not necessarily recommend to skip it and to underestimate it's possibilities, for (sequential or local) object-container handling for example:

In F95 we can implement kind of type-bound procedures within modules through simple naming conventions. This may appear primitive but is very powerfulinstead: The main advantage is that we can implement more than one derivedtype within a single module and we can also ‘bind’ more than only one derived type object to a single procedure. Usually we should not do such, with only one exception: To implement sophisticated container management (with somewhat effort).

As far as I do understand it, Fortran 90 is designed to support ‘arrays of structures’ (see ‘The High Performance Fortran Handbook’, chapter 3.5). The compilers do support this even together with use of intrinsic procedures.

Example: To develop a text-based user interface we could implement a derived type TextLine object and collection in a single module, something like this (code-snippets only):

module teli_admTextLine
..
..
!*** derived type object definition:
type, public :: teli_adtTextLine
private
character(len=200) :: m_chrTextLine
!
integer :: m_intColObjectKey ! unique object key in the collection
end type teli_adtTextLine

!*** derived type collection definition:
type, public :: telic_colTextLine
private
type (teli_adtTextLine), dimension (:), pointer :: m_Objects
end type telic_colTextLine

A simple example of a two-type-bound procedure (to get an object (reference) from the collection using the object’s array index within that collection) could then be:

subroutine telic_GetObjectByArrayIndex (Collection, intArrayIndex, Object)
type (telic_colTextLine), intent (inout) :: Collection
integer, intent (in) :: intArrayIndex
type (teli_adtTextLine), intent (out) :: Object
integer :: intUpperBound
!
if (associated (Collection % m_Objects)) then
Object = Collection % m_Objects (intArrayIndex)
end if
!
end subroutine telic_GetObjectByArrayIndex

With F95 we have extended possibilities to directly access object members within the collection, for example to get an object’s array index within the collection through it’s unique object key (code-snippets only):

where (Collection % m_Objects (1:intUpperBound) % m_intColObjectKey == intColObjectKey)
logMask = .true.
elsewhere
logMask = .false.
end where

int_ArrayIndex = maxloc (Collection % mA_Objects (1:intUpperBound) % &
m_intColObjectKey, mask = logMask)
..
..
end module teli_admTextLine

Years later, Microsoft invented a similar syntax to handle object collections with 'LINQ to Objects'.

My personal main reason to stick with a Fortran 95 programming style, is the prospect to implement new classes of computer algorithms by combining F95style with F08/18 coarrays.
FortranFan (10-22-18, 10:06 PM)
On Monday, October 22, 2018 at 2:41:20 PM UTC-4, Michael Siehl wrote:

> .. I would not necessarily recommend to skip it and to underestimate it'spossibilities, for (sequential or local) object-container handling for example:
> ..
> My personal main reason to stick with a Fortran 95 programming style, is the prospect to implement new classes of computer algorithms by combining F95 style with F08/18 coarrays.


@Michael Siehl appears to be again mistaking a *coding style* with languagestandard specification and the processor(s) (compiler) supporting it.

Current Fortran standard (Fortran 2008) supports prior Fortran standards (i..e., almost all of earlier revisions albeit with certain, limited deletionsin the language). So with conforming compilers today of the current Fortran standard, one can code in various "styles" including Fortran 2008, Fortran 90/95, or even FORTRAN 77, etc.

But then if some other coder mistakes a coding style, say "Fortran 95" as dictated by sticking to features in that revision of the standard, for a compiler that only supports up to Fortran 95 language standard e.g., Compaq Visual Fortran v6.6a, then the various "safeguards" from current standard will NOT be available to the detriment of the programmer.

One big example of such a "safeguard" is with the ALLOCATABLE attribute of objects where, starting with 2003 revision, Fortran language effectively brought in almost all the useful aspects of "smart pointers" in C++ () that this other "lesser" language (to paraphrase someone!) could only bring in over a decade later. Fortran 95 language standard had gaps when it came to practical uses of ALLOCATABLE objects. So Fortran 2003 and later revisions of Fortran can make "safe" codes that conform to Fortran 95 standard but which may otherwise be "unsafe" e.g., failure to deallocate memory used by local objects.

It's with such features and many other facilities in mind that anyone starting to look at Fortran now should consider Fortran 2008 or even the soon-to-be-published Fortran 2018, considering the 5th edition of Modern Fortran Explained as posted upthread.

Once a coder has a good overview of what the official Fortran standard includes and (s)he starts to understand the support of the features in the compiler(s) to be used, the coder can begin to develop suitable code designs and programming paradigms (procedural/object-based/object-oriented, etc.) in conjunction with one's coding needs.
Ron Shepard (10-23-18, 02:46 AM)
On 10/22/18 3:06 PM, FortranFan wrote:
> One big example of such a "safeguard" is with the ALLOCATABLE attribute of objects where, starting with 2003 revision, Fortran language effectively brought in almost all the useful aspects of "smart pointers" in C++ () that this other "lesser" language (to paraphrase someone!) could only bring in over a decade later. Fortran 95 language standard had gaps when it came to practical uses of ALLOCATABLE objects. So Fortran 2003 and later revisions of Fortran can make "safe" codes that conform to Fortran 95 standard but which may otherwise be "unsafe" e.g., failure to deallocate memory used by local objects.


I was thinking of replying to this point too. Allocatable arrays were
hamstrung in f90 and f95. There was a TR released almost at the same
time as f95 that fixed some of the biggest problems. I have always
thought that the f95 standard itself should have been delayed a month or
so to incorporate all of that directly. Instead, it took another 8 years
until f2003 to get all fixed.

Also, pointer assignments with lower bounds on the lhs were not allowed
in f90 and f95. So in addition to forcing programmers to use pointers
instead of allocatables, the pointer implementation itself lacked an
important feature. There was a workaround, that I and everyone else
used, but it was never clear to me that the workaround was strictly
conforming. This was a feature that certainly should have been included
in f90 itself. Lower bounds to arrays had been in fortran since f77, and
it was a step backward to not include it with pointer assignments of arrays.

But in any case, it was eventually fixed in f2003. So that is the
standard that I would recommend now. The newer standards are not yet
fully supported by most compilers. Hopefully that will change soon.

$.02 -Ron Shepard
Michael Siehl (10-23-18, 02:42 PM)
My above code snippets are derived from working template/framework codes that were originally developed with Digital Visual Fortran 5. Last, somewhat extensive, testing was in 2013 using several compilers. At this time I did some minor change to allow for use with the g95/Silverfrost compiler. I didjust run a test case with current gfortran and the codes are still working..

The end version of the framework was enabled for deep (derived type) objectnesting and to allow for deep and shallow copying through the nested object hierarchy. It worked but was way to complicated (and thus error prone) for use with production codes. This was with sequential programming.

With parallel programming through coarrays, the situation may be different because I want to avoid (local) derived type object nesting yet, with the only exception of nesting derived type objects within a (type safe) derived type collection (array) object. (As somewhat shown above).

Not before 2019/2020, I may setup a new simplified version of the frameworkand upload it to a GitHub repository then. This is still complicated enough and will require extensive testing.

Replacing the pointer components with allocatable instead may not work withthe codes I have.
John E (10-23-18, 05:20 PM)
> What are the best intuitive books to learn Fortran 90/95?

Assuming you really mean fortran 2003 or later, I'd recommend both of these "modern fortran" books because they do a good job of steering you towards better (more modern) fortran approaches.





One note: I have the kindle versions and code is not formatted very well there though I assume in the paper version it looks fine (?).

But TBH neither of these really explains things all that intuitively, just better than most of the others IMO. There is a real need for some beginner/intermediate level fortran books that even get in the ballpark of, say, almost any python book.
Eugene Epshteyn (10-23-18, 05:51 PM)
On Tuesday, October 23, 2018 at 11:21:04 AM UTC-4, John E wrote:
> > What are the best intuitive books to learn Fortran 90/95?

> Assuming you really mean fortran 2003 or later, I'd recommend both of these "modern fortran" books because they do a good job of steering you towards better (more modern) fortran approaches.
>
>
> One note: I have the kindle versions and code is not formatted very well there though I assume in the paper version it looks fine (?).


Both of these books are formatted correctly in paper version.

They are also good books, but I wouldn't necessarily consider them introductory books. You are better off knowing some of the language, before reading them.
baf (10-23-18, 06:13 PM)
On 10/23/2018 8:51 AM, Eugene Epshteyn wrote:
> On Tuesday, October 23, 2018 at 11:21:04 AM UTC-4, John E wrote:
>>> What are the best intuitive books to learn Fortran 90/95?

>> Assuming you really mean fortran 2003 or later, I'd recommend both of these "modern fortran" books because they do a good job of steering you towards better (more modern) fortran approaches.
>>
>>

> They are also good books, but I wouldn't necessarily consider them introductory books. You are better off knowing some of the language, before reading them.


I agree. Try Fortran for Scientists & Engineers (4th edition) by
Stephen Chapman as an introductory book. It covers Fortran 2008.

Similar Threads