MATLAB: Extracting data from file.

data importdata miningMATLABstringtext file

Dear all Matlab expert,
This question might be very simple for many of you but I have no idea how to compile it together. The following is a file which can be opened by notepad/wordpad that have 13000 ++ lines in it. I would like to extract data that start from line 300.I have bold the area.It contains 21 sets of five variation that need to be compiled together. as an example surface (21<12<13)have 5 variation that need to be arranged side by side.Each variation have 120 data in 3 column. I think i will be able to do the manipulation later but for the mean time i would like a direction /guidance to import the data into matlab matrices properly so i can manipulate it.
Regards, Mo
Thread Name & Version = MCNP5_RSICC, 1.40
_
._ _ _ ._ ._ |_
| | | (_ | | |_) _)
|
+--------------------------------------------------------------------+
| This program was prepared by the Regents of the University of |
|California at Los Alamos National Laboratory (the University) under |
| contract number W-7405-ENG-36 with the U.S. Department of Energy |
|(DoE). The University has certain rights in the program pursuant to|
| the contract and the program should not be copied or distributed |
| outside your organization. All rights in the program are reserved |
|by the DoE and the University. Neither the U.S. Government nor the |
| University makes any warranty, express or implied, or assumes any |
| liability or responsibility for the use of this software. |
+--------------------------------------------------------------------+
1mcnp version 5 ld=11012005 12/01/11 02:23:53 *********************************************************************** probid = 12/01/11 02:23:53 inp=aa20 outp=oaa20o

warning. universe map (print table 128) disabled.
1- c Created on: Monday, November 14, 2011 at 16:03
2- 1 1 -1.14 -6 -4 5 trcl=1 $ Insert 1
3- 2 1 -1.14 -7 -4 5 trcl=1 $ Insert 2
4- 3 1 -1.14 -8 -4 5 trcl=1 $ Insert 3
5- 4 0 -10 trcl=1 $ Source
6- 5 1 -1.14 -9 -4 11 #4 trcl=1 $ Air Gap Above the Source
7- 6 1 -1.14 -2 -4 5 #1 #2 #3 #5 #4 trcl=1 $ Nylon 6/6
8- 7 2 -1.19 -1 -4 3 #1 #2 #3 #5 #6 #4 trcl=1 $ Perspex Casing
9- c Detector
10- 8 3 -5.323 -21 u=1
11- c Detector Diphragm
12- 9 4 -11.35 21 u=1
13- c Lattice Design
14- 12 0 12 -13 -18 11 fill=1 u=2 lat=1
15- 13 0 12 -14 11 -18 15 -17 fill=2
16- 14 0 -22 #7 #1 #2 #3 #5 #6 #4 #13 $ Perspex Casing
17- 15 0 22
18-
19- c Main block - pespex & nylon 6-6
20- 1 cz 5
21- 2 cz 4.7
22- 3 pz -6
23- 4 pz 6
24- 5 pz -5.7
25- c Inserts
26- 6 c/z 2.5 0 0.5
27- 7 c/z 0 -2.5 0.95
28- 8 c/z -2.5 0 1.265
29- 9 c/z 0 2.5 0.1
30- c Source
31- 10 s 0 2.5 0 0.099
warning. this surface has been replaced by a surface of type sy
32- 11 pz -0.25
33- 12 px -5
34- 13 px -4.5
35- 14 px 5
36- 15 py 5.1
37- 16 py 7.6
38- 17 py 5.6
39- 18 pz 0.25
40- 19 pz -0.25
41- c Collimator
42- 21 c/y -4.75 0 0.249
43- 22 so 15
44-
45- c sudut memutar 20 degree
46- *tr1 0 0 0 20 110 90 70 20 90 90 90 0
47- mode p
48- m1 10000. -0.097976 $Nylon 6/6
49- 6000. -0.636856 7000. -0.123779 8000. -0.141389
50- m2 1000. -0.080538 $Perspex
51- 6000. -0.599848 8000. -0.319614
52- m3 32000. -1 $Germanium
53- m4 82000. -1 $Lead
54- imp:p 1 11r 0 $ 1, 15
55- sdef par=2 erg=0.0595 pos=0.855 2.349 0
56- c0 -0.0872 -0.0366 0.0366 0.0872 1
57- fc01
58- f01:p (21<12<13)(21<12[-19:0 0:0 0:0]<13)
59- e01 0 1.e-5 0.001 119i 0.060
60- fm01 1000000000
61- nps 1000000000
comment. lattice speed tally modifications will not be used.
surface 3 and surface 7003 are the same. 7003 will be deleted.
surface 4 and surface 1004 are the same. 1004 will be deleted.
surface 4 and surface 2004 are the same. 2004 will be deleted.
surface 4 and surface 3004 are the same. 3004 will be deleted.
surface 4 and surface 5004 are the same. 5004 will be deleted.
surface 4 and surface 6004 are the same. 6004 will be deleted.
surface 4 and surface 7004 are the same. 7004 will be deleted.
surface 5 and surface 1005 are the same. 1005 will be deleted.
surface 5 and surface 2005 are the same. 2005 will be deleted.
surface 5 and surface 3005 are the same. 3005 will be deleted.
surface 5 and surface 6005 are the same. 6005 will be deleted.
surface 11 and surface 19 are the same. 19 will be deleted.
surface 11 and surface 5011 are the same. 5011 will be deleted.
comment. 13 surfaces were deleted for being the same as others.
comment. surface 12 appears more than once in a chain.
surface 12 is in cells 12 and 13 in chain
12 < 13
comment. surface 18 appears more than once in a chain.
surface 18 is in cells 12 and 13 in chain
12 < 13
comment. surface 11 appears more than once in a chain.
surface 11 is in cells 12 and 13 in chain
12 < 13
warning. 3 energy bins of tally 1 are below energy cutoff.
1cells print table 60
atom gram photon
cell mat density density volume mass pieces importance
1 1 1 5.18674E-02 1.14000E+00 9.18916E+00 1.04756E+01 1 1.0000E+00
2 2 1 5.18674E-02 1.14000E+00 3.31729E+01 3.78171E+01 1 1.0000E+00
3 3 1 5.18674E-02 1.14000E+00 5.88189E+01 6.70535E+01 1 1.0000E+00
4 4 0 0.00000E+00 0.00000E+00 4.06438E-03 0.00000E+00 1 1.0000E+00
5 5 1 5.18674E-02 1.14000E+00 1.92285E-01 2.19205E-01 0 1.0000E+00
6 6 1 5.18674E-02 1.14000E+00 0.00000E+00 0.00000E+00 0 1.0000E+00
7 7 2 1.07364E-01 1.19000E+00 0.00000E+00 0.00000E+00 0 1.0000E+00
8 8 3 4.41586E-02 5.32300E+00 0.00000E+00 0.00000E+00 0 1.0000E+00
9 9 4 3.29849E-02 1.13500E+01 0.00000E+00 0.00000E+00 0 1.0000E+00
10 12 0 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0 1.0000E+00
11 13 0 0.00000E+00 0.00000E+00 2.50000E+00 0.00000E+00 0 1.0000E+00
12 14 0 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0 1.0000E+00
13 15 0 0.00000E+00 0.00000E+00 0.00000E+00 0.00000E+00 0 0.0000E+00
total 1.03877E+02 1.15565E+02
warning. surface 16 is not used for anything.
minimum source weight = 1.0000E+00 maximum source weight = 1.0000E+00
***************************************************
* Random Number Generator = 1 *
* Random Number Seed = 19073486328125 *
* Random Number Multiplier = 19073486328125 *
* Random Number Adder = 0 *
* Random Number Bits Used = 48 *
* Random Number Stride = 152917 *
***************************************************
4 warning messages so far.
1cross-section tables print table 100
table length
tables from file mcplib04
1000.04p 1898 ENDF/B-VI Release 8 Photoatomic Data for 1-H mat 100 02/07/03
6000.04p 3152 ENDF/B-VI Release 8 Photoatomic Data for 6-C mat 600 02/07/03
7000.04p 3194 ENDF/B-VI Release 8 Photoatomic Data for 7-N mat 700 02/07/03
8000.04p 3272 ENDF/B-VI Release 8 Photoatomic Data for 8-O mat 800 02/07/03
10000.04p 3278 ENDF/B-VI Release 8 Photoatomic Data for 10-NE mat1000 02/07/03
32000.04p 7027 ENDF/B-VI Release 8 Photoatomic Data for 32-GE mat3200 02/07/03
82000.04p 10010 ENDF/B-VI Release 8 Photoatomic Data for 82-PB mat8200 02/07/03
total 31831
maximum photon energy set to 100.0 mev (maximum electron energy)
tables from file el03
1000.03e 2329 6/6/98
6000.03e 2333 6/6/98
7000.03e 2333 6/6/98
8000.03e 2333 6/6/98
10000.03e 2335 6/6/98
32000.03e 2349 6/6/98
82000.03e 2373 6/6/98
warning. material 3 has been set to a conductor.
warning. material 4 has been set to a conductor.
***********************************************************************************************************************
dump no. 1 on file runtpf nps = 0 coll = 0 ctm = 0.00 nrn = 0
6 warning messages so far.
***********************************************************************************************************************
dump no. 2 on file runtpf nps = 150209165 coll = 229830692 ctm = 60.01 nrn = 4128522362
***********************************************************************************************************************
dump no. 3 on file runtpf nps = 300079026 coll = 459154685 ctm = 120.02 nrn = 8247885765
***********************************************************************************************************************
dump no. 4 on file runtpf nps = 449804440 coll = 688244578 ctm = 180.02 nrn = 12363091305
***********************************************************************************************************************
dump no. 5 on file runtpf nps = 599311899 coll = 917020420 ctm = 240.03 nrn = 16472535697
***********************************************************************************************************************
dump no. 6 on file runtpf nps = 748720828 coll = 1145669183 ctm = 300.04 nrn = 20579570832
***********************************************************************************************************************
dump no. 7 on file runtpf

Best Answer

Hello,
Here the code.
I think it is very complicated works with your data.
But I have write this code.
clear; clc;
fid = fopen('Data01.txt');
tline = fgetl(fid);
x = 1;
while ischar(tline)
data01{x} = tline;
tline = fgetl(fid);
x = x + 1;
end
fclose(fid);
id1 = 1; id2 = 1;
querystr1 = 'surface(21<12<13)'; %don't use space

querystr2 = 'cosinebin:-8.72000E-02to-3.66000E-02'; %don't use space
for x = 1 : length(data01)
tmpdata = regexprep(data01{x},' ','');
if strcmp(tmpdata,querystr1) == 1
linestr1(id1) = x; id1 = id1 + 1;
end
if strcmp(tmpdata,querystr2) == 1
linestr2(id2) = x; id2 = id2 + 1;
end
end
for x = 1 : length(linestr1)
for y = 1 : length(linestr2)
diff = abs(linestr1(x) - linestr2(y));
if diff == 1
lowintv = linestr2(y) + 2;
end
end
end
idk = 1;
idl = lowintv;
while ~any(findstr(data01{idl},'total'));
data02{idk} = textscan(data01{idl},'%f %f %f');
idk = idk + 1;
idl = idl + 1;
end
Now you can get your data stored in variable 'data02'.
Note that you can change the variable 'querystr1' and 'querystr2' with two headers that you want to search.
But, you maynot insert any space in variable 'querystr1' and 'querystr2'.
Try to run it.