Extract all indexes inside a text file

7 views (last 30 days)
How can I extract all the indexes from the following text file? It works for 01June2020 but not for 04June2020.
fid = fopen('01JUNE2020_0000Z.TXT');
cnt=0;
while ~feof(fid)
aa = fgetl(fid);
if length(aa) >= 68
aa = [aa,''];
if strcmp(aa(1:67),' 1 CAPE Total ')
Cape_Total(cnt,1) = str2num(aa(67:length(aa)));
end
if strcmp(aa(1:67),' 1 K Index ')
K_Index(cnt,1) = str2num(aa(67:length(aa)));
end
if strcmp(aa(1:67),' 1 LI - Lifted Index ')
Lifted_Index(cnt,1) = str2num(aa(67:length(aa)));
end
if strcmp(aa(1:67),' 1 SI - Showalter Index ')
Showalter_Index(cnt,1) = str2num(aa(67:length(aa)));
end
if strcmp(aa(1:67),' 1 SWEAT Index ')
SWEAT_Index(cnt,1) = str2num(aa(67:length(aa)));
end
if strcmp(aa(1:67),' 1 TT - Total Totals ')
Total_Totals(cnt,1) = str2num(aa(67:length(aa)));
end
cnt = cnt + 1;
end
display(cnt)
end
  2 Comments
Star Strider
Star Strider on 3 Jun 2022
There do not appear to be any numbers associated with those rows in the ‘04JUN2020’ file:
opts = weboptions('ContentType','text');
W1 = webread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1020870/01JUNE2020_0000Z.TXT', opts)
W1 =
' RAOB: 01JUNE2020_0000Z.TXT // 98433 - ---- - TANAY, PH at 2020060100 Data Type: CODED Integrated data levels: 98 Lat: 14�34'00" N Lon: 121�22'00" E Elev: 614 meters _____________________________________________________________________ Weight Parameter Weak Moderate Strong ------ ----------------------------------- ---- ------ ------ 1 200 mb Wind Speed (kt) 29 1 500 mb Wind Speed (kt) 16 1 700 mb Wind Speed (kt) 10 1 700 mb Dewpoint Depression (C) 1.7 1 850 mb Wind Speed (kt) 4 1 850 mb Dewpoint (C) 13.0 1 700 - 500 mb lapse rate (C/km) -5.1 1 Boyden Index 99.3 1 BRN - Bulk Richardson No. 756 1 BRN Shear (m�/s�) 1.9 1 CAP Strength 3.0 1 CAPE 0-3 km, AGL 99 1 CAPE Total 1366 1 Craven SigSvr Parameter (mixed-layer lift) 0 1 CT - Cross Totals 17.5 1 DCAPE 6.0 km, AGL 576 1 Delta Theta-e (ePT) 26.0 1 EHI - Energy Helicity Index 0.2 1 GOES HMI (Hybrid Microburst Index) 12 1 Hail (cm) 0.43 1 HI - Humidity Index 19.7 1 JI - Jefferson Index 30 1 K Index 35.8 1 KO Index -9.6 1 LFC-LCL height (m) 854 1 LFC - Level of Free Convection (mb) 820 1 LI - Lifted Index -3.0 1 MDPI - Microburst Day Potential Index 0.9 1 NCAPE (Normalized CAPE) 0.12 1 S Index 38.3 1 SCP - Supercell Composite Parameter 0.0 1 Severity - Thunderstorm Severiry Index 3.4 1 SHIP - Significant Hail Parameter 0.1 1 SI - Showalter Index 1.6 1 srH - storm-relative Helicity (0-3 km) 19 1 STP - Significant Tornado Parameter 0.0 1 Surface Dewpoint (C) 21.5 1 SWEAT Index 180.0 1 T2 Gust (kt) 30 1 TI - Thompson Index 39 1 TQ Index 17 1 TT - Total Totals 42.0 1 VGP - Vorticity Generation Parameter 0.197 1 VT - Vertical Totals 24.5 1 Waterspout Index 46 1 WBZ - WetBulb Zero Hgt (ft,AGL) * 11774 1 Windex (kt) 27 1 WMSI - Wet Microburst Severity Index 37 ==== ====== ====== Weighted Category Totals: 25 13 10 RPM = 21% RPM = RAOB Parameter Metric '
W2 = webread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1020875/04JUNE2020_0000Z.TXT', opts)
W2 =
' RAOB: 04JUNE2020_0000Z.TXT // 98433 - ---- - TANAY, PH at 2020060400 Data Type: CODED Integrated data levels: 4 Lat: 14�34'00" N Lon: 121�22'00" E Elev: 614 meters _____________________________________________________________________ Weight Parameter Weak Moderate Strong ------ ----------------------------------- ---- ------ ------ 1 200 mb Wind Speed (kt) 1 500 mb Wind Speed (kt) 1 700 mb Wind Speed (kt) 1 700 mb Dewpoint Depression (C) 1 850 mb Wind Speed (kt) 1 850 mb Dewpoint (C) 1 700 - 500 mb lapse rate (C/km) 1 Boyden Index 1 BRN - Bulk Richardson No. 1 BRN Shear (m�/s�) 1 CAP Strength 1 CAPE 0-3 km, AGL 0 1 CAPE Total 0 1 Craven SigSvr Parameter (mixed-layer lift) 1 CT - Cross Totals 1 DCAPE 6.0 km, AGL 9 1 Delta Theta-e (ePT) 1 EHI - Energy Helicity Index 1 GOES HMI (Hybrid Microburst Index) 1 Hail (cm) 1 HI - Humidity Index 1 JI - Jefferson Index 1 K Index 1 KO Index 1 LFC-LCL height (m) 1 LFC - Level of Free Convection (mb) 1 LI - Lifted Index 1 MDPI - Microburst Day Potential Index 1 NCAPE (Normalized CAPE) 0.00 1 S Index 1 SCP - Supercell Composite Parameter 0.0 1 Severity - Thunderstorm Severiry Index 4.9 1 SHIP - Significant Hail Parameter 1 SI - Showalter Index 1 srH - storm-relative Helicity (0-3 km) 1 1 STP - Significant Tornado Parameter 0.0 1 Surface Dewpoint (C) 22.9 1 SWEAT Index 1 T2 Gust (kt) 1 TI - Thompson Index 1 TQ Index 1 TT - Total Totals 1 VGP - Vorticity Generation Parameter 0.0 1 VT - Vertical Totals 1 Waterspout Index 1 WBZ - WetBulb Zero Hgt (ft,AGL) * 1 Windex (kt) 1 WMSI - Wet Microburst Severity Index ==== ====== ====== Weighted Category Totals: 9 0 1 RPM = 10% RPM = RAOB Parameter Metric '
.
Munir Baldomero
Munir Baldomero on 3 Jun 2022
That is how the software generate the data from the upper-air sounding. There are missing value due to lack of data obtained from the balloon flight

Sign in to comment.

Accepted Answer

Jon
Jon on 3 Jun 2022
Edited: Jon on 3 Jun 2022
I'm not quite clear what you want to do with the data, but I'm assuming you want to get the text table into some form that you can extract desired numerical values out of it.
I used the MATLAB "Import Data" button on the HOME tab of the main MATLAB UI, and fiddled with the parameters to generate the attached function for reading your data into a table. The most important thing turned out to be using fixed width columns and dragging the sliders to the appropriate column widths.
Once you have the data into a table you can get for example the value of weak DCAPE 6.0 km, AGL
T = importfile('04JUNE2020_0000Z.txt',15,62)
T{T.Parameter=="DCAPE 6.0 km, AGL",'Weak'}
Weight Parameter Weak Moderate Strong
______ ____________________________________________ ____ ________ ______
1 "200 mb Wind Speed (kt)" NaN NaN NaN
1 "500 mb Wind Speed (kt)" NaN NaN NaN
1 "700 mb Wind Speed (kt)" NaN NaN NaN
1 "700 mb Dewpoint Depression (C)" NaN NaN NaN
1 "850 mb Wind Speed (kt)" NaN NaN NaN
1 "850 mb Dewpoint (C)" NaN NaN NaN
1 "700 - 500 mb lapse rate (C/km)" NaN NaN NaN
1 "Boyden Index" NaN NaN NaN
1 "BRN - Bulk Richardson No." NaN NaN NaN
1 "BRN Shear (m²/s²)" NaN NaN NaN
1 "CAP Strength" NaN NaN NaN
1 "CAPE 0-3 km, AGL" 0 NaN NaN
1 "CAPE Total" 0 NaN NaN
1 "Craven SigSvr Parameter (mixed-layer lift)" NaN NaN NaN
1 "CT - Cross Totals" NaN NaN NaN
1 "DCAPE 6.0 km, AGL" 9 NaN NaN
1 "Delta Theta-e (ePT)" NaN NaN NaN
1 "EHI - Energy Helicity Index" NaN NaN NaN
1 "GOES HMI (Hybrid Microburst Index)" NaN NaN NaN
1 "Hail (cm)" NaN NaN NaN
1 "HI - Humidity Index" NaN NaN NaN
1 "JI - Jefferson Index" NaN NaN NaN
1 "K Index" NaN NaN NaN
1 "KO Index" NaN NaN NaN
1 "LFC-LCL height (m)" NaN NaN NaN
1 "LFC - Level of Free Convection (mb)" NaN NaN NaN
1 "LI - Lifted Index" NaN NaN NaN
1 "MDPI - Microburst Day Potential Index" NaN NaN NaN
1 "NCAPE (Normalized CAPE)" 0 NaN NaN
1 "S Index" NaN NaN NaN
1 "SCP - Supercell Composite Parameter" 0 NaN NaN
1 "Severity - Thunderstorm Severiry Index" 4.9 NaN NaN
1 "SHIP - Significant Hail Parameter" NaN NaN NaN
1 "SI - Showalter Index" NaN NaN NaN
1 "srH - storm-relative Helicity (0-3 km)" 1 NaN NaN
1 "STP - Significant Tornado Parameter" 0 NaN NaN
1 "Surface Dewpoint (C)" NaN NaN 22.9
1 "SWEAT Index" NaN NaN NaN
1 "T2 Gust (kt)" NaN NaN NaN
1 "TI - Thompson Index" NaN NaN NaN
1 "TQ Index" NaN NaN NaN
1 "TT - Total Totals" NaN NaN NaN
1 "VGP - Vorticity Generation Parameter" 0 NaN NaN
1 "VT - Vertical Totals" NaN NaN NaN
1 "Waterspout Index" NaN NaN NaN
1 "WBZ - WetBulb Zero Hgt (ft,AGL) *" NaN NaN NaN
1 "Windex (kt)" NaN NaN NaN
1 "WMSI - Wet Microburst Severity Index" NaN NaN NaN
ans =
9
  6 Comments
Jon
Jon on 3 Jun 2022
If this answered your question, when you get a chance please accept the answer, so others will know an answer is available

Sign in to comment.

More Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!