function som_gui(varargin)
%SOM_GUI is a GUI for initialization and training of SOM and it is 
%based on somtoolbox version 2.0 
%
%som_gui;
%som_gui([sD]);
%
%INPUT ARGUMENT ([]'s optional) 
%
%[sD]  (struct) SOM data struct
%
%NOTE! There are several internal actions, but DO NOT activate GUI with them.
%     
%OUTPUT ARGUMENTS
%
%[handle]  (handle) to the GUI figure.
%
%[HANDLE] = SOM_GUI([DATA])  activates an figure where you can initialize and 
%train SOM 
%
%See also PREPROCESS SOM_VIS_GUI



global NEWMAP NEWST MAPSAVED MAP DATA  LOAD_NAME LOAD_DATA;
global SAVEMAP ALGORITHM HANDLE2 STOPOLINIT INIT_TYPE;
global STRAIN1 STRAIN2 SOTHERS;


if nargin == 0
  main_gui;
  action = 'dummy';	
elseif nargin == 1
   temp = varargin{1};
   if isstruct(temp);
      DATA = temp;
      main_gui;
      action = 'input_data';
   else
     action = temp;			
   end
end 

switch(action)
  case 'jump_loadgui3'
     loadgui3;		
  case 'load_data'
     loadgui3;
  case 'workspace_edit'
     Handle = findobj(gcbf,'Tag','EditText2');
     set(Handle,'String','');
  case 'file_edit'
     Handle = findobj(gcbf,'Tag','EditText1');
     set(Handle,'String','');
  case 'workspace'
       Handle = findobj(gcbf,'Tag','Radiobutton2');
       Value = get(Handle,'Value');
       HandleTemp = findobj(gcbf,'Tag','Radiobutton1');
       if Value == 1	
          set(HandleTemp,'Value',0);
          HandleBar = findobj(gcbf,'Tag','PopupMenu1');
          set(HandleBar,'Enable','off');
	  set(HandleBar,'Visible','off');
	  Handle3 = findobj(gcbf,'Tag','StaticText3');
	  set(Handle3,'Visible','off');
	  Handle3 = findobj(gcbf,'Tag','Checkbox1');
	  set(Handle3,'Visible','off');
	  Handle3 = findobj(gcbf,'Tag','EditText3');
	  set(Handle3,'Visible','off');
	  Handle = findobj(gcbf,'Tag','EditText2');
	  set(Handle,'String','');
	end
  case 'file'
       Handle = findobj(gcbf,'Tag','Radiobutton1');
       Value = get(Handle,'Value');
       HandleTemp = findobj(gcbf,'Tag','Radiobutton2');
       if Value == 1
          set(HandleTemp,'Value',0);
          HandleBar = findobj(gcbf,'Tag','PopupMenu1');
          set(HandleBar,'Enable','on');
	  set(HandleBar,'Visible','on');
	  Handle3 = findobj(gcbf,'Tag','StaticText3');
	  set(Handle3,'Visible','on');
	  Handle3 = findobj(gcbf,'Tag','Checkbox1');
	  set(Handle3,'Visible','on');
	  Handle3 = findobj(gcbf,'Tag','EditText3');
	  set(Handle3,'Visible','on'); 
	  Handle = findobj(gcbf,'Tag','EditText1');
	  set(Handle,'String','');
	end
  case 'file_select'
	Handle = findobj(gcbf,'Tag','PopupMenu1');
	temp = get(Handle,'String');
	val = get(Handle,'Value');
	Handle1 = findobj(gcbf,'Tag','Checkbox1');
	Handle2 = findobj(gcbf,'Tag','EditText3');
	if strcmp(temp{val},'dat file')
	   set(Handle2,'String','x');
	   set(Handle1,'Enable','on');
	   set(Handle2,'Enable','on');
	   set(Handle1,'Visible','on');
	   set(Handle2,'Visible','on');
	else 
	   set(Handle1,'Value',0);
           set(Handle1,'Enable','off');
	   set(Handle2,'Enable','off');
	   set(Handle1,'Visible','off');
	   set(Handle2,'Visible','off');
	end
  case 'missing'
       Handle = findobj(gcf,'Tag','Checkbox1');
       set(Handle,'Value',1);	
  case 'load_ok'
     Handle1 = findobj(gcbf,'Tag','EditText1');
     Handle2 = findobj(gcbf,'Tag','EditText2');
     Name1 = get(Handle1,'String');
     Name2 = get(Handle2,'String');
     if isempty(Name1) & not(isempty(Name2))
	Handle = findobj(gcbf,'Tag','PopupMenu1');
	type = get(Handle,'String');
	val = get(Handle,'Value');
	type = type{val};
	if strcmp(type,'mat file')
	    ltemp = 'load:::';
	    ltemp = strcat(ltemp,Name2);
            ltemp = strrep(ltemp,':::',' ');
	    evalin('base',ltemp);
	    DATA = evalin('base','sD');
	    LOAD_DATA = evalin('base','sD.data');
	    LOAD_NAME = evalin('base','sD.name');
	    LOAD_NAME = strrep(LOAD_NAME,'.','_');
	    load_labels = evalin('base','sD.labels');
	    load_comp_names = evalin('base','sD.comp_names');
	    DATA = som_data_struct(LOAD_DATA);
	    DATA.name = LOAD_NAME;
	    DATA.comp_names = load_comp_names;
	    DATA.labels = load_labels;
	else
	   Handle = findobj(gcbf,'Tag','Checkbox1');
	   value = get(Handle,'Value');
	   if value == 0	
	     temp = 'som_read_data(''';
	     temp = strcat(temp,Name2,''');');
	   else 
	     Handle = findobj(gcbf,'Tag','EditText3');
	     missing = get(Handle,'String');
	     if not(isempty(missing))
		temp = 'som_read_data(''';
	        temp = strcat(temp,Name2,'''',',','''',missing,''');');
	     else
		temp = 'som_read_data(''';
	        temp = strcat(temp,Name2,''');');
 	     end
	   end	
	   evalin('base',temp);
	   DATA = evalin('base','ans');
	   name = DATA.name;
	   temp = findstr('/',name);
	   if not(isempty(temp))	
	   	name = name(temp(end)+1:end);
	   end
           name = strrep(name,'.','_');		
	   LOAD_NAME = name;
	   DATA.name = name;	
	end
     elseif isempty(Name2) & not(isempty(Name1))
	LOAD_DATA = evalin('base',Name1);
	if not(isstruct(LOAD_DATA))
          DATA = som_data_struct(LOAD_DATA);
	  LOAD_NAME = Name1;
	  DATA.name = Name1;
	else
	  DATA = LOAD_DATA;
	  name = DATA.name;
	  temp = findstr('/',name);
	  if not(isempty(temp))	
	     name = name(temp(end)+1:end);
	   end
           name = strrep(name,'.','_');		
	   LOAD_NAME = name;
	   DATA.name = name;
	end
     else 
	errmsg = {'Give name of data before loading'};
	errordlg(errmsg,'Empty data name!');
	return;
     end
     close(gcbf);			     			
     if not(isempty(MAP))
	clear MAP;
        global MAP;
	str1 = 'Map:  <empty>';
	str2 = 'Train'
	Handle = findobj(gcf,'Tag','StaticText3');
	set(Handle,'String',str1);
	Handle = findobj(gcf,'Tag','StaticText8');
	set(Handle,'String',str2);
      end	
      temp =  'Data:';
      temp = strcat(temp,' <',LOAD_NAME,'>');	
      Handle = findobj(gcf,'Tag','StaticText4');
      set(Handle,'String',temp);
      som_gui('def_initialization');
      Handle = findobj(gcf,'Tag','Pushbutton2');
      set(Handle,'Enable','off');
      Handle = findobj(gcf,'Tag','Pushbutton4');
      set(Handle,'Enable','on');
      Handle = findobj(gcf,'Tag','Pushbutton9');
      set(Handle,'Enable','on');
      Handle = findobj(gcf,'Tag','Subuimenu2');
      set(Handle,'Enable','on');
      Handle = findobj(gcf,'Tag','&Help/InfoHelp windowuimenu1');
      set(Handle,'Enable','on');
      Handle = findobj(gcf,'Tag','&Init&Trainuimenu1');
      set(Handle,'Enable','on');
      Handle = findobj(gcf,'Tag','&Init&TrainInitialize1');
      set(Handle,'Enable','on');
      Handle = findobj(gcf,'Tag','Subuimenu1');
      set(Handle,'Enable','off'); %%%%%%????????	
      Handle = findobj(gcf,'Tag','StaticText10');
      set(Handle,'String','Status <data loaded>');	
  case 'input_data' 
	name = DATA.name;
        newname = strrep(name,'.','_');
	DATA.name = newname;
	temp = strcat('Data:  <',newname,'>');	
	Handle = findobj(gcf,'Tag','StaticText4');
      	set(Handle,'String',temp);
	som_gui('def_initialization');
      	Handle = findobj(gcf,'Tag','Pushbutton2');
      	set(Handle,'Enable','off');
      	Handle = findobj(gcf,'Tag','Pushbutton4');
      	set(Handle,'Enable','on');
      	Handle = findobj(gcf,'Tag','Pushbutton9');
      	set(Handle,'Enable','on');
      	Handle = findobj(gcf,'Tag','Subuimenu2');
      	set(Handle,'Enable','on');
      	Handle = findobj(gcf,'Tag','&Help/InfoHelp windowuimenu1');
      	set(Handle,'Enable','on');
      	Handle = findobj(gcf,'Tag','&Init&Trainuimenu1');
      	set(Handle,'Enable','on');
      	Handle = findobj(gcf,'Tag','&Init&TrainInitialize1');
      	set(Handle,'Enable','on');
     	Handle = findobj(gcf,'Tag','Subuimenu1');
      	set(Handle,'Enable','off'); %%%%%%????????	
     	Handle = findobj(gcf,'Tag','StaticText10');
      	set(Handle,'String','Status <data loaded>');	
  case 'def_initialization'
	sTopol = som_topol_struct('data',DATA);
	Handle = findobj(gcf,'Tag','StaticText5');
	temp = num2str(sTopol.msize);
	temp = strcat('map size:',' [',temp,']');
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText6');	
	set(Handle,'String','type: linear');
	Handle = findobj(gcf,'Tag','StaticText20');
	temp = strcat('lattice:',sTopol.lattice);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText21');
	temp = strcat('shape:',sTopol.shape);
	set(Handle,'String',temp);
        STOPOLINIT = sTopol;
        INIT_TYPE = 'linear';
  case 'change_initialization'
	initialization2;
	Handle = findobj(gcf,'Tag','PopupMenu1');	
	temp = get(Handle,'String');
	val = loop(temp,INIT_TYPE);
	set(Handle,'Value',val);
	Handle = findobj(gcf,'Tag','PopupMenu2');	
	temp = get(Handle,'String');
	val = loop(temp,STOPOLINIT.lattice);
	set(Handle,'Value',val);
	Handle = findobj(gcf,'Tag','PopupMenu3');	
	temp = get(Handle,'String');
	val = loop(temp,STOPOLINIT.shape);
	set(Handle,'Value',val);
	Handle = findobj(gcf,'Tag','EditText1');	
	temp = num2str(STOPOLINIT.msize);
        msize = strcat('[',temp,']');
	set(Handle,'String',msize);
  case 'change_initialization_ok'
	Handle = findobj(gcbf,'Tag','PopupMenu1');
	temp = get(Handle,'String');
	val = get(Handle,'Value');
	INIT_TYPE = temp{val};
	Handle = findobj(gcbf,'Tag','PopupMenu2');
	temp = get(Handle,'String');
	val = get(Handle,'Value');	
	lattice = temp{val};
	Handle = findobj(gcbf,'Tag','PopupMenu3');
	temp = get(Handle,'String');
	val = get(Handle,'Value');	
	shape = temp{val};
	Handle = findobj(gcbf,'Tag','EditText1');
	temp = get(Handle,'String');
	msize = str2num(temp);
	STOPOLINIT = som_set('som_topol','msize',msize,'lattice',lattice,'shape',shape);
	close(gcf);
	Handle = findobj(gcf,'Tag','StaticText5');
	temp = num2str(STOPOLINIT.msize);
	temp = strcat('map size:',' [',temp,']');
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText6');
	temp = strcat('type:',INIT_TYPE);	
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText20');
	temp = strcat('lattice:',STOPOLINIT.lattice);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText21');
	temp = strcat('shape:',STOPOLINIT.shape);
	set(Handle,'String',temp);
  case 'change_initialization_cancel'
	close(gcf);
	return;
  case 'def_values_others'
	Handle = findobj(gcf,'Tag','StaticText19');
	temp = strcat('tracking:',SOTHERS.tracking);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText12');
	temp = strcat('order:',SOTHERS.oder);
	set(Handle,'String',temp); 
	Handle = findobj(gcf,'Tag','StaticText14');
	temp = strcat('length_type:',SOTHERS.length_type);
	set(Handle,'String',temp);
  case 'def_values_train'
 	STRAIN1 = som_train_struct(ALGORITHM,'data',DATA);
	STRAIN2 = som_train_struct('previous',STRAIN1);
  case 'fill_fields'
	neigh = STRAIN1.neigh;
	mask = STRAIN1.mask;
	rad_ini1 = STRAIN1.radius_ini;
	rad_ini2 = STRAIN2.radius_ini;
	rad_fin1 = STRAIN1.radius_fin;
	rad_fin2 = STRAIN2.radius_fin;
	trainlen1 = num2str(STRAIN1.trainlen);
	trainlen2 = num2str(STRAIN2.trainlen);
	alpha_ini1 = num2str(STRAIN1.alpha_ini);
	alpha_ini2 = num2str(STRAIN2.alpha_ini);
	if strcmp(ALGORITHM,'seq')
        	alpha_type = STRAIN1.alpha_type; %%% only in sequential
        	Handle = findobj(gcf,'Tag','StaticText28');
	        temp = strcat('alpha type:',alpha_type);
	        set(Handle,'String',temp);
	end
	Handle = findobj(gcf,'Tag','StaticText11');
	temp = strcat('neigh: ',neigh);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText22');
	temp = num2str(rad_fin1);
	temp = strcat('radius final:',temp);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText25');
	temp = num2str(rad_fin2);
	temp = strcat('radius final:',temp);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText11');
	temp = strcat('neigh: ',neigh);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText17');
	temp = num2str(rad_ini1);
	temp = strcat('radius initial:',temp);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText24');
	temp = num2str(rad_ini2);
	temp = strcat('radius initial:',temp);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText16');
	temp = num2str(trainlen1);
	temp = strcat('training length:',temp);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText23');
	temp = num2str(trainlen2);
	temp = strcat('training length:',temp);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText26');
	temp = strcat('alpha initial:',alpha_ini1);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText27');
	temp = strcat('alpha initial:',alpha_ini2);
	set(Handle,'String',temp);
  case 'browse'	
	HandleWorkspace = findobj(gcbf,'Tag','Radiobutton2');
	HandleFile = findobj(gcbf,'Tag','Radiobutton1');
	WorkspaceVal = get(HandleWorkspace,'Value');
	FileVal = get(HandleFile,'Value');
	if FileVal == 1
	   Handle = findobj(gcbf,'Tag','PopupMenu1');
	   str = get(Handle,'String');
	   value = get(Handle,'Value');
	   str = str{value};
	   if strcmp(str,'mat file')
	      filtter = '*.mat';
	   else
	      filtter = '*.dat*';
	   end 
	   [filename pathname] = uigetfile(filtter,'Load file.');
	   temp = strcat(pathname,filename);
	   Handle = findobj(gcbf,'Tag','EditText2');
	   set(Handle,'String',temp);
	elseif WorkspaceVal == 1
	   HANDLE2 = gcf;
	   works;
	   temp = evalin('base','who');
	   index2 = 1;

	   for index = 1:length(temp)
	      if isnumeric(evalin('base',temp{index}))
		test = size(evalin('base',temp{index}));
		if test(1) ~= 1 & test(2) ~= 1
		   names{index2} = temp{index};	
		   index2 = index2 + 1;
		end
	      end
	   end
		
	   for index = 1:length(temp)
		variable = evalin('base',temp{index});
		if isstruct(variable)
		   fnames = fieldnames(variable);
		   if size(fnames,1) == 6 & strcmp(fnames(1),'type') & strcmp(variable.type,'som_data')
		     names{index2} = temp{index};	
		     index2 = index2 + 1;
		   end	
	        end 
	   end		
	   Handle = findobj(gcf,'Tag','Listbox1');
	   set(Handle,'String',names);
	else
	   errmsg = 'Select browse type: Workspace or file.';
	   errordlg(errmsg,'Browse error!');
	   return;
	end
  case 'works_ok'
	Handle = findobj(gcbf,'Tag','Listbox1');
	temp = get(Handle,'String');
	val = get(Handle,'Value');
	data = temp{val};
	Handle = findobj(HANDLE2,'Tag','EditText1');
	set(Handle,'String',data);
	close;
  case 'works_cancel'
	close;
  case 'load_cancel'
	close;	
  case 'init'			
     if strcmp(INIT_TYPE,'random')
	  MAP = som_randinit(DATA,STOPOLINIT);
     else 
	  MAP = som_lininit(DATA,STOPOLINIT);
     end
     NEWMAP = MAP;	
     temp = 'Map:';
     temp = strcat(temp,' <',MAP.name,'>');
     Handle = findobj(gcbf,'Tag','StaticText3');
     set(Handle,'String',temp);
     Handle = findobj(gcbf,'Tag','StaticText10');
     set(Handle,'String','Status <map initialized>');
     ALGORITHM = 'batch';
     Handle = findobj(gcbf,'Tag','Pushbutton4');
     set(Handle,'Enable','off');
     Handle = findobj(gcbf,'Tag','Pushbutton6');
     set(Handle,'Enable','on');
     Handle = findobj(gcbf,'Tag','Pushbutton5');
     set(Handle,'Enable','on');		
     SOTHERS.tracking = '1';
     SOTHERS.length_type = 'epochs';
     SOTHERS.oder = 'random';			
     som_gui('def_values_topol');
     som_gui('def_values_train');
     som_gui('def_values_others');
     som_gui('fill_fields');
     Handle = findobj(gcbf,'Tag','Pushbutton4');
     set(Handle,'Enable','off');
     Handle = findobj(gcbf,'Tag','Pushbutton9');
     set(Handle,'Enable','off');
     Handle = findobj(gcbf,'Tag','Radiobutton1');
     set(Handle,'Enable','on');
     Handle = findobj(gcbf,'Tag','&Init&TrainChange initialization valuesuimenu1');
     set(Handle,'Enable','on');
     Handle = findobj(gcbf,'Tag','&Init&TrainTrain1');
     set(Handle,'Enable','on');
     Handle = findobj(gcbf,'Tag','&Help/InfoData infouimenu1');
     set(Handle,'Enable','on');	
     Handle = findobj(gcbf,'Tag','Subuimenu2');
     set(Handle,'Enable','off');
     Handle = findobj(gcbf,'Tag','&Init&Trainuimenu1');
     set(Handle,'Enable','off');
     Handle = findobj(gcbf,'Tag','&Init&TrainInitialize1');
     set(Handle,'Enable','off');  %%%%%%%%%%%??????????			
     Handle = findobj(gcbf,'Tag','StaticText9');
     set(Handle,'String','training type: batch');	
  case 'def_train'
     tlen_type = SOTHERS.length_type;
     sample_order = SOTHERS.oder;	
     tracking = SOTHERS.tracking;
     test = str2num(tracking);
     Handle = findobj(gcbf,'Tag','Radiobutton1');
     tempval = get(Handle,'Value');
     if strcmp(ALGORITHM,'seq')
	if tempval ~= 1
     	   [MAP NEWST] = som_seqtrain(MAP,DATA,'train',STRAIN1,tlen_type,sample_order);
	end
	if test > 1
		figure;
		set(gcf,'Name',MAP.name);
	        set(gcf,'NumberTitle','off');
	end
	[NEWMAP NEWST] = som_seqtrain(MAP,DATA,'train',STRAIN2,'tracking',test,tlen_type,sample_order); 
     else
	if tempval ~= 1
	   [MAP NEWST] = som_batchtrain(MAP,DATA,'train',STRAIN1);
	end
	if test > 1
	   figure;
	   set(gcf,'Name',MAP.name);
	   set(gcf,'NumberTitle','off');
	end
	   [NEWMAP NEWST] = som_batchtrain(MAP,DATA,'train',STRAIN2,'tracking',test);
     end
     MAP = NEWMAP;
     clear MAPSAVED;	
     Handle = findobj(gcbf,'Tag','StaticText10');
     set(Handle,'String','Status <map trained>');
     Handle = findobj(gcbf,'Tag','Load/SaveSubuimenu1');
     set(Handle,'Enable','on');		
     Handle = findobj(gcbf,'Tag','Load/SaveSave mapuimenu1');
     set(Handle,'Enable','on');	 
     Handle = findobj(gcbf,'Tag','&Load/SaveSave mapSave in workspaceuimenu1');
     set(Handle,'Enable','on');
     Handle = findobj(gcbf,'Tag','&ToolsSubuimenu1');
     set(Handle,'Enable','on');
     Handle = findobj(gcbf,'Tag','&Init&TrainChange initialization valuesuimenu1');
     set(Handle,'Enable','off');
     Handle = findobj(gcbf,'Tag','&Init&TrainTrain1');
     set(Handle,'Enable','off');			
  case 'clear_all'
	Handle = findobj(gcbf,'Enable','off');
	set(Handle,'Enable','on');
	Handle = findobj(gcbf,'Tag','Radiobutton1');
	set(Handle,'Value',0);
	Handle = findobj(gcbf,'Tag','StaticText10');
	set(Handle,'String','Status <no action>');
	Handle = findobj(gcbf,'Tag','StaticText3');
	set(Handle,'String','Map: <empty>');
	Handle = findobj(gcbf,'Tag','StaticText4');
	set(Handle,'String','Data: <empty>');
	Handle = findobj(gcbf,'Tag','StaticText20');
	set(Handle,'String','lattice:');
	Handle = findobj(gcbf,'Tag','StaticText11');
	set(Handle,'String','neigh:');
	Handle = findobj(gcbf,'Tag','StaticText16');
	set(Handle,'String','training length:');
	Handle = findobj(gcbf,'Tag','StaticText23');
	set(Handle,'String','training length:');	
	Handle = findobj(gcbf,'Tag','StaticText17');
	set(Handle,'String','radius initial:');
	Handle = findobj(gcbf,'Tag','StaticText24');
	set(Handle,'String','radius initial:');
	Handle = findobj(gcbf,'Tag','StaticText5');
	set(Handle,'String','map size:');
	Handle = findobj(gcbf,'Tag','StaticText21');
	set(Handle,'String','shape:');
	Handle = findobj(gcbf,'Tag','StaticText12');
	set(Handle,'String','order:');
	set(Handle,'Visible','off');
	Handle = findobj(gcbf,'Tag','StaticText14');
	set(Handle,'String','length type:');
	set(Handle,'Visible','off');
	Handle = findobj(gcbf,'Tag','StaticText22');
	set(Handle,'String','radius final:');
	Handle = findobj(gcbf,'Tag','StaticText25');
	set(Handle,'String','radius final:');
	Handle = findobj(gcbf,'Tag','StaticText19');
	set(Handle,'String','tracking:');
	Handle = findobj(gcbf,'Tag','StaticText7');
	set(Handle,'String','Initialization');
	Handle = findobj(gcbf,'Tag','StaticText28');
	set(Handle,'String','alpha type:');
	set(Handle,'Visible','off');
	Handle = findobj(gcbf,'Tag','StaticText26');
	set(Handle,'String','alpha initial:');
	Handle = findobj(gcbf,'Tag','StaticText27');
	set(Handle,'String','alpha initial:');
	Handle = findobj(gcbf,'Tag','StaticText6');
	set(Handle,'String','type:');
	Handle = findobj(gcbf,'Tag','StaticText9');
	set(Handle,'String','training type:');
	Handle = findobj(gcbf,'Tag','Pushbutton9');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','Pushbutton6');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','Pushbutton4');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','Pushbutton5');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','Pushbutton2');
	set(Handle,'Enable','on');
	Handle = findobj(gcbf,'Tag','Radiobutton1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','Load/SaveSave mapuimenu1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','&Load/SaveSave mapSave in workspaceuimenu1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','Subuimenu2');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','&ToolsSubuimenu1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','&Help/InfoHelp windowuimenu1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','&Help/InfoData infouimenu1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','&Init&Trainuimenu1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','&Init&TrainInitialize1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','&Init&TrainChange initialization valuesuimenu1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','&Init&TrainTrain1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'Tag','Load/SaveSubuimenu1');
	set(Handle,'Enable','off');
	Handle = findobj(gcbf,'String','alpha initial:');
	set(Handle,'Visible','off');
	clear;
        clear global;
  case 'change_def'
     
     ButtonName = questdlg('Select training type!',...
		'Change values.',...
		'Batch','Sequential','Cancel',...
	        'Batch');	
     if strcmp(ButtonName,'Sequential')
	Handle = findobj(gcbf,'Visible','off');
	set(Handle,'Visible','on');
	ALGORITHM = 'seq';
	Handle = findobj(gcf,'Tag','StaticText9');
	set(Handle,'String','training type: sequential');
	new_para2_2;	
	Handle = findobj(gcf,'Tag','StaticText1');
	set(Handle,'String','Change parameters for sequential training');
	Handle = findobj(gcf,'Enable','off');
	set(Handle,'Enable','on');
	Handle = findobj(gcf,'Visible','off');
	set(Handle,'Visible','on');
     elseif strcmp(ButtonName,'Batch')
	ALGORITHM = 'batch';
	Handle = findobj(gcbf,'Tag','StaticText26');
	set(Handle,'Visible','off');
	Handle = findobj(gcbf,'Tag','StaticText27');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','StaticText9');
	set(Handle,'String','training type: batch');
	Handle = findobj(gcf,'Tag','StaticText12');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','StaticText28');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','StaticText14');
	set(Handle,'Visible','off');
	new_para2_2;	
	Handle = findobj(gcf,'Tag','StaticText1');
	set(Handle,'String','Change parameters for batch training');
	Handle = findobj(gcf,'Tag','PopupMenu3');
	set(Handle,'Enable','off');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','PopupMenu4');
	set(Handle,'Enable','off');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','PopupMenu5');
	set(Handle,'Enable','off');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','StaticText17');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','StaticText18');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','StaticText19');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','StaticText13');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','StaticText14');
	set(Handle,'Visible','off');
	Handle = findobj(gcf,'Tag','EditText6');
	set(Handle,'Visible','off');
	set(Handle,'Enable','off');
	Handle = findobj(gcf,'Tag','EditText10');
	set(Handle,'Visible','off');
	set(Handle,'Enable','off');
     else 
	return;	
     end
     som_gui('def_values_train');	
     mask = STRAIN1.mask;
     Handle = findobj(gcf,'Tag','Listbox1');
     set(Handle,'String',DATA.comp_names);
     som_gui('fill_new_defaults');
   case 'fill_new_defaults'
	Handle = findobj(gcf,'Tag','EditText4');
	temp = num2str(STRAIN1.radius_ini);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','EditText8');
	temp = num2str(STRAIN2.radius_ini);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','EditText5');
	temp = num2str(STRAIN1.radius_fin);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','EditText9');
	temp = num2str(STRAIN2.radius_fin);
	set(Handle,'String',temp);		
	Handle = findobj(gcf,'Tag','EditText6');
	temp = num2str(STRAIN1.alpha_ini);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','EditText10');
	temp = num2str(STRAIN2.alpha_ini);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','EditText7');
	temp = num2str(STRAIN1.trainlen);
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','EditText11');
	temp = num2str(STRAIN2.trainlen);
	set(Handle,'String',temp);	
	Handle = findobj(gcf,'Tag','Listbox2');
	temp = num2str(STRAIN1.mask');
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','PopupMenu2');
	string = get(Handle,'String');
	val = loop(string,SOTHERS.tracking);
	set(Handle,'Value',val);
	Handle = findobj(gcf,'Tag','PopupMenu1');
	string = get(Handle,'String');
	val = loop(string,STRAIN1.neigh);
	set(Handle,'Value',val);
	if strcmp(ALGORITHM,'seq')
	   Handle = findobj(gcf,'Tag','PopupMenu3');
	   string = get(Handle,'String');
	   val = loop(string,SOTHERS.length_type);
	   set(Handle,'Value',val);
	   Handle = findobj(gcf,'Tag','PopupMenu4');
	   string = get(Handle,'String');
	   val = loop(string,SOTHERS.oder);
	   set(Handle,'Value',val);
	   Handle = findobj(gcf,'Tag','PopupMenu5');
	   string = get(Handle,'String');
	   val = loop(string,STRAIN1.alpha_type);
	   set(Handle,'Value',val);
	end			
  case 'set_batch_mask'
	Handle = findobj(gcbf,'Tag','Listbox2');
	temp = get(Handle,'String');
	mask = str2num(temp);
	Handle = findobj(gcbf,'Tag','Listbox1');
	replace = get(Handle,'Value');
	Handle = findobj(gcbf,'Tag','EditText2');
	temp = get(Handle,'String');
	value = str2num(temp);
	if not(isempty(value))
	  mask(replace) = value;
	  Handle = findobj(gcbf,'Tag','Listbox2');
	  temp = num2str(mask);
	  set(Handle,'String',temp);
	end
   case 'set_new_parameters'
	Handle = findobj(gcbf,'Tag','Listbox2');
	temp = get(Handle,'String');
	mask = str2num(temp); %%%%%%%%%%%%% Do somthing
	mask = mask';
	Handle = findobj(gcbf,'Tag','PopupMenu1');
	temp = get(Handle,'String');
	val = get(Handle,'Value');
	neigh = temp{val};
	Handle = findobj(gcbf,'Tag','PopupMenu2');
	temp = get(Handle,'String');
	val = get(Handle,'Value');
	SOTHERS.tracking = temp{val};  %%%%% finetune phase!
	Handle = findobj(gcbf,'Tag','EditText4');
	temp = get(Handle,'String');
	rad_ini1 = str2num(temp);
	Handle = findobj(gcbf,'Tag','EditText8');
	temp = get(Handle,'String');
	rad_ini2 = str2num(temp);
	Handle = findobj(gcbf,'Tag','EditText5');
	temp = get(Handle,'String');
	rad_fin1 = str2num(temp);	
	Handle = findobj(gcbf,'Tag','EditText9');
	temp = get(Handle,'String');
	rad_fin2 = str2num(temp);
	Handle = findobj(gcbf,'Tag','EditText6');
	temp = get(Handle,'String');
	alpha_ini1 = str2num(temp);
	Handle = findobj(gcbf,'Tag','EditText10');
	temp = get(Handle,'String');
	alpha_ini2 = str2num(temp);		
	Handle = findobj(gcbf,'Tag','EditText7');
	temp = get(Handle,'String');
	train_length1 = str2num(temp);
	Handle = findobj(gcbf,'Tag','EditText11');
	temp = get(Handle,'String');
	train_length2 = str2num(temp);
	if strcmp(ALGORITHM,'seq')
		Handle = findobj(gcbf,'Tag','PopupMenu3');
		temp = get(Handle,'String');
		val = get(Handle,'Value');
		SOTHERS.length_type = temp{val};
		Handle = findobj(gcbf,'Tag','PopupMenu4');
		temp = get(Handle,'String');
		val = get(Handle,'Value');
		SOTHERS.oder= temp{val};
		Handle = findobj(gcbf,'Tag','PopupMenu5');
		temp = get(Handle,'String');
		val = get(Handle,'Value');
		alpha_type = temp{val};
	else 
		alpha_type = 'inv';
	end
	STRAIN1.neigh = neigh;
	STRAIN2.neigh = neigh;
	STRAIN1.mask = mask;
	STRAIN2.mask = mask;	
	STRAIN1.radius_ini = rad_ini1;
	STRAIN2.radius_ini = rad_ini2;
	STRAIN1.radius_fin = rad_fin1;
	STRAIN2.radius_fin = rad_fin2;
	STRAIN1.alpha_ini = alpha_ini1;
	STRAIN2.alpha_ini = alpha_ini2;					
	STRAIN1.alpha_type = alpha_type;
	STRAIN2.alpha_type = alpha_type;
	STRAIN1.trainlen = train_length1;
	STRAIN2.trainlen = train_length2;
	close(gcbf);
	som_gui('fill_fields');
	som_gui('def_values_others');
   case 'change_parameters_cancel'
	close(gcbf);
	
   case 'batch_cancel'
	close(gcbf);
   case 'only_finetune'
	Handle = findobj(gcbf,'Tag','Radiobutton1');
	test = get(Handle,'Value');
	if test == 1
		Handle = findobj(gcbf,'Tag','StaticText16');
		set(Handle,'Enable','off');
		Handle = findobj(gcbf,'Tag','StaticText17');
		set(Handle,'Enable','off');
		Handle = findobj(gcbf,'Tag','StaticText22');
		set(Handle,'Enable','off');
		Handle = findobj(gcbf,'Tag','StaticText26');
		set(Handle,'Enable','off');
	else 
		Handle = findobj(gcbf,'Tag','StaticText16');
		set(Handle,'Enable','on');
		Handle = findobj(gcbf,'Tag','StaticText17');
		set(Handle,'Enable','on');
		Handle = findobj(gcbf,'Tag','StaticText22');
		set(Handle,'Enable','on');
		Handle = findobj(gcbf,'Tag','StaticText26');
		set(Handle,'Enable','on');
	end
   case 'preprocess'
	if isempty(DATA)
	   helpmsg = {'Load data before tryinig to preprocess!'};
	   helpdlg(helpmsg,'Empty Data!');
	   return;
	end
	preprocess(DATA);
	waitfor(gcf);
	prompt = {'Name of preprocessed data in workspace?'};
	tittle = 'Reload preprocessed data!';
	lineNo = 1;
	def = {DATA.name};
	answer = inputdlg(prompt,tittle,lineNo,def);
	if isempty(answer)
	  return;
	end
	data = answer{1};
	new_name = retname;
	assignin('base',new_name,data);
	str = ['exist(' new_name ')'];	
	temp = evalin('base',str); 
	if temp ~= 1
	 temp = strcat('Variable ''',data,''' doesn''t exist in workspace.',...
		'Old Data which is not preprocessed will be used.');
	  errordlg(temp,'Unknown variable!');
	  return;
	end
        evalin('base',['clear ' new_name ]) 
	Handle = findobj(gcf,'Tag','StaticText4');
	temp = strcat('Data: <',data,'>');
	set(Handle,'String',temp);
	Handle = findobj(gcf,'Tag','StaticText10');
	set(Handle,'String','Status <data preprocessed>');
	DATA = evalin('base',data);
        som_gui('def_initialization');
   case 'visualize'
	if isempty(MAP)
	   helpmsg = {'Train map before tryinig to visualize it!'};
	   helpdlg(helpmsg,'Empty Map!');
	   return;
	end
	som_vis_gui(MAP);
  case 'savemap'
	if isempty(MAP)
	      str = {'There is no map to be saved! Train map before saving.'};
     	      helpdlg(str,'Empty map!');	
	      return;
	end
	[FileName Path] = uiputfile('*.cod','Save file!');
	if FileName ~= 0
	   temp = strcat(Path,FileName);
	   som_write_cod(MAP,temp);
	   MAPSAVED = 'SAVED';
	end
	Handle = findobj(gcf,'Tag','StaticText10');
	set(Handle,'String','Status <map saved>');	 
  case 'save_workspace'
    if isempty(NEWMAP)
      str = {'There is no map to be saved! Train map before saving.'};
      helpdlg(str,'Empty map!');
      return;
    else
      prompt = {'Save map as?'};
      title = 'Save map!';
      lineNo = 1;
      answer = inputdlg(prompt,title,lineNo);
      if isempty(answer)
	return;
      end
      if not(isempty(answer{1}))

        ws_variable = evalin('base','who');
	max_length = 0;
	for index = 1:size(ws_variable,1)
	   if max_length < size(ws_variable{index},2)
		max_length = size(ws_variable{index},2);
	   end
	end
	length = max_length + 1;
	tempfoo(1:1:length) = 'A'; 
	assignin('base',tempfoo,answer{1});
	str = ['exist(' tempfoo ')'];	
	temp = evalin('base',str); %%%%%%%%%%@@@@@@@@@
        evalin('base',['clear ' tempfoo ]) 
	if temp == 0
	  assignin('base',answer{1},NEWMAP);
	  MAPSAVED = 'SAVED';
	elseif temp ~= 0
	  Questmsg = strcat('Variable',' ''',answer{1},'''',...
	      ' exist. Overwrite?');
	  ButtonName = questdlg(Questmsg);
	  switch(ButtonName)
	    case 'Yes'
	      assignin('base',answer{1},NEWMAP);
	      MAPSAVED = 'SAVED';
	    case 'No' 
	      som_gui('save_workspace');		
	    end
	 end	
      else
	  helpmsg = {'There cannot be any empty field in ''save'''};
	  helpdlg(helpmsg,'Help Save!');
	  som_gui('save'); 
      end
    end
    Handle = findobj(gcf,'Tag','StaticText10');
    set(Handle,'String','Status <map saved>');
   case 'map_size'
	Handle = findobj(gcbf,'Tag','EditText1');
	size = get(Handle,'String');
	val = str2num(size);
	if isempty(val)
	   errordlg({'Correct map size is form ''[x y]'',',...
	   'where both x and y are nubers.'},'Incorrect map size!');
	   temp = num2str(STOPOLINIT.msize);
	   temp = strcat('[',temp,']');   
	   set(Handle,'String',temp);
	   return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 2
	   errordlg({'Correct map size is form ''[x y]'',',...
	   'where both x and y are nubers.'},'Incorrect map size!');
	   temp = num2str(STOPOLINIT.msize);
	   temp = strcat('[',temp,']');   
	   set(Handle,'String',temp);
	   return; 
	end 
	Handle = findobj(gcbf,'Tag','EditText2');
	set(Handle,'String','');
	
  case 'munits'
	Handle = findobj(gcbf,'Tag','EditText2');
	temp = get(Handle,'String');
	value = str2num(temp);
	if isempty(value)
	   errordlg({'Correct map units is number'},'Incorrect map units!');
	   return;
	end
	[test1 test2] = size(value);
	if test1 ~= 1 | test2 ~= 1
	   errordlg({'Correct map units is number'},'Incorrect map units!');
	   return; 
	end
	topol = som_topol_struct('munits',value,'data',DATA);
	Handle = findobj(gcbf,'Tag','EditText1');
	temp = num2str(topol.msize);
	msize = strcat('[',temp,']');	
	set(Handle,'String',msize);	
  case 'check_rough_radini'
	Handle = findobj(gcbf,'Tag','EditText4');	
	string = get(Handle,'String');
	val = str2num(string);
	if isempty(val)
		errordlg({'Initial radius must be number!'},...
		'Incorrect initial radius!');
		temp = num2str(STRAIN1.radius_ini);
		set(Handle,'String',temp);
		return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 1
		errordlg({'Initial radius must be single valued number!'},...
		'Incorrect initial radius!');
		temp = num2str(STRAIN1.radius_ini);
		set(Handle,'String',temp);
		return;
	end
   case 'check_fine_radini'
	Handle = findobj(gcbf,'Tag','EditText8');	
	string = get(Handle,'String');
	val = str2num(string);
	if isempty(val)
		errordlg({'Initial radius must be number!'},...
		'Incorrect initial radius!');
		temp = num2str(STRAIN2.radius_ini);
		set(Handle,'String',temp);
		return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 1
		errordlg({'Initial radius must be single valued number!'},...
		'Incorrect initial radius!');
		temp = num2str(STRAIN2.radius_ini);
		set(Handle,'String',temp);
		return;
	end	
    case 'check_rough_radfin'
	Handle = findobj(gcbf,'Tag','EditText5');	
	string = get(Handle,'String');
	val = str2num(string);
	if isempty(val)
		errordlg({'Final radius must be number!'},...
		'Incorrect final radius!');
		temp = num2str(STRAIN1.radius_fin);
		set(Handle,'String',temp);
		return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 1
		errordlg({'Final radius must be single valued number!'},...
		'Incorrect final radius!');
		temp = num2str(STRAIN1.radius_fin);
		set(Handle,'String',temp);
		return;
	end
   case 'check_fine_radfin'
	Handle = findobj(gcbf,'Tag','EditText9');	
	string = get(Handle,'String');
	val = str2num(string);
	if isempty(val)
		errordlg({'Final radius must be number!'},...
		'Incorrect final radius!');
		temp = num2str(STRAIN2.radius_fin);
		set(Handle,'String',temp);
		return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 1
		errordlg({'Final radius must be single valued number!'},...
		'Incorrect final radius!');
		temp = num2str(STRAIN2.radius_fin);
		set(Handle,'String',temp);
		return;
	end
   case 'check_rough_alphaini'
	Handle = findobj(gcbf,'Tag','EditText6');	
	string = get(Handle,'String');
	val = str2num(string);
	if isempty(val)
		errordlg({'Alpha initial must be number!'},...
		'Incorrect initial  alpha!');
		temp = num2str(STRAIN1.alpha_ini);
		set(Handle,'String',temp);
		return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 1
		errordlg({'Alpha initial must be single valued number!'},...
		'Incorrect final radius!');
		temp = num2str(STRAIN1.alpha_ini);
		set(Handle,'String',temp);
		return;
	end
   case 'check_fine_alphaini'
	Handle = findobj(gcbf,'Tag','EditText10');	
	string = get(Handle,'String');
	val = str2num(string);
	if isempty(val)
		errordlg({'Alpha initial must be number!'},...
		'Incorrect initial  alpha!');
		temp = num2str(STRAIN2.alpha_ini);
		set(Handle,'String',temp);
		return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 1
		errordlg({'Alpha initial must be single valued number!'},...
		'Incorrect final radius!');
		temp = num2str(STRAIN2.alpha_ini);
		set(Handle,'String',temp);
		return;
	end
   case 'check_rough_trainlen'
	Handle = findobj(gcbf,'Tag','EditText7');	
	string = get(Handle,'String');
	val = str2num(string);
	if isempty(val)
		errordlg({'Training length must be number!'},...
		'Incorrect training length!');
		temp = num2str(STRAIN1.trainlen);
		set(Handle,'String',temp);
		return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 1
		errordlg({'Training length must be single valued number!'},...
		'Incorrect training length!');
		temp = num2str(STRAIN1.trainlen);
		set(Handle,'String',temp);
		return;
	end	
   case 'check_fine_trainlen'
	Handle = findobj(gcbf,'Tag','EditText11');	
	string = get(Handle,'String');
	val = str2num(string);
	if isempty(val)
		errordlg({'Training length must be number!'},...
		'Incorrect training length!');
		temp = num2str(STRAIN2.trainlen);
		set(Handle,'String',temp);
		return;
	end
	[test1 test2] = size(val);
	if test1 ~= 1 | test2 ~= 1
		errordlg({'Training length must be single valued number!'},...
		'Incorrect training length!');
		temp = num2str(STRAIN2.trainlen);
		set(Handle,'String',temp);
		return;
	end	
  case 'close'
    if isempty(MAPSAVED)
      if not(isempty(NEWMAP))
	quest = 'Save map before closing?';
	ButtonName = questdlg(quest);
	switch ButtonName
	  case 'Yes'
	    som_gui('savemap');		
	    som_gui('clear');
	    clear global;
	    close(gcbf);
	  case 'No'
	    som_gui('clear');	
	    clear global;
	    close(gcbf);
	  case 'Cancel'

	end
      else
	som_gui('clear');
	clear global;
	close(gcbf);	
      end	
    else
      som_gui('clear');
      clear global;
      close(gcbf);
    end
  case 'help'
    web file:///share/somtoolbox/vs2/html/som_GUI.html;
  case 'helpwin'
    file1 = tempname;
    file1 = strcat(file1,'.m');
    directory = tempdir;	
    html2tex('file:///share/somtoolbox/vs2/html/som_GUI.html',file1);
    addpath (directory);
    helpwin (file1);
    rmpath (directory);
    delete (file1);			  		
  case 'helpwin2'
    helpwin som_gui;	
  case 'data_info'
	if isempty(DATA)
		helpmsg = 'Load data first!';
		helpdlg(helpmsg,'Empty data!');
		return;
	end
	file_name = tempname;
	file_name = strcat(file_name,'.m');
	fid = fopen(file_name,'w');
	fprintf(fid,'%% %+35s\n','DATA INFO');
	fprintf(fid,'%%\n');
	print_info(DATA,2,fid);
	directory = tempdir;
	addpath (directory);
	helpwin (file_name);
	fclose(fid);
	delete(file_name);
	rmpath (directory);
  case 'map_info'
	if isempty(MAP)
		helpmsg = 'There is no map!';
		helpdlg(helpmsg,'Empty map!');
		return;
	end
	file_name = tempname;
	file_name = strcat(file_name,'.m');
	fid = fopen(file_name,'w');
	fprintf(fid,'%% %+35s\n','MAP INFO');
	fprintf(fid,'%%\n');
	print_info(MAP,2,fid);
	directory = tempdir;
	addpath (directory);
	helpwin (file_name);
	fclose(fid);
	delete(file_name);
	rmpath (directory); 
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% (SUB) FUNCTIONS

function [val] = loop(cell_data, search_data)
for val = 1: length(cell_data) 
  if strcmp(cell_data{val},search_data)
    break;
  end
end
if not(strcmp(cell_data{val},search_data))
  val = -1;
end



function [] = comp_names(names,fid)
last = size(names);
for index=1:last
	fprintf(fid,'%% %s\n',names{index})
end	

function [] = fill_field(names,mask,fid)
last = size(mask);
for index=1:last
	num = num2str(mask(index))
	fprintf(fid,'%% %-15s %-2s\n',names{index},num)
end	

function fig = main_gui()



h0 = figure('Color',[0.8 0.8 0.8], ...
	'MenuBar','none', ...
	'Name','SOM Toolbox -- Initialization & Training', ...
	'NumberTitle','off', ...
	'PaperType','a4letter', ...
	'Position',[644 44 538 748], ...
	'RendererMode','manual', ...
	'Tag','Fig1');
h1 = uimenu('Parent',h0, ...
	'Label','&Load/Save', ...
	'Tag','uimenu1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''jump_loadgui3'');', ...
	'Label','Load Data', ...
	'Tag','Subuimenu1');
h2 = uimenu('Parent',h1, ...
	'Label','Save map', ...
	'Enable','off',...
	'Tag','Load/SaveSubuimenu1');
h3 = uimenu('Parent',h2, ...
	'Callback','som_gui(''save_workspace'');', ...
	'Enable','off', ...
	'Label','Save in workspace', ...
	'Tag','Load/SaveSave mapuimenu1');
h3 = uimenu('Parent',h2, ...
	'Callback','som_gui(''savemap'');', ...
	'Enable','off', ...
	'Label','Write cod-file', ...
	'Tag','&Load/SaveSave mapSave in workspaceuimenu1');
h1 = uimenu('Parent',h0, ...
	'Label','&Tools', ...
	'Tag','uimenu2');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''preprocess'');', ...
	'Enable','off', ...
	'Label','Preprocess Data', ...
	'Tag','Subuimenu2');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''visualize'');', ...
	'Enable','off', ...
	'Label','Visualize Map', ...
	'Tag','&ToolsSubuimenu1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''clear_all'');', ...
	'Label','Clear all', ...
	'Tag','&ToolsSubuimenu2');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''close'');', ...
	'Label','Close Figure', ...
	'Tag','&ToolsClear alluimenu1');
h1 = uimenu('Parent',h0, ...
	'Label','&Help/Info', ...
	'Tag','&ToolsClose Figureuimenu1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''help'');', ...
	'Label','WWW Help', ...
	'Tag','Helpuimenu1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''helpwin'');', ...
	'Label','Help window', ...
	'Tag','Helpuimenu2');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''helpwin2'');', ...
	'Label','About GUI', ...
	'Tag','&Help/InfoHelp windowuimenu2');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''data_info'');', ...
	'Enable','off', ...
	'Label','Data info', ...
	'Tag','&Help/InfoHelp windowuimenu1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''map_info'');', ...
	'Enable','off', ...
	'Label','Map info', ...
	'Tag','&Help/InfoData infouimenu1');
h1 = uimenu('Parent',h0, ...
	'Label','&Init/Train', ...
	'Tag','&Init/Train1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''change_initialization'');', ...
	'Enable','off', ...
	'Label','Change initialization values', ...
	'Tag','&Init&Trainuimenu1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''init'');', ...
	'Enable','off', ...
	'Label','Initialize', ...
	'Tag','&Init&TrainInitialize1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''change_def'');', ...
	'Enable','off', ...
	'Label','Change training values', ...
	'Tag','&Init&TrainChange initialization valuesuimenu1');
h2 = uimenu('Parent',h1, ...
	'Callback','som_gui(''def_train'');', ...
	'Enable','off', ...
	'Label','Train', ...
	'Tag','&Init&TrainTrain1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[20.8 10 316 585], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[29 485.6 300 103], ...
	'Style','frame', ...
	'Tag','Frame2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 514.4 275.2 20], ...
	'String','Map: <empty>', ...
	'Style','text', ...
	'Tag','StaticText3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 490.4 275.2 20], ...
	'String','Data: <empty>', ...
	'Style','text', ...
	'Tag','StaticText4');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[29 389.6 300 92], ...
	'Style','frame', ...
	'Tag','Frame3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'FontWeight','bold', ...
	'ListboxTop',0, ...
	'Position',[39 456 280 20], ...
	'String','Initialization', ...
	'Style','text', ...
	'Tag','StaticText7');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[190 442 120 15], ...
	'String','map size:', ...
	'Style','text', ...
	'Tag','StaticText5');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 420 120 15], ...
	'String','lattice:', ...
	'Style','text', ...
	'Tag','StaticText20');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 442 120 15], ...
	'String','type:', ...
	'Style','text', ...
	'Tag','StaticText6');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[190 420 120 15], ...
	'String','shape:', ...
	'Style','text', ...
	'Tag','StaticText21');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''change_initialization'');', ...
	'Enable','off', ...
	'ListboxTop',0, ...
	'Position',[135 394.4 80 20], ...
	'String','Change values', ...
	'Tag','Pushbutton9');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[28.8 22 300 364], ...
	'Style','frame', ...
	'Tag','Frame4');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'FontWeight','bold', ...
	'ListboxTop',0, ...
	'Position',[39 362.4 280 20], ...
	'String','Training ', ...
	'Style','text', ...
	'Tag','StaticText8');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'FontWeight','bold', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 345 128 20], ...
	'String','General values:', ...
	'Style','text', ...
	'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'ListboxTop',0, ...
	'Position',[40 330 270 15], ...
	'String','training type:', ...
	'Style','text', ...
	'Tag','StaticText9');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[190 305 120 15.2], ...
	'String','tracking:', ...
	'Style','text', ...
	'Tag','StaticText19');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 305 120 14.4], ...
	'String','neigh:', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[190 280 120 14.4], ...
	'String','order:', ...
	'Style','text', ...
	'Visible','off',...
	'Tag','StaticText12');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 255 120 15.2], ...
	'String','alpha type:', ...
	'Style','text', ...
	'Visible','off',...
	'Tag','StaticText28');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 280 120 15.2], ...
	'String','length type:', ...
	'Style','text', ...
	'Visible','off',...
	'Tag','StaticText14');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[38.4 67 128 157.6], ...
	'Style','frame', ...
	'Tag','Frame2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[181.6 67 128 157.6], ...
	'Style','frame', ...
	'Tag','Frame3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[40 200 124.8 19.2], ...
	'String','Rough', ...
	'Style','text', ...
	'Tag','StaticText13');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[195.2 200 102.4 20], ...
	'String','Finetune', ...
	'Style','text', ...
	'Tag','StaticText15');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[44.8 125 115.2 20], ...
	'String','training length:', ...
	'Style','text', ...
	'Tag','StaticText16');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[44.8 175 115.2 20], ...
	'String','radius initial:', ...
	'Style','text', ...
	'Tag','StaticText17');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[44.8 150 115.2 20], ...
	'String','radius final:', ...
	'Style','text', ...
	'Tag','StaticText22');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[44 100 114.4 20], ...
	'String','alpha initial:', ...
	'Style','text', ...
	'Visible','off',...
	'Tag','StaticText26');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[190 125 112 20], ...
	'String','training length:', ...
	'Style','text', ...
	'Tag','StaticText23');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[190 175 112 20], ...
	'String','radius initial:', ...
	'Style','text', ...
	'Tag','StaticText24');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[190 150 112 20], ...
	'String','radius final:', ...
	'Style','text', ...
	'Tag','StaticText25');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[190 100 114 20], ...
	'String','alpha initial:', ...
	'Style','text', ...
	'Visible','off',...
	'Tag','StaticText27');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''change_def'');', ...
	'Enable','off', ...
	'ListboxTop',0, ...
	'Position',[135 38 80 20], ...
	'String','change values', ...
	'Tag','Pushbutton6', ...
	'TooltipString','Change default values in training.');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''load_data'');', ...
	'ListboxTop',0, ...
	'Position',[348 507.2 80 35.2], ...
	'String','LOAD DATA', ...
	'Tag','Pushbutton2', ...
	'TooltipString','Load data file.');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''init'');', ...
	'Enable','off', ...
	'ListboxTop',0, ...
	'Position',[349.6 420 80 35.2], ...
	'String','INITIALIZE', ...
	'Tag','Pushbutton4', ...
	'TooltipString','Initialize map.');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''def_train'');', ...
	'Enable','off', ...
	'ListboxTop',0, ...
	'Position',[349.6 312 80 35.2], ...
	'String','TRAIN', ...
	'Tag','Pushbutton5', ...
	'TooltipString','Train map whit default values');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''close'');', ...
	'ListboxTop',0, ...
	'Position',[350 60 80 35.2], ...
	'String','CLOSE', ...
	'Tag','Pushbutton8', ...
	'TooltipString','Close figure');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'FontWeight','bold', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 230 151.2 20], ...
	'String','Varying values:', ...
	'Style','text', ...
	'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[40 538.4 275.2 20], ...
	'String','Status <no action>', ...
	'Style','text', ...
	'Tag','StaticText10');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''only_finetune'');', ...
	'Enable','off', ...
	'ListboxTop',0, ...
	'Position',[44 74.40000000000001 115.2 20], ...
	'String','Only Finetune', ...
	'Style','radiobutton', ...
	'Tag','Radiobutton1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'FontWeight','bold', ...
	'ListboxTop',0, ...
	'Position',[42.4 566.4 274.4 15.2], ...
	'String','Information', ...
	'Style','text', ...
	'Tag','StaticText18');
if nargout > 0, fig = h0; end







function fig = loadgui3()

temp = {'dat file';'mat file'};

h0 = figure('Color',[0.8 0.8 0.8], ...
	'Name','Load data!', ...
	'NumberTitle','off', ...
	'PaperType','a4letter', ...
	'Position',[368 765 495 199], ...
	'Tag','Fig3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[4.800000000000001 7.2 340 146.4], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[10 84 329 65.59999999999999], ...
	'Style','frame', ...
	'Tag','Frame2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[10 12 329 70.40000000000001], ...
	'Style','frame', ...
	'Tag','Frame3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'FontWeight','bold', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[20 136.8 74.40000000000001 11.2], ...
	'String','From', ...
	'Style','text', ...
	'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''workspace'');', ...
	'ListboxTop',0, ...
	'Position',[20 112.8 80 20], ...
	'String','Workspace', ...
	'Style','radiobutton', ...
	'Tag','Radiobutton2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''file'');', ...
	'ListboxTop',0, ...
	'Position',[20 92 80 19.2], ...
	'String','File', ...
	'Style','radiobutton', ...
	'Tag','Radiobutton1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''workspace_edit'');', ...
	'FontSize',12, ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[110.4 112.8 140 20], ...
	'Style','edit', ...
	'Tag','EditText1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''file_edit'');', ...
	'FontSize',12, ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[110.4 92 140 19.2], ...
	'Style','edit', ...
	'Tag','EditText2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''browse'');', ...
	'ListboxTop',0, ...
	'Position',[269.6 92 41.6 38.40000000000001], ...
	'String','Browse', ...
	'Tag','Pushbutton3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''load_ok'');', ...
	'ListboxTop',0, ...
	'Position',[350 90 40 30], ...
	'String','Load', ...
	'Tag','Pushbutton1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''load_cancel'');', ...
	'ListboxTop',0, ...
	'Position',[350 50 40 30], ...
	'String','Cancel', ...
	'Tag','Pushbutton2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''file_select'');', ...
	'ListboxTop',0, ...
	'Max',2, ...
	'Min',1, ...
	'String',temp,...
	'Position',[166.4 44.8 120 20], ...
	'Style','popupmenu', ...
	'Tag','PopupMenu1', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'FontWeight','bold', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[20 68.8 316.8 12], ...
	'String','Parameters for file', ...
	'Style','text', ...
	'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[20 44.8 115.2 16.8], ...
	'String','File type ', ...
	'Style','text', ...
	'Tag','StaticText3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Position',[20 22.4 120 20], ...
	'String','Missing value char', ...
	'Style','checkbox', ...
	'Tag','Checkbox1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''missing'');',...
	'ListboxTop',0, ...
	'Position',[204.8 22.4 44.8 20], ...
	'String','x', ...
	'Style','edit', ...
	'Tag','EditText3');
if nargout > 0, fig = h0; end



function fig = works()


h0 = figure('Color',[0.8 0.8 0.8], ...
	'Name','Load from workspace!', ...
	'NumberTitle','off', ...
	'PaperType','a4letter', ...
	'Position',[691 256 260 258], ...
	'Tag','Fig1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[11.2 30.4 188.8 170.4], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''works_ok'');', ...
	'ListboxTop',0, ...
	'Position',[22.4 4 60 24.8], ...
	'String','OK', ...
	'Tag','Pushbutton1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''works_cancel'');', ...
	'ListboxTop',0, ...
	'Position',[127.2 3.2 60 24.8], ...
	'String','Cancel', ...
	'Tag','Pushbutton2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Position',[24.8 40.8 160 132], ...
	'String',' ', ...
	'Style','listbox', ...
	'Tag','Listbox1', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'FontWeight','bold', ...
	'ListboxTop',0, ...
	'Position',[44 180 120 14.4], ...
	'String','Matrixs in workspace', ...
	'Style','text', ...
	'Tag','StaticText1');
if nargout > 0, fig = h0; end



function fig = initialization2()


temp1 = {'random';'linear'};
temp2 = {'hexa';'rect'};
temp3 = {'sheet';'cyl';'toroid'};


h0 = figure('Color',[0.8 0.8 0.8], ...
	'Name','Change initialization parameters!', ...
	'NumberTitle','off', ...
	'PaperType','a4letter', ...
	'Position',[594 542 411 176], ...
	'Tag','Fig2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[10.4 8 259.2 130], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''change_initialization_ok'');', ...
	'ListboxTop',0, ...
	'Position',[277.6 63.2 49.6 40.8], ...
	'String','OK', ...
	'Tag','Pushbutton1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''change_initialization_cancel'');', ...
	'ListboxTop',0, ...
	'Position',[278.4 16.8 48.8 45.6], ...
	'String','Cancel', ...
	'Tag','Pushbutton2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'FontWeight','bold', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[76 110 140 17.6], ...
	'String','Initialization parameters:', ...
	'Style','text', ...
	'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[15 80 56.8 20], ...
	'String','type:', ...
	'Style','text', ...
	'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Max',2, ...
	'Min',1, ...
	'Position',[60 82 60 20], ...
	'String',temp1, ...
	'Style','popupmenu', ...
	'Tag','PopupMenu1', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[15 25 60 20], ...
	'String','map size:', ...
	'Style','text', ...
	'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''map_size'');', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[60 28 60 20], ...
	'Style','edit', ...
	'Tag','EditText1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[15 50 50 20], ...
	'String','lattice:', ...
	'Style','text', ...
	'Tag','StaticText3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Max',2, ...
	'Min',1, ...
	'Position',[60 53 60 20], ...
	'String',temp2, ...
	'Style','popupmenu', ...
	'Tag','PopupMenu2', ...
	'Value',2);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[140 50 60 20], ...
	'String','shape:', ...
	'Style','text', ...
	'Tag','StaticText4');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Max',3, ...
	'Min',1, ...
	'Position',[190 53 60 20], ...
	'String',temp3, ...
	'Style','popupmenu', ...
	'Tag','PopupMenu3', ...
	'Value',2);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[140 25 40 20], ...
	'String','munits:', ...
	'Style','text', ...
	'Tag','StaticText5');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''munits'');', ...
	'ListboxTop',0, ...
	'Position',[190 28 60 20], ...
	'Style','edit', ...
	'Tag','EditText2');
if nargout > 0, fig = h0; end


function fig = new_para2_2()

temp1 = {'0';'1';'2';'3'};
temp2 = {'gaussian';'cutgauss';'ep';'bubble'};
temp3 = {'epochs';'samples'};
temp4 = {'random';'ordered'};
temp5 = {'inv';'linear';'power'};


h0 = figure('Color',[0.8 0.8 0.8], ...
	'Name','Change training parameters!', ...
	'NumberTitle','off', ...
	'PaperType','a4letter', ...
	'Position',[758 468 390 473], ...
	'Tag','Fig3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[6.4 32 300.8 337.6], ...
	'Style','frame', ...
	'Tag','Frame1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[165.6 52 124.8 141.6], ...
	'Style','frame', ...
	'Tag','Frame3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[25 53.6 128 140], ...
	'Style','frame', ...
	'Tag','Frame2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''batch_cancel'');', ...
	'ListboxTop',0, ...
	'Position',[200 4 90.40000000000001 28], ...
	'String','Cancel', ...
	'Tag','Pushbutton2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''set_new_parameters'');', ...
	'ListboxTop',0, ...
	'Position',[32 4 90.40000000000001 28], ...
	'String','Set parameters', ...
	'Tag','Pushbutton1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Max',4, ...
	'Min',1, ...
	'Position',[220 254.4 60 15.2], ...
	'String',temp1, ...
	'Style','popupmenu', ...
	'Tag','PopupMenu2', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Max',4, ...
	'Min',1, ...
	'Position',[92 252.4 60 15], ...
	'String',temp2, ...
	'Style','popupmenu', ...
	'Tag','PopupMenu1', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'Callback','som_gui(''batch_cancel'');', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[158.4 248.8 60 20], ...
	'String','tracking', ...
	'Style','text', ...
	'Tag','StaticText6');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'Callback','som_gui(''batch_cancel'');', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 248 60 20], ...
	'String','neigh.', ...
	'Style','text', ...
	'Tag','StaticText5');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 284.8 29.6 16], ...
	'String','mask:', ...
	'Style','text', ...
	'Tag','StaticText2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Position',[92 280 188 28], ...
	'String',' ', ...
	'Style','listbox', ...
	'Tag','Listbox2', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 305 36 20], ...
	'String','Set', ...
	'Style','text', ...
	'Tag','StaticText3');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''set_batch_mask'');', ...
	'Position',[92 309 100 20], ...
	'String',' ', ...
	'Style','listbox', ...
	'Tag','Listbox1', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[195 305 50 20], ...
	'String','to value', ...
	'Style','text', ...
	'Tag','StaticText4');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''set_batch_mask'');', ...
	'ListboxTop',0, ...
	'Position',[247.2 309.6 29.6 20], ...
	'Style','edit', ...
	'Tag','EditText2');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''check_fine_trainlen'');', ...
	'ListboxTop',0, ...
	'Position',[247.2 89 30.4 15.2], ...
	'Style','edit', ...
	'Tag','EditText11');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''check_fine_alphaini'');', ...
	'ListboxTop',0, ...
	'Position',[247.2 63 30.4 14.4], ...
	'Style','edit', ...
	'Visible','off',...
	'Enable','off',...
	'Tag','EditText10');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''check_fine_radfin'');', ...
	'ListboxTop',0, ...
	'Position',[247.2 113.6 30.4 15.2], ...
	'Style','edit', ...
	'Tag','EditText9');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''check_fine_radini'');', ...
	'ListboxTop',0, ...
	'Position',[247.2 138.4 30.4 15.2], ...
	'Style','edit', ...
	'Tag','EditText8');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[174.4 88 68 15.2], ...
	'String','training length', ...
	'Style','text', ...
	'Tag','StaticText16');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[174.4 63 68 14.4], ...
	'String','alpha initial', ...
	'Style','text', ...
	'Visible','off',...
	'Tag','StaticText14');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[174.4 112.8 68 15.2], ...
	'String','radius final', ...
	'Style','text', ...
	'Tag','StaticText12');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[174.4 137.6 68 15.2], ...
	'String','radius initial', ...
	'Style','text', ...
	'Tag','StaticText10');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''check_rough_trainlen'');', ...
	'ListboxTop',0, ...
	'Position',[112 89 29.6 15.2], ...
	'Style','edit', ...
	'Tag','EditText7');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''check_rough_alphaini'');', ...
	'ListboxTop',0, ...
	'Position',[112 64 29.6 14.4], ...
	'Style','edit', ...
	'Visible','off',...
	'Enable','off',...
	'Tag','EditText6');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''check_rough_radfin'');', ...
	'ListboxTop',0, ...
	'Position',[112 115.2 29.6 15.2], ...
	'Style','edit', ...
	'Tag','EditText5');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[1 1 1], ...
	'Callback','som_gui(''check_rough_radini'');', ...
	'ListboxTop',0, ...
	'Position',[112 140 29.6 15.2], ...
	'Style','edit', ...
	'Tag','EditText4');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 88 68 15.2], ...
	'String','training length', ...
	'Style','text', ...
	'Tag','StaticText15');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 64 68 14.4], ...
	'String','alpha initial', ...
	'Style','text', ...
	'Visible','off',...
	'Tag','StaticText13');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 114.4 68 15.2], ...
	'String','radius final', ...
	'Style','text', ...
	'Tag','StaticText11');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.8 0.8 0.8], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 139.2 68 15.2], ...
	'String','radius initial', ...
	'Style','text', ...
	'Tag','StaticText9');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[185.6 162.4 89.60000000000001 20], ...
	'String','Finetune', ...
	'Style','text', ...
	'Tag','StaticText8');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Position',[37.6 164.8 98.40000000000001 18.4], ...
	'String','Rough', ...
	'Style','text', ...
	'Tag','StaticText7');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'FontWeight','bold', ...
	'ListboxTop',0, ...
	'Position',[51.2 336.8 219.2 20], ...
	'String','Change parameters for batch training', ...
	'Style','text', ...
	'Tag','StaticText1');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 228 54.40000000000001 15.2], ...
	'String','length type', ...
	'Style','text', ...
	'Tag','StaticText17');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'BackgroundColor',[0.701960784313725 0.701960784313725 0.701960784313725], ...
	'ListboxTop',0, ...
	'Max',2, ...
	'Min',1, ...
	'Position',[92 229.4 60 15], ...
	'String',temp3, ...
	'Style','popupmenu', ...
	'Tag','PopupMenu3', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[159.2 227.2 51.2 15.2], ...
	'String','order', ...
	'Style','text', ...
	'Tag','StaticText18');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Max',2, ...
	'Min',1, ...
	'Position',[220 231.2 60 15.2], ...
	'String',temp4, ...
	'Style','popupmenu', ...
	'Tag','PopupMenu4', ...
	'Value',1);
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'HorizontalAlignment','left', ...
	'ListboxTop',0, ...
	'Position',[30 203.2 64 15.2], ...
	'String','learning func', ...
	'Style','text', ...
	'Tag','StaticText19');
h1 = uicontrol('Parent',h0, ...
	'Units','points', ...
	'ListboxTop',0, ...
	'Max',3, ...
	'Min',1, ...
	'Position',[92 206.4 60 15], ...
	'String',temp5, ...
	'Style','popupmenu', ...
	'Tag','PopupMenu5', ...
	'Value',1);
if nargout > 0, fig = h0; end

	




function print_info(sS,level,fid)



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% check arguments


%error(nargchk(1, 2, nargin))  % check no. of input args is correct

if ~isstruct(sS),
  if ~iscell(sS) | ~isstruct(sS{1}), 
    error('Input argument is not a struct or a cell array of structs.')
  end
  csS = sS;
else
  csS = {sS};
end

if nargin<2 | isnan(level) | isempty(level), level = 1; end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% print struct information

for c=1:length(csS), 
 sS = csS{c};

 switch sS.type, 
 case 'som_map', 
  mdim = length(sS.topol.msize);
  [munits dim] = size(sS.codebook);
  t    = length(sS.trainhist);  
  if t==0, st='uninitialized'; 
  elseif t==1, st = 'initialized';
  else st = sprintf('initialized, trained %d times',t-1);
  end

  % level 1
  fprintf(fid,'%% Struct type                           : %s\n', sS.type);
  fprintf(fid,'%% Map name                              : %s\n', sS.name);
  fprintf(fid,'%% Input dimension                       : %d\n', dim);
  fprintf(fid,'%% Map grid size                         : ');
  for i = 1:mdim - 1, fprintf(fid,'%% %d x ',sS.topol.msize(i)); end
  fprintf(fid,'%% %d\n', sS.topol.msize(mdim));
  fprintf(fid,'%% Lattice type (rect/hexa)              : %s\n', sS.topol.lattice);
  fprintf(fid,'%% Shape (sheet/cyl/toroid)              : %s\n', sS.topol.shape);
  fprintf(fid,'%% Neighborhood type                     : %s\n', sS.neigh);
  fprintf(fid,'%% Mask                                  : ');
  if dim,
    for i = 1:dim-1, fprintf(fid,'%% %d ',sS.mask(i)); end; 
    fprintf(fid,'%% %d\n',sS.mask(dim));
  else fprintf(fid,'%% \n');
  end
  fprintf(fid,'%% Training status                       : %s\n', st);
   
  % level 1,
  status = cell(dim,1);
  for i=1:dim, 
    n = length(sS.comp_norm{i});
    if n, 
      uninit = strcmp('uninit',{sS.comp_norm{i}.status});
      done   = strcmp('done',{sS.comp_norm{i}.status});
      undone = strcmp('undone',{sS.comp_norm{i}.status});
      if sum(uninit)==n, status{i} = 'no normalization';
      elseif sum(done)==n, status{i} = 'normalized';
      elseif sum(undone)==n, status{i} = 'denormalized';
      else status{i} = 'partial';
      end
    else status{i} = 'no normalization'; end
  end
  if level>1, 
    fprintf(fid,'%% Vector components\n');
    M = sS.codebook;
    fprintf(fid,'%%  #   name          mask     min    mean     max     std  status\n');
    fprintf(fid,'%%  --- ------------  ----  ------  ------  ------  ------  ------\n');
    for i = 1:dim,
      fprintf(fid,'%%  %-3d %-12s  %-4.2f  %6.1g  %6.1g  %6.1g  %6.1g  %s\n', ...
              i,sS.comp_names{i}, sS.mask(i), ...
              min(M(:,i)),mean(M(:,i)),max(M(:,i)),std(M(:,i)),status{i});
    end
  end

  % level 3
  if level>2,
    fprintf(fid,'%% Vector component normalizations\n');
    fprintf(fid,'%%  #   name          method (i=uninit,u=undone,d=done)\n');
    fprintf(fid,'%%  --- ------------  ---------------------------------------\n');
    for i=1:dim,  
      fprintf(fid,'%%  %-3d %-12s  ',i,sS.comp_names{i});
      n = length(sS.comp_norm{i}); 
      for j=1:n, 
        m = sS.comp_norm{i}(j).method;
        s = sS.comp_norm{i}(j).status;
        if strcmp(s,'uninit'), c='i'; 
        elseif strcmp(s,'undone'), c='u'; 
        else c='d';
        end
        fprintf(fid,'%% %s[%s] ',m,c);
      end
      fprintf(fid,'%% \n');
    end
  end
  
  % level 4
  if level>3,
    fprintf(fid,'%% Training history\n');
    for i=1:t, 
      sT = sS.trainhist(i);
      fprintf(fid,'%% * Algorithm: %8s  Trainlen:  %8d\n',sT.algorithm,sT.trainlen);
      fprintf(fid,'%%   Data: %13s  Qerror:    %8.3f\n',sT.data_name,sT.qerror);
      if i>1, 
        fprintf(fid,'%%   Neighborh: %8s  Mask:  ',sT.neigh);
        for i = 1:dim-1, fprintf(fid,'%% %d ',sT.mask(i)); end; 
        fprintf(fid,'%% %d\n',sT.mask(mdim));
        fprintf(fid,'%%   Radius:  %4.2f->%4.2f  Alpha: %5.3f (%s)\n', ...
		sT.radius_ini,sT.radius_fin,sT.alpha_ini,sT.alpha_type);
      end
      fprintf(fid,'%%   Time:  %s\n',sT.time);
    end
  end

 case 'som_data',

  [dlen dim] = size(sS.data);
  if dlen*dim
    ind      = find(~isnan(sum(sS.data')));
  else ind = []; end
  complete = size(sS.data(ind,:),1);
  partial  = dlen - complete;
  values   = prod(size(sS.data));
  missing  = sum(sum(isnan(sS.data))); 

  % level 1  
  fprintf(fid,'%% Struct type             : %s\n', sS.type);
  fprintf(fid,'%% Data name               : %s\n', sS.name);
  fprintf(fid,'%% Vector dimension        : %d\n', dim);
  fprintf(fid,'%% Number of data vectors  : %d\n', dlen);
  fprintf(fid,'%% Complete data vectors   : %d\n', complete);
  fprintf(fid,'%% Partial data vectors    : %d\n', partial);  
  if values, r = floor(100 * (values - missing) / values); else r = 0; end
  fprintf(fid,'%% Complete values         : %d of %d (%d%%)\n', ...
          values-missing, values, r); 

  % level 2,
  status = cell(dim,1);
  for i=1:dim, 
    n = length(sS.comp_norm{i});
    if n, 
      uninit = strcmp('uninit',{sS.comp_norm{i}.status});
      done   = strcmp('done',{sS.comp_norm{i}.status});
      undone = strcmp('undone',{sS.comp_norm{i}.status});
      if sum(uninit)==n, status{i} = 'no normalization';
      elseif sum(done)==n, status{i} = 'normalized';
      elseif sum(undone)==n, status{i} = 'denormalized';
      else status{i} = 'partial';
      end
    else status{i} = 'no normalization'; end
  end
  if level>1, 
    fprintf(fid,'%% Vector components\n');
    D = sS.data;
    fprintf(fid,'%%  #   name            min     mean     max     std  missing      status\n');
    fprintf(fid,'%%  --- ------------  ------  ------  ------  ------  -----------  ------\n');
    for i = 1:dim,
      known = find(~isnan(D(:,i))); 
      miss = dlen-length(known);
      fprintf(fid,'%%  %-3d %-12s  %6.1g  %6.1g  %6.1g  %6.1g  %5d (%2d%%)  %s\n', ...
              i,sS.comp_names{i}, ...
              min(D(known,i)),mean(D(known,i)),max(D(known,i)),std(D(known,i)), ...
              miss,floor(100*miss/dlen),status{i});
    end
  end

  % level 3
  if level>2,
    fprintf(fid,'%% Vector component normalizations\n');
    fprintf(fid,'%%  #   name          method (i=uninit,u=undone,d=done)\n');
    fprintf(fid,'%%  --- ------------  ---------------------------------------\n');
    for i=1:dim,  
      fprintf(fid,'%%  %-3d %-12s  ',i,sS.comp_names{i});
      n = length(sS.comp_norm{i});         
      for j=1:n, 
        m = sS.comp_norm{i}(j).method;
        s = sS.comp_norm{i}(j).status;
        if strcmp(s,'uninit'), c='i'; 
        elseif strcmp(s,'undone'), c='u'; 
        else c='d';
        end
        fprintf(fid,'%% %s[%s] ',m,c);
      end
      fprintf(fid,'%% \n');
    end
  end

 case 'som_topol', 

  mdim = length(sS.msize);
 
  % level 1
  fprintf(fid,'%% Struct type                           : %s\n',sS.type);
  fprintf(fid,'%% Map grid size                         : ');
  for i = 1:mdim - 1, fprintf(fid,'%% %d x ',sS.msize(i)); end
  fprintf(fid,'%% %d\n', sS.msize(mdim));
  fprintf(fid,'%% Lattice type (rect/hexa)              : %s\n', sS.lattice);
  fprintf(fid,'%% Shape (sheet/cyl/toroid)              : %s\n', sS.shape);

 case 'som_train', 

  % level 1
  fprintf(fid,'%% Struct type                           : %s\n',sS.type);
  fprintf(fid,'%% Training algorithm                    : %s\n',sS.algorithm);
  fprintf(fid,'%% Training data                         : %s\n',sS.data_name);
  fprintf(fid,'%% Neighborhood function                 : %s\n',sS.neigh);
  fprintf(fid,'%% Mask                                  : ');
  dim = length(sS.mask);
  if dim, 
    for i = 1:dim-1, fprintf(fid,'%% %d ',sS.mask(i)); end; 
    fprintf(fid,'%% %d\n',sS.mask(end));
  else fprintf(fid,'%% \n'); end
  fprintf(fid,'%% Initial radius                        : %-6.1f\n',sS.radius_ini);
  fprintf(fid,'%% Final radius                          : %-6.1f\n',sS.radius_fin);
  fprintf(fid,'%% Initial learning rate (alpha)         : %-6.1f\n',sS.alpha_ini);
  fprintf(fid,'%% Alpha function type (linear/inv)      : %s\n',sS.alpha_type);
  fprintf(fid,'%% Training length                       : %d\n',sS.trainlen);
  fprintf(fid,'%% Average quantization error            : %-6.1f\n',sS.qerror);
  fprintf(fid,'%% When training was done                : %s\n',sS.time);

 case 'som_norm', 
  
  % level 1
  fprintf(fid,'%% Struct type                           : %s\n',sS.type);
  fprintf(fid,'%% Normalization method                  : %s\n',sS.method);
  fprintf(fid,'%% Status                                : %s\n',sS.status);

  % level 2
  if level>1, 
    fprintf(fid,'%% Parameters:\n');
    sS.params
  end
 end
end

function [] = html2tex(html_addres,texfile)

tempfile = tempname;
fid = fopen(texfile,'w');
eval(['!lynx -dump ' html_addres ' > ' tempfile]);
fid2 = fopen(tempfile,'r');
while not(feof(fid2))
	line = fgets(fid2);
	line = strcat('%',line);
	fprintf(fid,'%s',line);
end
	fclose(fid);
	fclose(fid2);
	delete (tempfile);


function [name] = retname
resnames = who;
if size(resnames,1) > 0
  max_length = size(resnames{1},2);
  for index = 1:size(resnames,1)
    if size(resnames{index},2) > max_length
	max_length =  size(resnames{index},2);
    end
  end
 length = max_length + 1;
 name(:,1:1:length) = 'A' 				
else
 name = 'A';
end	
%%


