How to transfer data from a messy .rpt file to an array

22 views (last 30 days)
How can I transfer the numerical values from a .rpt file with several lines of headings, and columns with different kind of data like the next one:
Experim: offD_deck Lib: PROG Co: turb Parti: offDe
User: j Date: 2020:12:13 Time: 18:23:10
Library dependency list: MATH V3.2 PORTS_LIB V1.1.3 PROGNOSIS V1.0 TURBO V4.0.1
Programme and Version: PRS V3.6.19
---------------------------------------------------------
CASE = ""
CALC = "stey-1"
POINT = ""
STATUS = STEADY_OK
ESI = 0
TIME = 0
A18= 2.32450494 (m^2)
A8= 0.622564773 (m^2)
Amb.Flui= defaultFl
Amb.M_in= 0.8 (-)
Amb.Pa_in= 101325 (Pa)
Amb.Pt_in= 101325 (Pa)
Amb.g= 287.046 (J/(kg·K))
Amb.TbRef= 217.391 (K)
ETC ETC ETC........
The .rpt file contains about 1700 lines and I only need the numerical values in one array.
The numerical values count with different formats (floating, decimal,....), but I would need only those that are floating.
I have realize that the separator before and after each number is different (before, just a space; after, a tab).
I tried with A=fscanf(fid, '%f' ), but it didn't worked.
Thanks
  1 Comment
dpb
dpb on 13 Dec 2020
Attach a file. Easiest likely will be to read the file as cellstr() array and then parse the data

Sign in to comment.

Answers (1)

dpb
dpb on 13 Dec 2020
>> data=textread('output.rpt','%s','delimiter','\n','headerlines',5)
data =
14×1 cell array
{'CASE = ""' }
{'CALC = "stey-1"' }
{'POINT = ""' }
{'STATUS = STEADY_OK' }
{'ESI = 0' }
{'TIME = 0' }
{'A18= 2.32450494→(m^2)' }
{'A8= 0.622564773→(m^2)' }
{'Amb.Flui= defaultFl' }
{'Amb.M_in= 0.8→(-)' }
{'Amb.Pa_in= 101325→(Pa)' }
{'Amb.Pt_in= 101325→(Pa)' }
{'Amb.g= 287.046→(J/(kg·K))'}
{'Amb.TbRef= 217.391→(K)' }
>> vals=data(contains(data,char(9)))
vals =
7×1 cell array
{'A18= 2.32450494→(m^2)' }
{'A8= 0.622564773→(m^2)' }
{'Amb.M_in= 0.8→(-)' }
{'Amb.Pa_in= 101325→(Pa)' }
{'Amb.Pt_in= 101325→(Pa)' }
{'Amb.g= 287.046→(J/(kg·K))'}
{'Amb.TbRef= 217.391→(K)' }
>> vals=str2double(extractBetween(vals,' ',char(9)));
>> fprintf('%f\n',vals)
2.324505
0.622565
0.800000
101325.000000
101325.000000
287.046000
217.391000
>>
this handles the ill-formed case of
'Amb.Flui= defaultFl'
by tossing it out since doesn't have the trailing \t.
More esoteric parsing with regexp could help; this just uses the high level builtin parsing functions.

Community Treasure Hunt

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

Start Hunting!