The FutureIntroduction to FORTRANFORTRAN HistoryStatement FormatSlide 5Slide 6Building a FORTRAN ProgramStructure of a Fortran ProgramSlide 9Fortran ProgramFortran SubroutineSlide 12Fortran FunctionSlide 14Fortran Block DataSlide 16Fortran Program OrganizationFortran VariableFortran Variable TypingSlide 20Slide 21Slide 22Slide 23Slide 24Slide 25Fortran ArraysSlide 27Slide 28Fortran Variables and SubroutinesFortran Common BlocksSlide 31Slide 32Fortran EquivalenceFortran ParameterFortran LiteralsSlide 36Fortran ExpressionsFortran Numerical OperatorsSlide 39Intrinsic FunctionsType ConversionSlide 42TruncationMath FunctionsSlide 45Slide 46Fortran StatementsFortran AssignmentFortran BranchingSlide 50Slide 51Slide 52Fortran ContinueFortran IFFortran 3-way IfFortran Logical IfSlide 57Fortran Modern IfSlide 59Slide 60Fortran LoopingSlide 62Slide 63Slide 64Slide 65Slide 66Slide 67Fortran Subroutine InvocationSlide 69Miscellaneous StatementsFortran I/O StatementsSlide 72Slide 73Slide 74Slide 75Slide 76Slide 77Slide 78Slide 79Fortran I/O ListFortran Formatted I/OSlide 82Slide 83FORMAT StatementFormat SpecifiersFormat Specifiers – cont’dSlide 87Slide 88Slide 89Slide 90Other FORMAT FeaturesOther I/O FeaturesSlide 93Slide 94Slide 95Slide 96Slide 97Sub ProgramsSlide 99Slide 100Slide 101Slide 102Slide 103Array StorageSlide 105Slide 106Slide 107Slide 108Slide 109Slide 110Statement FunctionsFortran BooksNot FortranAE6382 The FutureAE6382Introduction to FORTRANHistory and purpose of FORTRANFORTRAN essentialsProgram structureData types and specification statementsEssential program controlFORTRAN I/Osubfunctions and subroutinesExtensions for Fortran 95Pitfalls and common coding problemsSample problemsOBJECTIVESAE6382FORTRAN HistoryOne of the oldest computer languagescreated by John Backus and released in 1957designed for scientific and engineering computationsVersion historyFORTRAN 1957FORTRAN II FORTRAN IVFORTRAN 66 (released as ANSI standard in 1966)FORTRAN 77 (ANSI standard in 1977)FORTRAN 90 (ANSI standard in 1990)FORTRAN 95 (ANSI standard version)FORTRAN 2003 (ANSI standard version)Many different “dialects” produced by computer vendors (Digital VAX Fortran, now Intel Fortran)Large majority of existing engineering software is coded in FORTRAN (various versions)AE6382Statement FormatFORTRAN before 90 requires a fixed formatBased on the punch card in use when Fortran was created PROGRAM MAINC COMMENTS ARE ALLOWED IF A “C” IS PLACED IN COLUMN #1 DIMENSION X(10) READ(5,*) (X(I),I=1,10) WRITE(6,1000) X 1000 FORMAT(1X,’THIS IS A VERY LONG LINE OF TEXT TO SHOW HOW TO CONTINUE ’ * ‘THE STATEMENT TO A SECOND LINE’,/,10F12.4)1-5Label67-72 Statements73-80OptionalLine #sAny character: continuation lineAE6382Statement FormatFORTRAN fixed format“C” in column 1 indicates that line is a commentcolumns 1-5 are reserved for statement labels–statement labels are not required unless the statement is the target of a goto–labels are numeric values onlycolumn 6 is the continuation flag–any character in column 6, other than space or “0”, indicates that this line is a continuation of the previous line–there is usually a limit of 19 on the number of continuationscolumns 7-72 are contain Fortran statementscolumns 73-80 is for sequence information–only of any use when using punch cardsAE6382Statement FormatIBM punch cardAE6382Building a FORTRAN ProgramFORTRAN is a complied language (like C) so the source code (what you write) must be converted into machine code before it can be executed (e.g. Make command)FORTRANProgramFORTRANCompilerLibrariesLink withLibrariesExecutable FileSource CodeObject CodeExecutable CodeExecuteProgramTest & DebugProgramMake Changesin Source CodeAE6382Structure of a Fortran ProgramFortran is a compiled languageall memory is allocated statically at compile time–there is no standard method for allocating additional memory in a Fortran program before Fortran 90–memory is allocated in a predictable manner, a fact which can be used by the programmer to his advantage or distressthere is no official recursion before Fortran 90–some vendor implementations had recursive capabilities–static memory allocation is at odds with the use of a stack which is needed for recursionFortran does not guarantee value of un-initialized memoryAE6382Structure of a Fortran ProgramFortran consists of program unitsprogramfunctionsubroutineblock dataThe program unit contains the main code and the point where execution startsin Fortran 77 a program begins with the program statementearlier versions of Fortran did not have a program statement unless a vendor dialect provided onethe end statement terminates the program unitAE6382Fortran ProgramThe program unit contains the main code and the point where execution startsin Fortran 77 a program begins with the program statementearlier versions of Fortran did not have a program statement unless a vendor dialect provided onethe end statement terminates the program unit–marks end of statements that belong to program–during execution it will cause the program to halta program unit may contain internal sub-programs–internal functions–internal subroutinesAE6382Fortran SubroutineThe subroutine unit contains Fortran code that can be called from other Fortran codea subroutine begins with a subroutine statementcontains a name for the subroutinea list of formal argumentssubroutines may be internal or externalan internal subroutine is included in the code of program unit and is only callable by the programan external subroutine is created outside of a program unit and is callable from everywhereAE6382Fortran Subroutine SUBROUTINE MULT(A,B,C) C = A * B RETURN END CALL MULT(5.0,X,VALUE)AE6382Fortran FunctionThe function unit contains Fortran code that can be called from other Fortran codeIt differs from a subroutine in that it returns a valuea subroutine begins with a function statementcontains a name for the functiona list of formal argumentsspecifies a return typefunctions may be internal or externalan internal function is included in the code of program unit and is only callable by the programan external function is created outside of a program unit and is callable from
View Full Document