Reading data with multiple headers
5 views (last 30 days)
Show older comments
I have a huge vtk data that contains multiple dataset (total of 7).
Each dataset is divided by some title in the format of: string number number string.
I identified how to extract the first dataset, but I do not know how to exact the next datasets.
Each dataset represent some 3D coordinate data. For example if there were 1 2 3 4 5 6 in the dataset, that simply means (1,2,3) and (4,5,6). A number before floats in the header represents the number of coordinates in the dataset. For the example I gave in the previous sentence, it should be 2 float.
Can someone help me on how to do this?
I couldn't attach the data since it was too large. Hence, I copied a portion of my data down below.
Data looks like this:
# vtk DataFile Version 2.0
CFD_results
ASCII
DATASET UNSTRUCTURED_GRID
POINTS 3 floats
0.00996074 0.0054144 -0.134876 2.11545e-05 0.0100366 -0.135006 0.00497977 0.00996415 -0.134936
p 1 3 float
-3.65022e-09 -0.000371252 -0.000183657 -8.9538e-05 0.000226161 -0.00031672 -0.000252209 -0.000295019 -0.000275176
wallShearStress 3 3 float
3.1775e-05 2.5129e-05 -3.8414e-05 0 0 0 0 0 0
3 Comments
J. Alex Lee
on 1 Sep 2020
i made a first pass at an answer, i'm not sure it's the best...but also on another note, it's odd because i thought vtk files are more self-descriptive...maybe that's only for the binary formats where it has to tell you how many bytes make up data blocks, not for ascii formats...
Answers (1)
J. Alex Lee
on 1 Sep 2020
other experts on the forum for text parsing may have better ways, but you can scan through line by line and apply regular expression
fid = fopen("vtkfile")
while feof(fid)
linebuffer = fgetl(fid);
hdr = regexp(linebuffer,"\w+ \d+ \d+ \w+","match");
% i'm flying solo with the regexp, i don't know if this pattern will work
% you'll have to look at regexp docs to check
if ~isempty(hdr)
% this is a header
% do something special
% presumably you need to parse the 2 numbers that tell you
% how the following data is formatted or something
else
% this is not a header
% treat the line appropriately
end
end
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!