Presentation is loading. Please wait.

Presentation is loading. Please wait.

File I/O 1. Goals of this chapter 2. Inputs Files 3. Output Files 4. File Formats 5. General Concept, lots of examples 6. High-Level vs. Low-Level 1.

Similar presentations


Presentation on theme: "File I/O 1. Goals of this chapter 2. Inputs Files 3. Output Files 4. File Formats 5. General Concept, lots of examples 6. High-Level vs. Low-Level 1."— Presentation transcript:

1 File I/O 1. Goals of this chapter 2. Inputs Files 3. Output Files 4. File Formats 5. General Concept, lots of examples 6. High-Level vs. Low-Level 1

2 1. Goals of this chapter Understand why external files are greatly used in programming, such as.txt,.xls,.dat… Recognize when to use a file vs. hardcoding data Understand how Matlab sees any file Define and recognize delimiting-characters  Depending on which type of file, choose an appropriate built-in function Remember the overall idea behind each built-in function Remember the logical order of reading/writing a file 2

3 2. Input Files What is an “input-file”? It is file that contains the givens needed to solve part of the problem, or maybe the entire problem LOTS of data (as little as 5 lines to billions of lines…) 3 Some examples of input files…

4 Property Sales in Flagler (North of Daytona Beach) 4 INPUT FILE

5 Property Listing in Ormond Beach (North of Daytona Beach) 5 Online data dated March 21 st 2010.

6 Hurricane Data 6 Online data dated March 21 st 2010, nhc.noaa.gov INPUT FILE

7 Hurricane Data... What? 7 Same as previous file… A text file doesn’t always look pretty. Try different softwares to open it until one shows clearly the columns and rows! -Notepad -Wordpad -Internet explorer -Firefox -word INPUT FILE

8 Coefficient of Friction 8.xls, Excel format.txt, text format(INPUT FILES)

9 3. Output Files What is an “output-file”? It is a file which contains the results (once the problem has been solved). Most common example: I _ V O _ C _ 9

10 4. File Formats Files are stored in essentially two different formats: ASCII text, and binary. ASCII text consists entirely of characters which have meaning within the ASCII table. The only special codes are already present in the ASCII table, such as newlines and tabs. Notepad, for example, works only with ASCII text files. 10

11 4. File Formats, cont. Binary files may contain some ASCII text, but will also contain data which has meaning to the program which was intended to use the file. MS Word, for example, embeds codes for margins, bold, underline, HTML, etc in the file. These codes only have meaning to Word – not to programs like Notepad. Idea: Word can work with Notepad files, but Notepad cannot work with Word files. 11

12 5. General Concept When reading data from a file, Matlab continually requests values from the file data stream until the end of the file is reached. As the data is received, the program must identify the delimiting characters (tabs, spaces, enter key, special characters..) and reformat the data to reconstruct the organization of the data as represented in a file. When writing data to a file: to preserve the organization of the data, the appropriate delimiting characters must be inserted into the stream of information. 12 FileProgram An I nput Stream of information ProgramFile An O uput Stream of information

13 5. General Concept, cont. Using the data contained inside input-files Analyze, min, max, average Estimate trends (stock market) Use it as a database for one or two variables (coefficient of friction) Use it to give user possibilities to pick from Plot 13 Examples…

14 Analyzing Flagler Sales Price of properties function of square footage Linear Fitting of all data points (red) Standard deviation (green) 14

15 Attendance Sheet 15 OUTPUT FILE

16 Analyze grades 16 INPUT FILE OUTPUT FILE

17 Plot Hurricane Data This is a final project in JAVA (CS225) in Fall 2007 that analyzed the hurricane input file. 17

18 5. General Concept, cont. Using the data contained inside input-files Analyze, min, max, average Estimate trends (stock market) Use it as a database for one or two variables (coefficient of friction) Use it to give user possibilities to pick from Plot Using output-files, once populated with data Print them Email them Publish in a report Reuse as an input file for another software 18

19 5. General Concept, cont. Although there are only a few ADVANTAGES to using files, the ones that do exist are sufficient in themselves!!! 1. LOTS of data, usually contained in very little variables (possibly only 1 cell-array!) 2. The software is developed knowing that the file cannot change format, but definitely knowing that the file can grow in size! Although the hurricane data obviously gets updated yearly, the software to analyze the data does not change a bit! 3. User does not have to enter the data: less prone to errors. 4. Long term saving/backup of data. 19

20 5. General Concept, cont. Only certain formats can be analyzed. Some are:.txt.xlsx.csv.dat.jpg.png.gif.trk The following is not possible under MATLAB.docx (Note: most binary files are not possible) 20

21 NOW THAT YOU HAVE AN IDEA.. How is all this done? 21

22 5. General Concept, cont. There are two types of built-in functions High-level functions: one (and 1 only) command opens the file, read or writes data, and closes the file. All is stored immediately in variable(s). Low-level functions: 1. one command needs to open the file, 2. another command (maybe more than one) needs to read or write the data, 3. and finally another command closes the file. 22 Each of these concepts is detailed in separate powerpoint lessons…

23 Wrapping Up What is an input file? What is an output file? What examples of input files were shown? What examples of output files were shown? What can be done with output files? What can be done with input files? What is the difference between high-level and low-level I/O functions? 23


Download ppt "File I/O 1. Goals of this chapter 2. Inputs Files 3. Output Files 4. File Formats 5. General Concept, lots of examples 6. High-Level vs. Low-Level 1."

Similar presentations


Ads by Google