
clear
close all
datapath='/Users/brian/Documents/cheesehead/data/ISFS/isfs_fluxes.mat';
load(datapath)
    
    h = figure(1);clf
    ha = tight_subplot(4,5,[.015 .015],[.1 .12],[.08 .08]);
   %ha = tight_subplot(5,1,[btwn plot vert / horz],[bottom top],[left right])
   
order=[1 2 6 7 3 4 8 9 13 14 18 19 20 11 12 16 17];%order the sites so the roughly match their quadrant locations
%maxf=[8 8 24 8 8 8 8 8 8 8 18 8 8 8 8 8 8];
maxf=[7.8 8 30 8 6.6 7.5 6.2 8.7 6.1 6.3 16.2 6.7 6.6 7.5 7.2 6.4 6.1];
 SITES=upper(sites);
for j=1:length(sites)

windrose_isfs(wd(:,j),ws(:,j),'ndirections',24,'anglenorth',0,'angleeast',90,...
    'vwinds',[0:1:8],'cmap','jet',...
    'min_radius',0.075,'legendvariable','WS','titlestring',[SITES{j}],...
    'nfreq',4,'freqlabelangle',45,'maxfrequency',maxf(j),'LegendType',0,'axes',ha(order(j)),...
    'labels',{' ',' ',' ',' '},'titlefontsize',18,'titlefontweight','normal') ;

 if j==length(sites)
l=windrose_isfs(wd(:,j),ws(:,j),'ndirections',24,'anglenorth',0,'angleeast',90,...
    'vwinds',[0:1:8],'cmap','jet',...
    'min_radius',0.075,'legendvariable','WS','titlestring',[SITES{j}],...
    'nfreq',4,'freqlabelangle',45,'maxfrequency',maxf(j),'LegendType',2,'axes',ha(order(j)),...
    'labels',{' ',' ',' ',' '},'titlefontsize',18,'titlefontweight','normal') ;
 end
 
end



AxesH = axes('Parent', h, ...
  'Units', 'normalized', ...
  'Position', [0, 0, 1, 1], ...
  'Visible', 'off', ...
  'XLim', [0, 1], ...
  'YLim', [0, 1], ...
  'NextPlot', 'add');
ftsz=30;
TextH = text(0.5,.96, 'N', ...
  'HorizontalAlignment', 'center', ...
  'VerticalAlignment', 'top','fontsize',ftsz);
TextH = text(0.5,.04, 'S', ...
  'HorizontalAlignment', 'center', ...
  'VerticalAlignment', 'bottom','fontsize',ftsz);
TextH = text(0.04,0.5, 'W', ...
  'HorizontalAlignment', 'left', ...
  'VerticalAlignment', 'bottom','fontsize',ftsz);
TextH = text(0.97,.5, 'E', ...
  'HorizontalAlignment', 'right', ...
  'VerticalAlignment', 'bottom','fontsize',ftsz);
set(l,'Position',[.85 .6 0 0])

axes(ha(5));set(gca,'visible','off')
axes(ha(10));set(gca,'visible','off')
axes(ha(15));set(gca,'visible','off')


set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [11 8.5]);
set(gcf, 'PaperUnits', 'normal');
set(gcf, 'PaperPosition', [0.0 0.0 1 1]);


print('/Users/brian/Documents/cheesehead/plots/wind_roses/ISFS/isfs_roses','-dpng','-r300');
%plotter([mfilename ],12,9,'m2')

% %

%maxf=[8 8 24 8 8 8 8 8 8 8 18 8 8 8 8 8 8];
maxf=[8 8 30 8 7 7.5 7 8 7 7 18 7 7 8 7 7 7];
for j=1:length(sites)
 
    h = figure(1);clf
    ha = tight_subplot(1,1,[.015 .015],[.1 .12],[.02 .25]);
   %ha = tight_subplot(5,1,[btwn plot vert / horz],[bottom top],[left right])
 %keep maxf wd ws SITES sites ha order j   
    l=windrose_sites(wd(:,j),ws(:,j),'ndirections',24,'anglenorth',0,'angleeast',90,...
    'vwinds',[0:1:8],'cmap','jet',...
    'min_radius',0.075,'legendvariable','WS','titlestring',[SITES{j}],...
    'nfreq',4,'freqlabelangle',45,'maxfrequency',maxf(j),'LegendType',2,'axes',ha(1),...
    'labels',{'N','S','E','W'} ,'titlefontsize',18,'titlefontweight','bold') ;

set(l,'Position',[.85 .5 0 0])


set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [7 5]);
set(gcf, 'PaperUnits', 'normal');
set(gcf, 'PaperPosition', [0.0 0.0 1 1]);


print(['/Users/brian/Documents/cheesehead/plots/wind_roses/ISFS/rose_' sites{j} ] ,'-dpng','-r300');
%plotter([mfilename ],12,9,'m2')

end
%
mfilepath = [mfilename('fullname') '.m'];
[fList,pList] = matlab.codetools.requiredFilesAndProducts(mfilepath);
archive_path='/Users/brian/Documents/cheesehead/plots/wind_roses/ISFS/archive/';
    if ~exist(archive_path, 'dir')
       mkdir(archive_path)
    end
 [d1 d2 d3]=datevec(date);datestring=[sprintf('%04d',d1) '_' sprintf('%02d',d2) '_' sprintf('%02d',d3) ];

for k=1:length(fList)
    k
    strbeg=strfind(fList{k},'/');strbeg=strbeg(end);strend=strfind(fList{k},'.m');
filename=fList{k}(strbeg+1:strend-1);
copyfile(fList{k},[archive_path filename '_' datestring '.m']);

end

[a,b]=system(['GetFileInfo ' datapath]); s=strfind(b,'created: ')+9; crdat=b(s:s+18)

header1 = ['\nThe data file that was used to create these plots was:\n ' datapath ];
header2 = ['\nThe date that the above file was created was: \n' crdat];
fid=fopen([ archive_path 'readme_' datestring '.txt'],'w');
fprintf(fid, [ header1 ]);
    fprintf(fid,'\n') ;
        fprintf(fid,'\n') ;


fprintf(fid, [ header2 ]);

fclose(fid);true