I have a text file that is in a rather funky format. The file comes out of a relational database (Antelope) and consists of earthquake location, dates, times, phase information, etc. I need to parse out and collect the 'data blocks' that are in between each header line. I need the header lines as well for each "block". I have edited the file to include an EOB (end of block) marker to make this task easier, but it's not as trivial as I thought. Here's an image of the first 68 or so lines (out of about 1 million).
I'd like to pull the 4 columns below each header…. for example the first section is:
2015 1 22 0 8 58.537 45.97929 -129.98717 1.184 0.0 1.039 3.621 0.036 1 AXCC1 0.843 1.00 P AXAS2 1.263 1.00 P AXEC1 0.923 1.00 P AXEC2 1.103 1.00 P AXEC3 1.088 1.00 P AXCC1 1.873 0.25 S AXAS1 2.728 0.06 S AXAS2 2.168 0.25 S AXEC1 1.708 0.33 S AXEC2 2.043 0.25 S AXEC3 2.113 0.25 S
and put those in an array. But I need to be able to associate the header line, specifically the last integer in the header line (1 in this case), with each code block.
So far my code looks like this, but obviously it is not working yet. I don't get any errors but it's missing and skipping data etc.
fid=fopen('ph2dt_catalog8_edit.dat');Block=1;while (~feof(fid)) InputText=textscan(fid,'%s',1,'delimiter','\n'); HeaderLines{Block,1}=InputText{1}; disp(HeaderLines{Block}); FormatString='%s%f%f%s'; InputText=textscan(fid, FormatString, 'delimiter','WhiteSpace','CollectOutput',1); Data{Block,1} = cell2mat(InputText{2}); [NumRows,NumCols] = size(Data{Block}); eob=textscan(fid,'%s',1,'delimiter','\n'); Block=Block +1;end
Can anyone offer any suggestions. Let me know if I need to clarify anything further.
Best Answer