function [bin,lab,num,binB,binBB,waveGr]=dummy_jti(name,opt,boxes,num)
%opt(1)=1 onda se pravi kategorija za NaN
%name je ili ime varijable iz data fajla ili vektor
%ukoliko je ime moze biti i vise imena
%opt(3)=1 pravi binB(ase) za svaku varijablu posebno, ovo samo za binarne multiple
%opt(4) oznacava broj nivoa u BlokMultiploj
%opt(5) oznacava selval, ako je NaN onda samo veci od nule !!! OVO ne radi, a ovo je da se okrene sum+ i sum- u nestpars
%opt(6) oznacava da treba da koristi vallab a ne iz frequencies
%opt(7) je whole, ako je 1 racuna na celoj bazi a ne samo na onima koji nisu Nan, th sysmis 
	waveGr = [];
	if isstr(name)
		if ~strcmp(name,"$TOTAL")
			if filter_name~=""
				bin = Data(:,filter_name)~=0;
				if opt(4)>1
					j = size(bin,1);
					x = make(j*opt(4),1,1);
					for i=1:opt(4)
						x(((i-1)*j+1):i*j)=bin;
					end
					bin = x;
				end
			else
				bin = ones(ncase*opt(4),1);
			end
			binB = bin;
			binBB = bin;
			lab = "Total";
			num = 1;
		else
			if opt(4)>1
				if DataIsMultiple(name)
					name1 = GetVarName(name);
					x = make(ncase*opt(4),1,1);
					for i=1:opt(4)
						x(((i-1)*ncase+1):i*ncase)=Data(:,name1(i));
					end
				else
					if (~vext(name))
						error("Variable '"+name+"' is not existing in database")
					end
					x = Data(:,name);
					x = make(opt(4),1,x);
					%for i=1:opt(4)
					%	x(((i-1)*ncase+1):i*ncase)=Data(:,name);
					%end
				end
			else
				if left(name,1)~="$"
					if (~vext(name))
						error("Variable '"+name+"' is not existing in database")
					end
				end
				x = Data(:,name);
			end
			if any(DataIsMultiple(name)==2)
				if opt(7)
					binBB = ones(size(x));
				elseif opt(3)
					binBB = x~=NaN;
				else
					binBB = rsum(x~=NaN)>0;
					binBB = make(1,size(x,2),binBB);
				end
				bin = find(x==NaN);
				if any(bin)
					x(bin) = 0;
				end
				bin = x;
				names = GetVarName(name);
				lab = GetVarLabel(names);
				f=find(~strcmp(lab,""));
				if (any(f))
					lab(f)=names(f);
				end
				num = 1:max(size(lab));
			else
				if ~def(num)
					[num,f]=freq(x);
				end
				a=size(num,1);
				if a & num(a)==NaN & opt(1)==0
					num(a)=[];
					a=a-1;
				end
				if opt(6)==1
					[lab, num1] = GetNumLabel(GetVarName(name));
					ind = find((num in num1')==0);
					if ind~=[]
						lab = [lab;num2str("%0.2f",num(ind))];
						num = [num1;num(ind)];
						if (num(a)==NaN)
							lab(a) = "Missing";
						end
					else
						num = num1;
					end
				end

				%[num,f]=freq(x);
				if size(x,1)==0
					DataSelect();
					error("No valid cases on '"+name+"' variable, or no selected cases");
				end
				if ~a
					bin = zeros(size(x,1),1);
					binB= make(size(x,1),1,1);
					binBB= make(size(x,1),1,1);
					lab = "Empty variable - " + name(1);
					num = Inf;
				else
					bin = zeros(size(x,1),a);
					if opt(6)==1
						for i=1:a
							bin(:,i) = rsum(x==num(i));
						end
					else
						lab = make(a,1,"");
						for i=1:a
							bin(:,i) = rsum(x==num(i));
							pomlab = GetNumLabel(GetVarName(name),num(i));
							f = find(strcmp(pomlab,""));
							if (any(f))
								lab(i) = pomlab(f(1));
							elseif num(i)==NaN
								lab(i) = "Missing";
							else
								lab(i)=num2str("%0.2f",num(i));
							end
						end
					end
					if size(boxes,2)>1
						m = max(size(boxes));
						m =  (m-mod(m,4))/4;
						labBox = make(m,1,"");
						binBox = zeros(size(x,1),m);
						
						for i=1:m
							labBox(i) = boxes((i-1)*4+1);
							binBox(:,i) = (x>=str2num(boxes((i-1)*4+2))) & (x<=str2num(boxes((i-1)*4+4)));
						end
						lab = [lab;labBox];
						bin = [bin,binBox];
						num = [num;zeros(m,1)];
						a = a+m;
					end
					if left(name,1)~="@"
						%binBB = make(1,a,rsum(bin)>0);
						if opt(1) | opt(7)
						%if opt(1)==0
							binBB = make(size(x,1),a,1);
						else
							binBB = make(1,a,rsum(x~=NaN)>0);
						end
					else
						binBB = bin;
					end
				end
				
				global gWave
				if (name==gWave)
					waveGr = size(bin,2);
				end
			end
		end
	else
		[num,f]=freq(name);
	    a=max(size(num));
	    if num(a)==NaN
	    	num(a)=[];
	  		a=a-1;
	  	end
		if size(name,2)==1
			bin = zeros(size(name,1),a);
			for i=1:a
				bin(:,i) = (name==num(i));
			end
			binB = make(1,a,rsum(bin)>0);
		elseif size(name,1)==1
			bin = zeros(a,size(name,2));
			for i=1:a
				bin(i,:) = (name==num(i));
			end
			binB = make(a,1,csum(bin)>0);
		else
			error("Argument for function 'dummy' has to be a vector")
		end
	end

	global Selector
	if Selector~=[]
		bin = bin & Selector;
		binB = binBB & Selector;
	else
		binB = binBB;
	end
end