Lập trình bằng ngôn ngữ lập trình Fortran

Nội dung chính gồm

Chương 1: THÀNH PHẦN VÀ CẤU TRÚC CHƯƠNG TRÌNH FORTRAN

1.1. Lịch sử phát triển

1.2. Cấu trúc của chương trình FORTRAN 90/95

 1.2.1. Cấu trúc chương trình

 1.2.2. Đặt tên (name)

 1.2.3. Bộ ký tự (Character set)

 1.2.4. Các dạng chương trình nguồn (source forms)

 1.3. Kiểu dữ liệu (Data Type), hằng và biến

1.3.1. Các kiểu số liệu sẵn có

1.3.2. Kiểu số liệu do người dùng định nghĩa

1.4. Biến (Variable)

Chương 2: BIỂU THỨC VÀ LỆNH GÁN

2.1. Biểu thức

2.1.1. Biểu thức số học

2.1.2. Biểu thức Logic

2.2 Lệnh gán (Assignment statements)

2.2.1. Lệnh gán số học

2.2.2. Lệnh gán Logic

2.2.3. Gán chuỗi ký tự

2.3. Gán mảng và mô tả biến mảng

2.4 Gán con trỏ và mô tả biến con trỏ

Chương 3: CÁC PHÁT BIỂU CHỈ ĐỊNH VÀ ĐIỀU KHIỂN THỰC HIỆN

3.1 Các phát biểu chỉ định (Specification statements)

 3.1.1 Phát biểu AUTOMATIC và STATIC

 3.1.2 Phát biểu COMMON

 3.1.3 Phát biểu DATA

 3.1.4 Phát biểu EQUIVALENCE

 3.1.5 Phát biểu NAMELIST

3.2 Các phát biểu điều khiển thực hiện (execution control)

 3.2.1 Các phát biểu rẽ nhánh (Branch statements)

 3.2.2 Phát biểu IF số học (Arithmetic IF statement)

 3.2.3 Phát biểu CALL

 3.2.4 Cấu trúc CASE

 3.2.5 Phát biểu CONTINUE

 3.2.6 Cấu trúc DO

 3.2.7 Phát biểu END

Chương 4: CÁC ĐƠN VỊ CHƯƠNG TRÌNH VÀ CÁC THỦ TỤC

4.1 Khaí niệm cơ bản

4.2 Chương trình chính (Main program)

4.3 Module và các thủ tục trong module(Module and module procedure)

4.4 Chương trình BLOCK DATA

4.5 Chương trình con FUNCTION

4.6 Chương trình con SUBROUTINE

4.7. Hàm định nghĩa trực tiếp

Chương 5: CÁC THỦ TỤC THƯ VIỆN

5.1. Phân lớp các thủ tục

5.2. Các hàm thư viện (Intrinsic functions)

5.3. Các chương trình con thư viện SUBROUTINE

Chương 6: ĐỌC VÀ GHI SỐ LIỆU

6.1 Các bản ghi và file (Records and files)

6.2 Các phát biểu truyền số liệu (I/O)

6.3 Phát biểu READ

 6.3.1 Truy cập tuần tự

 6.3.2 Truy cập trực tiếp

 6.3.3 Phát biểu READ với Internal file

6.4 Phát biểu WRITE

 6.4.1 Kiểu truy cập tuần tự

 6.4.2 Kiểu truy cập trực tiếp

 6.4.3 Phát biểu WRITE với Internal file

6.5 Phát biểu PRINT

6.6 Các dạng mô tả format

6.7 Phát biểu mở file

6.8 Phát biểu đóng file

 

doc79 trang | Chuyên mục: Fortran | Chia sẻ: dkS00TYs | Lượt xem: 1966 | Lượt tải: 5download
Tóm tắt nội dung Lập trình bằng ngôn ngữ lập trình Fortran, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
al1 = 24.0
 real2 = 28.0d0
 z1 = (38.0,0.0)
 z2 = (316.0d0,0.0d0)
 char1 = 'A'
 char2 = '0123456789'
 array(1) = 41
 array(2) = 42
 array(3) = 43
 WRITE (*, example)
The preceding example produces the following output: 
 &EXAMPLE
 INT1 = 11,
 INT2 = 12,
 INT3 = 14,
 LOG1 = T,
 LOG2 = T,
 LOG3 = T,
 REAL1 = 24.00000 ,
 REAL2 = 28.0000000000000 ,
 Z1 = (38.00000,0.0000000E+00),
 Z2 = (316.0000,0.0000000E+00),
 CHAR1 = A,
 CHAR2 = 0123456789,
 ARRAY = 41, 42, 43
 /
Rules for Unformatted Sequential WRITE Statements 
Rules for Unformatted Sequential WRITE Statements
Unformatted, sequential WRITE statements transfer binary data (without translation) between the entities specified in the I/O list and the current record. Only one record is written.
Objects of intrinsic or derived types can be transferred.
This form of WRITE statement writes exactly one record. If there is no I/O item list, the statement writes one null record.
If the file is connected for formatted, list-directed, or namelist I/O, unformatted data transfer is prohibited.
Examples
The following example shows an unformatted, sequential WRITE statement:
 WRITE (UNIT=6, IOSTAT=IO_STATUS) A, B, C
For More Information:
See I/O control-list specifiers. 
See I/O lists. 
6.3.2.2 Forms for Direct-Access WRITE Statements 
Forms for Direct-Access WRITE Statements
Direct-access WRITE statements transfer output data to external records with direct access. (The attributes of a direct-access file are established by the OPEN statement.)
A direct-access WRITE statement can be formatted or unformatted, and takes one of the following forms:
Formatted:
WRITE (eunit, format, rec [, iostat] [, err]) [io-list]
Unformatted:
WRITE (eunit, rec [, iostat] [, err]) [io-list] 
For more information, see WRITE in the A to Z Reference.
This section discusses the following topics:
Rules for Formatted Direct-Access WRITE Statements 
Rules for Unformatted Direct-Access WRITE Statements 
For More Information:
See I/O control-list specifiers. 
See I/O lists. 
6.3.2.3 Forms and Rules for Internal WRITE Statements 
Forms and Rules for Internal WRITE Statements
Internal WRITE statements transfer output data to an internal file.
An internal WRITE statement can only be formatted. It must include format specifiers (which can use list-directed formatting). Namelist formatting is not permitted.
An internal WRITE statement takes the following form:
WRITE (iunit, format [, iostat] [, err]) [io-list] 
For more information on syntax, see WRITE in the A to Z Reference.
Formatted, internal WRITE statements translate data from binary to character form by using format specifications for editing (if any). The translated data is written to an internal file.
Values can be transferred from objects of intrinsic or derived types. For derived types, values of intrinsic types are transferred from the components of intrinsic types that ultimately make up these structured objects.
If the number of characters written in a record is less than the length of the record, the rest of the record is filled with blanks. The number of characters to be written must not exceed the length of the record.
Character constants are not delimited by apostrophes or quotation marks, and each internal apostrophe or quotation mark is represented externally by one apostrophe or quotation mark.
Examples
The following example shows an internal WRITE statement:
 INTEGER J, K, STAT_VALUE
 CHARACTER*50 CHAR_50
 ...
 WRITE (FMT=*, UNIT=CHAR_50, IOSTAT=STAT_VALUE) J, K
For More Information:
6.4 Các câu lệnh thao tác trên file
Phần II. Môi trường lập trình Compaq Visual Fortran 6.6a
Phụ lục 1. Một số câu hỏi, bài tập và chương trình mẫu
Phụ lục 2. Tra cứu cú pháp các câu lệnh FORTRAN 90
FORTRAN 77 Data Types
The data types defined by ANSI FORTRAN 77 are as follows: 
INTEGER 
REAL 
DOUBLE PRECISION 
COMPLEX 
LOGICAL 
CHARACTER [*n], where n is between 1 and 32,767 
The data type of a variable, symbolic constant, or function can be declared in a specification statement. If its type is not declared, the compiler determines a data type by the first letter of the variable, constant, or function name. A type statement can also dimension an array variable. 
Default requirements for these data types are listed in the following table: 
Type
Bytes
INTEGER 
4 
REAL 
4 
DOUBLE PRECISION 
8 
COMPLEX 
8 
LOGICAL 
4 
CHARACTER 
1 
CHARACTER*n 
n 1 
1 Where the maximum n is 32,767. 
FORTRAN 77 Intrinsic Functions
Function syntax
Type of return value
ABS (gen) 
Same as argument 
ACOS (real) 
Same as argument 
AIMAG (cmp8) 
REAL 
AINT (real) 
Same as argument 
ALOG (real4) 
REAL 
ALOG10 (real4) 
REAL 
AMAX0 (intA, intB [, intC ] ...) 
REAL 
AMAX1 (real4A, real4B, [, real4C ] ...) 
REAL 
AMIN0 (intA, intB [, intC ] ...) 
REAL 
AMIN1 (real4A, real4B [, real4C ] ...) 
REAL 
AMOD (value, mod) 
REAL 
ANINT (value) 
REAL 
ASIN (real) 
Same as argument 
ATAN (real) 
Same as argument 
ATAN2 (realA, realB) 
Same as argument 
CABS (cmp) 
Same as argument; COMPLEX returns REAL 
CCOS (cmp8) 
COMPLEX 
CHAR (int) 
CHARACTER 
CLOG (cmp8) 
COMPLEX 
CMPLX (genA [, genB ]) 
COMPLEX 
CONJG (cx8value) 
COMPLEX 
COS (gen) 
Same as argument 
COSH (real) 
Same as argument 
CSIN (cmp8) 
COMPLEX 
CSQRT (cx8value) 
COMPLEX 
DABS (r8value) 
DOUBLE PRECISION 
DACOS (dbl) 
DOUBLE PRECISION 
DASIN (dbl) 
DOUBLE PRECISION 
DATAN (dbl) 
DOUBLE PRECISION 
DATAN2 (dblA, dblB) 
DOUBLE PRECISION 
DBLE (value) 
DOUBLE PRECISION 
DCOS (dbl) 
DOUBLE PRECISION 
DCOSH (dbl) 
DOUBLE PRECISION 
DDIM (dblA, dblB) 
DOUBLE PRECISION 
DEXP (dbl) 
DOUBLE PRECISION 
DIM (genA, genB) 
Same as arguments 
DINT (rvalue) 
DOUBLE PRECISION 
DLOG (dbl) 
DOUBLE PRECISION 
DLOG10 (dbl) 
DOUBLE PRECISION 
DMAX1 (dblA, dblB [, dblC ] ...) 
DOUBLE PRECISION 
DMIN1 (dblA, dblB [dblC ] ...) 
DOUBLE PRECISION 
DMOD (value, mod) 
DOUBLE PRECISION 
DNINT (dbl) 
DOUBLE PRECISION 
DPROD (real4A, real4B) 
DOUBLE PRECISION 
DREAL (cxvalue) 
DOUBLE PRECISION 
DSIGN (dblA, dblB) 
DOUBLE PRECISION 
DSIN (dbl) 
DOUBLE PRECISION 
DSINH (dbl) 
DOUBLE PRECISION 
DSQRT (rvalue) 
DOUBLE PRECISION 
DTAN (dbl) 
DOUBLE PRECISION 
DTANH (dbl) 
DOUBLE PRECISION 
EXP (gen) 
Same as argument 
FLOAT (ivalue) 
REAL 
IABS (int) 
Same as argument 
ICHAR (char) 
INTEGER 
IDIM (intA, intB) 
INTEGER 
IDINT (dbl) 
INTEGER 
IDNINT (dbl) 
INTEGER 
IFIX (real4) 
REAL 
INDEX (charA, charB) 
INTEGER 
INT (gen) 
INTEGER 
ISIGN (intA, intB) 
INTEGER 
LEN (char) 
INTEGER 
LGE (charA, charB) 
LOGICAL 
LGT (charA, charB) 
LOGICAL 
LLE (charA, charB) 
LOGICAL 
LLT (charA, charB) 
LOGICAL 
LOG (gen) 
Same as argument 
LOG10 (real) 
Same as argument 
MAX (genA, genB [, genC ] ...) 
INTEGER or REAL 
MAX0 (intA, intB [, intC ] ...) 
INTEGER 
MAX1 (realA, realB [, realC ] ...) 
INTEGER 
MIN (genA, genB [, genC ] ...) 
INTEGER or REAL 
MIN0 (intA, intB [, intC ] ...) 
INTEGER 
MIN1 (realA, real [, real ] ...) 
INTEGER 
MOD (genA, genB) 
REAL 
NINT (real) 
INTEGER 
REAL (gen) 
REAL 
SIGN (genA, genB) 
INTEGER or REAL 
SIN (gen) 
Same as argument 
SINH (real) 
Same as argument 
SNGL(dbl) 
REAL 
SQRT (gen) 
Same as argument 
TAN (real) 
Same as argument 
TANH (real) 
Same as argument 
FORTRAN 77 Statements
ASSIGN label TO variable
BACKSPACE {unitspec | 
( [UNIT=]unitspec [, ERR=errlabel] [, IOSTAT=iocheck] )} 
BLOCK DATA [blockdataname] 
CALL sub [( [actuals] )] 
CHARACTER [*chars] vname [*length] [(dim)] [, vname [*length] [(dim)] 
CLOSE ( [UNIT=]unitspec 
[, ERR=errlabel] [, IOSTAT=iocheck] [, STATUS=status] ) 
COMMON [/[cname] /] nlist[[,] / [cname] /nlist ] ... 
COMPLEX vnam [(dim)] [, vname [(dim)]] ... 
CONTINUE 
DATA nlist /clist/ [[,] nlist /clist/ ] ... 
DIMENSION array ([lower:]upper [, {[lower:]upper ] ) 
DO [label [,] ] dovar = start, stop [, inc] 
DOUBLE PRECISION vname [(dim)] [, vname [(dim)] ] ... 
ELSE    statementblock
ELSE IF (expression) THEN    statementblock
END
END IF
ENDFILE {unitspec | 
( [UNIT=] unitspec [, ERR=errlabel] [, IOSTAT=iocheck] )} 
ENTRY ename [ ( [formal [, formal ] ...] )] 
EQUIVALENCE (nlist) [, (nlist)] ... 
EXTERNAL name [, name ] ... 
FORMAT [editlist] 
[type] FUNCTION func ([formal ] [, formal ] ...) 
GOTO variable [ [,] (labels)] 
GOTO (labels) [,] n
GOTO label
IF (expression) label1, label2, label3
IF (expression) statement
IF (expression) THEN       statementblock1    [ELSE IF (expression) THEN       statementblock2] ...    [ELSE       statementblock3] END IF
IMPLICIT type (letters) [, type (letters)] ...
INQUIRE ( {[UNIT=]unitspec | FILE=file} 
[, ACCESS=access] [, BLANK=blank] [, DIRECT=direct] [, ERR=errlabel] [, EXIST=exist] [, FORM=form] [, FORMATTED=formatted] [, IOSTAT=iocheck] [, NAME=name] [, NAMED=named] [, NEXTREC=nextrec] [, NUMBER=num] [, OPENED=opened] [, RECL=recl] [, SEQUENTIAL=seq] [, UNFORMATTED=unformatted] ) 
INTEGER vname [(dim)] [, vname [ (dim)] ] ... 
INTRINSIC names 
LOGICAL vname [(dim)] [, vname [(dim)] ] ... 
OPEN ( [UNIT=]unitspec [, ACCESS=access] 
[, BLANK=blanks] [, ERR=errlabel] [, FILE=file] [, FORM=form] [, IOSTAT=iocheck] [, RECL=recl] [, STATUS=status] ) 
PARAMETER (name=constexpr [, name=constexpr] ...) 
PAUSE [prompt] 
PRINT { *, | formatspec | } [, iolist] 
PROGRAM program-name
READ {formatspec, | ( [UNIT=] unitspec 
[, [FMT=]formatspec][, END=endlabel ] [, ERR=errlabel] [, IOSTAT=iocheck] [, REC=rec] )} iolist 
REAL vname [(dim)] [, vname [(dim)] ] ... 
RETURN [ordinal ] 
REWIND {unitspec | ( [UNIT=] unitspec 
[, ERR=errlabel] [, IOSTAT=iocheck] )} 
SAVE [names] 
STOP [message] 
SUBROUTINE subr [([ formal [, formal ] ...] )] 
WRITE ( [UNIT=] unitspec 
[, [FMT=] formatspec] [, ERR=errlabel] [, IOSTAT=iocheck] [, REC=rec] ) iolist 

File đính kèm:

  • docLập trình bằng ngôn ngữ lập trình Fortran.doc