 clear all
 close all
 for Np=1:1000
 Np

% cd('../../RESTARTED2/result');
  load(['../../RESTARTED2/result/PrN' num2str(Np) '.mat']);
  %RPK','RPH','RSP','Profile',

 step=0.005;
pp2=pchip((1:(2^16)).*0.0012495,Profile(1,:),40:step:48);
prof=pp2(1:1000);
pp2=pchip((1:(2^16)).*0.0012495,RPH(1,:),40:step:48);
prH=pp2(1:1000);
pp2=pchip((1:(2^16)).*0.0012495,RPK(1,:),40:step:48);
prK=pp2(1:1000);



 fileID = fopen(['../data/profile' num2str(Np) '.txt'],'r');
A=fscanf(fileID,'%f %f');
fclose(fileID);
profc2=A(2:2:end)';

 [Chic2l(Np),Corrc2l(Np),ExterProfile]=PositionDirection(profc2./sum(profc2),prof./sum(prof));
 [ChiKl(Np),CorrKl(Np),ExterProfile]=PositionDirection(prK./sum(prK),prof./sum(prof));
 [ChiHl(Np),CorrHl(Np),ExterProfile]=PositionDirection(prH./sum(prH),prof./sum(prof));

 pp3=pchip((1:(1e+3)).*0.005,profc2,0:0.0012495:2);

%  hold on
 diap=32500:(32500+length(pp3)-1);
%  plot(Profile(1,diap)./sum(Profile(1,diap)),'r')
%  hold on
 [Chic2h(Np),Corrc2h(Np),ExterProfile]=PositionDirection(pp3./sum(pp3),Profile(1,diap)./sum(Profile(1,diap)));
 [ChiKh(Np),CorrKh(Np),ExterProfile]=PositionDirection(RPH(1,diap)./sum(RPH(1,diap)),Profile(1,diap)./sum(Profile(1,diap)));
 [ChiHh(Np),CorrHh(Np),ExterProfile]=PositionDirection(RPK(1,diap)./sum(RPK(1,diap)),Profile(1,diap)./sum(Profile(1,diap)));
 end
   save dataInterp.mat Chic2l ChiKl  ChiHl Corrc2l  CorrKl CorrHl Chic2h ChiKh  ChiHh Corrc2h  CorrKh CorrHh
   