Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5+ Input / Output Sec. 5.4 & 5.5 (p. 283 – 295) File Processing ( 檔案處理 )

Similar presentations


Presentation on theme: "Chapter 5+ Input / Output Sec. 5.4 & 5.5 (p. 283 – 295) File Processing ( 檔案處理 )"— Presentation transcript:

1 Chapter 5+ Input / Output Sec. 5.4 & 5.5 (p. 283 – 295) File Processing ( 檔案處理 )

2 The WRITE Statement and the General READ Statement WRITE (6, *) Gravity, Weight An output device having unit number 6 WRITE (*, *) Gravity, Weight PRINT *, Gravity, Weight READ (5, *) Code, Time, Rate An input device having unit number 5 READ (5, 10) Code, Time, Rate 10 FORMAT (I6, 2F6.2)

3 The WRITE Statement WRITE (6, *) Gravity, Weight An output device having unit number 6 is equivalent to the following form: WRITE (6, FMT = *) Gravity, Weight WRITE (UNIT = 6, FMT = *) Gravity, Weight or WRITE (Output_Unit, *) Gravity, Weight WRITE (UNIT = Output_Unit, FMT = *) Gravity, Weight

4 The General READ Statement READ (5, *) Code, Time, Rate An input device having unit number 5 is equivalent to the following form: READ (5, FMT = *) Code, Time, Rate READ (UNIT = 5, FMT = *) Code, Time, Rate or READ (In, *) Code, Time, Rate READ (UNIT = In, FMT = *) Code, Time, Rate

5 The WRITE Statement The WRITE statement has more complicated syntax than the PRINT statement, but it is a more general output statement. The ADVANCE = clause is used to specify whether output should advance to a new line after the current output has been completed.

6 ADVANCE ADVANCE = “ NO ” causes nonadvancing output, where ADVANCE = “ YES ” is the default ( 棄權 ; 系統默認值 ) condition and causes an advance to a new line of output after the WRITE statement has been executed.

7 ADVANCE PRINT *, “ Enter last name to be used: ” READ *, LastNumber WRITE (*, ‘ (A) ’, ADVANCE = “ NO ” ) & “ Enter last name to be used: ” READ *, LastNumber Enter last name to be used: 10

8 5.5 File Processing ( 檔案處理 ) OPEN (UNIT = 12, FILE = “ INFO.DAT ”, & STATUS = “ OLD ”, & ACTION = “ READ ”, & POSITI ON = “ REWIND ”, & IOSTAT = OpenStatus) IF (OpenStatus > 0) STOP “ *** Cannot open file *** ” IF (OpenStatus > 0) ! End of file READ (12, *) Code, Temperature, Pressure

9 File Input/Output DO READ (12, *, END = 20) Code, & Temperature, Pressure ‧ ‧ ‧ ‧ ‧ Count= Count +1 END DO ‧ ‧ ‧ ‧ ‧ 20 CONTINUE ‧ ‧ ‧ ‧ ‧

10 File Processing OPEN (UNIT = 13, FILE = “ REPORT ”, & STATUS = “ NEW ”, & ACTION = “ WRITE ”, & IOSTAT = OpenStatus) WRITE (13, ‘ (1X, I3, F7.0, F10.2) ’ ) & Code, Temperature, Pressure CLOSE (13)


Download ppt "Chapter 5+ Input / Output Sec. 5.4 & 5.5 (p. 283 – 295) File Processing ( 檔案處理 )"

Similar presentations


Ads by Google