Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: parfor: fopen Issues
Date: Wed, 24 Jun 2009 11:03:01 +0000 (UTC)
Organization: RMIT
Lines: 20
Message-ID: <h1t155$jbg$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1245841381 19824 172.30.248.38 (24 Jun 2009 11:03:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 24 Jun 2009 11:03:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1372013
Xref: news.mathworks.com comp.soft-sys.matlab:550173


I have a simulation which runs over &#8216;n&#8217; successive iterations using the parfor command. At each iteration, a series of scripts are generated using the fopen command; these contain user-defined commands for an external program. MATLAB then runs the script file and saves the results. The files are named according to the index of the parfor command (e.g parfor ii = 1:20). I am using the MATLABPOOL with a local scheduler. 

At each iteration the contents of the files are updated i.e. files are never deleted the naming index remains according to the state of the parfor command and the contents (user-defined script commands) are updated.

On most occasions the simulations run successfully with no issues. However, on some rare occasions an error is reported relating the failure of fopen as:

??? Error using ==> parallel_function at 587
Error in ==> Main_Flight at 70
Invalid file identifier.  Use fopen to generate a valid file identifier.

Error in ==> Optz_v2 at 203
    matlabpool local 4 

The code where MATLAB is pointing to is as:
script = [mesh_prefix, int2str(ii),'.bat'];
[fidd] = fopen(script, 'wt');
fprintf(fidd, '%s','Cscript.exe //NoLogo Airfoil_',num2str(ii),'.vbs | xfoil.exe');
fclose all

I&#8217;m not sure why MATLAB won&#8217;t open the file in question as it is in the working directory. As I mentioned earlier, the simulations run successfully on most occasions however, there is an obvious scenario which results in this error. Any suggestions please?