21

Click here to load reader

Fortran - Sintaxe (1)

Embed Size (px)

Citation preview

Page 1: Fortran - Sintaxe (1)

Sintaxe de FortranProf. Tiago Chagas

[email protected]

Page 2: Fortran - Sintaxe (1)

Funções Trigonométricas

Page 3: Fortran - Sintaxe (1)

Funções Trigonométricas

Page 4: Fortran - Sintaxe (1)

Estrutura Básica do Fortran

PROGRAMPRINTWRITEREADSTOPEND

Page 5: Fortran - Sintaxe (1)

Comando de Atribuição

Pseudocódigo Fortran

Inteiro : x1x1 2 + 3 ;

Integer x1x1 = 2 + 3

Page 6: Fortran - Sintaxe (1)

Programa Mínimo

Pseudocódigo Fortran

ALGORITMO minimoVar X1 : InteiroINICIO X1 2 + 3 ;FIM

PROGRAM minimoInteger X1

X1 = 2 + 3

END

Page 7: Fortran - Sintaxe (1)

Ler e Escrever

Pseudocódigo Fortranvara : inteiroINICIO

Ler ( a )Escrever ( a ) Escrever(‘fim de programa’)

FIM

PROGRAM minimoInteger a

Read*, aWrite*, aWrite *, ‘fim de programa’

END

Page 8: Fortran - Sintaxe (1)

Estrutura Condicional

Pseudocódigo Fortran

x1 : Inteiro

INICIOx1 2 + 3 SE x1 > 5 ENTAO escreve (‘maior que 5’)SENAO escreve ( ‘x1=‘, x1)FIM

PROGRAM meuprogInteger x1x1 = 2 + 3IF ( x1 .GT. 5) print *, ‘maior que 5’ELSE print *,’x1=‘, x1END IFEND

Page 9: Fortran - Sintaxe (1)

Operadores Aritméticos

Operador Pseudocódigo Fortran + x + x - y - y

POT ( x,y) x**y RAD (x) SQRT(x)

/ / x Div y IFIX(x / y)

x MOD y MOD( x, y ) * * + + - -

Page 10: Fortran - Sintaxe (1)

Operadores Lógicos

Pseudocódigo Fortran Fortran90 = .EQ. = =

<> .NE. /= > .GT. >

>= .GE. >= < .LT. <

<= .LE. <=

Page 11: Fortran - Sintaxe (1)

Expressões Lógicas

Pseudocódigo Fortran E lógico .AND.

Ou lógico .OR. Não .NOT.

Equivalência Lógica .EQV. Não Eq. Lógica .NEQV.

Page 12: Fortran - Sintaxe (1)

Tipos de variáveis

Tipo Domínio das variáveis

Integer Inteiros positivos e negativos

Real Decimais positivos e negativos

Double precision

Decimais com mais casas decimais

Complex Complexos

Logical De valor .TRUE. Ou .FALSE.

Character Caracter único

Character *n Cadeia de literal, onde n é o tamanho da cadeia.

Page 13: Fortran - Sintaxe (1)

Constante

REAL piPARAMETER ( pi = 3.1415927 )

Page 14: Fortran - Sintaxe (1)

Pseudocódigo Fortran

// declaração de variáveisa, b, c, delta, x1, x2 : realINICIOLer ( a, b, c )  SE a <> 0 ENTAO início delta ← POT ( b, 2 ) - 4 * a * c escrever ( “delta =“, delta ) fim SENAO início escrever ( “é linear”) fimFIM SEFIM

PROGRAM calcula_raizes ! declaração de variáveis ! real a, b, c, delta, x1, x2 read*, a read*, b read*, c  IF ( a .NE. 0 ) THEN delta = b ** 2 - 4 * a * c print * , ‘ delta= ’ , deltaELSE print *, ‘ é linear ’ END IFSTOPEND

Page 15: Fortran - Sintaxe (1)

program calcularaizes real a, b, c, delta, x1, x2 print*, 'Programa de calculo de raizes' print*, 'a=' read*, a print*, 'b=' read*, b print*, 'c=' read*, c x1 = 0.0 x2 = 0.0 IF ( a .NE. 0 ) THEN delta = b ** 2 - 4 * a * c print *, 'delta =', delta ELSE print *, ' é linear ' END IF END

Page 16: Fortran - Sintaxe (1)

Sintaxe SE... SENAO

...SE a = 0 ENTAO ....SENAO ....FIM SE

...IF ( a = = 0 ) THEN ...ELSE ....END IF

Page 17: Fortran - Sintaxe (1)

Sintaxe SE... SENAO...SE

...SE a = 0 ENTAO ....SENAO SE a = 3 ENTAO .... FIMSEFIM SE

...IF ( a = = 0 ) THEN ...ELSEIF ( a = = 3 ) ....END IF

Page 18: Fortran - Sintaxe (1)

Sintaxe SE... SENAO...SE

...SE a = 0 E a > 10

ENTAO ....SENAO SE a = 3 ENTAO .... FIMSEFIM SE

...IF ( ( a = =

0 ) .AND. ( a > 10) ) THEN

...ELSEIF ( a = = 3 ) ....END IF

Page 19: Fortran - Sintaxe (1)

Sintaxe ESCOLHA

...Inteiro : a ;...ESCOLHA a CASO 1 : ....CASO 3 : ...CASO

CONTRARIO: ...FIM ESCOLHA

...Integer a...SELECT CASE

( a ) ...CASE (1) ...CASE (3) ...CASE DEFAULT ...END SELECT

Page 20: Fortran - Sintaxe (1)

Sintaxe ENQUANTO-FAÇA (teste no início)

Ler (n) ;cont 0 ; ENQUANTO cont < n

FACA inicio ... cont cont + 1; fimFIM ENQUANTO

Read*, nCont = 0 DO WHILE ( cont < n) ... cont = cont + 1

END DO

Page 21: Fortran - Sintaxe (1)

Sintaxe ENQUANTO-FAÇA (teste no início) com 2 condições

ENQUANTO (cont < n) E ( t = 0)

FACA iniciofimFIM ENQUANTO

DO WHILE (( cont < n) .AND. (t = = 0))

... cont = cont + 1

END DO