Home > matlab > parallel > dynareParallelDir.m

dynareParallelDir

PURPOSE ^

PARALLEL CONTEXT

SYNOPSIS ^

function dirlist = dynareParallelDir(filename,PRCDir,Parallel)

DESCRIPTION ^

 PARALLEL CONTEXT
 In a parallel context, this is a specialized version of dir() function.

 INPUTS
  o filename   []   ...
  o PRCDir     []   ...
  o Parallel   []   ...

  OUTPUTS
  o dirlist    []   ...

 Copyright (C) 2009-2011 Dynare Team

 This file is part of Dynare.

 Dynare is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 Dynare is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Dynare.  If not, see <http://www.gnu.org/licenses/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function dirlist = dynareParallelDir(filename,PRCDir,Parallel)
0002 % PARALLEL CONTEXT
0003 % In a parallel context, this is a specialized version of dir() function.
0004 %
0005 % INPUTS
0006 %  o filename   []   ...
0007 %  o PRCDir     []   ...
0008 %  o Parallel   []   ...
0009 %
0010 %  OUTPUTS
0011 %  o dirlist    []   ...
0012 %
0013 % Copyright (C) 2009-2011 Dynare Team
0014 %
0015 % This file is part of Dynare.
0016 %
0017 % Dynare is free software: you can redistribute it and/or modify
0018 % it under the terms of the GNU General Public License as published by
0019 % the Free Software Foundation, either version 3 of the License, or
0020 % (at your option) any later version.
0021 %
0022 % Dynare is distributed in the hope that it will be useful,
0023 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0024 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0025 % GNU General Public License for more details.
0026 %
0027 % You should have received a copy of the GNU General Public License
0028 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0029 
0030 dirlist=[];
0031 for indPC=1:length(Parallel),
0032     if ~ispc || strcmpi('unix',Parallel(indPC).OperatingSystem), %isunix || (~matlab_ver_less_than('7.4') && ismac),
0033         if Parallel(indPC).Local==0,
0034             if exist('OCTAVE_VERSION') % Patch for peculiar behaviour of ssh-ls under Linux.
0035                 % It is necessary to capture the ls warning message.
0036                 % To do it under the ssh protocol it is necessary to redirect the ls message in a text file.
0037                 % The file is 'OctaveStandardOutputMessage.txt' and it is
0038                 % saved in the Model directory.
0039                 [check, ax]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename, ' 2> OctaveStandardOutputMessage.txt']);
0040             else
0041                 [check, ax]=system(['ssh ',Parallel(indPC).UserName,'@',Parallel(indPC).ComputerName,' ls ',Parallel(indPC).RemoteDirectory,'/',PRCDir,'/',filename]);
0042             end
0043             if check ~= 0 || ~isempty(strfind(ax,'No such file or directory'));
0044                 ax=[];
0045             end
0046         else
0047 
0048             if exist('OCTAVE_VERSION') % Patch for peculiar behaviour of ls under Linux.
0049                 
0050                 % It is necessary to capture the ls warning message and properly manage the jolly char '*'!
0051                 [check ax]=system(['ls ' ,filename, ' 2> OctaveStandardOutputMessage.txt']);
0052                 
0053                 if check ~= 0 || ~isempty(strfind(ax,'No such file or directory'));
0054                     ax=[];
0055                 end
0056             else
0057                 try
0058                     ax=ls(filename);
0059                 catch
0060                     ax=[];
0061                 end
0062             end
0063 
0064         end
0065         dirlist = [dirlist, ax];
0066     else
0067         if exist('OCTAVE_VERSION'),     % Patch for peculiar behaviour of ls under Windows.
0068             if Parallel(indPC).Local==0,
0069                 ax0=dir(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\',filename]);
0070             else
0071                 ax0=dir(filename);
0072             end
0073             if isempty(ax0),
0074                 ax='';
0075             else
0076                 clear ax1;
0077                 for jax=1:length(ax0);
0078                     ax1{jax}=ax0(jax).name;
0079                 end
0080                 ax=char(ax1{:});
0081             end
0082 
0083         else
0084             if Parallel(indPC).Local==0,
0085                 ax=ls(['\\',Parallel(indPC).ComputerName,'\',Parallel(indPC).RemoteDrive,'$\',Parallel(indPC).RemoteDirectory,'\',PRCDir,'\',filename]);
0086             else
0087                 ax=ls(filename);
0088             end
0089         end
0090         dirlist = [dirlist; ax];
0091     end
0092 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005