h_1 = WndCreat ([], "RIM Weighting", [NaN,NaN,406,150], 2);

CtrCreat (h_1, 510, [9,10,200,13], "Name of the data file for weighting");
h_2 = CtrCreat (h_1, 410, [9,24,320,20], "");
CtrCreat (h_1, 110, [334,24,58,20], "Browse ...","f=FileOpenDialog(h_1);if (strlen(f));CtrSet(h_2,f);end;");

CtrCreat (h_1, 510, [9,50,200,13], "Name of the data file with margins");
h_3 = CtrCreat (h_1, 410, [9,64,320,20], "");
CtrCreat (h_1, 110, [334,64,58,20], "Browse ...","f=FileOpenDialog(h_1);if (strlen(f));CtrSet(h_3,f);end;");

CtrCreat (h_1, 110, [228,95,48,23], "OK","nf1 = CtrGet(h_3);nf2 = CtrGet(h_2);if (strlen(nf1) & strlen(nf2));WndClose(h_1);rim_m1;end;");
CtrCreat (h_1, 110, [281,95,48,23], "Cancel","WndClose(h_1);");


global macro rim_m1
	DataOpen(nf1)
	for i=1:nvar/2
		mar#i=Data(:,i*2-1:i*2);
		p=mar#i;pp=p(:,1);
		c=find(pp==NaN);
		if c~=[]
			p(c,:)=[];
			mar#i=p;
		end
	end
	%imena varijabli, tj margina po kojima se ponderise
	marvar=GetVarName(2:nvar:2)';
	brdim=nvar/2;
	
	DataOpen(nf2) %dodati koji fajl
	
	%provera da li postoje varijable u fajlu kao u mar-u
	%i ciscenje modaliteta koji nisu ostvareni u podacima
	vars=GetVarName(1:nvar);
	c=zeros(brdim,1);
	for i=1:brdim
		c(i)=sum(~strcmp(vars,marvar(i)));
	end
	c=find(~c);
	if c~=[]
		marvar(c)=[];
		if ~min(size(marvar))
			error("U fajlu nema ni jedna varijabla sa imenom margina")
		end
		k=1:brdim;
		k(c)=[];
		brdim=max(size(k));
		for j=1:brdim
			mar#(j)=mar#(k(j));
		end
	end
	for i=1:brdim
		j=find(~strcmp(vars,marvar(i)));
		if j~=[]
			vars(j)=[];
		end
	end
	if wgh~=[]
		j=find(~strcmp(vars,wgh_name));
		vars(j)=[];
	end
	rim_w2
end