Fortran 1- Basics Chapters 1-2 in your Fortran book.

Slides:



Advertisements
Similar presentations
1 Chapter 2 Basic Elements of Fortran Programming.
Advertisements

Fortran 4- Reading and Writing from Data Files Chapter 4 of your Fortran book.
Programming in Visual Basic
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Chapter 2 Basic Elements of Fortan
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
BIL101, Introduction to Computers and Information Systems Chapter 12 A Portable Scientific Visualization Program: GnuPlot Prepared by Metin Demiralp Istanbul.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Introduction to C Programming
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Input, Output, and Processing
Class Review. Basic Unix Commands list files in a directory: ls list files in a directory: ls remove files: rm remove files: rm rename files: mv rename.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Introduction to Programming with RAPTOR
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
INPUT / OUTPUT STATEMENTS
Chapter-4 Managing input and Output operation.  Reading, processing and writing of data are three essential functions of a computer program.  Most programs.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Topics Designing a Program Input, Processing, and Output
Chapter 1: Introduction to computers and C++ Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chapter 2 - Introduction to C Programming
ICS103 Programming in C Lecture 3: Introduction to C (2)
Chapter 2 - Introduction to C Programming
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
INPUT & OUTPUT scanf & printf.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Topics Designing a Program Input, Processing, and Output
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2 - Introduction to C Programming
Variables in C Topics Naming Variables Declaring Variables
Introduction to C Programming
Presentation transcript:

Fortran 1- Basics Chapters 1-2 in your Fortran book

About Fortran There are two versions that are commonly used: FORTRAN 77 and FORTRAN 90. FORTRAN 90 is the standardized version used internationally. The Fortran programming language has some very specific structural requirements of our programs, as well as a specific syntax for most of the commands that we will be using in creating a program.

About Fortran Programs With the use of a text editor we create a source code: – will typically have an extension for (for example program1.for) – essentially a set of instructions in the Fortran programming language that we wish the computer to execute. – Although it may not appear to be English, source code is essentially a group of English expressions or commands that we understand. The problem however is that the computer only understands machine language. The machine language that the computer understands is a binary language composed of 0’s and 1’s. All the numbers and letters that we want the computer to understand are essentially converted into a binary expression that the computer can understand.

Compilers a compiler translates the (English) source code into machine code so that the computer understands the commands The actual steps in the compiling process involve compiling the source code to create object files, then linking the object files together to form a single executable file. The executable file is a single file that will execute the desired computer instructions when invoked. The executable file has an exe extension; for example: program1.exe.

Variables Most programs will require the use of variables to make the program applicable to solve general problems. The variables that are to be used may consist of either letter or numeric characters. Variables take the following form:  1 to 6 characters in length  The first character of a name must be alphabetic  Fortran does not distinguish between upper and lower case letters Examples: DISTANCE - no good, too long TIME- valid PI- valid $- no good, illegal character($) TAX-RT- no good, illegal character (-) B3- valid 2X-no good, first character numeric

Data Types There are six basics types: Integers- whole number (positive, negative or zero); 32, -7 Real Values- decimal numbers or exponential; 15.45, Double-Precision Values Complex Values- 1-2i, 5i, Character Values- constants or strings; ‘velocity’, ‘Report 3’ Logical Values-.True.,.False.

Types of Variables When we define a variable we ask the computer to reserve a spot in memory for our particular variable. The type of variable that we specify can be specified by two methods: – implicit typing- determined by the first letter of the variable that we select. By default, Fortran sets variable names beginning with I, J, K, L, M, or N as integers. Therefore, any variable such as ‘IX’ or N2 are reserved as integers. If we tried to set N3=2.45, the Fortran program will save N3 =2. The decimal portion of the number will be truncated. Variable names beginning with the other letters A-H or O-Z will be stored as real values. – explicit typing - Fortran statements are used to specify a particular variable type: INTEGER area, width, height (not case sensitive) REAL I, length, mean (not case sensitive) These statements tell the compiler to assign memory locations, and to specify the types of values that will be stored in these locations.

Truncation and Mix-Mode Operations Truncation- when the computer stores a real number in an integer variable, it ignores the factional portion, or truncates it to a whole number. ex: I= 3 J=5 (I+J)/3 = 2|.6666  2 but, (I+J)/3.0 = ex: I**(1/2)  1 1/2 will truncate to 0 (0|.5) Mix-mode operations- operations involving both real numbers and integers ex:MASS = 2.519*WEIGHT This expression will first result in a real value from the multiplication and the truncation will take place when the value stored in the integer memory location for MASS. If WEIGHT = 100, the result from the multiplication is and the value that would be stored in MASS would be 251 (the decimal portion will be truncated). Intermediate results on operations between integers and real values are real values. The final results depend on the variable names that are used to store the results.

Intrinsic Functions FORTRAN has a number of built-in operators that we can use for calculations. Some of these functions include: SQRT( number or expression) COS (angle in radians) ABS (number or expression) etc. **Note ACOS, ASIN, ATAN are all “ARC” functions or the Trigonometric functions

Simple Input and Output List-directed input: we can receive input directly from the keyboard with the READ statement : READ*, variable list The program will wait for the user to input the required values. The data values from the user can be separated by commas or blanks. After the data has been typed into the command line, the user will press the return key and the program will continue. In general, the READ statement will have to be preceded by an instruction that asks the user to put the data in. This can be simply conducted with the List-Directed Output that takes the similar form as the List-Directed Input statements: PRINT*, expression list Values in the expression list should be separated by commas. Statements can be included in the Print statement by enclosing the desired expressions in single quotation marks or apostrophes: PRINT*, ‘Please input the area and length separated by commas’ this may be followed by: READ*, AREA, ALGTH Or if we have a variable named AREA PRINT*, ‘The Area of the rod is ’, AREA This will output the character string “The Area of the rod is” followed by the value of the variable AREA.

Formatting Output PRINT k, expression list where k is the address of a format statement for the output(recall that this is an address place in columns 1 through 5). For Example: Print 5, AREA, ALGTH 5 FORMAT (5X, ‘The area of the rod is ’, F6.2,/, + 5X,‘The length of the rod is ’, F6.3) The “5X” in the above expression is just specifying to leave 5 blanks before our character string. The basic form of this is #X, where # is the number of blanks that we wish to leave. The F6.3 in the format statement is telling the compiler the desired format for the values of AREA - at most 6 digits with 2 points past the decimal. The “/” in the above expression specifies to start a new line.

Formatting Data Types TypeForm Real Integer Exponential Fw.d Iw Ew.d w- total width of number including the decimal point and any minus sign d- number of digits after decimal If the actual output is larger than the widths specified in the formatting statement, the output will be asterisks. It is very important to remember to include room for the decimal and a potential minus sign for negative values. All of the values will be right justified so that if we specify too large of a space this will result in blank spaces preceding our output.

Statement Format Each statement that we put in a fortran program is entered on a single line. As we talk about the format of a line we will discuss a particular position on the line relative to column numbers. The makeup of each line must take the following form: 1)Columns 1 -5 Statement number or label- not every line will have a statement number. In some cases however we will want to number a particular line so that we can refer to the particular line in the program. 2)Column 6 is reserved for a continuation character. If a particular statement is too long, it will have to be continued on the next line. By placing a character (such as +) in the sixth column we tell the compiler that the statement on this particular line is a continuation of the previous line. 3)Columns 7-72 Fortran statement. The only exception to the above layout is that if an asterisk *, or a letter C are placed in column 1, the particular line is a comment statement. It is highly encouraged to use liberal comment statements in order to organize the material in your program. We can include blank lines anywhere in the program to separate portions of the program.

Program Structure The form of a program has some very basic requirements: The first line of a program usually consists of a PROGRAM statement. The program statement assigns a name to the program and takes the following form: PROGRAM program name The program name can be one to six characters (alphabetic or numeric) and must begin with a letter. PROGRAM TEST PROGRAM LOAD1 It is usually good programming format to have some comment lines follow the program statement to describe what the program does.

Stop and End Statements STOP statement: signals the computer to terminate execution of the program. In some instances, you may wish to exit the program if certain conditions exist. This is accomplished with a STOP statement. There are no arguments associated with the STOP statement, it is the only command on the particular line. The STOP statement is optional at the end of the program. If one is not placed in the program, the compiler will automatically place a STOP command in the executable to stop the program. END Statement: identifies the end of the FORTRAN PROGRAM. There are no arguments. The basic form of the program is therefore as follows: PROGRAM ROAD Specification Statements Executable Statements END Statement

Example