Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Class Review

2 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 files: mv copy file: cp copy file: cp examine files: cat examine files: cat make directory: mkdir make directory: mkdir remove directory: rmdir remove directory: rmdir print a file: lpr –P print a file: lpr –P query a printer: lpq –P query a printer: lpq –P remove a printer job: lprm –P jobid remove a printer job: lprm –P jobid

3 Compile a Fortran77 Program All Fortran Program must have.f postfix All Fortran Program must have.f postfix Compile a Fortran Program Compile a Fortran Program  f77  f77  g77  g77  f77 -o  f77 -o  g77 -o  g77 -o

4 Basic Components of a Computer program Data structures Data structures  Identifying the right data structures are half the solution. Flow of Instructions Flow of Instructions  The operations on that data.

5 Compiling Source program Source program Compilation is the process of translating the program’s source code into machine code. Compilation is the process of translating the program’s source code into machine code.

6 Basic Problem Solving 1. State the Problem Clearly 2. Describe the Input and Output 3. Develop a Method to Solve the Problem by Hand - Simple Algorithm 4. Develop a Solution that is general in nature - Pseudocode, Flow chart 5. Test the Solution with a variety of Steps

7 Flow charts A diagrammatical approach to problem solving. A diagrammatical approach to problem solving. Important Symbols: Important Symbols: Process Process Decision Decision

8 Flow chart of students’ grade system

9 Basic Fortran Fortran is a free format language Fortran is a free format language  Spaces are ignored  Fortran compiler is not case sensitive  HELLO, HELL O, Hello, and hello are the same One statement per line in Fortran77 One statement per line in Fortran77

10 FORTRAN Statement Format

11 Programming Elements Data Data  Constant  A quantity that does not change  For Example: 3.14159263.1415926 5 0.060.06  Variable  A representation for a quantity which is unknown or can vary  Represented by a symbolic variable name  For Example: A ALPHAALPHA X1X1 Operations Operations

12 Data Type Integers 32, -8 Real Values -15.45, 0.004 Double-precision values 3.1415, 1.000006 Complex values 1-2i, 5i Character value ‘velocity’,’hello’ Logical values.TRUE.,.FALSE.

13 Data Declaration Variable Declaration Variable Declaration  Explicit Typing  With specification statement  Example INTEGER variable listINTEGER variable list REAL variable listREAL variable list  Implicit Typing  Variable names begins with I, J, K, L, M, N IntegerInteger  Others RealReal  Explicit Typing rules Implicit Typing  Example  I becomes a real variable instead of an integer REAL IREAL I Fortran is a weak-typing language Fortran is a weak-typing language  Variables can be used without declaration (but this is not encouraged) Constant Declaration Constant Declaration  PARAMETER(name1=expression, name2=expression,…)  Example  PARAMETER (PI=3.1415923)

14 Simple Input and Output very simple to write out information and read in variables. PRINT *, expression list Examples:- PRINT*,’ENTER a value’ PRINT*,’VALUE OF A= ’,A,’.’ READ *, variable list Examples:-READ*,ValREAD*,A,B,C

15 Assign a value to a variable Form Form  Variable name=expression Example Example  PI = 3.1415926  VAR1 = VAR2  I = I + 1

16 Mixed-Mode Operations Arithmetic operations Arithmetic operations  Between two real values -> real values  Between two integer values -> integer  Between a real value and an integer -> real value  Example  ROOT = NUM**(1/2)

17 Truncation and Rounding Truncation Truncation  Ignore the fractional portion  Store the number portion of the real number Rounding Rounding  The integer closest in value to the real number Assign a real number to an integer Assign a real number to an integer  Truncation happen  Example  Real A  Integer I  A = 2.8  I = A -> I = 2

18 Underflow and Overflow Magnitude of a real number Magnitude of a real number  Exponent in range of –38 through 38 Exponent > 38 Exponent > 38  Overflow Exponent < -38 Exponent < -38  Underflow

19 Intrinsic Functions SQRT (X)Square Root of X ABS(X)Absolute value for X SIN (X)X in Radians COS (X)X in Radians TAN (X)X in Radians EXP (X)e to the X LOG (X) Natural Log X LOG 10(X)Base 10 to the X INT (X)Truncate X REAL (I) Make I a Real MOD(I,J) Remainder of I/J

20 Formatted PRINT Statements Form: Form:  PRINT format identifier, item list Format Identifier Format Identifier  An asterisk  A format specification  A reference to FORMAT statement

21 Basic Form of the Format statement n FORMAT(s1, s2, s3... sk) s1, s2,... are format specifications They can be character or numeric literals, or they can specify the output or input precision of character or numeric values.

22 Specifications Summary X – Spacing, No values X – Spacing, No values Iw – Integer Numbers Iw – Integer Numbers Fw.d – F5.2 FLOATING POINT OR REAL NUMBERS Fw.d – F5.2 FLOATING POINT OR REAL NUMBERS Aw – Alphanumeric Data Aw – Alphanumeric Data Ew.d – Real Numbers in E Notation Ew.d – Real Numbers in E Notation T – tab specifies column to tab to. T – tab specifies column to tab to. / – Continue in new line / – Continue in new line ‘ ‘ – Literals between the quotes ‘ ‘ – Literals between the quotes

23 Logical Expressions A logical expression is one that is evaluated as either.true. or.false. Notice the periods on either side of.true. and.false. A logical expression is one that is evaluated as either.true. or.false. Notice the periods on either side of.true. and.false. Logical constants Logical constants .TRUE. .FALSE. You can declare logical variables that can take on values of.true. or.false. You can declare logical variables that can take on values of.true. or.false. LOGICAL DONE, EASY, HARD

24 Relational Operators.EQ.Equal to.NE.Not Equal to.LT. Less Than.LE. Less Than or Equal to.GT. Greater Than.GE. Greater Than or Equal to Note: Expressions are always read and evaluated from left to right. A.LT.B ( A less than B ) A.LT.B ( A less than B )

25 Logical Operators.NOT..NOT..AND..AND..OR..OR..EQV..EQV..NEQV..NEQV. Note: Not valid to compare two logical variables with.EQ. or.NE. AB.NOT. A A.AND.BA.OR.BA.EQV.BA.NEQV.B.FALSE..FALSE..TURE..FALSE..FALSE..TURE..FALSE..FALSE..TURE..TURE..FALSE..TURE..FALSE..TURE..TURE..FALSE..FALSE..FALSE..TURE..FALSE..TURE..TURE..TURE..FALSE..TURE..TURE..TURE..FALSE.

26 Relational and Arithmetic Operator PrecedencePriorityOperationOrder 1Parentheses Innermost first 2Exponentiation Right to Left 3 * / Left to right 4 + - Left to right 5 Relational operators Left to right 6.NOT. 7.AND. 8.OR. 9.EQV.,.NEQV. Left to right

27 Logical IF Statement Format: IF (logical expression) executable statement If the logical expression is true, execute the statement on the same line. If the logical expression is false, jump to the next statement. Example: IF (A.LT.0) SUM = SUM+A

28 Block IF Statements example: Portion of Zero Divide Zero DivideZero Divide IF (DEN.EQ.0.0) THEN PRINT *,’ZERO DIVIDE’ PRINT *,’ZERO DIVIDE’ STOP STOP END IF FRACTN = NUM/DEN PRINT *,’FRACTION =’, FRACTN

29 IF – THEN – ELSE IF(logical-exp)THEN statement 1 statement 1..ELSE statement n statement n statement n+1 statement n+1 END IF

30 ELSE IF Statement IF(logical-exp)THEN statement 1. statement m ELSE IF (logical-exp) THEN statement m+1. statement n ELSE IF (logical-exp) THEN statement n+1. statement p ELSE statement p+1. statement q END IF

31 While Loops There are no while statements in Fortran 77 although many compilers have implemented one. Here is how you do it. There are no while statements in Fortran 77 although many compilers have implemented one. Here is how you do it. n if ( logical_exp) then statement – 1 statement – 1 statement – 2 statement – 2. go to n go to n end if

32 DO Loop Structure Format: DO kindex = initial, limit, increment statement 1 … statement n k CONTINUE k CONTINUE

33 Files Files are used for permanent storage When we handle files, we open, process, then close the file. Processing can be reading from or writing to the file.


Download ppt "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."

Similar presentations


Ads by Google