%%
%% plot_amie.m is written for plotting the calculated convection location from
%%  AMIE NH and SH electric potentials found in TIEGCM
%% BA Emery, September 2012 from /aim3/emery/cmit/plot_cloc.m

clear all; close all


% dmin = number of minutes between CMIT files 

% Set year 
year1 = 2004
dayn0 = 312;
dayn1 = 312;
dayn2 = 314;		
x1 = dayn1;	
x2 = dayn2;		
cpx = 325;
hpx = 390;
radn = 8;
radx = 33;
crit1n = 13;
crit1x = 34.9;
of18x = 17;
of24x = 9;
qjx = 1800;
win = -120;
wix = 120;

dmin = 1;


% Set if plot S+N (for dynamo, ifboth=0) or separate (ifboth=1)
ifboth=1

for ifold=0:1


% Open file of outputs 
if (ifold==-1)
 filloc = sprintf('CalcCLoc_04312-3')
 filhpcp = sprintf('old_amie_HP_CP_04312-3')
end
if (ifold==0)
 filifbad = sprintf('CalcCLoc_04312-3')
 badin = fopen(filifbad,'r');
 filloc = sprintf('AMIEcrit_calccloc_04312-3')
 filhpcp = sprintf('old_amie_calccloc_04312-3')
end
if (ifold==1)
 filloc = sprintf('AMIEcrit_old_04312-3')
 filhpcp = sprintf('old_amie_old_HP_CP_04312-3')
end
 locin = fopen(filloc,'r');
 hcpin = fopen(filhpcp,'r');

if (ifold==-1)

for i=1:2880
 linhp = fgetl(hcpin);
 inh = sscanf(linhp,'%s %s %s %s %s %s %s %f %f %f %f %f %f');
if i==1
 length(inh) 	%=29, for calccloc run
end
 hpb(i) = inh(25);
 hps(i) = inh(26);
 hpn(i) = inh(27);
 lincp = fgetl(hcpin);
 inc = sscanf(lincp,'%s %s %s %s %f %f %f %f');
if i==1
 length(inc)	%=20
end
 cpb(i) = inc(18);
 cps(i) = inc(19);
 cpn(i) = inc(20);
end

else

for i=1:2880
 linhp = fgetl(hcpin);
 inh = sscanf(linhp,'%s %s %s %s %s %s %f %f %f %f %f %f %f %f');
if i==1
 length(inh) 	%=31 for old run
end
 hpb(i) = inh(25);
 hps(i) = inh(26);
 hpn(i) = inh(27);
 cpb(i) = inh(29);
 cps(i) = inh(30);
 cpn(i) = inh(31);
end
%hps

end	% ifold else


nog = 0;
nogs1 = 0;
nogn1 = 0;
ng = 0;
i = 0;
i0 = 0;
i50 = 0;
i100 = 0;
i150 = 0;
i200 = 0;
for j=1:2880
 fracdayall(j) = dayn0 + j/1440.;
 linloc1 = fgetl(locin);
if (ifold<1)
% Ra(33-34),Rc(35-36) offc(37-38),dskofc(39-40),phid(41-42)
 if (ifold==-1)
  in1 = sscanf(linloc1,'%s %s %s %d %d %f %f %f %f %f %f %f %f %f %f');
  iflgs = in1(31);
  iflgn = in1(32);
 else
  linbad = fgetl(badin);
  inbad = sscanf(linbad,'%s %s %s %d %d %f %f %f %f %f %f %f %f %f %f');
  iflgs = inbad(31);
  iflgn = inbad(32);
 end
end		% ifold<1
if (ifold>-1)
 in1 = sscanf(linloc1,'%s %s %s %s %s %s %f %f %f %f %f %f %f %f %f %f%f %f %f %f %f %f %f %f %f %f');
% Save crit1 for all times ifold>-1
  crit1(j) = in1(42);
 if (ifold==1)
  crit1g(j) = crit1(j);
  iflgs = 0;
  iflgn = 0;
 else
  crit1c(j) = crit1(j);
 end
end	% ifold>-1
if j==1
length(in1)		% 61 for AMIEcrit with f6.2 or f7.2
linloc1
crit1(j)
in1(42),in1(43),in1(44)
end
 if (iflgs>0 & iflgn>0)
  nog = nog + 1;
 else
  i = i + 1; 
  if (iflgs>0) 
    nogs1 = nogs1 + 1;
  end
  if (iflgn>0) 
    nogn1 = nogn1 + 1;
  end
  fracdaymo(i) = dayn0 + j/1440.;
if (ifold==-1)
  rcs(i) = in1(33);
  rcn(i) = in1(34);
  ras(i) = in1(35);
  ran(i) = in1(36);
  offcs(i) = in1(37);
  offcn(i) = in1(38);
  dskofcs(i) = in1(39);
  dskofcn(i) = in1(40);
  phids(i) = in1(41)+24.;
  phidn(i) = in1(42)+24.;
  phins(i) = in1(43)+24.;
  phinn(i) = in1(44)+24.;
  if (phins(i)<20.)
   phins(i) = phins(i)+24.;
  end
  if (phinn(i)<20.)
   phinn(i) = phinn(i)+24.;
  end
else
  rcs(i) = in1(44);
  rcn(i) = in1(45);
  ras(i) = in1(46);
  ran(i) = in1(47);
  phids(i) = in1(50)+24.;
  phidn(i) = in1(51)+24.;
  phins(i) = in1(52)+24.;
  phinn(i) = in1(53)+24.;
  if (phins(i)<20.)
   phins(i) = phins(i)+24.;
  end
  if (phinn(i)<20.)
   phinn(i) = phinn(i)+24.;
  end
  if (ifold==1)
   offcs(i) = in1(54);
   offcn(i) = in1(55);
   dskofcs(i) = in1(58);
   dskofcn(i) = in1(59);
  else
% Set offsets from calculations from calccloc
   offcs(i) = inbad(37);
   offcn(i) = inbad(38);
   dskofcs(i) = inbad(39);
   dskofcn(i) = inbad(40);
%  Read default offsets in AMIEcrit
   offcblin(i) = in1(54);
   dskofcb0(i) = in1(58);
  end
end		% ifold else
  ramrc(i) = 0.5*(ras(i)+ran(i)-rcs(i)-rcn(i));
  offcb(i) = 0.5*(offcs(i)+offcn(i));
  cpbg(i) = cpb(j);
  hpbg(i) = hpb(j);
  
  if (cpb(j)<50.)
   i0 = i0 + 1;
   offc0(i0) = offcb(i);
  end
  if (cpb(j)>=50. & cpb(j)<100.)
   i50 = i50 + 1;
   offc50(i50) = offcb(i);
  end
  if (cpb(j)>=100. & cpb(j)<140.)
   i100 = i100 + 1;
   offc100(i100) = offcb(i);
  end
  if (cpb(j)>=140. & cpb(j)<200.)
   i150 = i150 + 1;
   offc150(i150) = offcb(i);
  end
  if (cpb(j)>=200.)
   i200 = i200 + 1;
   offc200(i200) = offcb(i);
  end
 end
end
phinn(1),phins(1)


nog,nogs1,nogn1,i	% 657,507,293,2223 of 2880
medofcs = median(offcs)			% 0.59
medofcn = median(offcn)			% 0.59
medofc = median(0.5*(offcs+offcn))	% 0.59 deg towards midnight
meddkofs = median(dskofcs)		% 1.67 deg 
meddkofn = median(dskofcn)		% 0.83 deg
meddkof = median(0.5*(dskofcs+dskofcn))	% 0.00 deg (ie, on noon-midnight line)
i0,i50,i100,i150,i200	% 493,523,719,445(1164),43(488)
% 493,523,558,606,43 for 50,100,140,200,300
medofc0 = median(offc0)			% 1.77 (0-50 kV)
medofc50 = median(offc50)		% 0.59 (50-100 kV)
medofc100 = median(offc100)		% 0.295 (100-140,150kV) 0.00 (100-200 kV)
medofc150 = median(offc150)		% -0.295 (140-200kV), -0.59 (150-200kV) (-0.4425 150-300 kV)
medofc200 = median(offc200)		% 0.00 (200-250kV)
medramrc = median(ramrc)


zero = [0.,0.];
fsize = 12;

if (ifold<1)

% Plot CP vs off24, and get polynomial fit
cpt = [0 cpx];
of24cp=polyfit(cpbg,offcb,1)
xcp=polyval(of24cp,cpt)

figure;
set(gcf,'position',[142    99   647   822])
H = gcf;
subplot('position',[0.10,0.10,0.87,0.84])
hold on;
title('Midnight Convection Offset vs AMIE CP for Nov 7-8, 2004','FontSize',15,'FontWeight','bold');
plot (cpbg,offcb,'sk');
plot (cpt,zero,'--k');
plot(cpt,xcp,'-r');
text (0.33*cpx,0.85*2*of24x-of24x,'AMIE off24(deg) ~ 2.0-0.0137*CP','Color','r','FontSize',fsize,'FontWeight','bold');
ylabel('off24 deg','FontSize',fsize,'FontWeight','bold');
xlabel('AMIE CP (kV)','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[0,300],'ylim',[-of24x,of24x],'FontSize',fsize,'box','on');

hold off;
end		% ifold==0

% Plot locations 
figure
xtot = [x1,x2];
dmlt = [9.39,9.39];
nmlt = [23.50,23.50];

% position [left bottom width height]
% Set size to be 8.5x11 inches
set(gcf,'position',[142    99   647   822])
H = gcf;

%subplot('position',[0.10,0.82,0.87,0.12])	% 1/7
subplot('position',[0.10,0.83,0.87,0.11])	% 1/8
hold on;
if (ifold==1)
 title('Convection Locations Etc for Nov 7-8, 2004 AMIE (old)','FontSize',15,'FontWeight','bold');
else
 title('Convection Locations Etc for Nov 7-8, 2004 AMIE (calccloc)','FontSize',15,'FontWeight','bold');
end
plot (fracdayall,cps,'-b');
plot (fracdayall,cpn,'-r');
text (x1+0.05*(x2-x1),0.90*cpx,'NH','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.10*(x2-x1),0.90*cpx,'SH','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('CP kV','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[0,cpx],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
%subplot('position',[0.10,0.70,0.87,0.12])	% 2/7
subplot('position',[0.10,0.72,0.87,0.11])	% 2/8
hold on;
plot (fracdaymo,rcs,'-b');
plot (fracdaymo,rcn,'-r');
text (x1+0.05*(x2-x1),0.90*(radx-radn)+radn,'NH','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.10*(x2-x1),0.90*(radx-radn)+radn,'SH','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('Rc deg','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[radn,radx],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
%subplot('position',[0.10,0.58,0.87,0.12])	% 3/7
subplot('position',[0.10,0.61,0.87,0.11])	% 3/8
hold on;
plot (fracdaymo,offcs,'-b');
plot (fracdaymo,offcn,'-r');
plot (xtot,zero,'--k');
if (ifold==1)
 text (x1+0.65*(x2-x1),6.0,'default offc=+1.10deg','Color','k','FontSize',fsize,'FontWeight','bold');
else
 text (x1+0.65*(x2-x1),6.0,'median(S,N,S+N)=+0.59deg','Color','k','FontSize',fsize,'FontWeight','bold');
 if (ifold==0)
  plot(fracdaymo,offcblin,'-y');
 end
end
text (x1+0.05*(x2-x1),6.0,'midnight','Color','k','FontSize',fsize,'FontWeight','bold');
text (x1+0.05*(x2-x1),-6.0,'noon','Color','k','FontSize',fsize,'FontWeight','bold');
ylabel('off24 deg','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[-of24x,of24x],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
%subplot('position',[0.10,0.46,0.87,0.12])	% 4/7
subplot('position',[0.10,0.50,0.87,0.11])	% 4/8
hold on;
plot (fracdaymo,dskofcs,'-b');
plot (fracdaymo,dskofcn,'-r');
plot (xtot,zero,'--k');
if (ifold==1)
 text (x1+0.65*(x2-x1),6.0,'default dskofc=-0.08deg','Color','k','FontSize',fsize,'FontWeight','bold');
else
 text (x1+0.73*(x2-x1),0.8*of18x,'median(S+N)=0.0deg','Color','k','FontSize',fsize,'FontWeight','bold');
end
text (x1+0.05*(x2-x1),0.8*of18x,'18 MLT','Color','k','FontSize',fsize,'FontWeight','bold');
text (x1+0.05*(x2-x1),-0.8*of18x,'06 MLT','Color','k','FontSize',fsize,'FontWeight','bold');
ylabel('off18 deg','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[-of18x,of18x],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
%subplot('position',[0.10,0.34,0.87,0.12])	% 5/7
subplot('position',[0.10,0.39,0.87,0.11])	% 5/8
hold on;
plot (fracdayall,hps,'-b');
plot (fracdayall,hpn,'-r');
text (x1+0.05*(x2-x1),0.90*hpx,'NH','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.10*(x2-x1),0.90*hpx,'SH','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('HP GW','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[0,hpx],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
%subplot('position',[0.10,0.22,0.87,0.12])	% 6/7
subplot('position',[0.10,0.28,0.87,0.11])	% 6/8
hold on;
plot (fracdaymo,ras,'-b');
plot (fracdaymo,ran,'-r');
text (x1+0.05*(x2-x1),0.90*(radx-radn)+radn,'NH','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.10*(x2-x1),0.90*(radx-radn)+radn,'SH','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('Ra deg','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[radn,radx],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
%subplot('position',[0.10,0.10,0.87,0.12])	% 7/7
subplot('position',[0.10,0.17,0.87,0.11])	% 7/8
hold on;
%plot (fracdaymo,ras-rcs,'-b');
%plot (fracdaymo,ran-rcn,'-r');
plot (fracdaymo,ramrc,'-k');
plot (xtot,zero,'--k');
if (ifold==1)
 text (x1+0.60*(x2-x1),-11.0,'median Ra-Rc=h2+.5=4.2 deg','Color','k','FontSize',fsize,'FontWeight','bold');
else
 text (x1+0.65*(x2-x1),-11.0,'median Ra-Rc=4.2 deg','Color','k','FontSize',fsize,'FontWeight','bold');
end
ylabel('Ra-Rc deg','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[-15,15],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
subplot('position',[0.10,0.06,0.87,0.11])	% 8/8
hold on;
plot (fracdaymo,phids,'-b');
plot (fracdaymo,phidn,'-r');
plot (fracdaymo,phins,'-b');
plot (fracdaymo,phinn,'-r');
plot (xtot,dmlt,'--k');
plot (xtot,nmlt,'--k');
text (x1+0.05*(x2-x1),0.10*28.,'NH','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.10*(x2-x1),0.10*28.,'SH','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('Day,Nit MLT','FontSize',fsize,'FontWeight','bold');
xlabel('Daynumber','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[0,28],'FontSize',fsize,'box','on');

hold off;

end	% ifold=0:1


% Read Wi at 2.5S (jj=18) and hemispheric Joule heating from .nc files

ht1 = 250.e+5;
ht2 = 325.e+5;
% wi_qj_calccloc_nov04.nc every 30 min 04312-3 Nov 7-8
 [ntc,dayfracc,utc,wiavc,qjsc,qjnc] = get_wi_qj_nc('wi_qj_calccloc_nov04.nc',ht1,ht2,18);
 [ntg,dayfracg,utg,wiavg,qjsg,qjng] = get_wi_qj_nc('wi_qj_old_nov04.nc',ht1,ht2,18);

for it=1:ntg
  ut30m(it) = dayn0 + (it*0.5)/24.;
end

% 4=165W, 22=75W, 40=15E, 58=105E
noon75w = dayn0 +(12.+5.)/24.;
noon105e = dayn0 + (12.-7.)/24.;
noon165w = dayn0 + (12.+11.)/24.;
noon15e = dayn0 + (12.-1.)/24.;

% Plot differences in crit(1) and Joule heating and Wi at equator
figure;
set(gcf,'position',[142    99   647   822])
H = gcf;

subplot('position',[0.10,0.82,0.87,0.12])	% 1/7
hold on;
if (ifold==1)
 title('Convection Locations Etc for Nov 7-8, 2004 AMIE (old)','FontSize',15,'FontWeight','bold');
else
 title('Convection Locations Etc for Nov 7-8, 2004 AMIE (calccloc)','FontSize',15,'FontWeight','bold');
end
plot (fracdayall,cps,'-b');
plot (fracdayall,cpn,'-r');
text (x1+0.05*(x2-x1),0.90*cpx,'NH','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.10*(x2-x1),0.90*cpx,'SH','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('CP kV','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[0,cpx],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
subplot('position',[0.10,0.70,0.87,0.12])	% 2/7
hold on;
plot (fracdayall,hps,'-b');
plot (fracdayall,hpn,'-r');
text (x1+0.05*(x2-x1),0.90*hpx,'NH','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.10*(x2-x1),0.90*hpx,'SH','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('HP GW','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[0,hpx],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
subplot('position',[0.10,0.58,0.87,0.12])	% 3/7
hold on;
plot (fracdayall,crit1g,'-b');
plot (fracdayall,crit1c,'-r');
text (x1+0.05*(x2-x1),0.90*(crit1x-crit1n)+crit1n,'calccloc','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.20*(x2-x1),0.90*(crit1x-crit1n)+crit1n,'old AMIE','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('crit(1) deg','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[crit1n,crit1x],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
subplot('position',[0.10,0.46,0.87,0.12])	% 4/7
hold on;
plot (ut30m,qjng,'-b');
plot (ut30m,qjnc,'-r');
text (x1+0.05*(x2-x1),0.90*qjx,'calccloc','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.20*(x2-x1),0.90*qjx,'old AMIE','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('NH QJ GW','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[0,qjx],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
subplot('position',[0.10,0.34,0.87,0.12])	% 5/7
hold on;
plot (ut30m,qjsg,'-b');
plot (ut30m,qjsc,'-r');
text (x1+1.05,1100.,'+64%','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.05*(x2-x1),0.90*qjx,'calccloc','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.20*(x2-x1),0.90*qjx,'old AMIE','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('SH QJ GW','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[0,qjx],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
subplot('position',[0.10,0.22,0.87,0.12])	% 6/7
hold on;
% ii=22=75W
% 4=165W, 22=75W, 40=15E, 58=105E
ytot = [win,wix];
xnoon = [noon75w,noon75w];
xnoon2 = [noon75w+1,noon75w+1];
plot (ut30m,wiavg(22,:),'-b');
plot (ut30m,wiavc(22,:),'-r');
plot (xtot,zero,'--k');
plot(xnoon,ytot,':k');
plot(xnoon2,ytot,':k');
text (noon75w,0.10*(wix-win)+win,'noon','Color','k','FontSize',fsize,'FontWeight','bold');
text (x1+0.05*(x2-x1),0.90*(wix-win)+win,'(2.5S,75W) calccloc','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.30*(x2-x1),0.90*(wix-win)+win,'old AMIE','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('Wi m/s','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[win,wix],'XTickLabel',{' ';},'FontSize',fsize,'box','on');
subplot('position',[0.10,0.10,0.87,0.12])	% 7/7
hold on;
% 4=165W, 22=75W, 40=15E, 58=105E
ytot = [win,wix];
xnoon = [noon105e,noon105e];
xnoon2 = [noon105e+1,noon105e+1];
plot (ut30m,wiavg(58,:),'-b');
plot (ut30m,wiavc(58,:),'-r');
plot (xtot,zero,'--k');
plot(xnoon,ytot,':k');
plot(xnoon2,ytot,':k');
text (noon105e,0.10*(wix-win)+win,'noon','Color','k','FontSize',fsize,'FontWeight','bold');
text (x1+0.05*(x2-x1),0.90*(wix-win)+win,'(2.5S,105E) calccloc','Color','r','FontSize',fsize,'FontWeight','bold');
text (x1+0.30*(x2-x1),0.90*(wix-win)+win,'old AMIE','Color','b','FontSize',fsize,'FontWeight','bold');
ylabel('Wi m/s','FontSize',fsize,'FontWeight','bold');
xlabel(' ','FontSize',fsize,'FontWeight','bold');
grid;
set (gca,'xlim',[x1,x2],'ylim',[win,wix],'FontSize',fsize,'box','on');

hold off


