write(*, label) list-of-variables label format format-code´ÙÀ½Àº ±¸Ã¼ÀûÀÎ ¿¹ÀÌ´Ù. Á¤¼ö º¯¼ö ÇϳªÀÇ °ªÀ» 4 ÀÚ¸¦ ÂïÀ» ¼ö ÀÖ´Â °ø°£¿¡ ÀμâÇÏ°í ½Ç¼ö º¯¼ö Çϳª¸¦ ¼Ò¼öÁ¡ ¾Æ·¡ 3 ÀÚ¸®±îÁö °íÁ¤µÈ ÇüÅ·ΠÀμâÇÏ°íÀÚ ÇÒ ¶§´Â ´ÙÀ½°ú °°ÀÌ ÇÑ´Ù.
write(*, 900) i, x 900 format (I4,F8.3)formatÀÇ ¹®Àå ¹øÈ£ 900Àº ÀÓÀ¸·Î ¼±ÅÃÇÑ °ÍÀÌ´Ù. º¸Åë ÀÌ·¡·Î ³»·Á°¡¸é¼ Å« ¹øÈ£¸¦ »ç¿ëÇÏ´Â °ÍÀÌ Æí¸®ÇÏ´Ù. format ´ÙÀ½¿¡ °ýÈ£(parenthesis)¸¦ ÇÏ°í ±× ¾È¿¡ format code¸¦ Àû´Â´Ù. I4´Â 4Ä¿¡ Á¤¼ö¸¦, F8.3 ´Â 8Ä¿¡ ½Ç¼ö¸¦ ¼Ò¼öÁ¡ ¾Æ·¡ 3ÀÚ¸®ÀÇ °íÁ¤µÈ ÇüÅ·ΠÀμâÇ϶ó´Â ¶æÀÌ´Ù.
format ¹®Àº ±× ÇÁ·Î±×·¥ ¾ÈÀÇ ¾î´À °÷¿¡ À־ »ó°ü¾ø´Ù. º¸Åë ÀÔÃâ·Â ¹® ¹Ù·Î ´ÙÀ½¿¡ ÇØ´ç format ¹®À» ³õ°Å³ª ÇÁ·Î±×·¥ ³¡¿¡ ¸ðµç format ¹®À» ¸ð¾Æ ³õ´Â ¹æ¹ýÀ» »ç¿ëÇÑ´Ù.
A - ¹®ÀÚ¿ (text string) D - ¹è¼öÁ¤¹Ðµµ, Áö¼ö Ç¥½Ã (double precision numbers, exponent notation) E - ½Ç¼ö, Áö¼ö Ç¥½Ã (real numbers, exponent notation) F - ½Ç¼ö, °íÁ¤ Çü½Ä (real numbers, fixed point format) I - Á¤¼ö (integer) X - ¼öÆò ¶ì±â (horizontal skip (space)) / - ¼öÁ÷ ¶ì±â (»õ ÁÙ) (vertical skip (newline))format Çü½Ä F (¶Ç´Â D, E)´Â ÀϹÝÀûÀ¸·Î Fw.d°¡ µÇ´Âµ¥ ¿©±â¼ w´Â ¼ýÀÚ¸¦ ÀûÀ» Àüü ÄÀ» ³ªÅ¸³»´Â Á¤¼ö »ó¼öÀÌ°í d´Â À¯È¿ ¼ýÀÚ¸¦ ³ªÅ¸³»´Â Á¤¼ö »ó¼öÀÌ´Ù.
Á¤¼öÀÇ °æ¿ì¿¡´Â Àüü Æø¸¸À» ±ÔÁ¤ÇÏ¸é µÇ¹Ç·Î IwÀÇ Çü½ÄÀÌ µÈ´Ù. ¸¶Âù°¡Áö·Î ¹®ÀÚ¿Àº Aw·Î ±ÔÁ¤ÇÒ ¼ö Àִµ¥ Àüü ÆøÀ» ÀûÁö ¾Ê±âµµ ÇÑ´Ù.
¼ýÀÚ³ª ¹®ÀÚ¿ÀÌ Àüü ĺ¸´Ù ÀÛÀ¸¸é ºóÄ(space)·Î ä¿öÁø´Ù. º¸Åë ¹®ÀÚÀÇ °æ¿ì¿¡´Â ¿À¸¥ÂÊ¿¡ ¸ÂÃß¿ÀÁöÁö¸¸ Á¤È®ÇÑ °ÍÀº format code¸¶´Ù ´Ù¸£´Ù.
¼öÆò ¶ì±â¸¦ ÇÒ ¶§´Â nX code¸¦ »ç¿ëÇÑ´Ù. ¾Æ´Â n °³ÀÇ ¼öÆò ºó ÄÀ» ÀǹÌÇÑ´Ù. nÀº »ý·«ÇÒ ¼ö ÀÖ°í ÀÌ °æ¿ì n=1 À» ÀǹÌÇÑ´Ù. ¼öÁ÷ ¶ì±â (»õ ÁÙ)Àº /¸¦ »ç¿ëÇÑ´Ù. slash Çϳª°¡ »õ ÁÙ Çϳª¸¦ ÀǹÌÇÑ´Ù. °¢°¢ÀÇ read ³ª write ¹®Àº »õÁÙ(newline)·Î ³¡³´Ù´Â Á¡À» ÁÖÀÇÇÑ´Ù. (ÀÌ °ÍÀÌ C¿Í ´Ù¸¥ Á¡ÀÌ´Ù)
x = 0.025 write(*,100) 'x=', x 100 format (A,F) write(*,110) 'x=', x 110 format (A,F5.3) write(*,120) 'x=', x 120 format (A,E) write(*,130) 'x=', x 130 format (A,E8.1)´Â ´ÙÀ½°ú °°Àº Ãâ·ÂÀ» ¸¸µç´Ù.
x= 0.0250000 x=0.025 x= 0.2500000E-01 x= 0.3E-01Note how blanks are automatically padded on the left and that the default field width for real numbers is usually 14. ¿ÞÂÊÀÌ ¾î¶»°Ô ºóÄÀ¸·Î ä¿öÁ³´ÂÁö »ìÆì º¸°í ½Ç¼öÀÇ ±â ¼³Á¤µÈ ÆøÀº º¸Åë 14ÀÓÀ» ¾Ë¾Æ µÐ´Ù. ¶Ç Fortran 77¿¡¼ 0-4ÀÇ ¼ýÀÚ´Â ¹ö¸®°í 5-9´Â ¿Ã¸®´Â ¹Ý¿Ã¸²ÇÏ´Â °ÍÀ» º¼ ¼ö ÀÖ´Ù.
ÀÌ ¿¹¿¡¼´Â °¢°¢ÀÇ write ¹®ÀÌ ´Ù¸¥ format ¹®À» »ç¿ëÇÏ¿´´Ù. ÇÏÁö¸¸ ´Ù¸¥ write ¹®¿¡¼ °°Àº format ¹®À» »ç¿ëÇÏ¿©µµ °ü°è¾ø´Ù. »ç½Ç»ó ÀÌ°ÍÀÌ format ¹®À» »ç¿ëÇÏ´Â ÀåÁ¡ÀÌ´Ù. In fact, this is one of the main advantages of using format statements. ¿¹¸¦ µé¾î Ç¥¸¦ ¸¸µé ¶§ °¢°¢ÀÇ ÁÙÀÌ °°Àº Çü½ÄÀÌ µÇµµ·Ï ÇÒ °æ¿ì Æí¸®ÇÏ´Ù.
write (*,'(A, F8.3)') 'The answer is x = ', x´Â ´ÙÀ½°ú °°´Ù.
write (*,990) 'The answer is x = ', x 990 format (A, F8.3)¶Ç´Â ¹®ÀÚ¿À» format ¹® ¾È¿¡ ³ÖÀ» ¼ö ÀÖ´Ù.
write (*,999) x 999 format ('The answer is x = ', F8.3)
do 10 i = 1, 5 write(*,1000) (a(i,j), j=1,10) 10 continue 1000 format (I6)ÀÌ °æ¿ì ÁÙ¿¡ ´ëÇÏ¿©´Â ¸í¹éÇÑ (explicit) do loop¸¦ »ç¿ëÇÏ¿´°í Ä¿¡ ´ëÇÏ¿©´Â Àº¿¬Áß¿¡ ³»ÀçÇÑ implicit loop¸¦ »ç¿ëÇÏ¿´´Ù.
format ¹®¿¡´Â ´ÙÀ½°ú °°ÀÌ ¹Ýº¹ÇÒ °æ¿ì°¡ ÀÖ´Ù.
950 format (2X, I3, 2X, I3, 2X, I3, 2X, I3)À̸¦ °£´ÜÈ÷ ³ªÅ¸³»¸é
950 format (4(2X, I3))¶Ç ¸í¹éÇÏ°Ô ¸î ¹ø ¹Ýº¹ÇÏ´ÂÁö ³ªÅ¸³»Áö ¾Ê°í ¹Ýº¹ÇÏ´Â °æ¿ìµµ °¡´ÉÇÏ´Ù. vectorÀÇ Ã³À½ 50 °³¸¦ ÇÑ ÁÙ¿¡ 10 °³¾¿ ÀμâÇÏ°íÀÚ ÇÒ ¶§ ´ÙÀ½°ú °°ÀÌ ÇÒ ¼ö ÀÖ´Ù.
write(*,1010) (x(i), i=1,50) 1010 format (10I6)format¹®¿¡ ÀÇÇÏ¸é ¿ °³ÀÇ ¼öÀÚ¸¦ ÀμâÇÏ¿©¾ß ÇÑ´Ù. ÇÏÁö¸¸ write ¹®¿¡¼´Â 50 °³¸¦ ÀμâÇÏ·Á°í ÇÑ´Ù. µû¶ó¼ óÀ½ 10 °³ÀÇ ¼ýÀÚ¸¦ ÀμâÇÑ µÚ °°Àº format ¹®À» »ç¿ëÇÏ¿© ´ÙÀ½ 10 °³¸¦ ÀμâÇÏ°í ±× ´ÙÀ½¿¡µµ ¹Ýº¹ÇÑ´Ù.
write(*,100) 12, 12345 write(*,110) 0.12345 write(*,110) 123.45 write(*,110) 12345.0 100 format (I4, 2X, I4) 110 format (F6.2)
1 | |||||||||||||
1 | 1 | ||||||||||||
1 | 2 | 1 | |||||||||||
1 | 3 | 3 | 1 | ||||||||||
1 | 4 | 6 | 4 | 1 | |||||||||
1 | 5 | 10 | 10 | 5 | 1 | ||||||||
1 | 6 | 15 | 20 | 15 | 6 | 1 |