%program for wind climatology , Beltville wind profiler
% read  data written by monstatsave.m  T.txt, W.txt, D.txt  

clear all
close all
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  DEFINE HOURS & ALTITUDES!!!!!!!!!!!!!!!!!

%HR1=0; HR2=3;
HR1=12; HR2=15;%
Z00=[1 3 5 7 9 11];  % [.2 .4 .6 0.8 1 1.2] km
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ZZ=(0.2:0.1:4)';           %vector of 39 altitudes in km


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t0=load('T.txt')+15/60/24; %time adjusted for 15 min in days
W0=load('W39.txt');  %filename corrected 2/15/2016
d0=load('D39.txt');  %filename corrected 2/15/2016

[t,it0,it]=unique(t0);
W=W0(:,it0);
d=d0(:,it0);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[year,mon,day,hr, mnt,sc]=datevec(t);  %adjusted for 15 min time


ndy1=datenum(2009,12,30,0,0,0);

for MON=1:12
	if MON==1; MONTH='JANUARY';end
	if MON==2; MONTH='FEBRUARY';end
	if MON==3; MONTH='MARCH';end
	if MON==4; MONTH='APRIL';end
	if MON==5; MONTH='MAY';end
	if MON==6; MONTH='JUNE';end
	if MON==7; MONTH='JULY';end
	if MON==8; MONTH='AUGUST';end
	if MON==9; MONTH='SEPTEMBER';end
	if MON==10; MONTH='OCTOBER';end
	if MON==11; MONTH='NOVEMBER';end
	if MON==12; MONTH='DECEMBER';end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    DEFINE TIME WINDOW  !!!!!!!!!!!!!!!!!!!!!!!
ind=find(t>ndy1 & mon==MON & hr>=HR1 & hr<=HR2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  data for selected MON
	    Tim=t(ind);
          Spd=W(:,ind);
          Dir=d(:,ind);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  

if HR1==0; HR1a='12 am'; end
if HR1==12;HR1a='12 pm'; end
if HR2==3; HR2a='3 am'; end
if HR2==15;HR2a='3 pm'; end

figure(MON)

h=axes;
set(gca,'xtick',[],'ytick',[],'xcolor',[1 1 1],'ycolor',[1 1 1]);

for iwr=1:6;
    ind=find(~isnan(Spd(Z00(iwr),:)) & ~isnan(Dir(Z00(iwr),:)));
    
    if iwr==1; x=0.25; y=0.8; 
    text(0.045,0.035,['WINDROSES. BELTSVILLE, MD WIND PROFILER. ',MONTH,...
    ', HOURS: ',HR1a,' to ',HR2a],'fontsize',[10],'fontweight','bold')
    text(0.045,0.015,'DATA: FROM 2010 to 2015','fontsize',[10],'fontweight','bold');
    hold on 
    end;
    if iwr==2; x=0.65; y=0.8; end;
    if iwr==3; x=0.25; y=0.5; end;
    if iwr==4; x=0.65; y=0.5; end;
    if iwr==5; x=0.25; y=0.2; end;
    if iwr==6; x=0.65; y=0.2; end;

wind_rose(90-Dir(Z00(iwr),:),Spd(Z00(iwr),:),'ax',[h x y 0.45],'cmap',[spring],'n',16,'labtitle',['Altitude=',num2str(ZZ(Z00(iwr)),2),' km']);

%hold on
    
end
orient tall
    print ('-dpdf',['WIND_ROSE_1_2010_12_2015_BELTSVILL_',MONTH,'_HOURS_',int2str(HR1),'_',int2str(HR2),'.pdf'])
end

