% This script reads the simulation output of main_ADAN-218.sedml and plots 
% the images that correspond to Figure 15 of the primary paper

%m=readtable("main_ADAN-218a_data.csv");
t = m.environment_Time_second_;

figure (1)
subplot(2,2,1)
xlabel('Time (s)')
hold on
yyaxis left
plot(t,m.Heart_U_lv_J_per_m3_/1000,'-r','LineWidth',1.5)
plot(t,m.Heart_U_rv_J_per_m3_/1000,'--r','LineWidth',1.5)
ylabel('Pressure (KJ/m^3)')
yyaxis right
plot(t,m.Heart_V_lv_m3_per_s_*1e6,'-b','LineWidth',1.5)
plot(t,m.Heart_V_rv_m3_per_s_*1e6,'--b','LineWidth',1.5)
ylabel('Flow (cm^3/s)')
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
hold off
a=legend('u\_lv','u\_rv','v\_lv','v\_rv','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [16,1];
grid on

subplot(2,2,2)
hold on
xlabel('Time (s)')
yyaxis left
plot(t,m.Heart_U_la_J_per_m3_/1000,'-r','LineWidth',1.5)
plot(t,m.Heart_U_ra_J_per_m3_/1000,'--r','LineWidth',1.5)
ylabel('Pressure (KJ/m^3)')
ylim([0,1.5])
yyaxis right
plot(t,m.Heart_V_la_m3_per_s_*1e6,'-b','LineWidth',1.5)
plot(t,m.Heart_V_ra_m3_per_s_*1e6,'--b','LineWidth',1.5)
ylabel('Flow (cm^3/s)')
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
hold off
a=legend('u\_la','u\_ra','v\_la','v\_ra','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [16,1];
grid on

subplot(2,2,3)
xlabel('Time (s)')
hold on
yyaxis left
plot(t,m.Pulmonary_U_par_J_per_m3_/1000,'-r','LineWidth',1.5)
plot(t,m.Pulmonary_U_pvn_J_per_m3_/1000,'--r','LineWidth',1.5)
ylabel('Pressure (KJ/m^3)')
yyaxis right
plot(t,m.Pulmonary_V_par_m3_per_s_*1e6,'-b','LineWidth',1.5)
plot(t,m.Pulmonary_V_pvn_m3_per_s_*1e6,'--b','LineWidth',1.5)
ylabel('Flow (cm^3/s)')
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
hold off
a=legend('u\_par','u\_pvn','v\_par','v\_pvn','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [16,1];
grid on

subplot(2,2,4)
xlabel('Time (s)')
hold on
yyaxis left
plot(t,m.Systemic_U_ivn_J_per_m3_/1000,'-r','LineWidth',1.5)
plot(t,m.Systemic_U_svn_J_per_m3_/1000,'--r','LineWidth',1.5)
ylabel('Pressure (KJ/m^3)')
ylim([0,1])
yyaxis right
plot(t,m.Systemic_V_ivn_m3_per_s_*1e6,'-b','LineWidth',1.5)
plot(t,m.Systemic_V_svn_m3_per_s_*1e6,'--b','LineWidth',1.5)
ylabel('Flow (cm^3/s)')
ylim([-200,500])
ax = gca;
ax.YAxis(1).Color = 'k';
ax.YAxis(2).Color = 'k';
hold off
a=legend('u\_ivn','u\_svn','v\_ivn','v\_svn','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [16,1];
grid on

figure (2)
subplot(3,2,1)
xlabel('Time (s)')
hold on
ylabel('Pressure (KJ/m^3)')
plot(t,m.Heart_U_root_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.thoracic_aorta_C100_U_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.abdominal_aorta_C114_U_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.external_iliac_L198_U_J_per_m3_/1000,'LineWidth',1.5)
a=legend('u\_root','u\_thoracic','u\_adbominal','u\_ext\_iliac','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [8,1];
hold off
grid on

subplot(3,2,2)
xlabel('Time (s)')
hold on
ylabel('Flow (cm^3/s)')
plot(t,m.Heart_V_lv_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.thoracic_aorta_C100_V_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.abdominal_aorta_C114_V_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.external_iliac_L198_V_m3_per_s_*1e6,'LineWidth',1.5)
a=legend('v\_root','v\_thoracic','v\_adbominal','v\_ext\_iliac','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [8,1];
hold off
grid on

subplot(3,2,3)
xlabel('Time (s)')
hold on
ylabel('Pressure (KJ/m^3)')
plot(t,m.common_carotid_L48_D_U_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.radial_T1_L92_U_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.posterior_tibial_T4_L214_U_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.vertebral_L2_U_J_per_m3_/1000,'LineWidth',1.5)
a=legend('u\_com\_carotid','u\_radial','u\_post\_tibial','u\_vertebral','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize=[8,1];
hold off
grid on

subplot(3,2,4)
xlabel('Time (s)')
hold on
ylabel('Flow (cm^3/s)')
plot(t,m.common_carotid_L48_D_V_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.radial_T1_L92_V_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.posterior_tibial_T4_L214_V_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.vertebral_L2_V_m3_per_s_*1e6,'LineWidth',1.5)
a=legend('v\_com\_carotid','v\_radial','v\_post\_tibial','v\_vertebral','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [8,1];
hold off
grid on

subplot(3,2,5)
xlabel('Time (s)')
hold on
ylabel('Pressure (KJ/m^3)')
plot(t,m.anterior_cerebral_L110_U_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.prefrontal_T130_R64_U_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.posterior_parietal_T129_R106_U_J_per_m3_/1000,'LineWidth',1.5)
plot(t,m.middle_cerebral_L114_U_J_per_m3_/1000,'LineWidth',1.5)
a=legend('u\_ant\_cerebral','u\_prefrontal','u\_post\_parietal','u\_mid\_cerebral','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [6,1];
hold off
grid on

subplot(3,2,6)
xlabel('Time (s)')
hold on
ylabel('Flow (cm^3/s)')
plot(t,m.anterior_cerebral_L110_V_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.prefrontal_T130_R64_V_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.posterior_parietal_T129_R106_V_m3_per_s_*1e6,'LineWidth',1.5)
plot(t,m.middle_cerebral_L114_V_m3_per_s_*1e6,'LineWidth',1.5)
a=legend('v\_ant\_cerebral','v\_prefrontal','v\_post\_parietal','v\_mid\_cerebral','location','NorthOutside','orientation','horizontal');
a.ItemTokenSize = [6,1];
hold off 
grid on