% All the following to be run on the nodes. This is called by
% parallel_sweep.m
function [results_st]=nodes_part(rangeA,rangeB,namefile)

results_st=[];

global kappa_MPc kappa_MPe M_
global tmprange range2 range1
% rangeA needs to be set here
warning('off')
if exist(['tmp_',num2str(labindex)],'dir')~=0
eval(['rmdir(''tmp_',num2str(labindex),''',''s'')']);
end
eval(['mkdir tmp_',num2str(labindex)]);
cd(['tmp_',num2str(labindex)]);
% addpath('/home/gianni/Dropbox/projects/AGKP_growth_credit/BDL_JIMF_submission_ex_version_27')

%% Some files must be copied in the new directory because dynare reads them with the parser and does not
%% understand that has to look into the path. These are the files that appear in GB.mod. Moreover GB.mod must be
%% in the directory wherefrom dynare is run.
eval(['copyfile ../',namefile,'.mod .']);
% eval(['copyfile ../',namefile,'_steadystate.m .']);
% !cp ../GB_steadystate.m .
 copyfile ../param_Lucas.m .
% copyfile ../param_GB_first_draft_8_feb_15.m .
% copyfile ../GB_steady_state_stuff.m .
% copyfile ../M_.mat .
copyfile ../preloop.m .
copyfile ../postloop.m .
%copyfile ../GB_HRkRER.m .
%copyfile ../GB_core_ss.m .
% rehash
% numberofnodes=numlabs;

%   load M_
%   assignin('base','M_',M_);
% disp(M_)

% to be run on node
%assign this to the nodes


range1=rangeB;
range2=rangeA;
%  disp(range2)
%  disp(range1)
 

 % disp(range2)
% disp(range2)

tmprange=range2;
% run command
% pause(labindex);

%% dynare call    
% dynare GB noclearall;
% diary('off')
% rehash
eval(['dynare ',namefile,' noclearall']);

%   results=evalin('base',['results_',num2str(labindex)]);
%% Results are saved within postloop.m at the end of the simulation. Reloaded here
tmp=load(['results_',num2str(labindex),'.mat']);        
results_st=tmp.results;
% results_st=struct('results',results);
cd ..
eval(['rmdir(''tmp_',num2str(labindex),''',''s'')'])


 

return