5. º¯¼ö, Á¾·ù ¹× ¼±¾ð (Variables, types, and declarations)
º¯¼ö À̸§ (Variable names)
Fortran¿¡¼ º¯¼ö À̸§Àº ¹®ÀÚ a-z¿Í ¼ýÀÚ 0-9 Áß¿¡¼ 1-6 ±ÛÀÚÀÌ´Ù. ùÀÚ´Â ¹®ÀÚÀ̾î¾ß¸¸ ÇÑ´Ù. (ÁÖÀÇ : Fortran 90¿¡¼´Â ±æÀÌÀÇ Á¦ÇÑÀÌ ¾ø´Ù.) Fortran 77Àº ´ë¹®ÀÚ¿Í ¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÏÁö ¾Ê°í ¸ðµç ±ÛÀÚ¸¦ ´ë¹®ÀÚ·Î °£ÁÖÇÑ´Ù. ±×·¯³ª °ÅÀÇ ´ëºÎºÐÀÇ Fortran 77 compiler°¡ ¼Ò¹®ÀÚ¸¦ ÀÐ¾î µéÀ̱â´Â ÇÑ´Ù.
Á¾·ù ¹× ¼±¾ð (Types and declarations)
¸ðµç º¯¼ö´Â ¼±¾ð¹®(declaration)¿¡¼ Á¤ÀÇÇÏ¿©¾ß¸¸ ÇÑ´Ù. ÀÌ´Â º¯¼öÀÇ Á¾·ù (type)¸¦ °áÁ¤ÇÑ´Ù. ´ëºÎºÐÀÇ ¼±¾ð¹®Àº ´ÙÀ½°ú °°´Ù.
integer list of variables
real list of variables
double precision list of variables
complex list of variables
logical list of variables
character list of variables
º¯¼ö ¸ñ·ÏÀº º¯¼ö À̸§À» ½°Ç¥·Î ³ª´©¾î ³õÀº °ÍÀÌ´Ù. °¢°¢ÀÇ º¯¼ö´Â Á¤È®ÇÏ°Ô ÇÑ ¹ø¸¸ ¼±¾ðÇÏ¿©¾ß ÇÑ´Ù. ¾î¶² º¯¼ö°¡ ¼±¾ðµÇÁö ¾ÊÀ¸¸é ±× Á¾·ù¸¦ °áÁ¤ÇÏ´Â ¹¬½ÃÀûÀÎ ±ÔÄ¢ (implicit rules)ÀÌ ÀÖ´Ù. º¯¼ö À̸§ÀÌ ¹®ÀÚ i-nÀ¸·Î ½ÃÀÛÇϸé Á¤¼ö(integer)ÀÌ°í ±× ¿ÜÀÇ °æ¿ì´Â ½Ç¼ö(real)ÀÌ´Ù.
¿À·¡ µÈ ¸¹Àº Fortran 77 program¿¡¼ ÀÌ ±ÔÄ¢À» »ç¿ëÇÑ´Ù. ±×·¯³ª ´õ ÀÌ»ó À̸¦ »ç¿ëÇÏÁö ¸»¾Æ¾ß ÇÑ´Ù. º¯¼ö¸¦ ¼±¾ðÇÏÁö ¾ÊÀ¸¸é ¿À·ù°¡ »ý±æ È®·üÀº ¾öû³ª°Ô Å©´Ù.
Á¤¼ö¿Í ºÎµ¿ ¼Ò¼öÁ¡ º¯¼ö (Integers and floating point variables)
Fortran 77¿¡´Â Á¤¼ö º¯¼ö´Â ÇÑ °¡Áö ÇüÅ»ÓÀÌ´Ù. Á¤¼ö´Â º¸Åë 32 bits (4 bytes) º¯¼ö·Î ÀúÀåµÈ´Ù. µû¶ó¼ ¸ðµç Á¤¼ö º¯¼ö´Â [-m,m] »çÀÌÀÇ ¼ýÀÚ°¡ µÈ´Ù. mÀº ´ë·« 2*10^9ÀÌ´Ù.
Fortran 77¿¡´Â real°ú double precisionÀ̶ó´Â ¼·Î ´Ù¸¥ µÎ °¡Áö ÇüÅÂÀÇ ºÎµ¿ ¼Ò¼öÁ¡ (floating point) º¯¼ö°¡ ÀÖ´Ù. º¸Åë realÀÌ Àû´çÇÏÁö¸¸ Á»´õ Á¤¹ÐÇÑ °è»êÀ» ÇÏ¿©¾ß ÇÑ´Ù¸é double precisionÀ» »ç¿ëÇÏ¿©¾ß ÇÑ´Ù. º¸Åë realÀº 4 byte º¯¼öÀÌ°í double precisionÀº 8 byteÀÌÁö¸¸ ±â°è¿¡ µû¶ó ´Ù¸£´Ù. ¾î¶² ºñÇ¥ÁØ Fortran¿¡¼´Â 8 byte ºÎÅë ¼Ò¼öÁ¡ º¯¼ö¸¦ ³ªÅ¸³¾ ¶§ real*8¸¦ »ç¿ëÇϱ⵵ ÇÑ´Ù.
¸Å°³ º¯¼ö¹® (parameter statement)
¾î¶² »ó¼öµéÀº ÇÑ ÇÁ·Î±×·¥¿¡¼ ¿©·¯ ¹ø ³ªÅ¸³´Ù. ÀÌ·± º¯¼ö´Â ÇÁ·Î±×·¥ ù ¸Ó¸®¿¡¼ ÇÑ ¹ø¸¸ Á¤ÀÇÇϸé ÆíÇÒ °ÍÀÌ´Ù. ÀÌ·± °æ¿ì ¸Å°³ º¯¼ö¹®parameter¸¦ »ç¿ëÇÑ´Ù. À̸¦ »ç¿ëÇϸé ÇÁ·Î±×·¥À» Àб⵵ ½±´Ù. ¿¹¸¦ µé¾î ¿øÀÇ ³ÐÀ̸¦ ±¸ÇÏ´Â ÇÁ·Î±×·¥µµ ´ÙÀ½°ú °°À̾²´Â °ÍÀÌ ÁÁÀ» °ÍÀÌ´Ù.
program circle
real r, area, pi
parameter (pi = 3.14159)
c This program reads a real number r and prints
c the area of a circle with radius r.
write (*,*) 'Give radius r:'
read (*,*) r
area = pi*r*r
write (*,*) 'Area = ', area
stop
end
¸Å°³º¯¼ö¹®(parameter)ÀÇ Çü½ÄÀº
parameter (name = constant, ... , name = constant)
ÀÌ°í ÀÌ¿¡ °üÇÑ ±ÔÄ¢Àº
- ¸Å°³º¯¼ö¹®(parameter)¿¡¼ Á¤ÀÇÇÑ º¯¼ö (variable)Àº ½ÇÁ¦¿¡¼ º¯¼ö°¡ ¾Æ´Ï¶ó ±× °ªÀÌ º¯ÇÏÁö ¾Ê´Â »ó¼öÀÌ´Ù.
- ±× º¯¼ö´Â ¿ÀÁ÷ ÇÑ ¸Å°³º¯¼ö¹®(parameter)¿¡¼¸¸ Á¤ÀÇÇÏ¿©¾ß ÇÑ´Ù.
- ¸Å°³º¯¼ö¹®(parameter)Àº ¾î¶² ¼öÇ๮(executable statement)º¸´Ù ¾Õ¿¡ ÀÖ¾î¾ß ÇÑ´Ù.
¸Å°³º¯¼ö¹®(parameter)À» »ç¿ëÇÏ´Â ÀÌÀ¯´Â
- À߸ø ÀÔ·ÂÇÒ È®·üÀ» ÁÙÀδÙ.
- ÇÑ ÇÁ·Î±×·¥¿¡¼ ¿©·¯ ¹ø ³ªÅ¸³ª´Â »ó¼öÀÇ °ªÀ» ½±°Ô ¹Ù²Ü ¼ö ÀÖ´Ù.
Exercises
- Exercise A
- ´ÙÀ½ Áß º¯¼ö À̸§À¸·Î Àû´çÇÏÁö ¾ÊÀº °ÍÀº ¾î´À °ÍÀΰ¡? ±× ÀÌÀ¯´Â?
A5, 5A, VARIABLE, XY3Z4Q, AT&T, NUMBER1, NO1, NO 1, NO_1, STOP
[Fortran Tutorial]
Ãæ³²´ëÇб³ ¹°¸®Çаú ¿À º´¼º