Read data from a complex text file

6 Ansichten (letzte 30 Tage)
RR RR
RR RR am 6 Nov. 2019
Kommentiert: Bob Thompson am 7 Nov. 2019
Hi all, I am writing some code using matlab but I am stuck at reading the output of a program.
The program generates a large text file. However I am intrested in reading some part of this file to be able to work with the data generated. I have attched the portion of the file that includes the data. The way that the data are written for any experiment are fixed. The data either have one value, or two values or a vector that are listed separately:
Experiment one has the name "Expt 1 Flash Calculation" and has the following fixed sections and variables ( the numerics will change if I run this experiment again. so it is desired to read the numerical values corresponding to each variable in the experiment):
Specified temperature Deg F 200
Specified pressure PSIA 500.0000
Mole Percentage in vapour 16.3351
Calculated GOR MSCF/BBL 0.1478
or
------------------- ------------ ------------
Liquid Vapour
Fluid properties ------------ ------------
Calculated Calculated
------------------- ------------ ------------
Mole Weight 131.7372 23.8229
Z-factor 0.2113 0.9017
Viscosity 0.0745 0.0121
Density LB/FT3 46.7967 1.9825
Molar Vol CF/LB-ML 2.8151 12.0165
------------------- ------------ ------------
or
------------------- ------------ ------------ ------------ ------------
Molar Distributions Total, Z Liquid,X Vapour,Y K-Values
Components ------------ ------------ ------------ ------------
Mnemonic Number Measured Calculated Calculated Calculated
------------------- ------------ ------------ ------------ ------------
N2 1 0.0400 0.0117 0.1852 15.8677
CO2 2 0.1300 0.1021 0.2732 2.6764
C1 3 15.8340 9.3167 67.5790 7.2535
C2 4 8.3819 7.8689 17.1312 2.1771
C3 5 11.5820 10.7484 9.7294 0.9052
C4 6 7.8216 8.6792 3.4289 0.3951
C5 7 5.0710 5.8649 1.0045 0.1713
C6 8 4.8210 5.6763 0.4403 0.0776
C7-C10 9 9.5540 23.3356 0.1853 0.0079
C11-C14 10 9.1118 10.8826 0.0419 0.0038
C15-C20 11 7.0614 8.4399 0.0012 0.0001
C21-C30 12 8.5915 9.0737 6.8582E-12 7.5584E-13
------------------- ------------ ------------ ------------ ------------
Composition Total 100.0000 100.0000 100.0000
------------------- ------------ ------------ ------------ ------------
Experiment Two has the name "Expt 1 Saturation Pressure Calculation" and has the following fixed sections and variables ( the numerics will change if I run this experiment again. so it is desired to read the numerical values corresponding to each variable in the experiment):
Specified temperature Deg F 200
Calculated bubble point pressure PSIA 961.6661
or
------------------- ------------ ------------
Liquid Vapour
Fluid properties ------------ ------------
Calculated Calculated
------------------- ------------ ------------
Mole Weight 114.1093 21.8571
Z-factor 0.3652 0.3652
Viscosity 0.0734 0.0132
Density LB/FT3 45.0971 3.6734
Molar Vol CF/LB-ML 2.5303 5.9501
------------------- ------------ ------------
or
------------------- ------------ ------------ ------------ ------------
Molar Distributions Total, Z Liquid,X Vapour,Y K-Values
Components ------------ ------------ ------------ ------------
Mnemonic Number Measured Calculated Calculated Calculated
------------------- ------------ ------------ ------------ ------------
N2 1 0.0400 0.0400 0.3258 8.1441
CO2 2 0.1300 0.1300 0.2076 1.5966
C1 3 8.8340 18.8340 75.8160 4.0255
C2 4 9.3819 9.3819 13.0035 1.3860
C3 5 17.5820 10.5820 6.8105 0.6436
C4 6 7.8216 7.8216 2.4485 0.3130
C5 7 5.0710 5.0710 0.7679 0.1514
C6 8 4.8210 4.8210 0.3624 0.0752
C7-C10 9 17.5540 19.5540 0.2053 0.0105
C11-C14 10 9.1118 9.1118 0.0501 0.0055
C15-C20 11 7.0614 7.0614 0.0022 0.0003
C21-C30 12 7.5915 7.5915 2.0066E-10 2.6432E-11
------------------- ------------ ------------ ------------ ------------
Composition Total 100.0000 100.0000 100.0000
------------------- ------------ ------------ ------------ ------------
I would like a function to serach the file, and start reading from an intrested point (after a unique name of the experiment where the data related to that experiment follows that string).
The user can specify (1) an experiment name such as as "Expt 1 Saturation Pressure Calculation" or "Expt 1 Flash Calculation" and (2) which data to extract from that experiments, and the function should return that.
For example, the user could ask the followings and the program should return:
A) "Molar Vol" from "Expt 1 Flash Calculation" and the program should return two values [ 2.8151 12.0165]. In other words, [ 2.8151 12.0165]= f("Molar Vol" , "Expt 1 Flash Calculation" )
B) "Mole Percentage in vapour" from "Expt 1 Flash Calculation" and the program should return [ 16.3351].
C) "Liquid, X" from "Expt 1 Flash Calculation" and the program should return the vector [ 0.0117 0.1021 9.3167 7.8689 10.7484 8.6792 5.8649 5.6763 23.3356 10.8826 8.4399 9.0737 ]
D) "Calculated bubble point pressure" from "Expt 1 Saturation Pressure Calculation" and the function returns 961.6661.
E) "K-Values" from experiment "Expt 1 Saturation Pressure Calculation" and the function should return the vector: [ 8.1441 1.5966 4.0255 1.386 0.6436 0.313 0.1514 0.0752 0.0105 0.0055 0.0003 2.64E-11]
  8 Kommentare
Walter Roberson
Walter Roberson am 7 Nov. 2019
I tend to find it easier to fileread() the entire file as text, and then to use regexp() and regexprep() to break into pieces that I can textscan()
Bob Thompson
Bob Thompson am 7 Nov. 2019
Using textscan() on a block is a great idea. I'm a little sad I never thought of that before, but I was stuck thinking it could only be applied to a file.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by