Εισαγωγή στην Fortran 77

Download Εισαγωγή στην Fortran 77

Post on 25-Sep-2015

7 views

Category:

Documents

3 download

Embed Size (px)

DESCRIPTION

Fortran 77 ,

TRANSCRIPT

<ul><li><p>-151: H FORTRAN 77 </p></li><li><p> 1 .............................................................................................................................. 3 </p><p>1.1 FORTRAN 77 .................................................................................... 3 1.1.1 ................................................................................................. 3 1.1.2 ................................................................................................ 4 1.1.3 ............................................................................................... 5 </p><p>1.2 ............................................................................................... 5 1.3 ( A)......................................................................................... 6 </p><p>1.3.1 .................................................................................................... 6 1.3.2 ................................................................................................ 7 1.3.3 ............................................................................. 7 </p><p>1.4 read print................................................................................................. 7 1.4.1 read .............................................................................................................. 7 1.4.2 print.............................................................................................................. 8 </p><p>2.4 ............................................................................. 8 2 .............................................................................................................................. 9 </p><p>2.1 ( ) ......................................................................................... 9 2.2 parameter ...................................................................................................... 9 2.3 (intrinsic functions) .................................................... 9 ........................................................................................................................... 10 2.4 (external function).................................................... 12 2.5 IF ............................................................................................. 14 ........................................................................................................ 15 </p><p> 3 ............................................................................................................................ 17 3.1 &amp; ( ) ..................................... 17 3.2 A do .................................................................................... 19 3.3 do while............................................... 25 </p><p> 4 ............................................................................................................................ 28 4.1 .................................................... 28 4.2 (subroutines)..................................................................................... 32 </p><p> 5 ............................................................................................................................ 37 5.1 ........................................................................................... 37 </p><p>5.1.1 .......................................................................................................... 38 </p><p>5.2 ( ) ....................................................................................... 39 5.2.1 (double precision).................................... 39 5.2.2 (complex)................................................................................. 40 </p><p>5.3 .............................................................................................. 41 5.3.1 Open........................................................................................................................ 41 5.3.2 Close ....................................................................................................................... 42 5.3.3 Write ....................................................................................................................... 42 5.3.4 Read........................................................................................................................ 43 </p></li><li><p> ,, // </p><p>3 </p><p> 1 </p><p>1.1 FORTRAN 77 . , ( ) . </p><p> FORTRAN 77 : 26 ( ) 0,1,2,...,9 : + - * / = ( ) . , _ </p><p>1. FORTRAN 77 . , print*,sum PrINt*, Sum pRInt*,suM </p><p>2. . print*, sum pr in t * , Su m </p><p>3. . : </p><p> 31 . oi : </p><p> ( ), 0,1,2,...,9 _ (underscore) </p><p>1.1.1 FORTRAN 77 : </p></li><li><p> ,, // </p><p>4 </p><p>program name stop end </p><p>1. FORTRAN 77 program end. : . </p><p> 2. program (. 1.1) </p><p> 3. stop . </p><p> stop end , end. </p><p> program name </p><p> 1 2 stop 3 stop end stop , . 3. </p><p>1.1.2 FORTRAN . : </p><p>1. 7 72 . 2. c ( *) 1, </p></li><li><p> ,, // </p><p>5 </p><p>3. 6 ( &amp;), . 72. </p><p>4. 2-5 ( ) () . </p><p>1.1.3 123456789.................................................................................................. program circle c c c c c r (input) c perimetros (output) c emvadon (output) real r, perimetros, emvadon print*, read*, r perimetros = 2.*3.14*r emvadon = 3.14*r**2 print*, :, perimetros print*, :, emvadon stop end </p><p>1.2 : + () - () * () / () ** ( ) </p></li><li><p> ,, // </p><p>6 </p><p> : </p><p>( ) 2dc</p><p>babac ++++ </p><p> FORTRAN 77 c*(a+b) + (a+b)/c + d**2 : : </p><p>1. 2. 3. </p><p> : 2*3+20 = 6+20 = 26 2+100/20 = 2+5 = 7 5+6*3**2 = 5+6*9 = 5+54 = 59 . : (2*3**2 +1)*2-6 = (2*9+1)*2-6 = (18+1)*2-6 = 19*2-6 = 38-6 = 32 </p><p>1.3 ( A) H FORTRAN 77 ( ) ( ). -, : 23 -100 2341 10000000001 , 23. 1.0000 .00231 -192. 134.2345 . 23 23. , FORTRAN 77 , . </p><p>1.3.1 FORTRAN 77 : </p></li><li><p> ,, // </p><p>7 </p><p> integer () real (, 8 ) </p><p> double precision (, 16 ) complex () character () logical (, true false) </p><p>1.3.2 </p><p> type .: integer a1, sum, count real energy, sum, r </p><p> A (implicit) </p><p> o FORTRAN 77 . , i, j, k, l, m ,n ( isum, jcount), , . a-h and o-z, (. sum, x, func) </p><p>1.3.3 </p><p> = </p><p> : a=0.5*10.**2 energy = 0.5*m*v**2, </p><p> m v . read (. ). </p><p>1.4 read print </p><p>1.4.1 read : read*, </p></li><li><p> ,, // </p><p>8 </p><p> . : read*,a1, r, energy : : 1 (,) </p><p>enter. 2 enter . </p><p>1.4.2 print : print*, / / . : print*, , emvadon 1 : ....... 2 . </p><p>2.4 , : </p><p>1. FORTRAN .f (. pogram1.f) </p><p>2. (compile) . g77 program1.f o program1.exe </p><p>3. program1.exe program1.exe 4. ( program1.exe, </p><p>(compiler) a.out) 5. program1.exe </p><p> : .exe . - (executable). </p></li><li><p> ,, // </p><p>9 </p><p> 2 </p><p>2.1 ( ) (. 1.3). , FORTRAN (implicit) . . ; (compiler) ( ) . : implicit none program (implicit none = ). compiler . . </p><p>2.2 parameter , parameter : parameter ( = ) : parameter . . . real pi, f, npi integer N parameter (pi=3.141592, N=100, f=3.2, npi=3.*pi) </p><p>2.3 (intrinsic functions) (+ - * / ) FORTRAN 77 . </p></li><li><p> ,, // </p><p>10 </p><p> (intrinsic functions) : ( ) : F77 sqrt(x) : || abs(x) : ex exp(x) : ln(x) log(x) : (x) sin(x) : (x) cos(x) : (x) tan(x) : (x) cotan(x) : ( abs) . abs . : F77 </p><p> int(x) Real integer ( . .) </p><p> real(x) Integer real max(x1,x2,) integer </p><p> real x1,x2, </p><p> min(x1,x2,) 1 5 . </p><p>123456789........................... program maxmin c 5 </p></li><li><p> ,, // </p><p>11 </p><p>c a1,a2,a3,a4,a5 (inputs) c maximum (output): c minimum (output): implicit none real a1,a2,a3,a4,a5, maximum, minimum print*, 5 read*, a1, a2, a3, a4, a5 maximum = max(a1,a2,a3,a4,a5) minimum = min(a1,a2,a3,a4,a5) print*, :,maximum print*, :,minimum stop end 2 : </p><p>||)]sin()[sin()( 2 xxxexf x +++= 123456789........................... program paradeigma implicit none real x, fx print*, read*, x fx= exp(x) + ( cos(x) + sin(x) )**2 + abs(x) print*, :, fx stop end =f(x1)+f(x2)+f(x3), </p><p> : </p></li><li><p> ,, // </p><p>12 </p><p>123456789........................... program paradeigma2 implicit none real x1, x2, x3, print*, 3 o read*, x1, x2, x3 = exp(x1) + ( cos(x1) + sin(x1) )**2 + abs(x1) &amp; + exp(x2) + ( cos(x2) + sin(x2) )**2 + abs(x2) &amp; + exp(x3) + ( cos(x3) + sin(x3) )**2 + abs(x3) print*, :, stop end . f(x) . : fx = f(x1)+f(x2)+f(x3) FORTRAN f(x) ! (external functions). . </p><p>2.4 (external function) : function ( ) ( ) = return end </p></li><li><p> ,, // </p><p>13 </p><p> f(x) : 123456789................................... real function f(x) implicit none real x f = exp(x) + ( cos(x) + sin(x) )**2 + abs(x) return end </p><p>1. . , . , prog.f func.f, : </p><p> g77 prog.f func.f o prog.exe : . </p><p>2. , . </p><p> 3. </p><p> return. </p><p>4. . : </p><p>)|(|),( yxeyxg += . </p><p>123456789........................... program paradeigma </p></li><li><p> ,, // </p><p>14 </p><p> implicit none real x, y, g print*, 2 o read*, x, y print*, :, g(x,y) stop end c real function g(x, y) implicit none real x, y g = exp(- ( abs(x) + y ) ) return end </p><p>2.5 IF . if. H if : if () then 1 endif : , 1. if endif. , if : If () if : if (1 ) then 1 </p></li><li><p> ,, // </p><p>15 </p><p>else if (2 ) then 2 else if ... else end if : , 1, (elseif) , 2 . , , else. , if endif. </p><p> = ( ): .eq. (equal to) ( ): .ne. ( not equal to) &gt; ( ) .gt. (gteater than) ( ) .ge. (greater than or equal to) &lt; ( ) .lt. (less than) ( ) .le. (less than or equal to) , . and. .or. : : , .and. .or. </p></li><li><p> ,, // </p><p>16 </p><p> end if return end</p></li><li><p> ,, // </p><p>17 </p><p> 3 </p><p>3.1 &amp; ( ) . , , , . , x integer, : x=2*3+10-2 =14 14 x. x real, 14 (. x=14.). . , . : real x x=5/2=2. () integer x x=5/2=2 () . x o, . x , 5 2 ( 5. 2.) : real x x=5./2.=2.5 , : </p></li><li><p> ,, // </p><p>18 </p><p> , . , real x x=5./2=2.5 ( x=5/2.=2.5 . . 5/2*4.+1. (. 1.2) . , , : </p><p> 5/2*4.+1.=2*4.+1.=8.+1.=9. . 4.*5/2+1. = 20./2+1.=10.+1.=11. . . . ... </p><p> o i=2 i=i+1 i 0=1 (). i ( 2) , 1 i , 3 , =12000 y=0.000034 : x=1.2+4 x=0.12E+5 </p></li><li><p> ,, // </p><p>19 </p><p> y=3.4E-5 y=34E-6 , nE n10</p><p>3.2 A do . do. do : do n=ni, nf, dn enddo n: ni: nf: dn: : </p><p>) )int(,0 max( dndnninf +</p><p> . max() int() FORTRAN 77 (. 1.2). do do-loop. </p><p> , 0 )int( +</p><p>dndnninf</p><p>, . , ni , ni+dn , . i) do I=1,21,2 (11 ) ii) do I=100,0,-2 (51 ) iii) do I=10,-1,2 (0 ) iv) do I=1,1,1 (1 ) </p></li><li><p> ,, // </p><p>20 </p><p> 1 1 15 </p><p>program doloop implicit none integer i do i=1,15,2 print*,i enddo stop end </p><p>1. , , . </p><p>2. (. ) </p><p>3. . , 11 , do i=1,11 print*,i,i**2 enddo </p><p>4...</p></li></ul>