views:

32

answers:

1

BRIEF SUMMARY OF WHAT I WANT: If I take a file name as argument of a function, how do I include that file name in the path location such that the name of the file in the path location is the one user enters. If you didn't understand what I am saying, then read below for explanation:

SECONDARY EXPLANATION:

I am making a general function which requires calling a software called CMG. The software needs a .dat file, whose name I am taking as argument in the function with general name in the argument as ReservoirModel_CMGBuilder. As you can see in the partial code below, this ReservoirModel_CMGBuilder file is kept in a folder whose path location I have entered. However the problem is since the file name is in quotes, so it does not identify the file name in the code. What I want is I take name of the .dat file name, needed for CMG, from the user and store it in name ReservoirModel_CMGBuilder, and then use this name in the path location to pick up that file.

Similarly I want to do this thing for Reportq_rwd and Reportq_rwo. How can I do this?

function [q_yearly,Swav_yearly]=q_from_CMG_general(nModel,nCell,T,ReservoirModel_CMGBuilder,poro_models_gslib_file,perm_models_gslib_file,Reportq)

ReservoirModel_CMGBuilder=[ReservoirModel_CMGBuilder '.dat']; % string concatenation
Reportq_rwd=[Reportq '.rwd'];
Reportq_rwo=[Reportq '.rwo'];

poro_models=gslib_file_to_matlab_var(nModel,nCell,poro_models_gslib_file);
perm_models=gslib_file_to_matlab_var(nModel,nCell,perm_models_gslib_file);

%% loop to run all nModel

for model_no=1:nModel

    %% Writing the porosity and permeability model one at a time in .inc file, which will be read and will work as input to porosity and permeability models in CMG

    dlmwrite('poro_model.inc',poro_models(:,model_no),'delimiter','\n');
    dlmwrite('perm_model.inc',perm_models(:,model_no),'delimiter','\n');

    %% Prior to driling an exploratory well or acquiring a seismic with just 5 producing wells

    %# Calls CMG
    system('mx200810.exe -f "C:\Documents and Settings\HSingh2\Desktop\Work\Model - SGEMS, CMG and MATLAB\ReservoirModel_CMGBuilder"') % Calls CMG

    %# Calls parameter report file and generates output file
    system('report.exe /f Reportq_rwd /o Reportq_rwo')
+3  A: 

If you concatenate something like this:

['foo"' bar '"baz']

you get a string like this: foo"bar"baz

So for your question:

system(['mx200810.exe -f "C:\Documents and Settings\HSingh2\Desktop\Work\Model - SGEMS, CMG and MATLAB\' ReservoirModel_CMGBuilder '"']) % Calls CMG

%# Calls parameter report file and generates output file
system(['report.exe /f "' Reportq_rwd '" /o "' Reportq_rwo '"'])

It might be easier to use sprintf:

system(sprintf('mx200810.exe -f "%s"', ...
    fullfile('c:', 'Documents and Settings', 'HSingh2', ...
             'Desktop', 'Work', 'Model - SGEMS, CMG and MATLAB', ...
             ReservoirModel_CMGBuilder)));

Also not the use of fullfile to construct the path name -- it'll automatically insert the right kind of path separator. Note if you want to use a \ in sprintf you need to escape it with a backslash.

Mark E
That was fast! Thanks :)
Harpreet