views:

60

answers:

2

My data is in following format:

TABLE NUMBER 1
                                                FILE: ReservoirModel_CMGBuilder.irf
                                                            WELL: Well-1
TIME    Oil Rate SC - Yearly    
day bbl/day 
-0.01   0   
364.99  35368.4 
729.99  29307   
1094.99 27309.5 
1460.99 26058.8 
1825.99 25100.4 
2190.99 24364   
2555.99 23757.1 
2921.99 23240.8 
3286.99 22785   
3651.99 22376.8 
4016.99 22006.1 
4382.99 21664.7 
4747.99 21348.3 
5112.99 21052.5 
5477.99 20774.1 
5843.99 20509.9 
6208.99 20259.7 
6573.99 20021.3 
6938.99 19793.5 
7304.99 19576.6 
TABLE NUMBER 2
                                                FILE: ReservoirModel_CMGBuilder.irf
                                                            WELL: Well-2
TIME    Oil Rate SC - Yearly    
day bbl/day 
-0.01   0   
364.99  43110.4 
729.99  37974.1 
1094.99 36175.9 
1460.99 34957.9 
1825.99 34036.3 
2190.99 33293.3 
2555.99 32665.8 
2921.99 32118.7 
3286.99 31626.4 
3651.99 31175.1 
4016.99 30758   
4382.99 30368.5 
4747.99 30005.1 
5112.99 29663   
5477.99 29340   
5843.99 29035.2 
6208.99 28752.4 
6573.99 28489.7 
6938.99 28244.2 
7304.99 28012.9 
TABLE NUMBER 3
                                                FILE: ReservoirModel_CMGBuilder.irf
                                                            WELL: Well-3
TIME    Oil Rate SC - Yearly    
day bbl/day 
-0.01   0   
364.99  41191.6 
729.99  36305.6 
1094.99 34612.2 
1460.99 33467.2 
1825.99 32595   
2190.99 31878.8 
2555.99 31266.4 
2921.99 30722.6 
3286.99 30220.7 
3651.99 29750.9 
4016.99 29310   
4382.99 28892.8 
4747.99 28498   
5112.99 28122.3 
5477.99 27772.8 
5843.99 27438.5 
6208.99 27132.3 
6573.99 26845.9 
6938.99 26575   
7304.99 26317.5 
TABLE NUMBER 4
                                                FILE: ReservoirModel_CMGBuilder.irf
                                                            WELL: Well-4
TIME    Oil Rate SC - Yearly    
day bbl/day 
-0.01   0   
364.99  23555.2 
729.99  20766.2 
1094.99 19860.2 
1460.99 19273.3 
1825.99 18853.9 
2190.99 18533.1 
2555.99 18276.2 
2921.99 18063.3 
3286.99 17883.1 
3651.99 17727.4 
4016.99 17590.5 
4382.99 17468.8 
4747.99 17359.6 
5112.99 17260.1 
5477.99 17168.4 
5843.99 17083.1 
6208.99 17004.3 
6573.99 16930.8 
6938.99 16860.5 
7304.99 16792.7 
TABLE NUMBER 5
                                                FILE: ReservoirModel_CMGBuilder.irf
                                                            WELL: Well-5
TIME    Oil Rate SC - Yearly    
day bbl/day 
-0.01   0   
364.99  27212.8 
729.99  23804.5 
1094.99 22679.8 
1460.99 21945.2 
1825.99 21412.3 
2190.99 20995.5 
2555.99 20652.6 
2921.99 20359.4 
3286.99 20102.9 
3651.99 19873.6 
4016.99 19665.7 
4382.99 19475.9 
4747.99 19301.4 
5112.99 19137.6 
5477.99 18981.4 
5843.99 18831.5 
6208.99 18688.5 
6573.99 18550.7 
6938.99 18417.7 
7304.99 18288.9 

Till now I was splitting this data of 5 wells into 5 different files, and reading the variables (time and q_yearly) from each file (e.g Reportq.rwo) in following way:

[TIME(:,j), q_yearly(:,j)]=textread('Reportq.rwo','%f\t%f','headerlines',5);

But now I am producing the data of those 5 files into 1 file as shown in beginning. Therefore I want to read the data from this above file for each well separately in Matlab. For example I want to read and store TIME data in vectors TIME1, TIME2, TIME3, TIME4, TIME5 for wells 1, 2, 3, 4, 5 respectively, and similarly for Oil Rate SC-Yearly.

Can someone help?

+4  A: 

First of all, I suggest you don't use variable names such as TIME1,TIME2 etc, since that gets messy quickly. Instead, you can e.g. use a cell array with five rows (one for each well), and one or two columns. In the sample code below, wellData{2,1} is the time for the second well, wellData{2,2} is the corresponding Oil Rate SC - Yearly.

There might be more elegant ways to do the reading; here's something quick:

%# open the file
fid = fopen('Reportq.rwo');

%# read it into one big array, row by row
fileContents = textscan(fid,'%s','Delimiter','\n');
fileContents = fileContents{1};
fclose(fid); %# don't forget to close the file again

%# find rows containing TABLE NUMBER
wellStarts = strmatch('TABLE NUMBER',fileContents);
nWells = length(wellStarts);

%# loop through the wells and read the numeric data
wellData = cell(nWells,2);
wellStarts = [wellStarts;length(fileContents)];

for w = 1:nWells 
    %# read lines containing numbers
    tmp = fileContents(wellStarts(w)+5:wellStarts(w+1)-1);
    %# convert strings to numbers
    tmp = cellfun(@str2num,tmp,'uniformOutput',false);
    %# catenate array
    tmp = cat(1,tmp{:});
    %# assign output
    wellData(w,:) = mat2cell(tmp,size(tmp,1),[1,1]);
end
Jonas
Thanks Jonas. This works good.
Harpreet
A: 

I used the readline.m code as a function (available to download for free) to keep my over all code less complex. Here's what I did to achieve my objective:

well=readline('Reportq.rwo',[1:130]);
wellData=cell2mat(cellfun(@str2num,well,'UniformOutput', false));
q_yearly1(:,j)=wellData(1:21,2);
q_yearly2(:,j)=wellData(22:42,2);
q_yearly3(:,j)=wellData(43:63,2);
q_yearly4(:,j)=wellData(64:84,2);
q_yearly5(:,j)=wellData(85:105,2);

It works pretty well, and the code readline.m is very general. Here's the link to download the readline.m code.

Harpreet