1. Trang chủ
  2. » Công Nghệ Thông Tin

beginning fortran slide

29 214 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 29
Dung lượng 1,12 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Why Learn It?• If you are pursuing a graduate degree in AOS, you will eventually run into Fortran: – An assignment – A research problem – Someone else’s code* *THIS is why commenting cod

Trang 2

What is Fortran?

• One of the oldest programming languages still

in use

• Fortran77, Fortran90

• Used primarily by geophysical sciences:

– Good at math and manipulation of large data sets – Consistent with earliest NWP models

Trang 3

I program in Fortran…

I program in Fortran…

Trang 4

Trang 5

Why Learn It?

• If you are pursuing a graduate degree in AOS, you will eventually run into Fortran:

– An assignment

– A research problem

– Someone else’s code*

*THIS is why commenting code is so important (later

on that)

Trang 6

Your Typical Program

Trang 7

Your Typical Program

c234567 PROGRAM MYPROGRAM

STOP END

Program Options

Declaration of Variables

MAIN CODE

MAIN CODE

The first seven columns

of the program code

are reserved for special

functions – most lines

of code begin on the

seventh column

Trang 8

Your Typical Program

Trang 9

Your Typical Program

c234567 PROGRAM MYPROGRAM

STOP END

Program Options

Declaration of Variables

MAIN CODE

MAIN CODE

All variables used

in the code have

to be declared at

the top, before

any of the main

code is run.

Trang 10

Your Typical Program

Trang 11

Your Typical Program

c234567 PROGRAM MYPROGRAM

STOP END

Program Options

Declaration of Variables

MAIN CODE

MAIN CODE This identifies the

end of the program

Trang 12

A More Complicated Program

PROGRAM MYPROGRAM Options

Declaration of Variables

MAIN CODE CALL MYSUBROUTINE MAIN CODE

STOP END SUBROUTINE MYSUBROUTINE Options

Declaration of Variables

MAIN CODE CALL MYSUBROUTINE MAIN CODE

RETURN END

Trang 13

A More Complicated Program

PROGRAM MYPROGRAM Options

Declaration of Variables

MAIN CODE CALL MYSUBROUTINE MAIN CODE

STOP END SUBROUTINE MYSUBROUTINE Options

Declaration of Variables MAIN CODE

RETURN END

Being able to trace the

flow of information is by

far the most important

thing to learn about

programming, in Fortran

or in any other language.

You will eventually have

to write code that is not

only able to perform

complicated functions,

but is readable to

someone else who

wishes to use it.

Trang 15

• Numbers can be:

– Integers – This is any integer value (e.g -5, 0, 1) – “Real”/”Floating-Point”/etc – This is any number (e.g 5.6, 2.11245)

In general, “integer” variables are good for

keeping counts of things, while “real” variables are used for data.

Trang 17

Logical Variables

• LOGICAL variables are either ‘true’ or ‘false’, and are usually used to determine if some set

of criteria has occurred or not

IF (Some variable is greater than 5) THEN

its_greater_than_five = TRUE ENDIF

Trang 18

• Usually you are going to need a whole block of numbers representing your data set (e.g a

block of numbers representing vorticity at

every point in some domain)

• You can specify an array of any of these

variable types

Trang 19

• The array has a type (INTEGER, REAL, etc.), a single name, and a set of dimensions:

VALUES(55,90)

Trang 22

VALUES (1,2)

VALUES (1,2)

VALUES (1,3)

VALUES (1,3)

VALUES (1,2)

VALUES (1,2) VALUESVALUES(2,2)(2,2) VALUESVALUES(3,2)(3,2)

VALUES (2,3)

VALUES (2,3) VALUESVALUES(3,3)(3,3) VALUESVALUES(4,3)(4,3)Each element of VALUES is identifiable by

its index.

Trang 23

VALUES (1,2)

VALUES (1,2)

VALUES (1,3)

VALUES (1,3)

VALUES (1,2)

VALUES (1,2) VALUESVALUES(2,2)(2,2) VALUESVALUES(3,2)(3,2)

VALUES (2,3)

VALUES (2,3) VALUESVALUES(3,3)(3,3) VALUESVALUES(4,3)(4,3)Each element of VALUES is identifiable by

its index.

Trang 24

Arrays

Trang 25

• Values in arrays have indices that correspond to their location in the array

• Loops provide the ability to go through each

member of the array individually:

For i = 1, 3

For j = 1, 2

VALUES(i,j) End

End

Trang 26

• Arrays, loops, logical traps, etc.

• Poor coding technique will come back to bite you!

Trang 27

• All coding languages allow you to sneak in

messages in the code itself to allow a reader to understand what is going on – these are called

Trang 28

• All coding languages allow you to sneak in

messages in the code itself to allow a reader to understand what is going on – these are called

Trang 29

In The Next Few Weeks

Ngày đăng: 24/10/2014, 21:33