計(jì)算機(jī)程式課件_第1頁(yè)
計(jì)算機(jī)程式課件_第2頁(yè)
計(jì)算機(jī)程式課件_第3頁(yè)
計(jì)算機(jī)程式課件_第4頁(yè)
計(jì)算機(jī)程式課件_第5頁(yè)
已閱讀5頁(yè),還剩24頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

算械程式

ComputerProgrammingLanguage

Lecture2IntroductiontoFortran

郭修伯助理教授(5488)

FixedFormat

?Fortran77(*.f/*.for)*******************

?InitialSetup?

********美****關(guān)*****

-棚位:1subroutineINITIAL

IMPLICITNONE

integerNP,NC

?c焉言主解character關(guān)5GFn

paraneter(NP=10O00,NC=12)

integernax9snax9ppvp,qvix,srnvsrn09l*>n9n

doubleprecisionpxpppz,uxupuzumxunpumz

—楠位:1-5999999y

comnon/NUM/nax,snax

common/PU/ux(NP)uy(NP)uz(NP)

?禹行虢ff

comnon/OMEGA/umx(NP)fumy(NP)funz(NP)

connon/PX/px(NP)fpy(NP),pz(NP)

Zcon15/srn(NP?0:NC)

-橄位:6comnon/SRN0/srn0(NP0:NC)

v

comnon/FILENAME/fn(3)

?篇序接橄位

do100q=1vnax

ux(q)=0.0

up(q)=O.0

-橄位:7-72uz(q)=0.0

unx(q)=0.0

umy(q)=0.0

■焉程式顯umz(q)=0.0

continue

FreeFormat

?Fortran90/95(*.f90)

-!之接篇得主解

-一行有132字元

-行虢在最前面?FreeFormat

-&篇速接上一行programmain

write(*,*)-Hello"?道也是言主解

v/rite(*,*)&

?'Hello”

wr&

&ite(?,*)"Hello"

en1

Asimpleprogram:printalineoftext

?Fortran90

2▼3?I厄國(guó)西聃病

?ThisistheFirstsimpleprogram

It?H.P.Kuo

programmain

implicitnone

write(*,*)"hello,world?

stop

end

Asimpleprogram:printalineoftext

?Fortran77

*************************************************

*SimpleProgram:Printaline*

*2003/2/20*

*Kuo*

*************************************************

PROGRAMMAIN

IMPLICITNONE

write(*,*)'hello,world!"

Istop

end

Asimpleprogram:addtwointegers

?Fortran90

-I|J—Iz--II.■[3]i

?Thisisthesecondsimpleprogram

g!H.P.Kuo

programmain

implicitnone

integeravb,c

b=1

c=2

a=b+c

write(*?*)a

stop

end

Asimpleprogram:addtwointegers

?Fortran77

,一嗎山西聃|grid三]移

MW關(guān)關(guān)半關(guān)藻關(guān)美關(guān)關(guān)關(guān)關(guān)關(guān)關(guān)關(guān)關(guān)關(guān)關(guān)美或關(guān)關(guān)關(guān)關(guān)關(guān)關(guān)關(guān)薨聚美關(guān)關(guān)關(guān)聚關(guān)黃關(guān)關(guān)關(guān)MM關(guān)關(guān)或關(guān)關(guān)

*SimpleProgram:add2intergers*

*2003/2/20*

*Kuo*

PROGRAMMAIN

IMPLICITNONE

INTEGERA_total,b,c

b=1

c=2

atotal=b+c

write(*,*)a__total

stop

en[

Importantissues

?程式前要:MComments

,Fortran77用罩引虢;Fortran90用曼引虢

?Fortranprogramscontainoneormore

functions,exactlyoneofwhichmustbe

main

?stopandend

■數(shù)擘建算式+3/產(chǎn)()

麓軍的程式結(jié)情

宣告

?向重月您要求一^^金象的看己意ft空^

-用大小嘉英文字母、1到9的數(shù)字和下橫;第一偃1

字母必須是字母或數(shù)字

-燮數(shù)名不窿艮度

?77-6字元

?90-31字元

-大小嘉字母意羲相同

-不可用Fortran的層曷維字

?Integer;Real;Complex;Character;Logical

Integer

?短整數(shù)(2bytes)-32768?32768

-Integer*2a(Fortran77)

-Integer(kind=2)a(Fortran90)

?晨整數(shù)(4bytes)-2147483648?2147483648

-Integera(Fortran77&90)

-Interger::a(Fortran90)

-Integer*4a(Fortran77)

-Integer(kind=4)a(Fortran90)

型魅宣告的重要性

?Thisisthesecondsimpleprogram

?H.P.Kuo

programmam

implicitnone

integera,b,c

b=3

c=2

a=b/c

write(*,*)a

stop

end

Real

-軍精舉度浮黑占數(shù)(4bytes)-3.4e38?3.4e38

-Reala(Fortran77&90)

-Real::a(Fortran90)

-Real*4a(Fortran77)

-Real(kind=4)a(Fortran90)

?曼帝青型度浮黑占數(shù)(8bytes)-1.79e308?L79e308

-Doubleprecisiona(Fortran77&90)

-Real*8a(Fortran77)

-Real(kind=8)a(Fortran90)

-UJ曲w;不怛“口

?Thisisthesecondsimpleprogram

H.P.Kuo

programmain

.real■■agb,c

b=3.0

C=2.0

a=b/cu」回曰]*即山

write(*,*)

?Thisisthesecondsimpleprogram

H.P.Kuo

end了

programmain

implicitnone

real::a,b,c

b=10080001.0

|c=2.0

a=b/c

write(*,*)a

stop

en4

Complex

?軍精津度^^(4bytes)-3.4e38?3.4e38

-Complexa(Fortran77&90)

-Complex::a(Fortran90)

-Complex*4a(Fortran77)

-Complex(kind=4)a(Fortran90)

?曼精津度禊數(shù)(8bytes)-1.79e3081.79e308

-Complex*8a(Fortran77)

-Complex(kind=8)a(Fortran90)

?Thisisthesecondsimpleprogram

MH.P.Kuo

programmain

implicitnone

complex::a,b

a=(1.Ov1.0)

b=(1.0,2.0)

write(*,*)*a+b=*,a+b

stop

end

Character

?字串(?字元)

-Character*20a(Fortran77)

-Character(len=20)a(Fortran90)

?Thisisthesecondsimpleprogram

!H.P.Kuo

programmain

implicitnone

character*30string

string="chemicalengineering,

write(*,*)string

-stop

:end

programmain

implicitnone

character*30stringl,string2,string3

stringl='chemical'//"engineering,

string2=Char(97)//Char(94)//Char(98)

string3=stringl

string3(1:8)='material"

write(*,*)stringl

write(*,*)string2

write(*,*)strings

stop

end

Logical

programmain

-Logicalaimplicitnone

logicala,b

integerc

a=.true.

|c=1

iF(a)then

virite(*,*)c

endif|

write(*,*)b

stop

end

READ輸入資料

?read(*J)a

?read(5,*)a

?read(5J00)a

?read(unit=5,fmt=100)a

fPractice"read"?Practice"read"

fKuo?Kuo

?*******************?M關(guān)芟關(guān)關(guān)關(guān)W關(guān)關(guān)關(guān)WW關(guān)關(guān)關(guān)關(guān)或關(guān)*

programmainprogrammain

implicitnoneimplicitnone

integercintegerc

write(*,*)'pleaseinputanintegerwrite(*,*)'pleaseinputaninteger,

read(5,*)cread(5,100)c

write(*,*)'yourinputis=',c

write(*,*)'yourinputis=',c

100Format(14)?trydifferentinputualues

stop

endstop

end

?Practice"read"?Practice"read"

tKuo?Kuo

?M關(guān)關(guān)W關(guān)關(guān)關(guān)關(guān)關(guān)關(guān)MM關(guān)關(guān)關(guān)MW關(guān)關(guān)?*******************

programmain

programmain

implicitnone

implicitnone

integerc

write(*,*)'pleaseinputaninteger'character*15c

read(unit=5,fnt=100)cwrite(*,*)'pleaseinputstrings'

write(*,*)*yourinputis=',cread(unit=5,Fmt=1O0)c

write(*,*)'yourinputis=',c

100Format(14)?trydifferentinputualues

100Format(ft15)!try'happybirthday

Lstop.

end

stop

end

MoreaboutFormat

?Refertotextbook4-4

-A10

-F9.3

-15

-G9.3

-3X

Implicit

?Implicitnone

?取消內(nèi)定型憩;聚接在Program之接

號(hào)―|厄底西聃.rid二][詞|[]磅

*************************************************

*SimpleProgram:add2intergers*

U2003/2/20*

Kuo*

*************************************************

PROGRAMMAIN

IMPLICITNONE

INTEGERAtotal,b,c

:;b=1-

c=2

a—total=b+c

write(*,*)a_total

stop

end

Parameter卷殳立常數(shù)值

?parameter(pi=3.14159)

?Pi=3.14159;G=9.81;R=8.314...etc.

?避免金昔^

?增加程式速度

programmain

implicitnone

real,parameter::pi=3.14159

realtheta

theta=sin(pi/6)

write(*/,(F3.1)t,)theta

L

stop英釜**英釜*關(guān)釜*釜委英釜釜委左釜圣英英釜關(guān)關(guān)英英/英英委釜釜*圣蕓MM*釜芟

end*SimpleProgram:parameter*

J*2003/2/20*

?Kuo*

??*?*?****?*****?*****?**?***??*?**???***?***?

PthROeGtRaA=MsiMnA(IpNi/6.0)

wIMrPitLeIC(IT*,1NO0N8E)theta

Format=(F3.1)

sREtAyLpi,theta

IePAnR]AMETER(pi=3.14159)

^定初始值

programmain

implicitnone

integer::a=1

real::b=2.2

complex::c=(1.0,2.0)

character(len=20)::d='chemicalengineering'

write(*,*)a,b,cfdt______________________________________________________

.p*SimpleProgram:parameter?

5top>2003/2/20*

end僦Kuo?

PROGRAMMAIN

IMPLICITNONE

INTEGERa

REALb

COMPLEXc

CHARACTER關(guān)20d

DATAa,b,c,d/1,2.2,(1.0,2.0),'chemicalengineering*/

write(*,*)a9b9c9d

5top|

end

型熊不同燮數(shù)^算

programmain

implicitnone

integer::a=1,b=2

real::c

c=a/b

write(*,*)'Firstualueofc=",c****************************************?4

c=real(a)/real(b)PROGRAMMAIN

write(*,*)'secondualueofc=',cIMPLICITNONE

stopINTEGERa,d

REALb.c

end

DATAb,c/2.2,1.1/

c=int(b/c)

write(*,*)'theualueoFc=*,c

d=b/c

write(*,*)'theualueoFd=',d

stop

end

Type

?integer,real,logical,character之夕'的型魅宣告

programmain

implicitnone

type::person

character(len=20)::name

integer::age

endtypeperson

type(person)::a,b

write(*,*)1nameForAstudent

read(*,*)a%name

write(*,*)'nameForBstudent

read(*,*)byname

write(*,*)1ageofAstudent'

read(*,*)a2age

write(*,*)'ageofBstudent'

read(*,*)b%age

write(*,100)aZname,a%age,byname,bZage

100Fornat('name:',A10/,'age:',13/,'name:',R18/,'age:',13)

stop

end

programmain

implicitnone

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論