Скачать презентацию Week 9 Controling I O Today s program Скачать презентацию Week 9 Controling I O Today s program

7d69dffab95664323d4a4cae0418c634.ppt

  • Количество слайдов: 17

Week 9 Controling I/O Week 9 Controling I/O

Today’s program • Review of the last quiz • Q&A about last weeks topics Today’s program • Review of the last quiz • Q&A about last weeks topics • New topic: I/O formatting

I/O External media Input Keyboard Disk file Magnetic tape etc. Computer’s memory Convert to I/O External media Input Keyboard Disk file Magnetic tape etc. Computer’s memory Convert to internal form real integer character Output Display Printer Disk file Magnetic tape etc. Convert to external form

User interface of F programs • • Character-based interface read/print statements List-directed I/O “Intelligent” User interface of F programs • • Character-based interface read/print statements List-directed I/O “Intelligent” read *, a, b, c, d • “Reasonable” print *, x, y, z

List-directed read • Value separators: – , (comma) – / (slash) – one or List-directed read • Value separators: – , (comma) – / (slash) – one or more consecutive blanks – end-of-record/end-of-line • Be careful with character data (read the book!)

List-directed print • It gives you a “reasonable”/readable output • But… Not much control List-directed print • It gives you a “reasonable”/readable output • But… Not much control over the space between values, digits after the decimal point, etc.

I/O editing External media Input Keyboard Disk file Magnetic tape etc. Computer’s memory Convert I/O editing External media Input Keyboard Disk file Magnetic tape etc. Computer’s memory Convert to internal form real integer character Output Display Printer Disk file Magnetic tape etc. Convert to external form

Format descriptors • Instead of: read *, input_list print *, output_list • read ch_expr, Format descriptors • Instead of: read *, input_list print *, output_list • read ch_expr, input_list • print ch_expr, output_list

Format descriptors • ch_expr is format specifier • (ed_des 1, ed_des 2, …) edit Format descriptors • ch_expr is format specifier • (ed_des 1, ed_des 2, …) edit descriptors - character-type data • read "(edit_descriptor_list)", input_list • print "(edit_descriptor_list)", output_list

Edit Descriptors • Integer data • iw Next w characters are to be read Edit Descriptors • Integer data • iw Next w characters are to be read and interpreted as an integer • read "(i 9)", n • read "(i 3, i 2, i 5)", a, b, c

Edit Descriptors • Tabs • tc • tln • trn read at position c Edit Descriptors • Tabs • tc • tln • trn read at position c n character before n character after

Edit Descriptors • Integer data • iw Next w characters are to be read Edit Descriptors • Integer data • iw Next w characters are to be read and interpreted as an integer • read "(i 9)", n • read "(i 3, i 2, i 5)", a, b, c

Edit Descriptors • Real data • fw. d • If there is a decimal Edit Descriptors • Real data • fw. d • If there is a decimal point, read next w characters and interpret it as a real number • If there is no decimal point, take d into account • ew. d

Edit Descriptors • Character data • aw – w < len – w > Edit Descriptors • Character data • aw – w < len – w > len • • a rightmost len characters stored w = len assumed Logical data Lw t , true, . T, . true. , . . .

Output editing • Essentially the same Output editing • Essentially the same

More control. . . • read (clist) input_list • write (clist) output_list • clist More control. . . • read (clist) input_list • write (clist) output_list • clist control list • keyword = value – unit = unit – fmt = ch_expr – iostat = io_status

Homework • Homework # 7: Problem 9. 11 from Ellis & Philips Deadline April Homework • Homework # 7: Problem 9. 11 from Ellis & Philips Deadline April 30. • All previous homework [HW#1 -6] deadline reset to April 23. Your last chance!