# ESTtalaKrmus.m
function Sj=ESTtalaKrmus(baasi0,xx,Li,Fjoud,qkoormus,EI)
#
#  computed a loading vector for uniformly distributed load 
#  and point load (q + F) for a beam
#  EI -- bending stiffness of the element
#  baasi0 -- scaling multiplier for the displacements (i = EJ/l)
#
##=========================================================================
## This Program is written by Andres Lahe,    2006-02-25
##                    e-mail: andres.lahe@ttu.ee
## LAST MODIFIED: Andres Lahe,    2010-08-05
## Copyright (c)  2006  by Tallinn University of Technology 
##                Department of Mechanics
##                http://www.ttu.ee/
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 2
## of the License, or (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
## http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
##========================================================================= 
#
#Li        # length of member
#Fjoud     # point load and distance of a load point  from start point
#qkoormus  # uniformly distributed load 
####
l=Li;
#==========
# Point load and distance of a load point  from start point
#       F         aF
#==========
#Fjoud=[0.0    0.0;	# force 1
#	 0.0    0.0;	# force 2
#	 0.0    0.0;	# force 3
#	 0.0    0.0;	# force 4
#	 0.0    0.0];	# force 5
#==========
#==========
# Uniformly distributed load and distances of start point and end point
#       qz         qA         qL
#==========
#qkoormus=[0.0     0.0   0.0   0.0;	# uniformly distributed load qz1
#          0.0     0.0   0.0   0.0;	# uniformly distributed load qz2
#          0.0     0.0   0.0   0.0];	# uniformly distributed load qz3
#==========
Fjoud;
qkoormus;
 eps1=0.000001;
FARV=size(Fjoud);
NFARV=FARV(1,1);
#
F1=Fjoud(1,1);
AF1=abs(F1);
FjouduS=size(Fjoud);
Fjoudu=FjouduS(1,1);
FZZZ=Fjoud(:,1);
FZZ=find(FZZZ);
FZY=size(FZZ);
Fjoudu=FZY(1,1);
##%http://www.network-theory.co.uk/docs/octave3/octave_87.html
if (AF1-eps1) > 0
switch (Fjoudu);
case{1}
Fz=Fjoud(1,1);
aLx=Fjoud(1,2);
vFz=yzTfzv(baasi0,xx,aLx,Fz,EI);
case{2}
Fz1=Fjoud(1,1);
aLx1=Fjoud(1,2);
vFz1=yzTfzv(baasi0,xx,aLx1,Fz1,EI);
Fz2=Fjoud(2,1);
aLx2=Fjoud(2,2);
vFz2=yzTfzv(baasi0,xx,aLx2,Fz2,EI);
vFz=vFz1+vFz2;
case{3}
Fz1=Fjoud(1,1);
aLx1=Fjoud(1,2);
vFz1=yzTfzv(baasi0,xx,aLx1,Fz1,EI);
Fz2=Fjoud(2,1);
aLx2=Fjoud(2,2);
vFz2=yzTfzv(baasi0,xx,aLx2,Fz2,EI);
Fz3=Fjoud(3,1);
aLx3=Fjoud(3,2);
vFz3=yzTfzv(baasi0,xx,aLx3,Fz3,EI);
vFz=vFz1+vFz2+vFz3;
case{4}
Fz1=Fjoud(1,1);
aLx1=Fjoud(1,2);
vFz1=yzTfzv(baasi0,xx,aLx1,Fz1,EI);
Fz2=Fjoud(2,1);
aLx2=Fjoud(2,2);
vFz2=yzTfzv(baasi0,xx,aLx2,Fz2,EI);
Fz3=Fjoud(3,1);
aLx3=Fjoud(3,2);
vFz3=yzTfzv(baasi0,xx,aLx3,Fz3,EI);
Fz4=Fjoud(4,1);
aLx4=Fjoud(4,2);
vFz4=yzTfzv(baasi0,xx,aLx4,Fz4,EI);
vFz=vFz1+vFz2+vFz3+vFz4;
case{5}
Fz1=Fjoud(1,1);
aLx1=Fjoud(1,2);
vFz1=yzTfzv(baasi0,xx,aLx1,Fz1,EI);
Fz2=Fjoud(2,1);
aLx2=Fjoud(2,2);
vFz2=yzTfzv(baasi0,xx,aLx2,Fz2,EI);
Fz3=Fjoud(3,1);
aLx3=Fjoud(3,2);
vFz3=yzTfzv(baasi0,xx,aLx3,Fz3,EI);
Fz4=Fjoud(4,1);
aLx4=Fjoud(4,2);
vFz4=yzTfzv(baasi0,xx,aLx4,Fz4,EI);
Fz5=Fjoud(5,1);
aLx5=Fjoud(5,2);
vFz5=yzTfzv(baasi0,xx,aLx5,Fz5,EI);
vFz=vFz1+vFz2+vFz3+vFz4+vFz5;
##?otherwise
endswitch
else
# disp(' Koondatud force puudub  '); 
vFz=[0.0; 0.0; 0.0; 0.0];
endif

##%%%%%%%%%%%%%%%%%%%%
qzv=qkoormus(1,1);
Aq1=abs(qzv);
qZZZ=qkoormus(:,1);
qZZ=find(qZZZ);
qZY=size(qZZ);
qARV=qZY(1,1);
#
if (Aq1-eps1) > 0
switch (qARV)
case{1}
qz=qkoormus(1,1);
aqA=qkoormus(1,2);
Li=qkoormus(1,3); # aqL -kui koormus lõppeb enne lõppu
# Li=qkoormus(1,4); # varda lõpp (vaja kohendada)
if (xx-aqA) >= eps
xarv=xx-aqA;
vB=yzThqz(baasi0,xarv,qz,EI);
else
vB(1,1)=0.0;
vB(2,1)=0.0;
vB(3,1)=0.0;
vB(4,1)=0.0;
# vB(1:4,1);
endif
#q0(1,1)=i0*qz*x^4/(24*EJ);
#Zq0(2,1)=-i0*qz*x^3/(6*EJ);
#Zq0(3,1)=-qz*x;
#Zq0(4,1)=-qz*x^2/2;
#  vaja lisada juht kui koormus lõppeb enne lõppu
case{2}
qz1=qkoormus(1,1);
Li1=qkoormus(1,3);
vB1=yzThqz(baasi0,xx,qz1,EI);
qz2=qkoormus(2,1);
Li2=qkoormus(2,3);
vB2=yzThqz(baasi0,xx,qz2,EI);
vB=vB1+vB2;
case{3}
qz1=qkoormus(1,1);
Li1=qkoormus(1,3);
vB1=yzThqz(baasi0,xx,qz1,EI);
qz2=qkoormus(2,1);
Li2=qkoormus(2,3);
vB2=yzThqz(baasi0,xx,qz2,EI);
qz3=qkoormus(3,1);
Li3=qkoormus(3,3);
vB3=yzThqz(baasi0,xx,qz3,EI);
vB=vB1+vB2+vB3;
case{4}
qz1=qkoormus(1,1);
Li1=qkoormus(1,3);
vB1=yzThqz(baasi0,xx,qz1,EI);
qz2=qkoormus(2,1);
Li2=qkoormus(2,3);
vB2=yzThqz(baasi0,xx,qz2,EI);
qz3=qkoormus(3,1);
Li3=qkoormus(3,3);
vB3=yzThqz(baasi0,xx,qz3,EI);
qz4=qkoormus(4,1);
Li4=qkoormus(4,3);
vB4=yzThqz(baasi0,xx,qz4,EI);
vB=vB1+vB2+vB3+vB4;
##?otherwise
endswitch
else
# disp(' Jaotatud koormus puudub  '); 
vB=[0.0; 0.0; 0.0; 0.0];
endif
##%%%%%%%%%%%%%
#vB=yzThqz(baasi0,xx,qz,EI);    
#vFz=yzTfzv(baasi0,xx,aLx,Fz,EI);  #yzfzv(baasi0,Li,aLx,Fx,Fz,EA,EI);
#vB=vB+vFz;
##%%%%%%%%%%%%%
vBs=vB+vFz;
Sj=vBs;
#
endfunction
