°t¦X Numerical Recipe ®Ñªº¨ä¥L Fortran «ü¥O
parameter
±N¤v¸g«Å§i¤F¼ÆÈ«¬ºA¡]¦p real ©Î integer¡^ªº¬YÓÅܼơA³]©wµ¹¥¦¤@Ó©T©wªº±`¼ÆÈ¡A¦b¾ãÓµ{¦¡¤º³oÓȳ£¤£·|¦A³QÅܧó¡C
parameter ±`¥Î©ó«Å§i°}¦C®Éªººû«×©w¸q¤§¥Î¡A¤ñ¤è»¡¡A³q¥Î°Æµ{¦¡ùئ³»Ýn¥Î¨ì¤@Ó A ªº°}¦C¡A¥¦¦b³oӰƵ{¦¡¤¤¬O«Å§i¦¨ A(NMAX)¡A¨ä¤¤ NMAX ·íµM¬O¦]À³¤£¦P¤§°ÝÃD©Ò»Ý¦³¤£¦P¤j¤p¡A¦Ó³q¥Î°Æµ{¦¡§Ų́ϥΪº®ÉÔÀ³¸Ó¬O¤£¥²§ï¼g¥¦ªº¡C¦ý¬O¡A«Å§iÁ`¬On¹w¯d°O¾ÐÅ餺ªº¦ì¸m¡A¦]¦¹n¥Î¹ê»ÚªºÈ¦Ó¤£¬O¥uÁ¿¤@Ó¥N¸¹ NMAX¡C«ç»ò¿ì©O¡H¸Ñ¨Mªº¤è®×¬O¡A¦b¥Dµ{¦¡¤¤¹ï©ó NMAX °£¤F«Å§i¼ÆÈ«¬ºA integer ¤§¥~¡A¦A¦h¥Î parameter «ü¥O§â¤j¤p«ü©w¦n¡C½sĶ¾¹¦b³sµ²°Æµ{¦¡®É¡A·|ª¾¹D NMAX ¤w¸g©w¦¨¦h¤ÖªºÈ¡A¦p¦¹§¹¦¨¸Ó¦³ªº°O¾ÐÅé«O¯d¤u§@¡A¤]´N¬O¹F¦¨ A(NMAX) ªº«Å§i¡C¦p¤U¨Ò¡G
program param_demo
integer NMAX
parameter (NMAX=20)
real A(NMAX),B(NMAX)
call sub01(A,B,NMAX)
do i=1,NMAX
¡@write (*,*) A,B
end do
end
subroutine sub01(A,B,NMAX)
ingeter NMAX,i
real A(NMAX),B(NAMX)
do i=1,NMAX
¡@ B(i)=A(i)**2
end do
end
function
©w¸q¨ç¼Æ¡]¨ç¦¡¡^¡A¥¦ªº§@ªk¦³ÂI¹³¬O°Æµ{¦¡¡A¤¹³\¨Ï¥ÎªÌ©w¸q¦Û¤vªº¨ç¼Æ¡]¤£¥²©w¸qªº¨º¨Ç¡A¦p sin¡A«h¥s°µ¤º«Ø¨ç¼Æ¡^¡A¥H©w¸q¹ê¼Æ¨ç¼Æ f(x) = 2x+1¡A¨ä§@ªk¦p¤U¡G
function f(x)
real f,x
f = 2*x+1
end¦b¥Î©óµ{¦¡¤¤®É¡A«h¹³¬O¤U¦C³oӼˤl
program use_ext
real f,x
external f
write(*,*) 'Please give a real number x :'
read (*,*) x
if(f(x).gt.0.0) then
write(*,*) 'f(x) is positive.'
else
write(*,*) 'f(x) is negative.'
end if
end³oùØ·|¥Î¨ì external ¬O¦]¬° f ¥»¨¤£¹³ sin ¬O¤º«Ø¨ç¼Æ¡A¦ý«on¥H¨ç¼Æªº¤è¦¡¥Î¦b³oÓµ{¦¡¤¤¡A¦]¦¹¬O "¥~³¡" ¦Û¦æ©w¸qªº¨ç¼Æ¡C
extrenal
«Å§i¤Þ¥Î¤@Ó¤w¸g¦b¥~³¡©w¸q¦n¤Fªº¨ç¼Æ¦b³oÓµ{¦¡©Î°Æµ{¦¡¤¤¨Ï¥Î¡A¨Ò¤l½Ð¨£¤W¤@¬q¡C
common
¥Dµ{¦¡»P°Æµ{¦¡¤§¶¡¡A¥H¤Î°Æµ{¦¡»P°Æµ{¦¡¤§¶¡¡A³q±`¬O¥H©I¥s®É¶Ç»¼¤Þ¼Æªº¤è¦¡¨ÓÅý¤U¼h°Æµ{¦¡¥Î±o¨ì©Ò»ÝªºÅܼơC¦pªG³o¼Ëªº°Æµ{¦¡¤ÎÅܼƦ³«Ü¦h¡Aµ{¦¡¼g°_¨Ó«Ü³Â·Ð¡A¬Æ¦Ü³q¥Î¡B¯S¥Î²V¦b¤@°_¤]®e©ö¥X¿ù¡C
¥t¤@ºØ¤èªk¬O«Å§i¤½¦@°Ï¶ô¡]common block¡^¡A ¨ä»yªk¬O common /name_a/ x, y, z¡A ³oùØ name_a ¬O¦Û©wªº¤½¦@°Ï¶ô¦W¡A¥H / / ¥]°_¨Ó¡A«á± x,y,z «h¬On³¯¦C©ó¤½¦@°ÏªºÅܼơ]ÅܼƤ~¥i¥H©ñ¡A¥H parameter ³]¹Lªº°Ñ¼Æ¤£¥i¥H©ñ¦b common block ¤¤¡^¡C¤@Óµ{¦¡¥i¥H«Å§i¦n´XÓ common block ¨Ó¤ÀÃþ¦s©ñÅܼơC