pom=pom;
Remove["Global`*"];
$HistoryLength=2;
SetDirectory[NotebookDirectory[]];
Off[FindRoot::"lstol",FindMinimum::"lstol",FindRoot::"nlnum",ReplaceAll::"reps"];
prechod[vlevo_,vpravo_]:=Module[{res,a,b},res=Solve[{a-b==vlevo,a+b==vpravo}];a+b*Tanh[((x-dPlech)/(0.5cm))]/.res[[1]]];

shift=0*3600;
dni=6;(*kolik dnu beru*)
n1=1;
t1=n1*24*3600;
nTake=24*dni;
t2=t1+(nTake-1)*3600;
datPokrObl=Take[<<"pokrytiOblohy",{n1*24,n1*24+nTake}]/.{a_List,b_}:>b/.Missing["NotAvailable"]->0.5;

datVenTeppom=Take[<<"venovniTeplota",{n1*24,n1*24+nTake}]/.{a_List,b_}:>b;
datVenTep=datVenTeppom/.{a___,b_Real,Missing["NotAvailable"],c_Real,d___}:>{a,b,0.5*(c+b),d};

zpracPocasi[dat_]:=Module[{iO=1,dvojice},dvojice=Thread[{(shift+t1+(#-1)*3600)&/@Range[Length[dat]],dat}];Interpolation[dvojice,InterpolationOrder->1]];
pokryti=zpracPocasi[datPokrObl];
teplota=zpracPocasi[datVenTep];
plText=Plot[teplota[24*3600t],{t,(t1/(24*3600)),(t2/(24*3600))},PlotPoints->1300,PlotStyle->{Thickness[0.005]},AxesLabel->{"t(day)","Text (°C)"},GridLines->Automatic];
plPokryti=Plot[pokryti[24*3600t],{t,(t1/(24*3600)),(t2/(24*3600))},PlotPoints->1300,PlotStyle->{Thickness[0.005]},AxesLabel->{"t(day)","clouds (-)"},GridLines->Automatic];

toMDH[t_]:=Module[{hd=3600,den,mesic,tp1,tp2,nm,nd,nh},den=24*hd;mesic=30*den;nm=Floor[(t/mesic)]+1;tp1=t-(nm-1)*mesic;nd=Floor[(tp1/den)];tp2=tp1-nd*den;nh=(tp2/hd);{nm,nd,nh}];
toMDH[29.51*24*3600];
hd=3600.;
den=24*hd;(*zem sirka*)
zs=50;
θ[t_,Odklon_]:= Pi-Odklon*(Pi/180) - ((2*Pi)*hd*t)/den; 
horiz[t_,Odklon_]:= (1/2)*(Abs[Cos[θ[t,Odklon]]] + 
     Cos[θ[t,Odklon]]); 
τ[hod_]:=hod-12; 
ucinnost[t_,α_,Odklon_]:=Module[{de,m,d,nh,h,vert,ucinnostPohlceni,vlivDoby=0.8},{m,d,nh}=toMDH[t];de[d_]:=-23.5*Cos[((2Pi)/360)*(30*m+d-21)];h[d_,hod_,zs_]:=(360/(2Pi))ArcSin[Sin[((2Pi)/360)de[d]]*Sin[zs((2Pi)/360)]+Cos[((2Pi)/360)de[d]]*Cos[zs((2Pi)/360)]*Cos [((2Pi)/360)15τ[hod]]];vert[hod_]:=(0.5*(1+Sign[h[d,hod,zs]]))*Cos[(h[d,hod,zs]-α)Degree];ucinnostPohlceni[hod_]:=vert[hod]*horiz[hod,Odklon];vlivDoby*ucinnostPohlceni[nh]];
(*vlivDoby se ma doplnit podle ampacity*)
(* α je sklon, 0 je stena, 90 strecha, ve stupnich*)
(*Odklon stupnne od jihu| V+ Z- os normaly, je to parametr steny*)

(*Plot[ucinnost[24*3600t,0,0],{t,(t1/(24*3600)),(t2/(24*3600))},PlotPoints->300,PlotStyle->{Thickness[0.005]},AxesLabel->{"t (day)","ηAbsorbtion  (-)"},GridLines->Automatic]*)

dumOdklon=0;
(*odchylka jizni steny domu od jihu, 0 odpovida smer jih*)
(*Ověření P0*)
 (*
P0x=1367;
Z=4;
H=450;
de[t_]:=-23.5*Cos[((2Pi)/360)*(30+(t/(24*3600))-21)];
SV[t_]=ArcSin[Sin[((2Pi)/360)de[d]]*Sin[zs((2Pi)/360)]+Cos[((2Pi)/360)de[d]]*Cos[zs((2Pi)/360)]*Cos [((2Pi)/360)15*((t/3600)-12)]]
Epsi=((9.38076*(Sin[SV[t]]+(((0.003+(((Sin[SV[t]]))^2)))^0.5)))/(2.0015*(1-H*(10^(-4)))))+0.91018;
P1=1.1*P0x*(E^((-(Z/Epsi))));
*)
P0=1060;
odklonKolektor=0;
sklonKolektor=35;
qZpom[t_]:=P0*ucinnost[t,0,dumOdklon-90];
qS[t_]:=P0*ucinnost[t,0,dumOdklon+180];
qVpom[t_]:=P0*ucinnost[t,0,dumOdklon+90];
qJpom[t_]:=P0*ucinnost[t,0,dumOdklon];qStrechapom[t_]:=P0*ucinnost[t,90,dumOdklon+90];
qKolektorpom[t_]:=P0*ucinnost[t,sklonKolektor,odklonKolektor];
Plot[qJpom[24*3600t]*(1-pokryti[24*3600t]),{t,(t1/(24*3600)),(t2/(24*3600))},PlotPoints->300,PlotStyle->{Thickness[0.005]},AxesLabel->{"t (day)","qZ  (W.(m^(-2)))"},GridLines->Automatic,PlotRange->All]
Plot[P0(1-pokryti[24*3600t]),{t,(t1/(24*3600)),(t2/(24*3600))},PlotPoints->300,PlotStyle->{Thickness[0.005]},AxesLabel->{"t (day)","qPokryti  (W.(m^(-2)))"},GridLines->Automatic,PlotRange->All]

ΔtInterp=0.045hd;
zinterpoluj[co_]:=Module[{dats},dats={#,co[#]*(1-pokryti[#])}&/@Range[t1,t2,ΔtInterp];Interpolation[dats,InterpolationOrder->1]];
qStrecha=zinterpoluj[qStrechapom];
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]

qZ=zinterpoluj[qZpom];
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]

qV=zinterpoluj[qVpom];
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]

qKolektor=zinterpoluj[qKolektorpom];
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]

qJ=zinterpoluj[qJpom];
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]

qSS=zinterpoluj[qS];
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]

dats={qJ,qZ,qSS,qV,qStrecha,qKolektor,teplota};
dats>>"dats";

mydats=<<"dats";
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