pom=pom;
Remove["Global`*"];
$HistoryLength=2;
SetDirectory[NotebookDirectory[]];
Off[FindRoot::"lstol",FindMinimum::"lstol",FindRoot::"nlnum",ReplaceAll::"reps",NIntegrate::"slwcon",NIntegrate::"ncvb"];

mydats=<<"dats";
teplotapom=mydats[[-1]];
intt={t1,t2}=mydats[[1,1,1]];
(*Plot[#[24*3600t],{t,(t1/(24*3600)),(t2/(24*3600))},PlotPoints->300,PlotStyle->{Thickness[0.005]},AxesLabel->{"t (day)","q  (W.(m^(-2)))"},GridLines->Automatic,PlotRange->All]&/@mydats*)
hodina=3600.;
den=24*hodina;
Print["{t1,t2}= ",Floor[((#)/den)]&/@intt," dni"];
Manipulate[
int=den*{pocatek,pocatek+Δ};
Plot[teplotapom[t*den],{t,pocatek,pocatek+Δ},PlotRange->{Automatic,{-15,ht}},AxesOrigin->{pocatek-1,0}],
{{Δ,5},2,Floor[(t2/den)]},{pocatek,1,Floor[(t2/den)]-Δ},{{ht,15},5,30},ControlPlacement->Top]

{tStart,tEnd}=int;
nInt=Round[((tEnd-tStart)/(Δtzprac=0.125*hodina))];
predzpracuj[fce_]:=Module[{dat},dat={#,fce[#]}&/@Range[tStart,tEnd,Δtzprac];Interpolation[dat,InterpolationOrder->1]];
{qJ,qZ,qS,qV,qStrecha,qKolektor,teplota}=predzpracuj/@mydats;
Plot[#[24*3600t],{t,(tStart/(24*3600)),(tEnd/(24*3600))},PlotPoints->300,PlotStyle->{Thickness[0.005]},AxesLabel->{"t (day)","q  (W.(m^(-2)))"},GridLines->Automatic,PlotRange->All]&/@%;

odrezPrechodaku=2*den;
cm=0.01;
vypoctovaVnejsiTeplota=-15;
dPlech=0.09 cm;
dPUR=4 cm;
dmax=dPlech+dPUR;
λPlech=50;
λPUR=0.024;
λPreklizka = 0.18;
rocPlech=7850*490;
rocPUR=30*1500;
UcinnostPanelu = 0.15;
PlochaPanelu=5;
αin=5.;
αext=9.;
Tin=22;
ϵ=0.95;
σ=5.67*10^-8;
Tzem=8;
ucinnosUzitiSlunZisku=0.5;
dPlechStrecha=0.09 cm;
dPURStrecha=4 cm;
dmaxStrecha=dPlechStrecha+dPURStrecha;
prechod[vlevo_,vpravo_,dPlech_]:=Module[{res,a,b},res=Solve[{a-b==vlevo,a+b==vpravo}];a+b*Tanh[((x-dPlech)/(0.5cm))]/.res[[1]]];
roc=prechod[rocPlech,rocPUR,dPlech];
λ=prechod[λPlech,λPUR,dPlech];
rocStrecha=prechod[rocPlech,rocPUR,dPlechStrecha];
λStrecha=prechod[λPlech,λPUR,dPlechStrecha];
pl[co_,popis_]:=Plot[co/.x->xx,{xx,0,dmax},PlotRange->All,AxesLabel->{"x [m]",popis},AxesOrigin->{0,0},PlotStyle->{Hue[0.63],Thickness[0.004]}];
plRoc=pl[roc,"ρc [(J/(K*(m^3)))]"];
plLambda=pl[λ,"λ [(W/(K*m))]"];
TdenniPrumerna=(1/(tEnd-tStart))NIntegrate[teplota[t],{t,tStart,tEnd}];
tmax=teplota[[1,1,2]];
prechodStart=Tanh[t-tStart];
Tden=teplota[t];

(*re*)
vyresStenu[roc_,λ_,qStena_,dmax_]:=Module[{rce,poc,okrVlevo,okrVpravo,res,teplotaStena,tokVlevo},
rce={roc*D[T[x,t],t]==D[λ*D[T[x,t],x],x]};
poc={T[x,tStart]==TdenniPrumerna};
okrVlevo={-λ*D[T[x,t],x]==αin*(Tin-T[x,t])*prechodStart}/.x->0;
okrVpravo={-λ*D[T[x,t],x]==(ϵ*σ*((((T[x,t]+273))^4)-(((teplota[t]+273))^4))+αext*(T[x,t]-teplota[t])-ϵ*qStena[t])*prechodStart}/.x->dmax;
res=NDSolve[Union[rce,poc,okrVlevo,okrVlevo,okrVpravo],{T[x,t],D[T[x,t],x]},{x,0,dmax},{t,tStart,tmax},MaxSteps->(10^6)][[1]];
tokVlevo[t_]:=(-λ*D[T[x,t],x]/.res)/.x->0;
tokVlevo[t]
];

tokJ[t_]=vyresStenu[roc,λ,qJ,dmax];
Plot[tokJ[t*den],{t,(tStart/den),(tmax/den)},AxesLabel->{"t [day]","q [W.(m^(-2))]"},PlotRange->All,PlotStyle->{Hue[0.63],Thickness[0.004]}];

tokS[t_]=vyresStenu[roc,λ,qS,dmax];
Plot[tokS[t*den],{t,(tStart/den),(tmax/den)},AxesLabel->{"t [day]","q [W.(m^(-2))]"},PlotRange->All,PlotStyle->{Hue[0.63],Thickness[0.004]}];

tokZ[t_]=vyresStenu[roc,λ,qZ,dmax];
Plot[tokZ[t*den],{t,(tStart/den),(tmax/den)},AxesLabel->{"t [day]","q [W.(m^(-2))]"},PlotRange->All,PlotStyle->{Hue[0.63],Thickness[0.004]}];

tokV[t_]=vyresStenu[roc,λ,qV,dmax];
Plot[tokV[t*den],{t,(tStart/den),(tmax/den)},AxesLabel->{"t [day]","q [W.(m^(-2))]"},PlotRange->All,PlotStyle->{Hue[0.63],Thickness[0.004]}];

tokStrecha[t_]=vyresStenu[rocStrecha,λStrecha,qStrecha,dmaxStrecha];
Plot[tokStrecha[t*den],{t,(tStart/den),(tmax/den)},AxesLabel->{"t [day]","q [W.(m^(-2))]"},PlotRange->All,PlotStyle->{Hue[0.63],Thickness[0.004]}];

dizZem=10cm;
tokZem[t_]:=((λPreklizka)/dizZem)*(Tin-Tzem);

Sokno=0.8*1.2;
nOkenJ=2;
nOkenZ=0;
nOkenS=0;
nOkenV=0;
nOkenStrecha=0;
nOken=nOkenJ+nOkenZ+nOkenS+nOkenV+nOkenStrecha;
kOkno=1;
pOkna[t_]=kOkno*(Tin-Tden)*nOken*Sokno;
pSlunZisky[t_]=ucinnosUzitiSlunZisku*Sokno*(nOkenJ*qJ[t]+nOkenZ*qZ[t]+nOkenS*qS[t]+nOkenV*qV[t]+nOkenStrecha+qStrecha[t]);
Plot[pSlunZisky[t*den],{t,(tStart/den),(tmax/den)},AxesLabel->{"t [day]","Q zisk [W]"},PlotRange->All,PlotStyle->{Hue[0.63],Thickness[0.004]}];

ucinnostRekuperaceVzduchu=0.6;
a=5.1;
b=2.2;
c=2.4;(*vyska budovy*)

objem=(a-2*dmax)*(b-2*dmax)*(c-dmaxStrecha);
cVzduch=1000;
mVzduch=(341./(Tin+273))*objem;
nHodinVymenyVzduchu=2;
pVzduch[t_]=cVzduch*(mVzduch/(nHodinVymenyVzduchu*3600))*(Tin-Tden)*(1-ucinnostRekuperaceVzduchu)//Expand;
Plot[pVzduch[t*den],{t,(tStart/den),(tmax/den)},AxesLabel->{"t [day]","Q vetrani [W]"},PlotRange->All,PlotStyle->{Hue[0.63],Thickness[0.004]}];

pVedeniStenami[t_]=(a*c-Sokno*(nOkenJ+nOkenS))*(tokJ[t]+tokS[t])+(b*c-Sokno*(nOkenV+nOkenZ))*(tokV[t]+tokZ[t])+(a*b-Sokno*nOkenStrecha)*tokStrecha[t]+a*b*tokZem[t];
Plot[pVedeniStenami[t*den],{t,(tStart/den),(tmax/den)},AxesLabel->{"t [day]","Q zdi [W]"},PlotRange->All,PlotStyle->{Hue[0.63],Thickness[0.004]}];

pPanel[t_]=qKolektor[t]*UcinnostPanelu*PlochaPanelu;
PzCelkem[t_]=pVzduch[t]+pVedeniStenami[t]+pOkna[t]-pSlunZisky[t];
plToky=Plot[{pPanel[t*den],pVzduch[t*den],pVedeniStenami[t*den],pOkna[t*den],PzCelkem[t*den]},{t,((tStart+odrezPrechodaku)/den),(tmax/den)},PlotRange->All,AxesLabel->{"t [den]","Q[W]"},PlotStyle->{{Green,Thickness[0.004]},{Red,Thickness[0.004]},{Black,Thickness[0.004]},{Blue,Thickness[0.004]},{Magenta,Thickness[0.004]}},PlotLabel->"panely    vzduch   vedeni    okna   celkem"]