Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 2 Basic Elements of Fortran

Similar presentations


Presentation on theme: "Chapter 2 Basic Elements of Fortran"— Presentation transcript:

1 Chapter 2 Basic Elements of Fortran

2 2-1 註解 “!”後的字元當為註解 < Ex. 程式片段> 註解的地方不會執行,是用來說明或偵錯,可提升程式可讀性。
! Local variables integer :: j, i, j1, alloc_err real(kind=kind_dbl) :: Delta_theta, theta, x, y, & b(mu*nu), U(mu,mu), new_ev(mu*nu) 註解的地方不會執行,是用來說明或偵錯,可提升程式可讀性。

3 2-2 續行 每一行的行尾出現”&”符號時表示下一行和本行 是連續的,在行頭出現”&”時,如果上一行的行
尾符號也是”&”,表示本行程式碼和上一行接續 < Ex. 程式片段> ! Local variables integer :: j, i, j1, alloc_err real(kind=kind_dbl) :: Delta_theta, theta, x, y, & b(mu*nu), U(mu,mu), new_ev(mu*nu) 這兩行是同一行

4 2-3 字元集 寫作程式時,可以使用的基本字元及符號 文字字元:A~Z or a~z (不區分字母的大小寫) 數字字元:0~9
特殊字元:+ - * / = ( ) , . “ ‘ & : _

5 2-4 Data type 電腦處理資料時,必須給定資料型態(data type), 系統才能配置適當的記憶體大小用來儲存資料。 儲存單位
bit:最小的儲存單位 一個bit只能儲存一個0或是1 byte:位元組 1 byte = 8 bit

6 2-4 Data type integer整數 integer(kind=2)
需16 bits (2 bytes) 儲存,整數介於±32767之間 (i.e 之間) integer(kind=4) 需32 bits (4 bytes) 儲存,整數介於± 之間

7 2-4 Data type real浮點數(小數) real(kind=4)單精確度 佔32 bits的長度,有效位數為6~8位
(max. value = min. value = ) real(kind=8)雙精確度 佔64 bits的長度,有效位數為15~61位 (max. value = min. value = )

8 2-4 Data type complex複數 character logical a+bi表示之;a,b為浮點數
“True” and “False”

9 2-5 數學運算式 算術運算子 運算優先順序 + 加法 - 減法 * 乘法 / 除法 ** 次方 ( ) 括號
+  加法 -  減法 *  乘法 /  除法 ** 次方 ( ) 括號 運算優先順序 ( ) → ** → * / → + -

10 2-6 程式架構 < Ex. 完整程式> < Ex. 執行結果> 自訂的名稱 program main
write(*,*) “hello, world!” stop end program main < Ex. 執行結果> hello, world! 程式開始→ 主程式碼  程式結束→ 主程式碼結束→ 可省略 可簡寫成 end program end


Download ppt "Chapter 2 Basic Elements of Fortran"

Similar presentations


Ads by Google