%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='CHS';

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

%If using the two month option, set the start date during the first month
startdate=15;

%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/KCHS/2009/9/30/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=30;

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

%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=[88 88 87 87 87 87 86 86 86 86 86 86 86 86 85 85 85 85 84 84 84 84 84 84 83 83 82 82 82 81];

%Same as above but for the normal lows
current_norm_lo=[70 70 70 70 70 70 70 69 69 69 69 69 68 68 68 68 68 67 67 67 66 65 65 65 64 63 63 62 62 62];

%Same as above but for the record highs
current_rec_hi=[95 97 97 99 99 97 95 96 98 97 95 94 93 94 96 97 96 96 98 98 94 96 95 95 94 93 94 94 91 92];

%Same as above but for the record lows
current_rec_lo=[56 57 57 60 52 54 58 57 55 51 49 52 56 52 51 53 54 55 51 53 52 49 46 44 51 49 51 50 50 42];

%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/KCHS/2009/10/31/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=31;

%enter number of second month
nextmonthno=10;

%enter normal highs for second month
next_norm_hi=[81 81 81 81 80 79 79 79 79 78 78 78 78 77 77 77 77 76 76 76 75 75 75 75 74 74 74 74 74 74 74];

%enter normal lows for second month
next_norm_lo=[61 60 60 59 59 59 59 58 57 57 57 56 56 56 56 56 55 54 54 54 54 54 53 52 52 52 51 51 51 51 51];

%enter record highs for second month
next_rec_hi=[91 93 93 92 94 93 91 90 89 89 88 87 88 88 87 86 91 88 87 87 88 87 86 87 88 86 87 86 85 85 87];

%enter record lows for second month
next_rec_lo=[44 43 42 37 42 45 44 43 39 35 39 40 42 39 40 38 37 37 39 34 37 33 33 36 34 33 33 32 27 27 35];

end

%Done editing!

%%%%%%%%%%%%DO NOT EDIT BEYOND THIS POINT%%%%%%%%%%%%%%%%%%%%%%%%%%%

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