clear 
close all
clc
%%
% Atenção ao caminho do arquivo!!
% no meu note: C:\Users\Milena\OneDrive\PosDoc\RioBranco\0_Ascii-files\
% no pc LFA: C:\Users\milen\OneDrive\PosDoc\RioBranco\0_Ascii-files\
% RioBranco-2018_AMES_TPR159_Level0_30min.csv
tit='RioBranco-2018';
path_to_read = 'C:\Users\Milena\OneDrive\PosDoc\RioBranco\0_Ascii-files\';
path_to_save = 'C:\Users\Milena\OneDrive\PosDoc\RioBranco\Meteo\';
C = importdata('C:\Users\Milena\OneDrive\PosDoc\RioBranco\0_Ascii-files\RioBranco-2018_AMES_TPR159_Level0_30min.csv');
time_num =C.data(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time

C.data(:,1) = time_num;
% os horaríos que neste arquivo são reportados como UTC, estao na vdd no
% horario de Sao Paulo (GMT -3). Corrigir somando 3h. 
%esse procedimento foi feito em 17/02/2020 e o novo arquivo level 0
%RioBranco-2018_AMES_TPR159_Level0_ 5 e 30 min já tem os horarios
%corrigidos. Nao é mais necessario usar a linha abaixo.
%C.data(:,1) = time_num + datenum(0,0,0,3,0,0);

header_info = C.textdata{1,1};
for i=2:size(C.textdata,2)
header{1,i-1} = C.textdata{2,i};
end
header{1,1} = 'Time (UTC)';

%Data_Matrix_RB = [];

%%
%%--------Open filesMarco sent 02/03/2020
% Atenção ao caminho do arquivo!!
% no meu note:
% C:\Users\Milena\OneDrive\PosDoc\RioBranco\0_Ascii-files\Level1\
% no pc LFA: C:\Users\milen\OneDrive\PosDoc\RioBranco\0_Ascii-files\Level1\
% RioBrancoBDMEP_BDMEP Meteo_RioBranco_Level1_30min.csv

BDMEP = importdata('C:\Users\Milena\OneDrive\PosDoc\RioBranco\0_Ascii-files\Level1\RioBrancoBDMEP_BDMEP Meteo_RioBranco_Level1_30min.csv');
BDMEP_time_num =BDMEP.data(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time

BDMEP.data(:,1) = BDMEP_time_num;

BDMEP_header_info = BDMEP.textdata{1,1};
for i=2:size(BDMEP.textdata,2)
BDMEP_header{1,i-1} = BDMEP.textdata{2,i};
end
BDMEP_header{1,1} = 'Time (UTC)';

% Temp mean -> col 2
% RH mean -> col 16
% pressure mean -> col 9

%%
%--------Open INMET files
% C:\Users\milen\OneDrive\PosDoc\RioBranco\INMET\
% INMET_Temperatura_RH_press.txt
%os dados do inmet tem 3 pontos por dia. Sempre as 0h 12h 18h em UTC.

inmet = importdata('C:\Users\Milena\OneDrive\PosDoc\RioBranco\INMET\INMET_Temperatura_RH_press.txt');
date_str_inmet = inmet.textdata(18:end, 2); %importa a coluna de data do arquivo inmet dd/mm/yyyy
date_datetime_inmet = datetime(date_str_inmet,'InputFormat','dd/MM/yyyy');  %transforma de str pra datetime format
date_num_inmet = datenum(date_datetime_inmet); %transforma em datenum format
%importa a coluna de hora do arquivo inmet formato 0 1200 1800. Por isso
%divide por 100 pra ficar o valor da hora real 0 12 18.
time_inmet = inmet.data(:,1)/100;  
%concatena a data (dd/mm/yyyy) com a hora (0 , 12 ou 18 )
date_num_inmet = datenum(date_datetime_inmet)+datenum(0,0,0,time_inmet,0,0);

date_time_str_inmet = datestr(date_num_inmet); %transformando em str so para conferir
%importa as coluna de temperatura, RH e pressao
temperature_inmet = inmet.data(:,2);
rh_inmet = inmet.data(:,3);
press_inmet = inmet.data(:,4);

%%
%%%%%%% simple statistics %%%%%%%%

Temp_mean = nanmean(C.data(:,2));
Temp_max = max(C.data(:,2));
Temp_min= min(C.data(:,2),[],'omitnan');
Temp_median = median(C.data(:,2), 'omitnan');

Temp_stats = [Temp_mean Temp_max Temp_min Temp_median];

RH_mean = nanmean(C.data(:,9));
RH_max = max(C.data(:,9));
RH_min= min(C.data(:,9),[],'omitnan');
RH_median = median(C.data(:,9), 'omitnan');

RH_stats = [RH_mean RH_max RH_min RH_median];


%%
Part_2 = C.data(C.data(:,1)>= datenum(2018,09,29,00,00,00),:);
Part2_st = datestr(Part_2(1,1),'dd-mmm-yyyy HH:MM:SS')

Temp_mean_part2 = nanmean(Part_2(:,2));
Temp_max_part2 = max(Part_2(:,2));
Temp_min_part2 = min(Part_2(:,2),[],'omitnan');
Temp_median_part2 = median(Part_2(:,2), 'omitnan');

Temp_stats_part2 = [Temp_mean Temp_max Temp_min Temp_median];

% temperatura oscilou entre 20 e 36 ºC
% max de temperatura por volta das 15h (UTC) ou 10h LT

% RH oscilou entre 92% e 55%
% min de RH por volta das 15h (UTC) ou 10h LT
% max por volta das 3h

%%
%%%%%%%%%%%%%%%%%%%%%%%% PLOTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%¨
%for local time
% dt = 5;     %(difference in time zone in hours)
% time_dif = datenum(0,0,0,dt,0,0);     %tranforms difference in timezone in datenum
% Data_Matrix_RB(:,2) = Data_Matrix_RB(:,1)-time_dif;


%figuras para comparar nossos dados corrigidos com os dados do INMET
figure
plot(date_num_inmet, temperature_inmet, '.-b')
hold on, grid on
plot(C.data(:,1),C.data(:,2),'r')
plot(BDMEP.data(:,1), BDMEP.data(:,2), '.k')
legend('temp INMET', 'our temperature','BDMEP','Location','north','Orientation','horizontal');
xlabel('Time (UTC)');
ylabel('Temperature (ºC)')
title('Temperature Rio Branco')
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([12 42]);
%saveas(gcf,strcat(path_to_save,tit,'_temp_compare_BDMEP'),'png') 

figure
plot(date_num_inmet, rh_inmet, '.-b')
hold on, grid on
plot(C.data(:,1),C.data(:,9),'r')
plot(BDMEP.data(:,1), BDMEP.data(:,16), '.k')
legend('RH INMET', 'our RH','RH BDMEP', 'Location','south','Orientation','horizontal');
xlabel('Time (UTC)');
ylabel('RH (%)')
title('Relative Humidity Rio Branco')
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([20 100]);
%saveas(gcf,strcat(path_to_save,tit,'RH_compare_BDMEP'),'png') 

figure
plot(date_num_inmet, press_inmet, '.-b')
hold on, grid on
plot(C.data(:,1),C.data(:,16),'r')
plot(BDMEP.data(:,1), BDMEP.data(:,9), '.k')
legend('Pressure INMET', 'our Pressure','Pressure BDMEP', 'Location','south','Orientation','horizontal');
xlabel('Time (UTC)');
ylabel('Pressure (mbar)')
title('Atmospheric Pressure Rio Branco')
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([980 1009]);
%saveas(gcf,strcat(path_to_save,tit,'pressure_compare_BDMEP'),'png') 

%%
% compare our data to inmet X-Y dispersion

X1 = date_num_inmet; %X1 is INMET time
X2 = C.data(:,1); %X2 is our time

ind_X2_X1 = NaN(size(X1)); %cria o vetor que vai receber os indices em que X2 = X1

for i = 1:length(X1)  %percorre o vetor X1
    ind = find(X1(i) == X2); %procura o index em que o elemento de X2 é igual ao elemento i de X1
    
    if ~isempty(ind) %ind_X2_X1 é alimentado apenas se ind tiver um valor 
        ind_X2_X1(i) = ind;
    else             % senão, ind_X2_X1 recece um NaN
        ind_X2_X1(i) = NaN;
    end
%     
%     ind
%     datestr(X2(ind))
%     pause
end


%%
%Regressões lineares para cada uma das variáveis
Y_temperature = C.data(ind_X2_X1,2);
mask_temperature = ~isnan(temperature_inmet) & ~isnan(Y_temperature);
[fit_temperature gof_temperature] = fit(temperature_inmet(mask_temperature),Y_temperature(mask_temperature),'poly1');

Y_rh = C.data(ind_X2_X1,9);
mask_rh = ~isnan(rh_inmet) & ~isnan(Y_rh);
[fit_rh gof_rh] = fit(rh_inmet(mask_rh),Y_rh(mask_rh),'poly1');

Y_pressure = C.data(ind_X2_X1,16);
mask_pressure = ~isnan(press_inmet) & ~isnan(Y_pressure);
[fit_pressure gof_pressure] = fit(press_inmet(mask_pressure),Y_pressure(mask_pressure),'poly1');


%%
%Plot das figuras da dispersão X-Y com a regressão linear
%para cada uma das variáveis metereologicas

%FIG 1 Temperature
color_time = date_num_inmet;
figure
scatter(temperature_inmet, Y_temperature,[],color_time  , 'filled');
hold on, grid on
plot(fit_temperature, '--k');
title('Temperature Rio Branco')
ylabel('Temperature (ºC)')
xlabel('INMET Temperature (ºC)')
legend('data',[num2str(fit_temperature.p1,'%1.2f'),'*x+',num2str(fit_temperature.p2,'%1.2f'),' R^2=',num2str(gof_temperature.rsquare,'%1.2f')], 'Location', 'northwest')
c = colorbar;
ticks_spacing = linspace(737297,7.3737e+05, 8);
c.Ticks = ticks_spacing;
c.TickLabels = datestr(c.Ticks, 24);
colormap('jet');
nome = '_temp_compare_INMET_x-y';
saveas(gcf,strcat(path_to_save,tit,nome),'png') 

%FIG2 RH
figure
scatter(rh_inmet,Y_rh,[],color_time  , 'filled')
hold on, grid on
plot(fit_rh, '--k');
xlabel('INMET RH (%)');
ylabel('RH (%)')
title('Relative Humidity Rio Branco')
legend('data',[num2str(fit_rh.p1,'%1.2f'),'*x+',num2str(fit_rh.p2,'%1.2f'),' R^2=',num2str(gof_rh.rsquare,'%1.2f')], 'Location', 'northwest')
c = colorbar;
ticks_spacing = linspace(737297,7.3737e+05, 8);
c.Ticks = ticks_spacing;
c.TickLabels = datestr(c.Ticks, 24);
colormap('jet');
nome = '_RH_compare_INMET_x-y';
saveas(gcf,strcat(path_to_save,tit,nome),'png') 

%FIG3 Pressure
figure
scatter(press_inmet, Y_pressure,[],color_time  , 'filled')
hold on, grid on
plot(fit_pressure, '--k');
xlabel('INMET Pressure (mbar)');
ylabel('Pressure (mbar)')
title('Atmospheric Pressure Rio Branco')
legend('data',[num2str(fit_pressure.p1,'%1.2f'),'*x+',num2str(fit_pressure.p2,'%1.2f'),' R^2=',num2str(gof_pressure.rsquare,'%1.2f')], 'Location', 'northwest')
c = colorbar;
ticks_spacing = linspace(737297,7.3737e+05, 8);
c.Ticks = ticks_spacing;
c.TickLabels = datestr(c.Ticks, 24);
colormap('jet');
nome = '_Pressure_compare_INMET_x-y';
%saveas(gcf,strcat(path_to_save,tit,nome),'png') 

%%
%figuras que plotam os dados metereologicos de RB
fig1=figure;
plot(C.data(:,1),C.data(:,2),'r')
hold on
plot(C.data(:,1),ones(length(C.data),1)*nanmean(C.data(:,2)),':k')
plot(C.data(:,1),ones(length(C.data),1)*nanmedian(C.data(:,2)),'--k')
grid on
ylabel('T (ºC)')
xlabel('Time (UTC)')
title('Temperature Rio Branco')
label_1 = header{1,2};
legend('Temperature','Mean','Median','Location','north','Orientation','horizontal' );
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([12 42]);
nome_1=['Temperature_Time_Series'];
%saveas(gcf,strcat(path_to_save,tit,nome_1),'png') 


%plot RH
fig1=figure;
plot(C.data(:,1),C.data(:,9),'b');
hold on
plot(C.data(:,1),ones(length(C.data),1)*nanmean(C.data(:,9)),':k')
plot(C.data(:,1),ones(length(C.data),1)*nanmedian(C.data(:,9)),'--k')
dynamicDateTicks([], [], 'dd/mm');
grid on
ylabel('RH (%)')
xlabel('Time UTC')
title('RH Rio Branco')
label_2 = header{1,9};
legend('RH','Mean','Median' ,'Location','south','Orientation','horizontal');
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([20 100]);
nome_2=['RH_Time_Series'];
% print(fig1,'-dpng',[nome_2,'.png']);
%saveas(gcf,strcat(path_to_save,tit,nome_2),'png') 

%plot pressure
fig1=figure;
plot(C.data(:,1),C.data(:,16),'k')
hold on
plot(C.data(:,1),ones(length(C.data),1)*nanmean(C.data(:,16)),':k')
plot(C.data(:,1),ones(length(C.data),1)*nanmedian(C.data(:,16)),'--k')
grid on
ylabel('Pressure (mbar)')
xlabel('Time (UTC)')
title('Atmospheric Pressure Rio Branco')
%label_1 = header{1,2};
legend('Pressure','Mean','Median','Location','south','Orientation','horizontal' );
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([980 1005]);
nome_3=['_Pressure_Time_Series'];
% print(fig1,'-dpng',[nome_2,'.png']);
%saveas(gcf,strcat(path_to_save,tit,nome_3),'png') 
%%
%Export LFA standart format
origsize=size(C.data,1);
export_variables = [C.data(:,2) C.data(:,9) C.data(:,16)];

Instrument='AMES';
Model='TPR159';
serial_num=' ';
Site=tit;
Val_level='3';
Proc_vers='1.0';
labels ={'Temperature', 'RH', 'Pressure'};
units = {'(Celsius)', '(Percentage)', '(mbar)'};
export_LFA_GoAmazon_jan2015(labels,units,Instrument,Model,serial_num,Site,Val_level,Proc_vers,origsize,C.data(:,1),export_variables)
%
%% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%import files saved at Level3
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
path_to_read = 'C:\Users\milen\OneDrive\PosDoc\RioBranco\';
path_to_save = 'C:\Users\milen\OneDrive\PosDoc\RioBranco\Meteo\';
%LFA: C:\Users\milen\OneDrive\PosDoc\RioBranco\0_Ascii-files\Level3
% meu note: C:\Users\Milena\OneDrive\PosDoc\RioBranco\0_Ascii-files\Level3
%RioBranco-2018_AMES_TPR159_Level2_30min.csv
meteo_L3 = importdata('C:\Users\Milena\OneDrive\PosDoc\RioBranco\0_Ascii-files\Level3\RioBranco-2018_AMES_TPR159_Level3_30min.csv');

time_num =meteo_L3.data(:,1)/(24*60*60)+datenum(1970,1,1); % unix time to matlab time
meteo_L3.data(:,1) = time_num;

header_info = meteo_L3.textdata{1,1};
header = meteo_L3.textdata{2,1};
header_meteo_L3 = strsplit(header, ';');
header_meteo_L3(1)=[];
header_meteo_L3{1,1} = 'Time (UTC)';

%%
%%%%%%% simple statistics %%%%%%%%

Temp_mean = nanmean(meteo_L3.data(:,2));
Temp_max = max(meteo_L3.data(:,2));
Temp_min= min(meteo_L3.data(:,2),[],'omitnan');
Temp_median = median(meteo_L3.data(:,2), 'omitnan');

Temp_stats = [Temp_mean Temp_max Temp_min Temp_median];

RH_mean = nanmean(meteo_L3.data(:,3));
RH_max = max(meteo_L3.data(:,3));
RH_min= min(meteo_L3.data(:,3),[],'omitnan');
RH_median = median(meteo_L3.data(:,3), 'omitnan');

RH_stats = [RH_mean RH_max RH_min RH_median];

Pressure_mean = nanmean(meteo_L3.data(:,4));
Pressure_max = max(meteo_L3.data(:,4));
Pressure_min= min(meteo_L3.data(:,4),[],'omitnan');
Pressure_median = median(meteo_L3.data(:,4), 'omitnan');

Pressure_stats = [Pressure_mean Pressure_max Pressure_min Pressure_median];
%%
fig1=figure;
plot(meteo_L3.data(:,1),meteo_L3.data(:,2),'r')
hold on
plot(meteo_L3.data(:,1),ones(length(meteo_L3.data),1)*nanmean(meteo_L3.data(:,2)),':k')
plot(meteo_L3.data(:,1),ones(length(meteo_L3.data),1)*nanmedian(meteo_L3.data(:,2)),'--k')
grid on
ylabel('T (ºC)')
xlabel('Time (UTC)')
title('Temperature Rio Branco')
%label_1 = header{1,2};
legend('Temperature','Mean','Median','Location','north','Orientation','horizontal' );
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([12 42]);
% nome_1=['Temperature_Time_Series'];
% saveas(gcf,strcat(path_to_save,tit,nome_1),'png')

fig1=figure;
plot(meteo_L3.data(:,1),meteo_L3.data(:,3),'b')
hold on
plot(meteo_L3.data(:,1),ones(length(meteo_L3.data),1)*nanmean(meteo_L3.data(:,3)),':k')
plot(meteo_L3.data(:,1),ones(length(meteo_L3.data),1)*nanmedian(meteo_L3.data(:,3)),'--k')
grid on
ylabel('RH (%)')
xlabel('Time (UTC)')
title('RH Rio Branco')
%label_1 = header{1,2};
legend('RH','Mean','Median','Location','south','Orientation','horizontal' );
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([20 100]);

fig1=figure;
plot(meteo_L3.data(:,1),meteo_L3.data(:,4),'k')
hold on
plot(meteo_L3.data(:,1),ones(length(meteo_L3.data),1)*nanmean(meteo_L3.data(:,4)),':k')
plot(meteo_L3.data(:,1),ones(length(meteo_L3.data),1)*nanmedian(meteo_L3.data(:,4)),'--k')
grid on
ylabel('Pressure (mbar)')
xlabel('Time (UTC)')
title('Atmospheric Pressure Rio Branco')
%label_1 = header{1,2};
legend('Pressure','Mean','Median','Location','south','Orientation','horizontal' );
dynamicDateTicks([], [], 'dd/mm');
xlim([737290 737370]);
ylim([980 1005]);

%%
%for diurnal profiles

[time_diel, meteo_median, meteo_mean, meteo_p25, meteo_p75] = diel_profile(meteo_L3.data(:,2:end), datetime(meteo_L3.data(:,1),'ConvertFrom','datenum'));

plot_diel_profiles_error_bar (time_diel,meteo_median, meteo_p25, meteo_p75)

%%
%for sunlight plot
[rs,t,d,z,b,r]=suncycle(-9.97,-67.81);

fig1=figure;
% set(fig1,'InvertHardcopy','on');
% set(gca,'FontSize', 12, 'LineWidth', 2); 

subplot(3,1,1)
ylim1 = 20;
ylim2 = 40;
% axis('off');
% axes1 = axes('Parent',fig1,...
% 'XTickLabel',{'0','2','4','6','8','10','12','14','16','18','20','22','24'},...
% 'XTick',[0 2 4 6 8 10 12 14 16 18 20 22 24]);

rectangle('Position',[rs(1),ylim1+1,rs(2)-rs(1),ylim2-ylim1-1.99],'FaceColor',[1 1 0.7],'EdgeColor',[1 1 0.7])
axis([-0.5 24 ylim1 ylim2])
hold on
errorbar(time_diel,meteo_median(:,1), meteo_median(:,1)- meteo_p25(:,1),meteo_p75(:,1)-meteo_median(:,1), '.r', 'markersize', 23, 'LineWidth', 1.75)
title(['Diel Profile'])
legend('boxoff')
%xlabel('Time (UTC)')
ylabel('Temperature (ºC)')
ylim([ylim1 ylim2])
ax = gca;
ax.XTick = [0 2 4 6 8 10 12 14 16 18 20 22 24];
ax.YTick = linspace(ylim1,ylim2,5);
% xlim(axes1,[-0.5 24])
box on
% set(gcf,'units','inch','position',[0,0,8,4]); %
% set(gcf,'PaperPositionMode','auto')

subplot(3,1,2)
ylim1 = 45;
ylim2 = 100;
rectangle('Position',[rs(1),ylim1+2.5,rs(2)-rs(1),ylim2-ylim1-5],'FaceColor',[1 1 0.7],'EdgeColor',[1 1 0.7])
axis([-0.5 24 ylim1 ylim2])
hold on
errorbar(time_diel,meteo_median(:,2), meteo_median(:,2)- meteo_p25(:,2),meteo_p75(:,2)-meteo_median(:,2), '.b', 'markersize', 23, 'LineWidth', 1.75)
legend('boxoff')
%xlabel('Time (UTC)')
ylabel('RH (%)')
ylim([ylim1 ylim2])
% xlim(axes1,[-0.5 24])
ax = gca;
ax.XTick = [0 2 4 6 8 10 12 14 16 18 20 22 24];
ax.YTick = [ylim1 60 70 80 90 ylim2]%linspace(ylim1,ylim2,3);
box on
% set(gcf,'units','inch','position',[0,0,8,4]); %
% set(gcf,'PaperPositionMode','auto')

subplot(3,1,3)
ylim1 = 985;
ylim2 = 995;
rectangle('Position',[rs(1),ylim1+0.7,rs(2)-rs(1),ylim2-ylim1-1.5],'FaceColor',[1 1 0.7],'EdgeColor',[1 1 0.7])
axis([-0.5 24 ylim1 ylim2])
hold on
errorbar(time_diel,meteo_median(:,3), meteo_median(:,3)- meteo_p25(:,3),meteo_p75(:,3)-meteo_median(:,3), '.k', 'markersize', 23, 'LineWidth', 1.75)
legend('boxoff')
xlabel('Time (UTC)')
ylabel('Pressure (mbar)')
ylim([ylim1 ylim2])
ax = gca;
ax.XTick = [0 2 4 6 8 10 12 14 16 18 20 22 24];
ax.YTick = linspace(ylim1,ylim2,5);
% xlim(axes1,[-0.5 24])
box on

%%
%plot errorbar at local time

time_diel_LT = NaN(24, 1);
time_zone = 5; %time_zone = difference from GMT

for m=1:24
    if time_diel(m)<time_zone
     time_diel_LT(m) = time_diel(m)-time_zone+24;
    else
     time_diel_LT(m) = time_diel(m)-time_zone;
    end
    
end

fig1=figure    
errorbar(time_diel_LT,meteo_median(:,1), meteo_median(:,1)- meteo_p25(:,1),meteo_p75(:,1)-meteo_median(:,1), '.', 'markersize', 23, 'LineWidth', 1.75)
ylabel('Temperature (]C)')
xlabel('Time (LT)')
title(['Diel Profile Local Time'])
xlim([-0.5 24])
set(gca,'Xtick', 0:2:24)
grid on    
%%
%for sunlight plot at Local Time
rs_LT = rs-5;

fig1=figure;
subplot(3,1,1)
ylim1 = 20;
ylim2 = 40;
rectangle('Position',[rs_LT(1),ylim1+1,rs_LT(2)-rs_LT(1),ylim2-ylim1-1.99],'FaceColor',[1 1 0.7],'EdgeColor',[1 1 0.7])
axis([-0.5 24 ylim1 ylim2])
hold on
errorbar(time_diel_LT,meteo_median(:,1), meteo_median(:,1)- meteo_p25(:,1),meteo_p75(:,1)-meteo_median(:,1), '.r', 'markersize', 23, 'LineWidth', 1.75)
title(['Diel Profile'])
legend('boxoff')
%xlabel('Local Time')
ylabel('Temperature (ºC)')
ylim([ylim1 ylim2])
ax = gca;
ax.XTick = [0 2 4 6 8 10 12 14 16 18 20 22 24];
ax.YTick = linspace(ylim1,ylim2,5);
box on

subplot(3,1,2)
ylim1 = 45;
ylim2 = 100;
rectangle('Position',[rs_LT(1),ylim1+2.5,rs_LT(2)-rs_LT(1),ylim2-ylim1-5],'FaceColor',[1 1 0.7],'EdgeColor',[1 1 0.7])
axis([-0.5 24 ylim1 ylim2])
hold on
errorbar(time_diel_LT,meteo_median(:,2), meteo_median(:,2)- meteo_p25(:,2),meteo_p75(:,2)-meteo_median(:,2), '.b', 'markersize', 23, 'LineWidth', 1.75)
legend('boxoff')
%xlabel('Local Time')
ylabel('RH (%)')
ylim([ylim1 ylim2])
ax = gca;
ax.XTick = [0 2 4 6 8 10 12 14 16 18 20 22 24];
ax.YTick = [ylim1 60 70 80 90 ylim2]%linspace(ylim1,ylim2,3);
box on

subplot(3,1,3)
ylim1 = 985;
ylim2 = 995;
rectangle('Position',[rs_LT(1),ylim1+0.7,rs_LT(2)-rs_LT(1),ylim2-ylim1-1.5],'FaceColor',[1 1 0.7],'EdgeColor',[1 1 0.7])
axis([-0.5 24 ylim1 ylim2])
hold on
errorbar(time_diel_LT,meteo_median(:,3), meteo_median(:,3)- meteo_p25(:,3),meteo_p75(:,3)-meteo_median(:,3), '.k', 'markersize', 23, 'LineWidth', 1.75)
legend('boxoff')
xlabel('Local Time')
ylabel('Pressure (mbar)')
ylim([ylim1 ylim2])
ax = gca;
ax.XTick = [0 2 4 6 8 10 12 14 16 18 20 22 24];
ax.YTick = linspace(ylim1,ylim2,5);
box on