Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jeff Henrikson (jhenriks@umd.edu) Lecture 12 Program Improvement Jeff Henrikson (jhenriks@umd.edu) http://www.atmos.umd.edu/~jeff/aosc347/ 1.

Similar presentations


Presentation on theme: "Jeff Henrikson (jhenriks@umd.edu) Lecture 12 Program Improvement Jeff Henrikson (jhenriks@umd.edu) http://www.atmos.umd.edu/~jeff/aosc347/ 1."— Presentation transcript:

1 Jeff Henrikson (jhenriks@umd.edu)
Lecture 12 Program Improvement Jeff Henrikson 1

2 Import/Export ASCII File
ASCII File with Known Data Format: Import Export csvread dlmread textscan textread fscanf csvwrite dlmwrite Cell Array {..} – access cellplot – visualize celldisp – display Parentheses ( ) Square brackets [ ] Curly brackets { } Angle brackets or chevrons ⟨ ⟩ Corner and half brackets 「」, ⌊ ⌋ Double brackets ⟦ ⟧ File with Unknown Data Format: uiimport Import Wizard Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

3 Atmospheric Sounding Open Explorer & go to http://weather.uwyo.edu
Navigate to Upper Air Observations  Soundings From the menu select Region: North America Type of plot: Text List Year: Month: Jul From: 15/12Z To: 15/12Z Find Sterling VA (IAD) on the map and click Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

4 Do not forget the quotes
urlread Copy & Paste urlname here Two fingers click on the page and choose View Page Source Type in the Command Window >> a = urlread (' Do not forget the quotes Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

5 urlread urlread reads all characters in the source file
Source file contains data and formatting text We need only the data not the formatting text Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

6 urlread a is an array of thousands of characters!
We have to locate the actual data within a Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

7 Locate Data Start & End Data are bound by delimiters Scroll down
Search for delimiters: strfind, regexp, strtok, etc. Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

8 String Find / Length Position=533 Position=610 Linefeed >>L1 = ' '; >>Id = length(L1)+1; % length of 1st data line =78 >>Ib = strfind(a, L1); % position of 1st char =533 >>Ie = Ib + Id-1; % position of last char =610 Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

9 Get Data Structure Start End Line 1 533 610 Line 2 611 687 
>> Je = strfind (a,'</PRE>'); % data bound >> Ix = Je(1)-1; % last data char = 9892 >> Ln = (Ix-Ib+1)/Id; % total num of data lines = 120 for l = 1:Ln i1 = Ib+(l-1)*Id; i2 = i1+Id; disp (a(i1:i2)) end Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

10 Convert String to Data We can read multiple lines and convert each line into a 1-d array >> b = str2num ( a (i1:i2) ) We need to convert the whole table into a 2-d array # of rows = num of data lines to read # of columns = num of data fields (=11) >> if length ( b ) < 11 indicate missing data => ignore the line Missing data Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang

11 Final Code Save this code into an M-File called L12E1.m
close; clear; clc a = urlread(' L1 =' '; Id = length(L1)+1; % length of 1st data line Ib = strfind(a, L1); % position of 1st char Ie = Ib + Id-1; % position of last char Je = strfind (a,'</PRE>'); % data bound Ix = Je(1)-1; % last data char Ln = (Ix-Ib+1)/Id; % total no of data lines Fn = 11; % no of fields Rn = 0; % no of valid data records for l = 1:Ln i1 = Ib+(l-1)*Id; i2 = i1+Id; b = str2num (a(i1:i2)); if (length(b)==Fn) % add the data if no missing Rn = Rn+1; z(Rn,:) = b(:); end disp([z(:,1),z(:,Fn)]); % for visual validation plot( z(:,3), z(:,1) ); set(gca, 'ydir','rev'); title('Sounding at Sterling'); xlabel('Temperature (C)'); ylabel('Pressures (hPa)'); Final Code Copyright © 2015 University of Maryland. This material may not be reproduced or redistributed in whole or in part without written permission from Xin-Zhong Liang


Download ppt "Jeff Henrikson (jhenriks@umd.edu) Lecture 12 Program Improvement Jeff Henrikson (jhenriks@umd.edu) http://www.atmos.umd.edu/~jeff/aosc347/ 1."

Similar presentations


Ads by Google