function gui_environment(varargin)
global zeng

action=varargin{1};
switch action
%================================================================
case 'initial'
    Parent_Size=get(varargin{2},'position');
    FG_Size=[Parent_Size(1) Parent_Size(2)-282 220 116];
    ScreenSize=get(0,'ScreenSize');
    if FG_Size(2)<60;
        FG_Size(2)=Parent_Size(2)+Parent_Size(4)+FG_Size(4)+70;
    end
    temp=findobj('type','figure','tag','gui_envi');
    if ~isempty(temp)
        set(temp,'position',FG_Size);
        figure(temp)
    else
        envi.parent=varargin{2};
        envi.figure = figure('Color',[0.8 0.8 0.8], ...
           'DeleteFcn','delete(gcbf);',...
           'Position',FG_Size, ...
           'menu','none',...
           'Name','Setting : Environment',...
           'NumberTitle','off',...
           'Resize','off',...
           'tag','gui_envi',...
           'ToolBar','none');
        set(envi.figure,'position',FG_Size) % stupid, but I need it for WinXp
        uicontrol('Parent',envi.figure, ...
        	'BackgroundColor',[0.8 0.8 0.8], ...
            'HorizontalAlignment','right',...
        	'ListboxTop',0, ...
        	'Position',[10 49 110 24], ...
        	'String','Temperature (C)', ...
        	'Style','text');
        uicontrol('Parent',envi.figure, ...
    	    'BackgroundColor',[0.8 0.8 0.8], ...
            'HorizontalAlignment','right',...
        	'ListboxTop',0, ...
        	'Position',[10 79 110 22], ...
        	'String','R extra-cel (Ohm-cm)', ...
        	'Style','text');
        envi.edit.temp=uicontrol('Parent',envi.figure, ...
        	'Units','pixel', ...
        	'BackgroundColor',[1 1 1], ...
        	'ListboxTop',0, ...
        	'Position',[130 49 55 22], ...
        	'String',num2str(zeng.temperature), ...
        	'Style','edit');
        envi.edit.re=uicontrol('Parent',envi.figure, ...
        	'Units','pixel', ...
        	'BackgroundColor',[1 1 1], ...
        	'ListboxTop',0, ...
        	'Position',[130 79 55 22], ...
        	'String',num2str(zeng.re), ...
        	'Style','edit');
        envi.button.okay = uicontrol('Parent',envi.figure, ...
	        'BackgroundColor',[0.847058823529412 0.8 0.7215686274509801], ...
            'callback','gui_environment(''okay'')',...
        	'ListboxTop',0, ...
    	    'Position',[23 11 50 22], ...
        	'String','OK', ...
        	'Tag','Pushbutton');
        envi.button.close = uicontrol('Parent',envi.figure, ...
    	    'BackgroundColor',[0.847058823529412 0.8 0.7215686274509801], ...
            'callback','delete(gcbf)',...
        	'ListboxTop',0, ...
	        'Position',[80 11 50 22], ...
        	'String','Close', ...
        	'Tag','Pushbutton');
        envi.button.apply = uicontrol('Parent',envi.figure, ...
	        'BackgroundColor',[0.847058823529412 0.8 0.7215686274509801], ...
            'callback','gui_environment(''okay'',''apply'')',...
        	'ListboxTop',0, ...
    	    'Position',[136 11 50 22], ...
        	'String','Apply', ...
        	'Tag','Pushbutton');
        set(envi.figure,'userdata',envi);
    end
case 'okay'
    envi=get(gcbf,'userdata');
    temp=str2num(get(envi.edit.temp,'string'));
    if isempty(temp)| ~isreal(temp)
      zexst('err','Temperature needs to be a number!!!, You know?');
      %set(exst.edit.pw,'string',num2str(exst.default.pw));
      return
   end
   if temp>50 | temp<=0
      zexst('err','I do not think the cell will survive at this temperature.');
      %set(exst.edit.pw,'string',num2str(exst.default.pw));
      return
   end
    zeng.temperature=temp;
    temp=str2num(get(envi.edit.re,'string'));
    if isempty(temp)| ~isreal(temp) | temp<=0
      zexst('err','Extracellular resistivity needs to be a positive number!!!, You know?');
      %set(exst.edit.pw,'string',num2str(exst.default.pw));
      return
    end
    zeng.re=temp;
    if nargin==1
        %from "okay"
    else
        %from "apply"
        zexst('calculate')
    end
end
