close all
clear all

monthname = {'81Jul','81Oct','82Jan','82Apr','82Jul','82Oct','83Jan','83Apr','83Jul'};
monthdate = {81000+datenum('01.06.1981','dd.mm.yyyy')-datenum('00.01.1981','dd.mm.yyyy'), 81000+datenum('01.09.1981','dd.mm.yyyy')-datenum('00.01.1981','dd.mm.yyyy'),...
             81000+datenum('01.12.1981','dd.mm.yyyy')-datenum('00.01.1981','dd.mm.yyyy'), 82000+datenum('01.03.1982','dd.mm.yyyy')-datenum('00.01.1982','dd.mm.yyyy'),...
             82000+datenum('01.06.1982','dd.mm.yyyy')-datenum('00.01.1982','dd.mm.yyyy'), 82000+datenum('01.09.1982','dd.mm.yyyy')-datenum('00.01.1982','dd.mm.yyyy'),...
             82000+datenum('01.12.1982','dd.mm.yyyy')-datenum('00.01.1982','dd.mm.yyyy'), 83000+datenum('01.03.1983','dd.mm.yyyy')-datenum('00.01.1983','dd.mm.yyyy'),...
             83000+datenum('01.06.1983','dd.mm.yyyy')-datenum('00.01.1983','dd.mm.yyyy'), 83000+datenum('01.09.1983','dd.mm.yyyy')-datenum('00.01.1983','dd.mm.yyyy')};
%
% read from MERL_datasheet_scans
%
filename = 'production.txt';
fprintf(' reading %s \n',filename);
if ~exist(filename,'file')
    error('cannot find the file: %s \n',filename);
end
readMERL(filename);
if size(data,2) ~= 10
        error('error in data size %d \n', size(data,2));
end
data = data.*1000/32;  % convert from g/m2/d to mmol/m2/d
sm_data = calc_season_mean(data,textdata,monthdate); 
figure
plot(sm_data(:,1),'-k.','LineWidth',1);hold on
plot(sm_data(:,5),'-rd','LineWidth',1);hold on
plot(sm_data(:,7),'-bo','LineWidth',1);hold on
plot(sm_data(:,9),'-m*','LineWidth',1);hold on
plot(sm_data(:,10),'-kv');
l1 = legend('C0','1X','4X','16X','32X');
set(l1,'Location','Northwest','box','off','FontSize',15,'Orientation','horizontal');
xlabel('months');
ylabel('system production (mmol O_2 m^-^2 d^-^1)','FontSize',15);
set(gca,'XTickLabel',monthname);
print(gcf,'-dpng', 'system_production');

%
filename = 'respiration.txt';
fprintf(' reading %s \n',filename);
if ~exist(filename,'file')
    error('cannot find the file: %s \n',filename);
end
readMERL(filename);
if size(data,2) ~= 10
        error('error in data size %d \n', size(data,2));
end
data = -data.*1000/32;  % convert from g/m2/d to mmol/m2/d
sm_data = calc_season_mean(data,textdata,monthdate); 
figure
plot(sm_data(:,1),'-k.','LineWidth',1);hold on
plot(sm_data(:,5),'-rd','LineWidth',1);hold on
plot(sm_data(:,7),'-bo','LineWidth',1);hold on
plot(sm_data(:,9),'-m*','LineWidth',1);hold on
plot(sm_data(:,10),'-kv','LineWidth',1);
l1 = legend('C0','1X','4X','16X','32X');
set(l1,'Location','Northwest','box','off','FontSize',15,'Orientation','horizontal');
xlabel('months');
ylabel('system respiration (mmol O_2 m^-^2 d^-^1)','FontSize',15);
set(gca,'XTickLabel',monthname);
print(gcf,'-dpng', 'system_respiration');