%Angela Zalucha 9/27/09
%Top level script for creating plot of obs hi & low, climo hi & low, and record hi & low for wx challenge city
%Note: obs hi and low are for midnight to midnight, not 6Z to 6Z.

%enter airport code for current city (3 letters - leave off the 'K')
city='SEA';

%You have the option of calculating one or two months of data.  Set to 1 for two months, 0 for one month.
use2months=0;

%Set the start date during the first month
startdate=1;

%This line gets the obs data off of the Weather Underground website.  In the path below, edit
%1. The station code
%2. The year
%3. The month (1 for Jan, 2 for Feb, etc.)
%4. The last day of the first month (or the only month if using the one month option)
% Example: http://www.wunderground.com/history/airport/KBOS/2009/9/30/MonthlyHistory.html?format=1
% The station code (1) is KBOS
% The  year (2) is 2009
% The month (3) is 9 (note: single digit months are entered as a single digit: 9, not 09)
% The last day of the month (4) is 30
unix('wget -q "http://www.wunderground.com/history/airport/KSEA/2010/2/28/MonthlyHistory.html?format=1"');

%nothing to edit in this line
unix('mv -f MonthlyHistory.html?format=1 currentmonth_obs_data.csv');

%edit the number of days in the first month
nodaysincurrentmonth=28;

%edit the number of the first month (1 for Jan, 2 for Feb, etc.)
currentmonthno=2;

%Enter a vector of the normal highs for the first month.  The length should be eqal to the number of days in that month
%Example: current_norm_hi=[77 77 76 76 76 76 75 75 75 74 74 74 73 73 73 72 72 72 72 71 71 70 70 70 69 69 69 68 68 68];
%This is tedious.  I don't know how to automate it.  You find the data on Weather Underground (click on "detailed
%history and climate", or probably on the weather underground
current_norm_hi=[48 48 48 48 48 48 49 49 49 49 49 49 49 49 50 50 50 50 50 50 50 50 51 51 51 51 51 51];

%Same as above but for the normal lows
current_norm_lo=[36 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 37 38 38 38 38 38 38 38];

%Same as above but for the record highs
current_rec_hi=[63 64 63 63 62 64 66 68 62 65 62 66 59 63 65 58 58 62 67 62 67 64 61 62 64 67 70 68];

%Same as above but for the record lows
current_rec_lo=[1 8 8 7 14 18 20 22 26 24 23 21 18 22 13 13 23 20 22 25 25 30 28 25 22 18 20 24];

%If you're using the one month option, you're done.  If you're using two months, continue editing.

if use2months==1

%Again, edit path name for 2nd month, just like above
   unix('wget -q "http://www.wunderground.com/history/airport/KATL/2010/2/28/MonthlyHistory.html?format=1"');

%nothing to edit here
   unix('mv -f MonthlyHistory.html?format=1 nextmonth_obs_data.csv');

%enter number of days in second month
   nodaysinnextmonth=28;

%enter number of second month
   nextmonthno=2;

%enter normal highs for second month
   next_norm_hi=[54 54 54 54 54 55 55 55 55 56 56 56 56 57 57 57 57 58 58 58 58 59 59 59 59 60 60 60];

%enter normal lows for second month
   next_norm_lo=[34 34 34 35 35 35 35 35 35 35 36 36 36 36 36 37 37 37 37 38 38 38 38 38 39 39 39 40];

%enter record highs for second month
   next_rec_hi=[77 73 76 78 76 73 72 79 79 76 75 74 75 77 80 78 76 75 78 78 75 74 79 77 78 80 79 78];

%enter record lows for second month
   next_rec_lo=[10 5 2 7 5 13 7 0 6 11 8 3 -9 2 13 11 5 8 13 16 10 8 19 17 9 14 13 13];
end

%Done editing!

%%%%%%%%%%%%DO NOT EDIT BEYOND THIS POINT%%%%%%%%%%%%%%%%%%%%%%%%%%%
startdate=startdate+1

 fid=fopen('currentmonth_obs_data.csv','r');
 monthnolength=length(num2str(currentmonthno));
 update_wx

 currentmonth_obs_hi=obs_hi;
 currentmonth_obs_lo=obs_lo;

 clear obs_hi obs_lo

 fulldate=clock;

if use2months==1

 if fulldate(2)==nextmonthno
  if fulldate(3)~=1
   fid=fopen('nextmonth_obs_data.csv','r');
   monthnolength=length(num2str(nextmonthno)); 
   update_wx
   obs_hi_to_plot=[currentmonth_obs_hi(startdate:nodaysincurrentmonth) obs_hi(1:length(obs_hi)-1)];
   obs_lo_to_plot=[currentmonth_obs_lo(startdate:nodaysincurrentmonth) obs_lo(1:length(obs_lo)-1)];
  else
   obs_hi_to_plot=currentmonth_obs_hi(startdate:length(currentmonth_obs_hi));
   obs_lo_to_plot=currentmonth_obs_lo(startdate:length(currentmonth_obs_hi));  
  end
 else
  obs_hi_to_plot=currentmonth_obs_hi(startdate:length(currentmonth_obs_hi)-1);
  obs_lo_to_plot=currentmonth_obs_lo(startdate:length(currentmonth_obs_hi)-1);
 end
 dayslabel=[startdate:nodaysincurrentmonth 1:nodaysinnextmonth];
 daysall=1:length(dayslabel);
 rec_hi=[current_rec_hi(startdate:nodaysincurrentmonth) next_rec_hi];
 rec_lo=[current_rec_lo(startdate:nodaysincurrentmonth) next_rec_lo];
 norm_hi=[current_norm_hi(startdate:nodaysincurrentmonth) next_norm_hi];
 norm_lo=[current_norm_lo(startdate:nodaysincurrentmonth) next_norm_lo];  
else
 obs_hi_to_plot=currentmonth_obs_hi(1:length(currentmonth_obs_hi)-1);
 obs_lo_to_plot=currentmonth_obs_lo(1:length(currentmonth_obs_lo)-1);
 daysall=1:nodaysincurrentmonth;
 dayslabel=daysall;
 rec_hi=current_rec_hi;
 rec_lo=current_rec_lo;
 norm_hi=current_norm_hi;
 norm_lo=current_norm_lo;
end

daysobs=1:length(obs_hi_to_plot);

switch currentmonthno
 case 1
  currentmonthnostr='jan';
 case 2
  currentmonthnostr='feb';
 case 3
  currentmonthnostr='mar';
 case 4
  currentmonthnostr='apr';
 case 5
  currentmonthnostr='may';
 case 6
  currentmonthnostr='jun';
 case 7
  currentmonthnostr='jul';
 case 8
  currentmonthnostr='aug';
 case 9
  currentmonthnostr='sep';
 case 10
  currentmonthnostr='oct';
 case 11
  currentmonthnostr='nov';
 case 12
  currentmonthnostr='dec';
end

if use2months==1;
switch nextmonthno
 case 1         
  nextmonthnostr='jan';
 case 2
  nextmonthnostr='feb';  
 case 3
  nextmonthnostr='mar';
 case 4
  nextmonthnostr='apr';
 case 5
  nextmonthnostr='may';
 case 6
  nextmonthnostr='jun';
 case 7
  nextmonthnostr='jul';                
 case 8    
  nextmonthnostr='aug';
 case 9
  nextmonthnostr='sep';
 case 10
  nextmonthnostr='oct';
 case 11
  nextmonthnostr='nov';
 case 12
  nextmonthnostr='dec';
end

monthstr=strcat(currentmonthnostr,'/',nextmonthnostr);

else

monthstr=currentmonthnostr;

end

clear dayslabelstr
for i=1:length(dayslabel)
dayslabelstr1=num2str(dayslabel(i));
if length(dayslabelstr1)==1
 dayslabelstr1=[' ' dayslabelstr1];
end
dayslabelstr(i,:)=dayslabelstr1;
end

mk_climo_plot_wxchallenge
