modern fortran

Download Modern Fortran

Post on 29-Nov-2015

99 views

Category:

Documents

2 download

Embed Size (px)

TRANSCRIPT

  • NUMERICAL MATHEMATICS AND SCIENTIFIC COMPUTATION

    Series Editors

    A. M. STUART E. SULI

  • NUMERICAL MATHEMATICS AND SCIENTIFIC COMPUTATION

    Books in the seriesMonographs marked with an asterisk () appeared in the series Monographs in Numerical Analysiswhich is continued by the current series.

    For a full list of titles please visit

    http://www.oup.co.uk/academic/science/maths/series/nmsc

    J. H. Wilkinson: The algebraic eigenvalue problem I. Du, A. Erisman, and J. Reid: Direct methods for sparse matrices M. J. Baines: Moving nite elements J. D. Pryce: Numerical solution of Sturm-Liouville problems

    C. Schwab: p- and hp- nite element methods: theory and applications in solid and uid mechanics

    J. W. Jerome: Modelling and computation for applications in mathematics, science, and engineering

    A. Quarteroni and A. Valli: Domain decomposition methods for partial dierential equations

    G. Em Karniadakis and S. J. Sherwin: Spectral/hp element methods for CFD

    I. Babuska and T. Strouboulis: The nite element method and its reliability

    B. Mohammadi and O. Pironneau: Applied shape optimization for uids

    S. Succi: The lattice Boltzmann equation: for uid dynamics and beyond

    P. Monk: Finite element methods for Maxwells equations

    A. Bellen and M. Zennaro: Numerical methods for delay dierential equations

    J. Modersitzki: Numerical methods for image registration

    M. Feistauer, J. Felcman, and I. Straskraba: Mathematical and computational methods for

    compressible ow

    W. Gautschi: Orthogonal polynomials: computation and approximation

    M. K. Ng: Iterative methods for Toeplitz systems

    M. Metcalf, J. Reid, and M. Cohen: Fortran 95/2003 explained

    G. Em Karniadakis and S. Sherwin: Spectral/hp element methods for computational uid dynamics,

    second edition

    D. A. Bini, G. Latouche, and B. Meini: Numerical methods for structured Markov chains

    H. Elman, D. Silvester, and A. Wathen: Finite elements and fast iterative solvers: with applications

    in incompressible uid dynamics

    M. Chu and G. Golub: Inverse eigenvalue problems: theory, algorithms, and applications

    J.-F. Gerbeau, C. Le Bris, and T. Lelie`vre: Mathematical methods for the magnetohydrodynamics of

    liquid metals

    G. Allaire and A. Craig: Numerical analysis and optimization: an introduction to mathematical

    modelling and numerical simulation

    K. Urban: Wavelet methods for elliptic partial dierential equations

    B. Mohammadi and O. Pironneau: Applied shape optimization for uids, second edition

    K. Bohmer: Numerical methods for nonlinear elliptic dierential equations: a synopsis

    M. Metcalf, J. Reid, and M. Cohen: Modern Fortran Explained

  • Modern Fortran Explained

    Michael MetcalfFormerly of CERN, Geneva, Switzerland

    John ReidJKR Associates, Oxfordshire

    and

    Malcolm CohenThe Numerical Algorithms Group, Oxfordshire

    1

  • 3Great Clarendon Street, Oxford ox2 6dp

    Oxford University Press is a department of the University of Oxford.It furthers the Universitys objective of excellence in research, scholarship,

    and education by publishing worldwide in

    Oxford New York

    Auckland Cape Town Dar es Salaam Hong Kong KarachiKuala Lumpur Madrid Melbourne Mexico City Nairobi

    New Delhi Shanghai Taipei Toronto

    With oces in

    Argentina Austria Brazil Chile Czech Republic France GreeceGuatemala Hungary Italy Japan Poland Portugal SingaporeSouth Korea Switzerland Thailand Turkey Ukraine Vietnam

    Oxford is a registered trade mark of Oxford University Pressin the UK and in certain other countries

    Published in the United Statesby Oxford University Press Inc., New York

    c Michael Metcalf, John Reid, and Malcolm Cohen 2011The moral rights of the authors have been assertedDatabase right Oxford University Press (maker)

    First edition published 1987 as Fortran 8x ExplainedSecond edition published 1989

    Third edition published 1990 as Fortran 90 ExplainedFourth edition published 1996 as Fortran 90/95 Explained

    Fifth edition published 1999Sixth edition published 2004 as Fortran 95/2003 Explained

    This edition published 2011

    All rights reserved. No part of this publication may be reproduced,stored in a retrieval system, or transmitted, in any form or by any means,

    without the prior permission in writing of Oxford University Press,or as expressly permitted by law, or under terms agreed with the appropriate

    reprographics rights organization. Enquiries concerning reproductionoutside the scope of the above should be sent to the Rights Department,

    Oxford University Press, at the address above

    You must not circulate this book in any other binding or coverand you must impose the same condition on any acquirer

    British Library Cataloguing in Publication Data

    Data available

    Library of Congress Cataloging in Publication Data

    Library of Congress Control Number: 2010941705

    Printed in Great Britainon acid-free paper by

    CPI Antony Rowe, Chippenham, Wiltshire

    ISBN 9780199601417 (Hbk)9780199601424 (Pbk)

    1 3 5 7 9 10 8 6 4 2

  • Preface

    Fortran remains one of the principal languages used in the elds of scientic, numerical,and engineering programming, and a series of revisions to the standard dening successiveversions of the language has progressively enhanced its power and kept it competitive withseveral generations of rivals.

    Beginning in 1978, the technical committee responsible for the development of Fortranstandards, X3J3 (now PL22.3 but still informally called J3), laboured to produce a new, much-needed modern version of the language, Fortran 90. Its purpose was to promote portability,reliability, maintainability, and efcient execution. . . on a variety of computing systems.That standard was published in 1991, and work began in 1993 on a minor revision, known asFortran 95. Subsequently, and with the same purpose, a further major upgrade to the languagewas prepared by J3 and the international committee, WG5. This revision, which includedobject-oriented programming features, is now known as Fortran 2003. This has now beenfollowed by a further revision, Fortran 2008, and, once again, it seems appropriate to preparea denitive informal description of the language that it denes. This continues the series ofeditions of this book the two editions of Fortran 8x Explained that described the two draftsof the standard (1987 and 1989), Fortran 90 Explained that described the Fortran 90 standard(1990), two editions of Fortran 90/95 Explained that included Fortran 95 too (1996 and 1999)and Fortran 95/2003 (2004), with its added chapters on Fortran 2003. In that nal endeavour,a third co-author was welcomed.

    In this book, an initial chapter sets out the background to the work on new standards,and the nine following chapters describe Fortran 95 (less its obsolescent features and theredundant Fortran 77 features whose use we deprecate) in a manner suitable both for graspingthe implications of its features, and for writing programs. We include the allocatable arrayextensions that were originally published as an ISO Technical Report and are now part ofFortran 2003, since they have been implemented in Fortran 95 compilers for many years.Some knowledge of programming concepts is assumed. In order to reduce the number offorward references and also to enable, as quickly as possible, useful programs to be writtenbased on material already absorbed, the order of presentation does not always follow that ofthe standard. In particular, we have chosen to defer to appendices the description of featuresthat are ofcially labelled as redundant (some of which were deleted from the Fortran 95standard) and other features whose use we deprecate. They may be encountered in oldprograms, but are not needed in new ones.

    Chapter 11 describes another part of Fortran 2003 that was originally dened by an ISOTechnical Report. This is followed, in Chapters 12 to 17, by descriptions of the other features

  • vi Preface

    dened by the Fortran 2003 standard. Chapter 18 describes a part of Fortran 2008 thatwas originally dened by an ISO Technical Report and two further chapters describe theother new features of Fortran 2008. The structure of the book thus allows the reader todistinguish clearly between Fortran 95 (plus allocatable array extensions), Fortran 2003, andthe new Fortran 2008 features. Note that, apart from a small number of deletions, each of thelanguages Fortran 77, Fortran 90, Fortran 95, Fortran 2003, and Fortran 2008 is a subset ofits successor.

    In order to make the book a complete reference work, it concludes with seven appendices.They contain, successively, a list of the intrinsic procedures, a description of various featureswhose use we deprecate and do not describe in the body of the book, a description ofobsolescent and deleted features, advice on avoiding compilation cascades, an extendedexample illustrating the use of object orientation, a glossary of Fortran terms, and solutionsto most of the exercises.

    It is our hope that this book, by providing complete descriptions of Fortran 95, Fortran 2003and Fortran 2008, will continue the helpful role that earlier editions played for thecorresponding versions of the standard, and that it will serve as a long-term reference workfor the modern Fortran programming language.

    Malcolm Cohen wishes to thank the Numerical Algorithms Group (NAG) for its encour-

    agement during the writing of this book.

  • Conventions used in this book

    Fortran displayed text is set in typewriter font:

    integer :: i, j

    and a line consisting of a colon indicates omitted lines:

    subroutine sort:

    end subroutine sort

    Informa

Recommended

View more >