2010-10-08 16:10:59 +02:00
function dirlist = dynareParallelDir ( filename,PRCDir,Parallel)
% PARALLEL CONTEXT
2010-10-22 11:27:26 +02:00
% In a parallel context, this is a specialized version of dir() function.
2010-10-08 16:10:59 +02:00
%
2010-10-22 11:27:26 +02:00
% INPUTS
% o filename [] ...
2011-02-01 23:21:00 +01:00
% o PRCDir [] ...
% o Parallel [] ...
2010-10-08 16:10:59 +02:00
%
2010-10-22 11:27:26 +02:00
% OUTPUTS
2011-02-01 23:21:00 +01:00
% o dirlist [] ...
2010-10-08 16:10:59 +02:00
%
2017-05-16 14:11:15 +02:00
% Copyright (C) 2009-2017 Dynare Team
2010-10-08 16:10:59 +02:00
%
% 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/>.
dirlist = [ ] ;
2017-05-16 12:42:01 +02:00
for indPC = 1 : length ( Parallel )
if ~ ispc || strcmpi ( ' unix' , Parallel ( indPC ) . OperatingSystem )
if Parallel ( indPC ) . Local == 0
if ~ isempty ( Parallel ( indPC ) . Port )
2013-03-27 16:30:12 +01:00
ssh_token = [ ' -p ' , Parallel ( indPC ) . Port ] ;
else
ssh_token = ' ' ;
end
2013-11-04 10:54:45 +01:00
if isoctave % Patch for peculiar behaviour of ssh-ls under Linux.
2017-05-16 15:10:20 +02:00
% It is necessary to capture the ls warning message.
% To do it under the ssh protocol it is necessary to redirect the ls message in a text file.
% The file is 'OctaveStandardOutputMessage.txt' and it is
% saved in the Model directory.
2013-03-27 16:30:12 +01:00
[ check , ax ] = system ( [ ' ssh ' , ssh_token , ' ' , Parallel ( indPC ) . UserName , ' @' , Parallel ( indPC ) . ComputerName , ' ls ' , Parallel ( indPC ) . RemoteDirectory , ' /' , PRCDir , ' /' , filename , ' 2> OctaveStandardOutputMessage.txt' ] ) ;
2011-02-01 23:21:00 +01:00
else
2013-03-27 16:30:12 +01:00
[ check , ax ] = system ( [ ' ssh ' , ssh_token , ' ' , Parallel ( indPC ) . UserName , ' @' , Parallel ( indPC ) . ComputerName , ' ls ' , Parallel ( indPC ) . RemoteDirectory , ' /' , PRCDir , ' /' , filename ] ) ;
2011-02-01 23:21:00 +01:00
end
2017-05-16 12:42:01 +02:00
if check ~= 0 || ~ isempty ( strfind ( ax , ' No such file or directory' ) )
2010-10-11 12:33:08 +02:00
ax = [ ] ;
2013-04-05 17:30:50 +02:00
else
indax = regexp ( ax , ' \n' ) ;
colax = indax ( 1 ) ;
rowax = length ( indax ) ;
ax = reshape ( ax ' , [ colax rowax ] ) ' ;
ax = ax ( : , 1 : end - 1 ) ;
2010-10-11 12:33:08 +02:00
end
2010-10-08 16:10:59 +02:00
else
2011-02-01 23:21:00 +01:00
2013-11-04 10:54:45 +01:00
if isoctave % Patch for peculiar behaviour of ls under Linux.
2017-05-16 15:10:20 +02:00
2011-02-01 23:21:00 +01:00
% It is necessary to capture the ls warning message and properly manage the jolly char '*'!
[ check ax ] = system ( [ ' ls ' , filename , ' 2> OctaveStandardOutputMessage.txt' ] ) ;
2017-05-16 15:10:20 +02:00
2017-05-16 12:42:01 +02:00
if check ~= 0 || ~ isempty ( strfind ( ax , ' No such file or directory' ) )
2011-02-01 23:21:00 +01:00
ax = [ ] ;
end
else
try
ax = ls ( filename ) ;
catch
ax = [ ] ;
end
2010-10-11 12:33:08 +02:00
end
2011-02-01 23:21:00 +01:00
2010-10-08 16:10:59 +02:00
end
else
2013-11-04 10:54:45 +01:00
if isoctave % Patch for peculiar behaviour of ls under Windows.
2017-05-16 12:42:01 +02:00
if Parallel ( indPC ) . Local == 0
2011-01-21 11:26:24 +01:00
ax0 = dir ( [ ' \\' , Parallel ( indPC ) . ComputerName , ' \' , Parallel ( indPC ) . RemoteDrive , ' $\' , Parallel ( indPC ) . RemoteDirectory , ' \' , PRCDir , ' \' , filename ] ) ;
else
ax0 = dir ( filename ) ;
end
2017-05-16 12:42:01 +02:00
if isempty ( ax0 )
2011-01-21 11:26:24 +01:00
ax = ' ' ;
else
2011-02-08 15:43:51 +01:00
clear ax1 ;
2017-05-16 12:42:01 +02:00
for jax = 1 : length ( ax0 )
2011-02-08 15:43:51 +01:00
ax1 { jax } = ax0 ( jax ) . name ;
2011-01-21 11:26:24 +01:00
end
2011-02-08 15:43:51 +01:00
ax = char ( ax1 { : } ) ;
2011-01-21 11:26:24 +01:00
end
2011-02-01 23:21:00 +01:00
2010-10-08 16:10:59 +02:00
else
2017-05-16 12:42:01 +02:00
if Parallel ( indPC ) . Local == 0
2011-01-21 11:26:24 +01:00
ax = ls ( [ ' \\' , Parallel ( indPC ) . ComputerName , ' \' , Parallel ( indPC ) . RemoteDrive , ' $\' , Parallel ( indPC ) . RemoteDirectory , ' \' , PRCDir , ' \' , filename ] ) ;
else
ax = ls ( filename ) ;
end
2010-10-08 16:10:59 +02:00
end
2013-04-05 17:30:50 +02:00
end
2017-05-16 12:42:01 +02:00
if isempty ( dirlist )
2013-04-05 17:30:50 +02:00
dirlist = ax ;
2017-05-16 12:42:01 +02:00
elseif ~ isempty ( ax )
2013-03-27 16:30:12 +01:00
dirlist = char ( dirlist , ax ) ;
2010-10-08 16:10:59 +02:00
end
end