1 / 33

Class Review

Class Review. Basic Unix Commands. list files in a directory: ls remove files: rm <filename> rename files: mv <oldfilename> <newfilename> copy file: cp <file 1> <file 2> examine files: cat <filename> make directory: mkdir <directoryname> remove directory: rmdir <directoryname>

caesar
Télécharger la présentation

Class Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class Review

  2. Basic Unix Commands list files in a directory: ls remove files: rm <filename> rename files: mv <oldfilename> <newfilename> copy file: cp <file 1> <file 2> examine files: cat <filename> make directory: mkdir <directoryname> remove directory: rmdir <directoryname> print a file: lpr –P<printer> <filename> query a printer: lpq –P<printer> remove a printer job: lprm –P<printer> jobid

  3. Compile a Fortran77 Program • All Fortran Program must have .f postfix • Compile a Fortran Program • f77 <filename> • g77 <filename> • f77 <filename> -o <executable filename> • g77 <filename> -o <executable filename>

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

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

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

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

  8. Flow chart of students’ grade system

  9. Basic Fortran • 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

  10. FORTRAN Statement Format

  11. Programming Elements • Data • Constant • A quantity that does not change • For Example: • 3.1415926 • 5 • 0.06 • Variable • A representation for a quantity which is unknown or can vary • Represented by a symbolic variable name • For Example: • A • ALPHA • X1 • Operations

  12. Data Type

  13. Data Declaration • Variable Declaration • Explicit Typing • With specification statement • Example • INTEGER variable list • REAL variable list • Implicit Typing • Variable names begins with I, J, K, L, M, N • Integer • Others • Real • Explicit Typing rules Implicit Typing • Example • I becomes a real variable instead of an integer • REAL I • Fortran is a weak-typing language • Variables can be used without declaration (but this is not encouraged) • 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*,Val READ*,A,B,C

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

  16. Mixed-Mode 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 • Ignore the fractional portion • Store the number portion of the real number • Rounding • The integer closest in value to the real number • 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 • Exponent in range of –38 through 38 • Exponent > 38 • Overflow • 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: • PRINT format identifier, item list • 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 • Iw – Integer Numbers • Fw.d – F5.2 FLOATING POINT OR REAL NUMBERS • Aw – Alphanumeric Data • Ew.d – Real Numbers in E Notation • T – tab specifies column to tab to. • / – Continue in new line • ‘ ‘ – 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. Logical constants .TRUE. .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 )

  25. Logical Operators .NOT. <Logical Expression> <Logical Expression> .AND. <Logical Expression> <Logical Expression> .OR. <Logical Expression> <Logical Expression> .EQV. <Logical Expression> <Logical Expression> .NEQV. <Logical Expression> Note: Not valid to compare two logical variables with .EQ. or .NE.

  26. Relational and Arithmetic Operator Precedence

  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 IF (DEN.EQ.0.0) THEN PRINT *,’ZERO DIVIDE’ STOP END IF FRACTN = NUM/DEN PRINT *,’FRACTION =’, FRACTN

  29. IF – THEN – ELSE IF(logical-exp)THEN statement 1 . . ELSE statement n 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. nif (logical_exp) then statement – 1 statement – 2 . go ton end if

  32. DO Loop Structure Format: DO k index = initial, limit, increment statement 1 … statement n 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.

More Related